From b2601d3a775399659c4444a519f51186e0651fba Mon Sep 17 00:00:00 2001 From: liumengyi Date: Mon, 13 Jan 2025 15:33:25 +0800 Subject: [PATCH] * [task#136280,done,2h] append files in action::editComment. --- module/action/config/form.php | 2 + module/action/control.php | 3 +- module/action/model.php | 53 ++++++++++++------- .../action/test/lib/action.unittest.class.php | 7 ++- module/action/test/model/updatecomment.php | 6 +-- module/action/ui/editcomment.html.php | 1 + 6 files changed, 48 insertions(+), 24 deletions(-) diff --git a/module/action/config/form.php b/module/action/config/form.php index c40654b7c8..c72f4d4232 100644 --- a/module/action/config/form.php +++ b/module/action/config/form.php @@ -6,3 +6,5 @@ $config->action->form->comment['actioncomment'] = array('type' => 'string', 'req $config->action->form->editComment = array(); $config->action->form->editComment['lastComment'] = array('type' => 'string', 'required' => true, 'default' => '', 'control' => 'editor'); $config->action->form->editComment['uid'] = array('type' => 'string', 'required' => false, 'default' => ''); +$config->action->form->editComment['deleteFiles'] = array('type' => 'array', 'required' => false, 'default' => array()); +$config->action->form->editComment['renameFiles'] = array('type' => 'array', 'required' => false, 'default' => array()); diff --git a/module/action/control.php b/module/action/control.php index a500a452ce..55bb41ef83 100755 --- a/module/action/control.php +++ b/module/action/control.php @@ -342,7 +342,7 @@ class action extends control /* Determine whether the update conditions are met. */ if(strlen(trim(strip_tags($commentData->lastComment, ''))) != 0) { - $error = $this->action->updateComment($actionID, $commentData->lastComment, $commentData->uid); + $error = $this->action->updateComment($actionID, $commentData); } if(!$error) @@ -365,6 +365,7 @@ class action extends control $this->view->title = $this->lang->action->editComment; $this->view->actionID = $actionID; $this->view->comment = $this->action->formatActionComment($action->comment); + $this->view->files = $this->file->getByObject('comment', $actionID); $this->display(); } diff --git a/module/action/model.php b/module/action/model.php index 151a5c014b..02e78c8710 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -245,6 +245,7 @@ class actionModel extends model } $action->comment = $this->file->setImgSize($action->comment, $this->config->action->commonImgSize); + $action->files = $this->file->getByObject('comment', $actionID); $actions[$actionID] = $action; } return $actions; @@ -762,7 +763,7 @@ class actionModel extends model { if(in_array($actionType, array('restoredsnapshot', 'createdsnapshot')) && in_array($action->objectType, array('vm', 'zanode')) && $value == 'defaultSnap') $value = $this->lang->{$objectType}->snapshot->defaultSnapName; - $desc = str_replace('$' . $key, (string)$value, $desc); + if(!is_array($value)) $desc = str_replace('$' . $key, (string)$value, $desc); } } @@ -909,8 +910,10 @@ class actionModel extends model $item = new stdClass(); if(strlen(trim(($action->comment))) !== 0) { + $currentAccount = !empty($action->hasRendered) ? zget($users, $action->actor) : $action->actor; + $item->comment = $this->formatActionComment($action->comment); - $item->commentEditable = $commentEditable && end($actions) == $action && $action->actor == $this->app->user->account && common::hasPriv('action', 'editComment'); + $item->commentEditable = $commentEditable && end($actions) == $action && $action->actor == $currentAccount && common::hasPriv('action', 'editComment'); } if($action->action === 'assigned' || $action->action === 'toaudit') @@ -923,9 +926,10 @@ class actionModel extends model if(!empty($action->history)) $item->historyChanges = $this->renderChanges($action->objectType, $action->history); - $item->id = $action->id; - $item->action = $action->action; - $item->content = $this->renderAction($action); + $item->id = $action->id; + $item->action = $action->action; + $item->hasRendered = true; + $item->content = $this->renderAction($action); if($action->objectType == 'instance' && in_array($action->action, array('adjustmemory', 'adjustcpu', 'adjustvol'))) unset($item->comment); @@ -1608,34 +1612,45 @@ class actionModel extends model * Update comment of a action. * * @param int $actionID - * @param string $comment - * @param string $uid + * @param object $newComment * @access public * @return bool */ - public function updateComment(int $actionID, string $comment, string $uid): bool - { - $action = $this->getById($actionID); - if(!$action) return false; + public function updateComment(int $actionID, object $newComment): bool + { + $action = $this->getById($actionID); + if(!$action) return false; - /* 只保留允许的标签。 */ - /* Keep only allowed tags. */ - $action->comment = trim(strip_tags($comment, $this->config->allowedTags)); + $action->files = $this->loadModel('file')->getByObject('comment', $actionID); - /* 处理评论内的图片。*/ - /* Handle images in comment. */ - $action = $this->loadModel('file')->processImgURL($action, 'comment', $uid); + /* 只保留允许的标签。 */ + /* Keep only allowed tags. */ + $action->comment = trim(strip_tags($newComment->lastComment, $this->config->allowedTags)); + + /* 处理评论内的图片。*/ + /* Handle images in comment. */ + $action = $this->loadModel('file')->processImgURL($action, 'comment', $newComment->uid); $this->dao->update(TABLE_ACTION) ->set('date')->eq(helper::now()) - ->set('comment')->eq($comment) + ->set('comment')->eq($newComment->lastComment) ->where('id')->eq($actionID) ->exec(); - $this->file->updateObjectID($uid, $action->objectID, $action->objectType); + + $this->file->updateObjectID($newComment->uid, $action->objectID, $action->objectType); + $this->file->processFileDiffsForObject('comment', $action, $newComment); + if(!empty($newComment->files)) + { + $action->files = $newComment->files; + $this->dao->update(TABLE_ACTION)->set('files')->eq($newComment->files)->where('id')->eq($actionID)->exec(); + } + $changes = common::createChanges($action, $newComment); + if($changes) $this->logHistory($actionID, $changes); return true; } + /** * 根据actions构建日期组。 * Build date group by actions diff --git a/module/action/test/lib/action.unittest.class.php b/module/action/test/lib/action.unittest.class.php index bbbe782f32..f170e6937e 100644 --- a/module/action/test/lib/action.unittest.class.php +++ b/module/action/test/lib/action.unittest.class.php @@ -546,8 +546,13 @@ class actionTest $tester->session->set('album', null); $tester->session->set('album', array($uid => array(1), 'used' => array($uid => array(1)))); } + $action = new stdclass(); + $action->lastComment = $comment; + $action->uid = $uid; + $action->deleteFiles = array(); + $action->renameFiles = array(); - $this->objectModel->updateComment($actionID, $comment, $uid); + $this->objectModel->updateComment($actionID, $action); unset($_POST); diff --git a/module/action/test/model/updatecomment.php b/module/action/test/model/updatecomment.php index f613ba8c28..28d0ced4ed 100755 --- a/module/action/test/model/updatecomment.php +++ b/module/action/test/model/updatecomment.php @@ -16,8 +16,8 @@ cid=1 - 测试更新action 1的备注, 备注被成功更新为备注1属性comment @备注1 - 测试更新action 2的备注, 备注被成功更新为备注2属性comment @备注2 -- 测试文件是否更新成功, 文件的objectType和objectID被更新为story和2 - - 属性objectType @story +- 测试文件是否更新成功, 文件的objectType和objectID被更新为comment和2 + - 属性objectType @comment - 属性objectID @2 */ @@ -31,4 +31,4 @@ $file = new fileTest(); r($action->updateCommentTest($actionIDList[0], $commentList[0], $uidList[0])) && p('comment') && e('备注1'); // 测试更新action 1的备注, 备注被成功更新为备注1 r($action->updateCommentTest($actionIDList[1], $commentList[1], $uidList[1])) && p('comment') && e('备注2'); // 测试更新action 2的备注, 备注被成功更新为备注2 -r($file->getByIdTest(1)) && p('objectType;objectID') && e('story;2'); //测试文件是否更新成功, 文件的objectType和objectID被更新为story和2 +r($file->getByIdTest(1)) && p('objectType;objectID') && e('comment;2'); //测试文件是否更新成功, 文件的objectType和objectID被更新为comment和2 diff --git a/module/action/ui/editcomment.html.php b/module/action/ui/editcomment.html.php index 3d98e75997..a1f8b75ba8 100644 --- a/module/action/ui/editcomment.html.php +++ b/module/action/ui/editcomment.html.php @@ -25,5 +25,6 @@ form set::name('lastComment'), html($comment) ), + fileSelector(set::defaultFiles(array_values($files))), set::actions($actions) );