LogableBehavior.php 21 KB

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