diff --git a/README.md b/README.md index c6ae8a8..a09ab46 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,23 @@ To access the module, you need to add this to your application configuration: ], ...... +Add the behavior actionlog to the models which should logged. While doing this, you can define which actions should be logged. Without defining these properties, all actions (create, update, delete) except the index action will be logged: + + ...... + public function behaviors() + { + return [ + 'actionlog' => [ + 'class' => 'cakebake\actionlog\behaviors\ActionLogBehavior', + 'logCreate' => true, + 'logUpdate' => true, + 'logDelete' => true, + 'logIndex' => false, + ], + ]; + } + ...... + Add the new menu item to your navbar: ...... diff --git a/behaviors/ActionLogBehavior.php b/behaviors/ActionLogBehavior.php index bb1556d..ee6dd25 100644 --- a/behaviors/ActionLogBehavior.php +++ b/behaviors/ActionLogBehavior.php @@ -29,6 +29,26 @@ class ActionLogBehavior extends Behavior */ public $message = null; + /** + * @var boolean whether to activate log for the index action. + */ + public $logIndex = false; + + /** + * @var boolean whether to activate log for the create action. + */ + public $logCreate = true; + + /** + * @var boolean whether to activate log for the update action. + */ + public $logUpdate = true; + + /** + * @var boolean whether to activate log for the delete action. + */ + public $logDelete = true; + /** * @inheritdoc */ @@ -44,21 +64,29 @@ public function events() public function beforeInsert($event) { - ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + if ($this->logCreate == true) { + ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + } } public function beforeUpdate($event) { - ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + if ($this->logUpdate == true) { + ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + } } public function beforeDelete($event) { - ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + if ($this->logDelete == true) { + ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + } } public function afterFind($event) { - ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + if ($this->logIndex == true) { + ActionLog::add(ActionLog::LOG_STATUS_INFO, $this->message !== null ? $this->message : __METHOD__); + } } }