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'] ]; } }