Skip to content

Commit

Permalink
Disable callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Feb 4, 2014
1 parent f57074b commit 4fd2469
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions Model/Behavior/LogableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class LogableBehavior extends ModelBehavior {
* - skip: array(). String array of actions to not log
* - ignore: array(). Fields to ignore
*
* @param Object $Model
* @param Model $Model
* @param array $config
*/
public function setup(Model $Model, $config = array()) {
Expand Down Expand Up @@ -142,7 +142,7 @@ public function enableLog(Model $Model, $enable = null) {
* (remember to use your own user key if you're not using 'user_id')
* 'user_id' : int (null) Defaults to all users, supply id if you want for only one User
*
* @param Object $Model
* @param Model $Model
* @param array $params
* @return array
*/
Expand Down Expand Up @@ -192,7 +192,7 @@ public function findLog(Model $Model, $params = array()) {
* @example $this->Model->findUserActions(301, array('model' => 'BookTest'));
* @example $this->Model->findUserActions(301, array('events' => true));
* @example $this->Model->findUserActions(301, array('fields' => array('id','model'),'model' => 'BookTest');
* @param Object $Model
* @param Model $Model
* @param integer $userId
* @param array $params
* @return array
Expand Down Expand Up @@ -287,7 +287,7 @@ public function findUserActions(Model $Model, $userId, $params = array()) {
* The $userData array is expected to look like the result of a
* User::find(array('id'=>123));
*
* @param Object $Model
* @param Model $Model
* @param array $userData
*/
public function setUserData(Model $Model, $userData = null) {
Expand All @@ -306,7 +306,7 @@ public function setUserData(Model $Model, $userData = null) {
* Used for logging custom actions that arent crud, like login or download.
*
* @example $this->Boat->customLog('ship', 66, array('title' => 'Titanic heads out'));
* @param Object $Model
* @param Model $Model
* @param string $action name of action that is taking place (dont use the crud ones)
* @param integer $id id of the logged item (ie foreign_id in logs table)
* @param array $values optional other values for your logs table
Expand All @@ -329,10 +329,23 @@ public function customLog(Model $Model, $action, $id = null, $values = array())
return $this->_saveLog($Model, $logData, $title);
}

/**
* LogableBehavior::clearUserData()
*
* @param Model $Model
* @return void
*/
public function clearUserData(Model $Model) {
$this->user = null;
}

/**
* LogableBehavior::setUserIp()
*
* @param Model $Model
* @param mixed $userIP
* @return void
*/
public function setUserIp(Model $Model, $userIP = null) {
if ($userIP === null) {
$userIP = Utility::getClientIp();
Expand Down Expand Up @@ -391,6 +404,12 @@ public function beforeSave(Model $Model, $options = array()) {
return true;
}

/**
* LogableBehavior::_prepareLog()
*
* @param Model $Model
* @return void
*/
protected function _prepareLog(Model $Model) {
if ($this->user === null) {
$this->setUserData($Model);
Expand Down Expand Up @@ -492,7 +511,7 @@ public function afterSave(Model $Model, $created, $options = array()) {
* If the userKey field in table, add it to dataset
* If userData is supplied to model, add it to the title
*
* @param Object $Model
* @param Model $Model
* @param array $logData
* @return mixed Success
*/
Expand Down Expand Up @@ -566,7 +585,7 @@ public function _saveLog(Model $Model, $logData, $title = null) {
$logData[$this->Log->alias]['description'] .= '.';
}
$this->Log->create($logData);
return $this->Log->save(null, false);
return $this->Log->save(null, array('validate' => false, 'callbacks' => false));
}

}

0 comments on commit 4fd2469

Please sign in to comment.