action.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. global $app;
  3. helper::import($app->getModulePath('', 'action') . 'model.php');
  4. class extactionModel extends actionModel
  5. {
  6. /**
  7. * Get user actions of password change and login since last two xxd poll.
  8. *
  9. * @param string $action
  10. * @access public
  11. * @return array
  12. */
  13. public function getListSinceLastPoll($action = '')
  14. {
  15. $lastPoll = date(DT_DATETIME1, strtotime($this->config->xxd->lastPoll . ' - ' . 2 * $this->config->xuanxuan->pollingInterval . ' second'));
  16. $actions = array();
  17. if($action === 'changepassword')
  18. {
  19. $actions = $this->dao->select('t1.id, t1.objectID, t1.date')->from(TABLE_ACTION)->alias('t1')
  20. ->leftJoin(TABLE_HISTORY)->alias('t2')->on('t1.id = t2.action')
  21. ->leftJoin(TABLE_USER)->alias('t3')->on('t1.objectID = t3.id')
  22. ->where('t3.clientStatus')->ne('offline')
  23. ->andWhere('t1.objectType')->eq('user')
  24. ->andWhere('t2.field')->eq('password')
  25. ->andWhere('t1.action')->eq('edited')
  26. ->andWhere('t1.date')->gt($lastPoll)
  27. ->orderBy('t1.`date`_desc')
  28. ->fetchAll();
  29. }
  30. elseif($action === 'loginxuanxuan')
  31. {
  32. $actions = $this->dao->select('id, objectID, date')->from(TABLE_ACTION)
  33. ->where('date')->gt($lastPoll)
  34. ->andWhere('action')->eq('loginxuanxuan')
  35. ->orderBy('`date`_desc')
  36. ->fetchAll();
  37. }
  38. $uniqueActions = array();
  39. foreach($actions as $action)
  40. {
  41. $exist = false;
  42. foreach($uniqueActions as $uniqueAction)
  43. {
  44. if($uniqueAction->objectID === $action->objectID)
  45. {
  46. $exist = true;
  47. break;
  48. }
  49. }
  50. if(!$exist) $uniqueActions[] = $action;
  51. }
  52. return $uniqueActions;
  53. }
  54. /**
  55. * Check log level for action.
  56. *
  57. * @param string $module
  58. * @param object $action
  59. * @access public
  60. * @return bool
  61. */
  62. public function checkLogLevel($module, $action)
  63. {
  64. $logLevel = (int)zget($this->config->xuanxuan, 'logLevel', 1);
  65. $actionLevel = zget($this->config->action->logLevel->{$module}, $action, 0);
  66. if($logLevel >= $actionLevel) return true;
  67. return false;
  68. }
  69. public function create($objectType, $objectID, $actionType, $comment = '', $extra = '', $actor = '', $autoDelete = true)
  70. {
  71. if(strtolower($actionType) == 'reconnectxuanxuan' or strtolower($actionType) == 'loginxuanxuan')
  72. {
  73. $ip = helper::getRemoteIp();
  74. $last = $this->server->request_time;
  75. $this->dao->update(TABLE_USER)->set('visits = visits + 1')->set('ip')->eq($ip)->set('last')->eq($last)->where('account')->eq($actor)->exec();
  76. }
  77. if(strtolower($actionType) == 'commented' && empty($comment)) return false;
  78. $actor = $actor ? $actor : (!empty($this->app->user->account) ? $this->app->user->account : 'system');
  79. $actionType = strtolower($actionType);
  80. $actor = ($actionType == 'openedbysystem' || $actionType == 'closedbysystem') ? '' : $actor;
  81. if($actor == 'guest' && $actionType == 'logout') return false;
  82. $objectType = str_replace('`', '', $objectType);
  83. $extra = (string)$extra;
  84. $action = new stdclass();
  85. $action->objectType = strtolower($objectType);
  86. $action->objectID = $objectID;
  87. $action->actor = $actor;
  88. $action->action = $actionType;
  89. $action->date = helper::now();
  90. $action->extra = (string)$extra;
  91. if(!$this->app->upgrading) $action->vision = $this->config->vision;
  92. if($objectType == 'story' && in_array($actionType, array('reviewpassed', 'reviewrejected', 'reviewclarified', 'reviewreverted', 'synctwins'))) $action->actor = $this->lang->action->system;
  93. /* 使用purifier处理注解。 */
  94. /* Use purifier to process comment. Fix bug #2683. */
  95. if(empty($comment)) $comment = '';
  96. $action->comment = fixer::stripDataTags($comment);
  97. $uid = $this->post->uid;
  98. if(is_string($uid)) $uid = array($uid);
  99. if(!is_array($uid)) $uid = array();
  100. $this->loadModel('file');
  101. foreach($uid as $value)
  102. {
  103. $action = $this->file->processImgURL($action, 'comment', $value);
  104. if($autoDelete) $this->file->autoDelete($value);
  105. }
  106. /* 获取对象的产品项目以及执行。 */
  107. /* Get product project and execution for this object. */
  108. $relation = $this->getRelatedFields($action->objectType, $objectID, $actionType, $extra);
  109. $action->product = $relation['product'];
  110. $action->project = (int)$relation['project'];
  111. $action->execution = (int)$relation['execution'];
  112. $this->dao->insert(TABLE_ACTION)->data($action)->autoCheck()->exec();
  113. $actionID = $this->dao->lastInsertID();
  114. $hasProductTable = true;
  115. $hasRecentTable = true;
  116. if($this->app->upgrading)
  117. {
  118. $fromVersion = $this->loadModel('setting')->getItem('owner=system&module=common&section=global&key=version');
  119. if(is_numeric($fromVersion[0]) && version_compare($fromVersion, '18.6', '<')) $hasRecentTable = false;
  120. if(strpos($fromVersion, 'pro') !== false) $hasRecentTable = false;
  121. if(strpos($fromVersion, 'biz') !== false && version_compare($fromVersion, 'biz8.6', '<')) $hasRecentTable = false;
  122. if(strpos($fromVersion, 'max') !== false && version_compare($fromVersion, 'max4.6', '<')) $hasRecentTable = false;
  123. if(strpos($fromVersion, 'ipd') !== false && version_compare($fromVersion, 'ipd1.0.1', '<')) $hasRecentTable = false;
  124. if(is_numeric($fromVersion[0]) && version_compare($fromVersion, '21.7.1', '<=')) $hasProductTable = false;
  125. if(strpos($fromVersion, 'pro') !== false) $hasProductTable = false;
  126. if(strpos($fromVersion, 'biz') !== false && version_compare($fromVersion, 'biz12.0', '<=')) $hasProductTable = false;
  127. if(strpos($fromVersion, 'max') !== false && version_compare($fromVersion, 'max7.0', '<=')) $hasProductTable = false;
  128. if(strpos($fromVersion, 'ipd') !== false && version_compare($fromVersion, 'ipd4.0', '<=')) $hasProductTable = false;
  129. }
  130. if($hasProductTable)
  131. {
  132. $productIdList = array_filter(explode(',', $action->product));
  133. foreach($productIdList as $productID) $this->dao->insert(TABLE_ACTIONPRODUCT)->set('action')->eq($actionID)->set('product')->eq($productID)->exec();
  134. }
  135. if($actionType == 'commented')
  136. {
  137. $oldAction = new stdclass();
  138. $oldAction->id = $actionID;
  139. $newAction = clone $oldAction;
  140. $this->file->processFileDiffsForObject('comment', $oldAction, $newAction);
  141. if(!empty($newAction->files))
  142. {
  143. $action->files = $newAction->files;
  144. $this->dao->update(TABLE_ACTION)->set('files')->eq($newAction->files)->where('id')->eq($actionID)->exec();
  145. }
  146. $changes = common::createChanges($oldAction, $newAction);
  147. if($changes) $this->logHistory($actionID, $changes);
  148. }
  149. if($hasRecentTable)
  150. {
  151. $action->id = $actionID;
  152. $this->dao->insert(TABLE_ACTIONRECENT)->data($action)->autoCheck()->exec();
  153. }
  154. $this->file->updateObjectID($uid, $objectID, $objectType);
  155. if(empty($this->app->installing) && empty($this->app->upgrading)) $this->loadModel('message')->send(strtolower($objectType), $objectID, $actionType, $actionID, $actor, $extra);
  156. $this->saveIndex($objectType, $objectID, $actionType);
  157. $changeFunc = 'after' . ucfirst($objectType);
  158. if(method_exists($this, $changeFunc)) call_user_func_array(array($this, $changeFunc), array($action, $actionID));
  159. return $actionID;
  160. }
  161. //**//
  162. }