Skip to content
This repository was archived by the owner on Jan 16, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

......
Expand Down
36 changes: 32 additions & 4 deletions behaviors/ActionLogBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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__);
}
}
}