From 2e8f0393ce4f81bbe82a83a1af70aee4a79bd148 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Fri, 16 Jul 2021 11:10:43 +0800 Subject: [PATCH] + Fix project entry points of API. --- api/v1/entries/project.php | 33 +++++++++++++++++++++++---------- module/project/control.php | 9 ++++++++- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/api/v1/entries/project.php b/api/v1/entries/project.php index 18c7a1772b..05334b9455 100644 --- a/api/v1/entries/project.php +++ b/api/v1/entries/project.php @@ -20,27 +20,40 @@ class projectEntry extends entry $this->sendError(400, 'error'); } - public function put($productID) + public function put($projectID) { - $oldProduct = $this->loadModel('product')->getByID($productID); + $oldProject = $this->loadModel('project')->getByID($projectID); + $linkedProducts = $this->project->getProducts($projectID); /* Set $_POST variables. */ - $fields = 'program,line,name,PO,QD,RD,type,desc,whitelist,status,acl'; - $this->batchSetPost($fields, $oldProduct); + $fields = 'name,begin,end,acl,parent,desc,PM,whitelist'; + $this->batchSetPost($fields, $oldProject); - $control = $this->loadController('product', 'edit'); - $control->edit($productID); + $products = array(); + $plans = array(); + foreach($linkedProducts as $product) + { + $products[] = $product->id; + $plans[] = $product->plan; + } + $this->setPost('products', $products); + $this->setPost('plans', $plans); + + $control = $this->loadController('project', 'edit'); + $control->edit($projectID); $data = $this->getData(); if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(!isset($data->result)) return $this->sendError(400, 'error'); - $this->sendSuccess(200, 'success'); + $project = $this->project->getByID($projectID); + $this->send(200, $project); } - public function delete($productID) + public function delete($projectID) { - $control = $this->loadController('product', 'delete'); - $control->delete($productID, 'yes'); + $control = $this->loadController('project', 'delete'); + $control->delete($projectID, 'yes'); $this->getData(); $this->sendSuccess(200, 'success'); diff --git a/module/project/control.php b/module/project/control.php index 591d245f6f..9aa49fa019 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -1416,12 +1416,19 @@ class project extends control /* Delete the execution under the project. */ $executionIdList = $this->loadModel('execution')->getByProject($projectID); - if(empty($executionIdList)) die(js::reload('parent')); + + if(empty($executionIdList)) + { + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); + die(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'); + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); + $this->session->set('project', ''); die(js::reload('parent')); }