* Refactor action control create method.

This commit is contained in:
wangxuepeng
2023-08-29 08:07:59 +00:00
parent f51da6cd09
commit 6a892e2c11
3 changed files with 7 additions and 9 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ class model extends baseModel
{
$this->dao->update($table)->set('deleted')->eq(1)->where('id')->eq($id)->exec();
$object = preg_replace('/^' . preg_quote((string) $this->config->db->prefix) . '/', '', trim($table, '`'));
$this->loadModel('action')->create($object, $id, 'deleted', '', $extra = ACTIONMODEL::CAN_UNDELETED);
$this->loadModel('action')->create($object, $id, 'deleted', '', $extra = (string)ACTIONMODEL::CAN_UNDELETED);
return true;
}
+1 -3
View File
@@ -20,10 +20,9 @@ class action extends control
* @access public
* @return void
*/
public function create($objectType, $actionType, $objectName)
public function create(string $objectType, string $actionType, string $objectName)
{
$actionID = $this->action->create($objectType, 0, $actionType, '', $objectName);
if($actionID)
{
$this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
@@ -34,7 +33,6 @@ class action extends control
}
}
/**
* 回收站。
* Trash.
+5 -5
View File
@@ -31,13 +31,13 @@ class actionModel extends model
* @access public
* @return int
*/
public function create($objectType, $objectID, $actionType, $comment = '', $extra = '', $actor = '', $autoDelete = true)
public function create(string $objectType, int $objectID, string $actionType, string $comment = '', string $extra = '', string $actor = '', bool $autoDelete = true): int
{
if(strtolower($actionType) == 'commented' and empty($comment)) return false;
if(strtolower($actionType) == 'commented' && empty($comment)) return false;
$actor = $actor ? $actor : (!empty($this->app->user->account) ? $this->app->user->account : 'system');
$actor = $actor ?? ($this->app->user->account ?? 'system');
$actionType = strtolower($actionType);
$actor = ($actionType == 'openedbysystem' or $actionType == 'closedbysystem') ? '' : $actor;
$actor = ($actionType == 'openedbysystem' || $actionType == 'closedbysystem') ? '' : $actor;
if($actor == 'guest' and $actionType == 'logout') return false;
$objectType = str_replace('`', '', $objectType);
@@ -51,7 +51,7 @@ class actionModel extends model
$action->extra = $extra;
if(!$this->app->upgrading) $action->vision = $this->config->vision;
if($objectType == 'story' and strpos(',reviewpassed,reviewrejected,reviewclarified,reviewreverted,synctwins,', ",$actionType,") !== false) $action->actor = $this->lang->action->system;
if($objectType == 'story' && in_array($actionType, array('reviewpassed', 'reviewrejected', 'reviewclarified', 'reviewreverted', 'synctwins'))) $action->actor = $this->lang->action->system;
/* Use purifier to process comment. Fix bug #2683. */
if(empty($comment)) $comment = '';