diff --git a/module/project/control.php b/module/project/control.php index 3c3a06130f..6fce0302c9 100755 --- a/module/project/control.php +++ b/module/project/control.php @@ -1867,61 +1867,43 @@ class project extends control } /** - * Delete a project. + * 删除一个项目,并弹窗确认 + * Delete a project and confirm. * - * @param int $projectID + * @param string $projectID * @param string $confirm * @param string $from browse|view + * * @access public * @return void */ - public function delete($projectID, $confirm = 'no', $from = 'browse') + public function delete(string $projectID, string $confirm = 'no', string $from = 'browse'): void { $projectID = (int)$projectID; + $project = $this->getByID($projectID); + if($confirm == 'no') { - $project = $this->project->getByID($projectID); return print(js::confirm(sprintf($this->lang->project->confirmDelete, $project->name), $this->createLink('project', 'delete', "projectID=$projectID&confirm=yes&from=$from"))); } else { - $this->loadModel('user'); - $this->loadModel('action'); - $this->project->delete(TABLE_PROJECT, $projectID); $this->dao->update(TABLE_DOCLIB)->set('deleted')->eq(1)->where('execution')->eq($projectID)->exec(); - $this->user->updateUserView($projectID, 'project'); - - /* Delete the execution under the project. */ - $executionIdList = $this->loadModel('execution')->getPairs($projectID); - - /* Delete shadow product.*/ - $project = $this->project->getByID($projectID); - if(!$project->hasProduct) - { - $productID = $this->loadModel('product')->getProductIDByProject($projectID); - $this->dao->update(TABLE_PRODUCT)->set('deleted')->eq(1)->where('id')->eq($productID)->exec(); - } + $this->loadModel('user')->updateUserView($projectID, 'project'); $message = $this->executeHooks($projectID); if($message) $this->lang->saveSuccess = $message; - if(empty($executionIdList)) - { - if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); - if($from == 'view') return print(js::locate($this->createLink('project', 'browse'), 'parent')); - return print(js::reload('parent')); - } - - $this->dao->update(TABLE_EXECUTION)->set('deleted')->eq(1)->where('id')->in(array_keys($executionIdList))->exec(); - foreach($executionIdList as $executionID => $execution) $this->action->create('execution', $executionID, 'deleted', '', ACTIONMODEL::CAN_UNDELETED); - $this->user->updateUserView($executionIdList, 'sprint'); + $this->projectZen->removeAssociatedProducts($project); + $this->projectZen->removeAssociatedExecutions($projectID); if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); $this->session->set('project', ''); if($from == 'view') return print(js::locate($this->createLink('project', 'browse'), 'parent')); return print(js::reload('parent')); + } } diff --git a/module/project/model.php b/module/project/model.php index c9f52f5f57..8e93f93cfb 100755 --- a/module/project/model.php +++ b/module/project/model.php @@ -1767,12 +1767,28 @@ class projectModel extends model return !dao::isError(); } + /** + * 删除项目并同步执行与产品等状态为删除 + * Deletes a project and updates related items: product|execution + * + * @param string $table product|execution + * @param int|array $idList + * + * @access public + * @return void + */ + public function deleteProductAndExcution(string $table, int|array $idList):void + { + $this->dao->update($table)->set('deleted')->eq(1)->where('id')->in($idList)->exec(); + } + /** * Update the program of the product. * * @param int $oldProgram * @param int $newProgram * @param array $products + * * @access public * @return void */ diff --git a/module/project/zen.php b/module/project/zen.php index dfd4234cd0..15a2bed7a8 100644 --- a/module/project/zen.php +++ b/module/project/zen.php @@ -56,9 +56,9 @@ class projectZen extends project * @param object $project * @param object $rawdata * @access protected - * @return bool + * @return bool */ - private function checkProductAndBranch(object $project, object $rawdata): bool + private function checkProductAndBranch(object $project, object $rawdata): bool { $linkedProductsCount = $this->project->getLinkedProductsCount($project, $rawdata); @@ -98,9 +98,9 @@ class projectZen extends project * @param object $project * @param object $rawdata * @access protected - * @return bool + * @return bool */ - private function checkDaysAndBudget(object $project, object $rawdata): bool + private function checkDaysAndBudget(object $project, object $rawdata): bool { /* Judge workdays is legitimate. */ $workdays = helper::diffDate($project->end, $project->begin) + 1; @@ -137,9 +137,9 @@ class projectZen extends project * @param object $project * @param object $rawdata * @access protected - * @return bool + * @return bool */ - private function checkProductNameUnqiue(object $project, object $rawdata): bool + private function checkProductNameUnqiue(object $project, object $rawdata): bool { /* When select create new product, product name cannot be empty and duplicate. */ if($project->hasProduct && isset($rawdata->newProduct)) @@ -542,4 +542,48 @@ class projectZen extends project ->remove('comment,readjustTime,readjustTask') ->get(); } + + /** + * 从项目中删除所有关联的执行。 + * removes all associated executions from the be deleted project + * + * @param int $projectID + * + * @access protected + * @return void + */ + protected function removeAssociatedExecutions(int $projectID): void + { + /* Delete the execution under the project. */ + $executionIdList = $this->loadModel('execution')->getPairs($projectID); + if(empty($executionIdList)) + { + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); + if($from == 'view') return print(js::locate($this->createLink('project', 'browse'), 'parent')); + return print(js::reload('parent')); + } + + $this->updateRelatedItemByDelete('zt_execution', array_keys($executionIdList)); + foreach($executionIdList as $executionID => $execution) $this->action->create('execution', $executionID, 'deleted', '', ACTIONMODEL::CAN_UNDELETED); + $this->user->updateUserView($executionIdList, 'sprint'); + } + + /** + * 从项目中删除所有关联的产品。 + * removes all associated products from the be deleted project + * + * @param object $projectID + * + * @access protected + * @return void + */ + protected function removeAssociatedProducts(object $project): void + { + /* Delete shadow product.*/ + if(!$project->hasProduct) + { + $productID = $this->loadModel('product')->getProductIDByProject($project->id); + $this->updateRelatedItemByDelete('zt_product', $productID); + } + } }