diff --git a/module/project/control.php b/module/project/control.php index 3f60d6c8fc..294f60977d 100755 --- a/module/project/control.php +++ b/module/project/control.php @@ -2168,6 +2168,11 @@ class project extends control } $oldProducts = $this->product->getProducts($projectID); + if($project->multiple and $project->model != 'waterfall') + { + $executions = $this->dao->select('id')->from(TABLE_EXECUTION)->where('project')->eq($projectID)->fetchPairs('id'); + $oldExecutionProducts = $this->dao->select('project,product')->from(TABLE_PROJECTPRODUCT)->where('project')->in($executions)->fetchGroup('project', 'product'); + } $this->project->updateProducts($projectID); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); @@ -2184,7 +2189,7 @@ class project extends control $diffProducts = array_merge(array_diff($oldProductIDs, $newProductIDs), array_diff($newProductIDs, $oldProductIDs)); if($diffProducts) $this->loadModel('action')->create('project', $projectID, 'Managed', '', !empty($_POST['products']) ? join(',', $_POST['products']) : ''); - if($project->multiple) + if($project->multiple and $project->model != 'waterfall') { $unlinkedProducts = array_diff($oldProductIDs, $newProductIDs); if(!empty($unlinkedProducts)) @@ -2192,8 +2197,14 @@ class project extends control $unlinkedProductPairs = array(); foreach($unlinkedProducts as $unlinkedProduct) $unlinkedProductPairs[$unlinkedProduct] = $oldProducts[$unlinkedProduct]->name; - $executionIDList = $this->execution->getIdList($projectID); - foreach($executionIDList as $executionID) $this->action->create('execution', $executionID, 'unlinkproduct', '', implode(',', $unlinkedProductPairs)); + $unlinkExecutions = array(); + foreach($oldExecutionProducts as $executionID => $executionProducts) + { + $unlinkExecutionProducts = array_intersect_key($unlinkedProductPairs, $executionProducts); + if($unlinkExecutionProducts) $unlinkExecutions[$executionID] = $unlinkExecutionProducts; + } + + foreach($unlinkExecutions as $executionID => $unlinkExecutionProducts) $this->action->create('execution', $executionID, 'unlinkproduct', '', implode(',', $unlinkExecutionProducts)); } } diff --git a/module/project/model.php b/module/project/model.php index ca3c45a74c..4718eb0b9b 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -2339,7 +2339,7 @@ class projectModel extends model $members = array_keys($this->getTeamMembers($projectID)); /* Link products of other programs. */ - if($_POST['otherProducts']) + if(!empty($_POST['otherProducts'])) { $products = array(); $otherProducts = $_POST['otherProducts']; @@ -2424,9 +2424,10 @@ class projectModel extends model } /* Delete the execution linked products that is not linked with the execution. */ - if((int)$projectID > 0) + $projectID = (int)$projectID; + if($projectID > 0) { - $executions = $this->dao->select('id')->from(TABLE_EXECUTION)->where('project')->eq((int)$projectID)->fetchPairs('id'); + $executions = $this->dao->select('id')->from(TABLE_EXECUTION)->where('project')->eq($projectID)->fetchPairs('id'); $this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('project')->in($executions)->andWhere('product')->notin($products)->exec(); if(!empty($_POST['division']))