From 44199b6d6ba0e2ebc2e7f693e374063147a88a21 Mon Sep 17 00:00:00 2001 From: Mat Fish Date: Mon, 10 Oct 2022 18:52:53 +0300 Subject: [PATCH] FR #2 --- CHANGELOG.md | 4 ++++ src/Plugin.php | 5 +++++ src/models/Settings.php | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a798ab..6d8c6c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Activity Log +## 1.1.2 - 2022-10-10 +### Added +- Added `requestFilter` setting [#2]((https://github.com/matfish2/craft-activity-log/issues/2)) + ## 1.1.1 - 2022-10-10 ### Fixed - Fix createdAt null [#1](https://github.com/matfish2/craft-activity-log/issues/1) diff --git a/src/Plugin.php b/src/Plugin.php index 4585d08..ddd8eaa 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -72,8 +72,13 @@ private function shouldRecord(): bool $isCp = $request->isCpRequest; $isAjax = $this->isAjax($request); $settings = self::getInstance()->getSettings(); + $true = $settings->recordOnlyActions ? $request->isActionRequest : true; + if ($settings->requestFilter) { + $true = $true && $settings->requestFilter->call($request); + } + if ($isCp) { if ($isAjax && ($settings->recordCpAjaxRequests || $this->isLoginRequest($request))) { return $true; diff --git a/src/models/Settings.php b/src/models/Settings.php index 3842226..9cbccee 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -11,11 +11,13 @@ class Settings extends Model public bool $recordCpAjaxRequests = false; public bool $recordOnlyActions = false; + public ?\Closure $requestFilter = null; public function rules() : array { return [ - [['recordSitePageRequests','recordSiteAjaxRequests','recordCpPageRequests','recordCpAjaxRequests','recordOnlyActions'], 'boolean'] + [['recordSitePageRequests','recordSiteAjaxRequests','recordCpPageRequests','recordCpAjaxRequests','recordOnlyActions'], 'boolean'], + [['callback'],'function'] ]; } }