LogableBehavior.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <?php
  2. /**
  3. * Logs saves and deletes of any model
  4. *
  5. * Requires the following to work as intended :
  6. *
  7. * - "Log" model ( empty but for a order variable [created DESC]
  8. * - "logs" table with these fields required :
  9. * - id [int] :
  10. * - title [string] : automagically filled with the display field of the model that was modified.
  11. * - created [date/datetime] : filled by cake in normal way
  12. *
  13. * - actsAs = array("Tools.Logable"); on models that should be logged
  14. *
  15. * Optional extra table fields for the "logs" table :
  16. *
  17. * - "description" [string] : Fill with a descriptive text of what, who and to which model/row :
  18. * "Contact "John Smith"(34) added by User "Administrator"(1).
  19. *
  20. * or if u want more detail, add any combination of the following :
  21. *
  22. * - "" [string] : automagically filled with the class name of the model that generated the activity.
  23. * - "foreign_id" [int] : automagically filled with the primary key of the model that was modified.
  24. * - "action" [string] : automagically filled with what action is made (add/edit/delete)
  25. * - "user_id" [int] : populated with the supplied user info. (May be renamed. See bellow.)
  26. * - "change" [string] : depending on setting either :
  27. * [name (alek) => (Alek), age (28) => (29)] or [name, age]
  28. *
  29. * - "version_id" [int] : cooperates with RevisionBehavior to link the the shadow table (thus linking to old data)
  30. *
  31. * Remember that Logable behavior needs to be added after RevisionBehavior. In fact, just put it last to be safe.
  32. *
  33. * Optionally register what user was responisble for the activity :
  34. *
  35. * - Supply configuration only if defaults are wrong. Example given with defaults :
  36. *
  37. * public $actsAs = array('Logable' => array('userModel' => 'User', 'userKey' => 'user_id'));
  38. *
  39. * - In AppController (or single controller if only needed once) add these lines to beforeFilter :
  40. *
  41. * if (count($this->uses) && $this->{$this->modelClass}->Behaviors->attached('Logable')) {
  42. * $this->{$this->modelClass}->setUserData($this->activeUser);
  43. * }
  44. *
  45. * Where "$activeUser" should be an array in the standard format for the User model used :
  46. *
  47. * $activeUser = array( $UserModel->alias => array( $UserModel->primaryKey => 123, $UserModel->displayField => 'Alexander'));
  48. * // any other key is just ignored by this behaviour.
  49. *
  50. * @author Alexander Morland (alexander#maritimecolours.no)
  51. * @co-author Eskil Mjelva Saatvedt
  52. * @co-author Ronny Vindenes
  53. * @co-author Carl Erik Fyllingen
  54. * @contributor Miha
  55. * @category Behavior
  56. * @version 2.2
  57. * @modified 3.june 2009 by Miha
  58. * @modified 2011-11-17 ms (mark scherer) cake2.0 ready
  59. *
  60. * 2011-11-17 ms
  61. */
  62. if (!defined('CLASS_USER')) {
  63. define('CLASS_USER', 'User');
  64. }
  65. class LogableBehavior extends ModelBehavior {
  66. public $user = null; # user data array
  67. public $UserModel = null;
  68. public $defaults = array(
  69. 'enabled' => true,
  70. 'userModel' => CLASS_USER,
  71. 'userKey' => 'user_id',
  72. 'change' => 'list',
  73. 'description_ids' => TRUE,
  74. 'skip' => array(),
  75. 'ignore' => array(),
  76. 'classField' => 'model',
  77. 'foreignKey' => 'foreign_id',
  78. 'autoRelation' => false, # attach relation to the model (hasMany Log)
  79. );
  80. /**
  81. * Cake called intializer
  82. * Config options are :
  83. * userModel : 'User'. Class name of the user model you want to use (User by default), if you want to save User in log
  84. * userKey : 'user_id'. The field for saving the user to (user_id by default).
  85. * change : 'list' > [name, age]. Set to 'full' for [name (alek) => (Alek), age (28) => (29)]
  86. * description_ids : TRUE. Set to false to not include model id and user id in the title field
  87. * skip : array(). String array of actions to not log
  88. *
  89. * @param Object $Model
  90. * @param array $config
  91. */
  92. public function setup(Model $Model, $config = array()) {
  93. if (!is_array($config)) {
  94. $config = array();
  95. }
  96. $this->settings[$Model->alias] = array_merge($this->defaults, $config);
  97. $this->settings[$Model->alias]['ignore'][] = $Model->primaryKey;
  98. $this->Log = ClassRegistry::init('Tools.Log');
  99. if ($this->settings[$Model->alias]['userModel'] != $Model->alias) {
  100. $this->UserModel = ClassRegistry::init($this->settings[$Model->alias]['userModel']);
  101. } else {
  102. $this->UserModel = $Model;
  103. }
  104. # session in the model available? use it!
  105. /*
  106. if (isset($Model->Session)) {
  107. $this->setUserData($Model, $Model->Session->read('Auth'));
  108. }
  109. */
  110. }
  111. public function settings(Model $Model) {
  112. return $this->settings[$Model->alias];
  113. }
  114. public function enableLog(Model $Model, $enable = null) {
  115. if ($enable !== null) {
  116. $this->settings[$Model->alias]['enabled'] = $enable;
  117. }
  118. return $this->settings[$Model->alias]['enabled'];
  119. }
  120. /**
  121. * Useful for getting logs for a model, takes params to narrow find.
  122. * This method can actually also be used to find logs for all models or
  123. * even another model. Using no params will return all activities for
  124. * the models it is called from.
  125. *
  126. * Possible params :
  127. * 'model' : mixed (null) String with className, null to get current or false to get everything
  128. * 'action' : string (null) String with action (add/edit/delete), null gets all
  129. * 'order' : string ('created DESC') String with custom order
  130. * 'conditions : array (array()) Add custom conditions
  131. * 'foreign_id' : int (null) Add a int
  132. *
  133. * (remember to use your own user key if you're not using 'user_id')
  134. * 'user_id' : int (null) Defaults to all users, supply id if you want for only one User
  135. *
  136. * @param Object $Model
  137. * @param array $params
  138. * @return array
  139. */
  140. public function findLog(Model $Model, $params = array()) {
  141. $defaults = array(
  142. $this->settings[$Model->alias]['classField'] => null,
  143. 'action' => null,
  144. 'order' => 'created DESC',
  145. $this->settings[$Model->alias]['userKey'] => null,
  146. 'conditions' => array(),
  147. $this->settings[$Model->alias]['foreignKey'] => null,
  148. 'fields' => array(),
  149. 'limit' => 50,
  150. );
  151. $params = array_merge($defaults, $params);
  152. $options = array('order' => $params['order'], 'conditions' => $params['conditions'], 'fields' => $params['fields'], 'limit' => $params['limit']);
  153. if ($params[$this->settings[$Model->alias]['classField']] === null) {
  154. $params[$this->settings[$Model->alias]['classField']] = $Model->alias;
  155. }
  156. if ($params[$this->settings[$Model->alias]['classField']]) {
  157. if ($this->Log->hasField($this->settings[$Model->alias]['classField'])) {
  158. $options['conditions'][$this->settings[$Model->alias]['classField']] = $params[$this->settings[$Model->alias]['classField']];
  159. } elseif ($this->Log->hasField('description')) {
  160. $options['conditions']['description LIKE '] = $params[$this->settings[$Model->alias]['classField']] . '%';
  161. } else {
  162. return false;
  163. }
  164. }
  165. if ($params['action'] && $this->Log->hasField('action')) {
  166. $options['conditions']['action'] = $params['action'];
  167. }
  168. if ($params[$this->settings[$Model->alias]['userKey']] && $this->UserModel && is_numeric($params[$this->settings[$Model->alias]['userKey']])) {
  169. $options['conditions'][$this->settings[$Model->alias]['userKey']] = $params[$this->settings[$Model->alias]['userKey']];
  170. }
  171. if ($params[$this->settings[$Model->alias]['foreignKey']] && is_numeric($params[$this->settings[$Model->alias]['foreignKey']])) {
  172. $options['conditions'][$this->settings[$Model->alias]['foreignKey']] = $params[$this->settings[$Model->alias]['foreignKey']];
  173. }
  174. return $this->Log->find('all', $options);
  175. }
  176. /**
  177. * Get list of actions for one user.
  178. * Params for getting (one line) activity descriptions
  179. * and/or for just one model
  180. *
  181. * @example $this->Model->findUserActions(301,array('model' => 'BookTest'));
  182. * @example $this->Model->findUserActions(301,array('events' => true));
  183. * @example $this->Model->findUserActions(301,array('fields' => array('id','model'),'model' => 'BookTest');
  184. * @param Object $Model
  185. * @param int $user_id
  186. * @param array $params
  187. * @return array
  188. */
  189. public function findUserActions(Model $Model, $user_id, $params = array()) {
  190. if (!$this->UserModel) {
  191. return null;
  192. }
  193. // if logged in user is asking for her own log, use the data we allready have
  194. if (isset($this->user) && isset($this->user[$this->UserModel->alias][$this->UserModel->primaryKey]) && $user_id == $this->user[$this->
  195. UserModel->alias][$this->UserModel->primaryKey] && isset($this->user[$this->UserModel->alias][$this->UserModel->displayField])) {
  196. $username = $this->user[$this->UserModel->alias][$this->UserModel->displayField];
  197. } else {
  198. $this->UserModel->recursive = -1;
  199. $user = $this->UserModel->find(array($this->UserModel->primaryKey => $user_id));
  200. $username = $user[$this->UserModel->alias][$this->UserModel->displayField];
  201. }
  202. $fields = array();
  203. if (isset($params['fields'])) {
  204. if (is_array($params['fields'])) {
  205. $fields = $params['fields'];
  206. } else {
  207. $fields = array($params['fields']);
  208. }
  209. }
  210. $conditions = array($this->settings[$Model->alias]['userKey'] => $user_id);
  211. if (isset($params[$this->settings[$Model->alias]['classField']])) {
  212. $conditions[$this->settings[$Model->alias]['classField']] = $params[$this->settings[$Model->alias]['classField']];
  213. }
  214. $data = $this->Log->find('all', array(
  215. 'conditions' => $conditions,
  216. 'recursive' => -1,
  217. 'fields' => $fields
  218. ));
  219. if (! isset($params['events']) || (isset($params['events']) && $params['events'] == false)) {
  220. return $data;
  221. }
  222. $result = array();
  223. foreach ($data as $key => $row) {
  224. $one = $row['Log'];
  225. $result[$key]['Log']['id'] = $one['id'];
  226. $result[$key]['Log']['event'] = $username;
  227. // have all the detail models and change as list :
  228. if (isset($one[$this->settings[$Model->alias]['classField']]) && isset($one['action']) && isset($one['change']) && isset($one[$this->
  229. settings[$Model->alias]['foreignKey']])) {
  230. if ($one['action'] == 'edit') {
  231. $result[$key]['Log']['event'] .= ' edited ' . $one['change'] . ' of ' . strtolower($one[$this->settings[$Model->alias]['classField']]) .
  232. '(id ' . $one[$this->settings[$Model->alias]['foreignKey']] . ')';
  233. // ' at '.$one['created'];
  234. } elseif ($one['action'] == 'add') {
  235. $result[$key]['Log']['event'] .= ' added a ' . strtolower($one[$this->settings[$Model->alias]['classField']]) . '(id ' . $one[$this->
  236. settings[$Model->alias]['foreignKey']] . ')';
  237. } elseif ($one['action'] == 'delete') {
  238. $result[$key]['Log']['event'] .= ' deleted the ' . strtolower($one[$this->settings[$Model->alias]['classField']]) . '(id ' . $one[$this->
  239. settings[$Model->alias]['foreignKey']] . ')';
  240. }
  241. } elseif (isset($one[$this->settings[$Model->alias]['classField']]) && isset($one['action']) && isset($one[$this->settings[$Model->alias]['foreignKey']])) { // have model,foreign_id and action
  242. if ($one['action'] == 'edit') {
  243. $result[$key]['Log']['event'] .= ' edited ' . strtolower($one[$this->settings[$Model->alias]['classField']]) . '(id ' . $one[$this->
  244. settings[$Model->alias]['foreignKey']] . ')';
  245. // ' at '.$one['created'];
  246. } elseif ($one['action'] == 'add') {
  247. $result[$key]['Log']['event'] .= ' added a ' . strtolower($one[$this->settings[$Model->alias]['classField']]) . '(id ' . $one[$this->
  248. settings[$Model->alias]['foreignKey']] . ')';
  249. } elseif ($one['action'] == 'delete') {
  250. $result[$key]['Log']['event'] .= ' deleted the ' . strtolower($one[$this->settings[$Model->alias]['classField']]) . '(id ' . $one[$this->
  251. settings[$Model->alias]['foreignKey']] . ')';
  252. }
  253. } else { // only description field exist
  254. $result[$key]['Log']['event'] = $one['description'];
  255. }
  256. }
  257. return $result;
  258. }
  259. /**
  260. * Use this to supply a model with the data of the logged in User.
  261. * Intended to be called in AppController::beforeFilter like this :
  262. *
  263. * if ($this->{$this->modelClass}->Behaviors->attached('Logable')) {
  264. * $this->{$this->modelClass}->setUserData($activeUser);/
  265. * }
  266. *
  267. * The $userData array is expected to look like the result of a
  268. * User::find(array('id'=>123));
  269. *
  270. * @param Object $Model
  271. * @param array $userData
  272. */
  273. public function setUserData(Model $Model, $userData = null) {
  274. if ($userData === null && isset($Model->Session)) {
  275. $userData = (array)$Model->Session->read('Auth');
  276. } elseif ($userData === null && class_exists('CakeSession')) {
  277. $userData = (array)CakeSession::read('Auth');
  278. }
  279. if ($userData !== null) {
  280. $this->user = $userData;
  281. }
  282. }
  283. /**
  284. * Used for logging custom actions that arent crud, like login or download.
  285. *
  286. * @example $this->Boat->customLog('ship', 66, array('title' => 'Titanic heads out'));
  287. * @param Object $Model
  288. * @param string $action name of action that is taking place (dont use the crud ones)
  289. * @param int $id id of the logged item (ie foreign_id in logs table)
  290. * @param array $values optional other values for your logs table
  291. */
  292. public function customLog(Model $Model, $action, $id = null, $values = array()) {
  293. $logData['Log'] = $values;
  294. /**
  295. @todo clean up $logData */
  296. if ($id === null) {
  297. $id = $Model->id;
  298. }
  299. if ($this->Log->hasField($this->settings[$Model->alias]['foreignKey']) && is_numeric($id)) {
  300. $logData['Log'][$this->settings[$Model->alias]['foreignKey']] = $id;
  301. }
  302. $title = null;
  303. if (isset($values['title'])) {
  304. $title = $values['title'];
  305. unset($logData['Log']['title']);
  306. }
  307. $logData['Log']['action'] = $action;
  308. $this->_saveLog($Model, $logData, $title);
  309. }
  310. public function clearUserData(Model $Model) {
  311. $this->user = null;
  312. }
  313. public function setUserIp(Model $Model, $userIP = null) {
  314. if ($userIP === null) {
  315. //App::uses();
  316. $userIP = CakeRequest::clientIp();
  317. }
  318. $this->userIP = $userIP;
  319. }
  320. public function beforeDelete(Model $Model) {
  321. $this->setUserData($Model);
  322. if (!$this->settings[$Model->alias]['enabled']) {
  323. return true;
  324. }
  325. if (isset($this->settings[$Model->alias]['skip']['delete']) && $this->settings[$Model->alias]['skip']['delete']) {
  326. return true;
  327. }
  328. $Model->recursive = -1;
  329. $Model->read();
  330. return true;
  331. }
  332. public function afterDelete(Model $Model) {
  333. if (!$this->settings[$Model->alias]['enabled']) {
  334. return true;
  335. }
  336. if (isset($this->settings[$Model->alias]['skip']['delete']) && $this->settings[$Model->alias]['skip']['delete']) {
  337. return true;
  338. }
  339. $logData = array();
  340. if ($this->Log->hasField('description')) {
  341. $logData['Log']['description'] = $Model->alias;
  342. if (isset($Model->data[$Model->alias][$Model->displayField]) && $Model->displayField != $Model->primaryKey) {
  343. $logData['Log']['description'] .= ' "' . $Model->data[$Model->alias][$Model->displayField] . '"';
  344. }
  345. if ($this->settings[$Model->alias]['description_ids']) {
  346. $logData['Log']['description'] .= ' (' . $Model->id . ') ';
  347. }
  348. $logData['Log']['description'] .= __('deleted');
  349. }
  350. $logData['Log']['action'] = 'delete';
  351. $this->_saveLog($Model, $logData);
  352. }
  353. public function beforeSave(Model $Model) {
  354. $this->setUserData($Model);
  355. if ($this->Log->hasField('change') && $Model->id) {
  356. $this->old = $Model->find('first', array('conditions' => array($Model->primaryKey => $Model->id), 'recursive' => -1));
  357. }
  358. return true;
  359. }
  360. public function afterSave(Model $Model, $created) {
  361. if (!$this->settings[$Model->alias]['enabled']) {
  362. return true;
  363. }
  364. if (!empty($this->settings[$Model->alias]['skip']['add']) && $created) {
  365. return true;
  366. } elseif (!empty($this->settings[$Model->alias]['skip']['edit']) && !$created) {
  367. return true;
  368. }
  369. $keys = array_keys($Model->data[$Model->alias]);
  370. $diff = array_diff($keys, $this->settings[$Model->alias]['ignore']);
  371. if (count($diff) === 0 && empty($Model->logableAction)) {
  372. return false;
  373. }
  374. if ($Model->id) {
  375. $id = $Model->id;
  376. } elseif ($Model->insertId) {
  377. $id = $Model->insertId;
  378. }
  379. if ($this->Log->hasField($this->settings[$Model->alias]['foreignKey'])) {
  380. $logData['Log'][$this->settings[$Model->alias]['foreignKey']] = $id;
  381. }
  382. if ($this->Log->hasField('description')) {
  383. $logData['Log']['description'] = $Model->alias . ' ';
  384. if (isset($Model->data[$Model->alias][$Model->displayField]) && $Model->displayField != $Model->primaryKey) {
  385. $logData['Log']['description'] .= '"' . $Model->data[$Model->alias][$Model->displayField] . '" ';
  386. }
  387. if ($this->settings[$Model->alias]['description_ids']) {
  388. $logData['Log']['description'] .= '(' . $id . ') ';
  389. }
  390. if ($created) {
  391. $logData['Log']['description'] .= __('added');
  392. } else {
  393. $logData['Log']['description'] .= __('updated');
  394. }
  395. }
  396. if ($this->Log->hasField('action')) {
  397. if ($created) {
  398. $logData['Log']['action'] = 'add';
  399. } else {
  400. $logData['Log']['action'] = 'edit';
  401. }
  402. }
  403. if ($this->Log->hasField('change')) {
  404. $logData['Log']['change'] = '';
  405. $db_fields = array_keys($Model->schema());
  406. $changed_fields = array();
  407. foreach ($Model->data[$Model->alias] as $key => $value) {
  408. if (isset($Model->data[$Model->alias][$Model->primaryKey]) && !empty($this->old) && isset($this->old[$Model->alias][$key])) {
  409. $old = $this->old[$Model->alias][$key];
  410. } else {
  411. $old = '';
  412. }
  413. if ($key != 'modified' && !in_array($key, $this->settings[$Model->alias]['ignore']) && $value != $old && in_array($key, $db_fields)) {
  414. if ($this->settings[$Model->alias]['change'] == 'full') {
  415. $changed_fields[] = $key . ' (' . $old . ') => (' . $value . ')';
  416. } elseif ($this->settings[$Model->alias]['change'] == 'serialize') {
  417. $changed_fields[$key] = array('old' => $old, 'value' => $value);
  418. } else {
  419. $changed_fields[] = $key;
  420. }
  421. }
  422. }
  423. $changes = count($changed_fields);
  424. if ($changes == 0) {
  425. return true;
  426. }
  427. if ($this->settings[$Model->alias]['change'] == 'serialize') {
  428. $logData['Log']['change'] = serialize($changed_fields);
  429. } else {
  430. $logData['Log']['change'] = implode(', ', $changed_fields);
  431. }
  432. $logData['Log']['changes'] = $changes;
  433. }
  434. if (empty($logData)) {
  435. return true;
  436. }
  437. return $this->_saveLog($Model, $logData);
  438. }
  439. /**
  440. * Does the actual saving of the Log model. Also adds the special field if possible.
  441. *
  442. * If model field in table, add the Model->alias
  443. * If action field is NOT in table, remove it from dataset
  444. * If the userKey field in table, add it to dataset
  445. * If userData is supplied to model, add it to the title
  446. *
  447. * @param Object $Model
  448. * @param array $logData
  449. */
  450. public function _saveLog(Model $Model, $logData, $title = null) {
  451. if ($title !== null) {
  452. $logData['Log']['title'] = $title;
  453. } elseif ($Model->displayField == $Model->primaryKey) {
  454. $logData['Log']['title'] = $Model->alias . ' (' . $Model->id . ')';
  455. } elseif (isset($Model->data[$Model->alias][$Model->displayField])) {
  456. $logData['Log']['title'] = $Model->data[$Model->alias][$Model->displayField];
  457. } else {
  458. $Model->recursive = -1;
  459. $Model->read(array($Model->displayField));
  460. $logData['Log']['title'] = $Model->data[$Model->alias][$Model->displayField];
  461. }
  462. if ($this->Log->hasField($this->settings[$Model->alias]['classField'])) {
  463. // by miha nahtigal
  464. $logData['Log'][$this->settings[$Model->alias]['classField']] = $Model->name;
  465. }
  466. if ($this->Log->hasField($this->settings[$Model->alias]['foreignKey']) && !isset($logData['Log'][$this->settings[$Model->alias]['foreignKey']])) {
  467. if ($Model->id) {
  468. $logData['Log'][$this->settings[$Model->alias]['foreignKey']] = $Model->id;
  469. } elseif ($Model->insertId) {
  470. $logData['Log'][$this->settings[$Model->alias]['foreignKey']] = $Model->insertId;
  471. }
  472. }
  473. if (!$this->Log->hasField('action')) {
  474. unset($logData['Log']['action']);
  475. } elseif (isset($Model->logableAction) && !empty($Model->logableAction)) {
  476. $logData['Log']['action'] = implode(',', $Model->logableAction); // . ' ' . $logData['Log']['action'];
  477. unset($Model->logableAction);
  478. }
  479. if ($this->Log->hasField('version_id') && isset($Model->version_id)) {
  480. $logData['Log']['version_id'] = $Model->version_id;
  481. unset($Model->version_id);
  482. }
  483. if ($this->Log->hasField('ip') && $this->userIP) {
  484. $logData['Log']['ip'] = $this->userIP;
  485. }
  486. if ($this->Log->hasField($this->settings[$Model->alias]['userKey']) && $this->user && isset($this->user[$this->UserModel->alias])) {
  487. $logData['Log'][$this->settings[$Model->alias]['userKey']] = $this->user[$this->UserModel->alias][$this->UserModel->primaryKey];
  488. }
  489. if ($this->Log->hasField('description')) {
  490. if (empty($logData['Log']['description'])) {
  491. $logData['Log']['description'] = __('Custom action');
  492. }
  493. if ($this->user && $this->UserModel && isset($this->user[$this->UserModel->alias])) {
  494. $logData['Log']['description'] .= ' ' . __('by') . ' ' . $this->settings[$Model->alias]['userModel'] . ' "' . $this->user[$this->UserModel->alias][$this->UserModel->displayField] . '"';
  495. if ($this->settings[$Model->alias]['description_ids']) {
  496. $logData['Log']['description'] .= ' (' . $this->user[$this->UserModel->alias][$this->UserModel->primaryKey] . ')';
  497. }
  498. } else {
  499. // UserModel is active, but the data hasnt been set. Assume system action.
  500. $logData['Log']['description'] .= __(' by System');
  501. }
  502. $logData['Log']['description'] .= '.';
  503. }
  504. $this->Log->create($logData);
  505. $this->Log->save(null, false);
  506. }
  507. }