From e7b5dcec092cb59a01f46b0aa02ad525c87b7b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E8=BE=B0=E8=BD=A9?= Date: Thu, 26 May 2022 11:22:43 +0800 Subject: [PATCH 1/6] * Create action for ztools. --- module/action/control.php | 41 ++++++++++++++++++++++++++++++++++++ module/action/lang/en.php | 3 +++ module/action/lang/zh-cn.php | 3 +++ 3 files changed, 47 insertions(+) diff --git a/module/action/control.php b/module/action/control.php index ac9224fabe..d9399b7dc9 100755 --- a/module/action/control.php +++ b/module/action/control.php @@ -11,6 +11,47 @@ */ class action extends control { + /** + * Create a action or delete all patch actions, this method is used by the Ztools. + * + * @param string $objectType + * @param string $actionType + * @param string $objectName + * @param bool $confirmDelete delete all patch actions when upgrade zentao. + * @access public + * @return int + */ + public function create($objectType, $actionType, $objectName, $confirmDelete = false) + { + if($confirmDelete) + { + $this->dao->delete()->from(TABLE_ACTION)->where('objectType')->eq('patch')->exec(); + + if(!dao::isError()) + { + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); + } + else + { + $this->send(array('result' => 'fail', 'message' => dao::getError())); + } + } + else + { + $actionID = $this->action->create($objectType, 0, $actionType, '', $objectName); + + if($actionID) + { + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); + } + else + { + $this->send(array('result' => 'fail', 'message' => 'error')); + } + } + } + + /** * Trash. * diff --git a/module/action/lang/en.php b/module/action/lang/en.php index 683a725743..7f67123d50 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -139,6 +139,7 @@ $lang->action->objectTypes['kanbancard'] = 'Kanban Card'; $lang->action->objectTypes['sonarqube'] = 'SonarQube Server'; $lang->action->objectTypes['sonarqubeproject'] = 'SonarQube Project'; $lang->action->objectTypes['stage'] = 'Stage'; +$lang->action->objectTypes['patch'] = 'Patch'; /* Used to describe operation history. */ $lang->action->desc = new stdclass(); @@ -232,6 +233,8 @@ $lang->action->desc->unlinkbug = '$date, 由 $actor 从计划 /* Used to display dynamic information. */ $lang->action->label = new stdclass(); +$lang->action->label->install = 'install '; +$lang->action->label->revert = 'revert '; $lang->action->label->created = 'created '; $lang->action->label->opened = 'opened '; $lang->action->label->openedbysystem = 'Opened by system '; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index d44fa78f60..953a74feb7 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -139,6 +139,7 @@ $lang->action->objectTypes['kanbancard'] = '看板卡片'; $lang->action->objectTypes['sonarqube'] = 'SonarQube服务器'; $lang->action->objectTypes['sonarqubeproject'] = 'SonarQube项目'; $lang->action->objectTypes['stage'] = '阶段'; +$lang->action->objectTypes['patch'] = '补丁'; /* 用来描述操作历史记录。*/ $lang->action->desc = new stdclass(); @@ -232,6 +233,8 @@ $lang->action->desc->unlinkbug = '$date, 由 $actor 从计划 /* 用来显示动态信息。*/ $lang->action->label = new stdclass(); +$lang->action->label->install = '安装'; +$lang->action->label->revert = '还原'; $lang->action->label->created = '创建'; $lang->action->label->opened = '创建'; $lang->action->label->openedbysystem = '系统创建'; From 53c84c3480a2c26910a46d804cc9a38a378b5fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E8=BE=B0=E8=BD=A9?= Date: Thu, 26 May 2022 17:10:33 +0800 Subject: [PATCH 2/6] * Delete /tmp/patch and patch actions after upgrade. --- module/action/control.php | 29 ++++++----------------------- module/action/model.php | 12 ++++++++++++ module/upgrade/control.php | 4 ++++ module/upgrade/model.php | 12 ++++++++++++ 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/module/action/control.php b/module/action/control.php index d9399b7dc9..096be220c0 100755 --- a/module/action/control.php +++ b/module/action/control.php @@ -17,37 +17,20 @@ class action extends control * @param string $objectType * @param string $actionType * @param string $objectName - * @param bool $confirmDelete delete all patch actions when upgrade zentao. * @access public * @return int */ - public function create($objectType, $actionType, $objectName, $confirmDelete = false) + public function create($objectType, $actionType, $objectName) { - if($confirmDelete) - { - $this->dao->delete()->from(TABLE_ACTION)->where('objectType')->eq('patch')->exec(); + $actionID = $this->action->create($objectType, 0, $actionType, '', $objectName); - if(!dao::isError()) - { - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); - } - else - { - $this->send(array('result' => 'fail', 'message' => dao::getError())); - } + if($actionID) + { + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); } else { - $actionID = $this->action->create($objectType, 0, $actionType, '', $objectName); - - if($actionID) - { - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); - } - else - { - $this->send(array('result' => 'fail', 'message' => 'error')); - } + $this->send(array('result' => 'fail', 'message' => 'error')); } } diff --git a/module/action/model.php b/module/action/model.php index 767dacdf18..e2b16c7c72 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -1555,6 +1555,18 @@ class actionModel extends model } } + /** + * delete action by objectType. + * + * @param string $objectType + * @access public + * @return void + */ + public function deleteByType($objectType) + { + $this->dao->delete()->from(TABLE_ACTION)->where('objectType')->eq($objectType)->exec(); + } + /** * Undelete a record. * diff --git a/module/upgrade/control.php b/module/upgrade/control.php index c0c7c862ea..ae4b2b9de1 100644 --- a/module/upgrade/control.php +++ b/module/upgrade/control.php @@ -153,6 +153,10 @@ class upgrade extends control if(!$this->upgrade->isError()) { $systemMode = $this->loadModel('setting')->getItem('owner=system&module=common§ion=global&key=mode'); + + /* Delete all patch actions if upgrade success. */ + $this->loadModel('action')->deleteByType('patch'); + if((empty($systemMode) && !isset($this->config->qcVersion) && strpos($fromVersion, 'max') === false) or ($systemMode != 'new' && strpos($fromVersion, 'max') === false && strpos($this->config->version, 'max') !== false)) { diff --git a/module/upgrade/model.php b/module/upgrade/model.php index e2dcbe34b7..3c00971053 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -1306,6 +1306,18 @@ class upgradeModel extends model } } + /* Delete all patch files when upgrade zentao. */ + $patchPath = $this->app->getTmpRoot() . 'patch'; + $isDir = is_dir($patchPath); + if(file_exists($patchPath)) + { + if(!is_writable($patchPath) or ($isDir and !$zfile->removeDir($patchPath)) or + (!$isDir and !$zfile->removeDir($patchPath))) + { + $result[] = 'rm -f ' . ($isDir ? '-r ' : '') . $patchPath; + } + } + return $result; } From 7dfa16f3b55efcfebb02035b74317f46d93184b8 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 6 Jun 2022 09:57:10 +0800 Subject: [PATCH 3/6] * Modify cli params. --- bin/ztcli | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/ztcli b/bin/ztcli index c5e19828b1..9ba6fe4177 100755 --- a/bin/ztcli +++ b/bin/ztcli @@ -15,7 +15,7 @@ error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT); define('IN_SHELL', true); /* Judge the args. */ -if($argc != 2) die('Usage: ' . basename(__FILE__) . " \n"); +if($argc > 3 or $argc < 2) die('Usage: ' . basename(__FILE__) . " \n"); /* Parse the request into params. */ $request = parse_url(trim($argv[1])); @@ -33,6 +33,13 @@ include './framework/helper.class.php'; $app = router::createApp('pms', dirname(dirname(__FILE__)), 'router'); $common = $app->loadCommon(); +/* Set the PATH_INFO request. */ +if(!empty($argv[2]) && $argv[2] == 'pathinfo') +{ + $config->requestType = 'PATH_INFO'; + $config->requestFix = '-'; +} + /* Set the PATH_INFO variable. */ if($config->requestType == 'PATH_INFO') { From 49c1f2161c3111eb8373c1d88219078be92db808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=8E=89=E6=98=A5?= <563917701@qq.com> Date: Mon, 6 Jun 2022 02:09:19 +0000 Subject: [PATCH 4/6] Update ztcli --- bin/ztcli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ztcli b/bin/ztcli index 9ba6fe4177..38252d263b 100755 --- a/bin/ztcli +++ b/bin/ztcli @@ -15,7 +15,7 @@ error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT); define('IN_SHELL', true); /* Judge the args. */ -if($argc > 3 or $argc < 2) die('Usage: ' . basename(__FILE__) . " \n"); +if($argc < 2 or $argc > 3) die('Usage: ' . basename(__FILE__) . " \n"); /* Parse the request into params. */ $request = parse_url(trim($argv[1])); From 8f4cc425500de706252b225bf278576cc2329ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E8=BE=B0=E8=BD=A9?= Date: Mon, 6 Jun 2022 10:09:48 +0800 Subject: [PATCH 5/6] * Modify function return. --- module/action/control.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/action/control.php b/module/action/control.php index 096be220c0..46f6b93c3d 100755 --- a/module/action/control.php +++ b/module/action/control.php @@ -18,7 +18,7 @@ class action extends control * @param string $actionType * @param string $objectName * @access public - * @return int + * @return void */ public function create($objectType, $actionType, $objectName) { From 6fe727b0095de6650a1b2431cedf8926f86dab82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=8E=89=E6=98=A5?= <563917701@qq.com> Date: Mon, 6 Jun 2022 02:13:20 +0000 Subject: [PATCH 6/6] Update model.php --- module/action/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/action/model.php b/module/action/model.php index af4a328348..20eb2b8f15 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -1556,7 +1556,7 @@ class actionModel extends model } /** - * delete action by objectType. + * Delete action by objectType. * * @param string $objectType * @access public