From 9ea1185649a0385094b46d36100f07a5b02b5fec Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Tue, 12 Jul 2022 09:10:05 +0000 Subject: [PATCH 1/2] * Finish task#60378. --- module/file/control.php | 10 +++++++++- module/file/model.php | 19 +++++++++++++++++++ module/testcase/control.php | 24 ++++++++++++++++++++++++ module/testcase/model.php | 26 ++++++++++++++++++-------- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/module/file/control.php b/module/file/control.php index 79f09b08eb..5320c04355 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -280,9 +280,14 @@ class file extends control $file = $this->file->getById($fileID); $this->dao->delete()->from(TABLE_FILE)->where('id')->eq($fileID)->exec(); $this->loadModel('action')->create($file->objectType, $file->objectID, 'deletedFile', '', $extra=$file->title); + /* Fix Bug #1518. */ $fileRecord = $this->dao->select('id')->from(TABLE_FILE)->where('pathname')->eq($file->pathname)->fetch(); if(empty($fileRecord)) @unlink($file->realPath); + + /* Update test case version for test case synchronization. */ + if($file->objectType == 'testcase') $this->file->updateTestcaseVersion($file); + return print(js::reload('parent')); } } @@ -331,9 +336,12 @@ class file extends control $extension = "." . $file->extension; $actionID = $this->loadModel('action')->create($file->objectType, $file->objectID, 'editfile', '', $fileName); - $changes[] = array('field' => 'fileName', 'old' => $file->title . $extension, 'new' => $fileName); + $changes[] = array('field' => 'fileName', 'old' => $file->title, 'new' => $fileName); $this->action->logHistory($actionID, $changes); + /* Update test case version for test case synchronization. */ + if($file->objectType == 'testcase' and $file->title != $fileName) $this->file->updateTestcaseVersion($file); + return print(js::reload('parent.parent')); } diff --git a/module/file/model.php b/module/file/model.php index 378bfbf5a5..2e68a57ab0 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -1046,4 +1046,23 @@ class fileModel extends model ->andWhere('deleted')->eq('0') ->fetchPairs(); } + + /** + * Update test case version. + * + * @param object $file + * @access public + * @return void + */ + public function updateTestcaseVersion($file) + { + $oldCase = $this->loadModel('testcase')->getByID($file->objectID); + $isLibCase = ($oldCase->lib and empty($oldCase->product)); + if($isLibCase) + { + $fromcaseVersion = $this->dao->select('fromCaseVersion')->from(TABLE_CASE)->where('fromCaseID')->eq($file->objectID)->fetch('fromCaseVersion'); + $fromcaseVersion += 1; + $this->dao->update(TABLE_CASE)->set('`fromCaseVersion`')->eq($fromcaseVersion)->where('`fromCaseID`')->eq($file->objectID)->exec(); + } + } } diff --git a/module/testcase/control.php b/module/testcase/control.php index 2806380aac..ce43238469 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1403,10 +1403,33 @@ class testcase extends control $case = $this->testcase->getById($caseID); $libCase = $this->testcase->getById($libcaseID); $version = $case->version + 1; + + $this->dao->delete()->from(TABLE_FILE)->where('objectType')->eq('testcase')->andWhere('objectID')->eq($caseID)->exec(); + foreach($libCase->files as $fileID => $file) + { + $fileName = pathinfo($file->pathname, PATHINFO_FILENAME); + $datePath = substr($file->pathname, 0, 6); + $realPath = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/" . "{$datePath}/" . $fileName; + + $rand = rand(); + $newFileName = $fileName . 'copy' . $rand; + $newFilePath = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/" . "{$datePath}/" . $newFileName; + copy($realPath, $newFilePath); + + $newFileName = $file->pathname; + $newFileName = str_replace('.', "copy$rand.", $newFileName); + + unset($file->id, $file->realPath, $file->webPath); + $file->objectID = $caseID; + $file->pathname = $newFileName; + $this->dao->insert(TABLE_FILE)->data($file)->exec(); + } + $this->dao->update(TABLE_CASE) ->set('version')->eq($version) ->set('fromCaseVersion')->eq($version) ->set('precondition')->eq($libCase->precondition) + ->set('title')->eq($libCase->title) ->where('id')->eq($caseID) ->exec(); @@ -1417,6 +1440,7 @@ class testcase extends control $step->version = $version; $this->dao->insert(TABLE_CASESTEP)->data($step)->exec(); } + echo js::locate($this->createLink('testcase', 'view', "caseID=$caseID&version=$version"), 'parent'); } diff --git a/module/testcase/model.php b/module/testcase/model.php index 0c58f2582e..d8c2412a02 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -799,15 +799,12 @@ class testcaseModel extends model $this->dao->update(TABLE_CASE)->data($case)->autoCheck()->batchCheck($requiredFields, 'notempty')->checkFlow()->where('id')->eq((int)$caseID)->exec(); if(!$this->dao->isError()) { - $isLibCase = ($oldCase->lib and empty($oldCase->product)); - $titleChanged = ($case->title != $oldCase->title); - if($isLibCase and $titleChanged) $this->dao->update(TABLE_CASE)->set('`title`')->eq($case->title)->where('`fromCaseID`')->eq($caseID)->exec(); - $this->updateCase2Project($oldCase, $case, $caseID); if($stepChanged) { $parentStepID = 0; + $isLibCase = ($oldCase->lib and empty($oldCase->product)); if($isLibCase) { $fromcaseVersion = $this->dao->select('fromCaseVersion')->from(TABLE_CASE)->where('fromCaseID')->eq($caseID)->fetch('fromCaseVersion'); @@ -1103,6 +1100,11 @@ class testcaseModel extends model foreach($cases as $caseID => $case) { $oldCase = $this->getByID($caseID); + + $caseChanged = false; + if($oldCase->title != $case->title) $caseChanged = true; + if($oldCase->precondition != $case->precondition) $caseChanged = true; + $this->dao->update(TABLE_CASE)->data($case) ->autoCheck() ->batchCheck($this->config->testcase->edit->requiredFields, 'notempty') @@ -1112,11 +1114,7 @@ class testcaseModel extends model if(!dao::isError()) { - $isLibCase = ($oldCase->lib and empty($oldCase->product)); - $titleChanged = ($case->title != $oldCase->title); $case->product = $oldCase->product; - if($isLibCase and $titleChanged) $this->dao->update(TABLE_CASE)->set('`title`')->eq($case->title)->where('`fromCaseID`')->eq($caseID)->exec(); - $this->updateCase2Project($oldCase, $case, $caseID); $this->executeHooks($caseID); @@ -1138,6 +1136,14 @@ class testcaseModel extends model } } } + + $isLibCase = ($oldCase->lib and empty($oldCase->product)); + if($isLibCase and $caseChanged) + { + $fromcaseVersion = $this->dao->select('fromCaseVersion')->from(TABLE_CASE)->where('fromCaseID')->eq($caseID)->fetch('fromCaseVersion'); + $fromcaseVersion += 1; + $this->dao->update(TABLE_CASE)->set('`fromCaseVersion`')->eq($fromcaseVersion)->where('`fromCaseID`')->eq($caseID)->exec(); + } } else { @@ -2357,6 +2363,10 @@ class testcaseModel extends model if(!$this->forceNotReview() and $stepChanged) $status = 'wait'; + if(!empty($_POST['title']) and $case->title != $this->post->title) $stepChanged = true; + if(!empty($_post['precondition']) and $case->precondition != $this->post->precondition) $stepchanged = true; + if(!empty($_POST['labels'][0])) $stepChanged = true; + return array($stepChanged, $status); } From 5b91324e83b690d53a722c5c1c59591f5582c21d Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Wed, 13 Jul 2022 02:15:09 +0000 Subject: [PATCH 2/2] * Finish task#60384. --- module/execution/control.php | 2 +- module/story/control.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/module/execution/control.php b/module/execution/control.php index 9cf79b345f..c06ed6c6bb 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -3966,8 +3966,8 @@ class execution extends control $projectID = $this->dao->findByID($executionID)->from(TABLE_EXECUTION)->fetch('project'); $planStories = array_keys($planStory); - $this->execution->linkStory($executionID, $planStories, $planProducts, $extra); if($this->config->systemMode == 'new' and $executionID != $projectID) $this->execution->linkStory($projectID, $planStories, $planProducts); + $this->execution->linkStory($executionID, $planStories, $planProducts, $extra); } $moduleName = 'execution'; diff --git a/module/story/control.php b/module/story/control.php index d24ca310df..05478015b2 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -162,12 +162,14 @@ class story extends control $object = $this->dao->findById((int)$objectID)->from(TABLE_PROJECT)->fetch(); if($object->type != 'project') { + if($this->config->systemMode == 'new') $this->action->create('story', $storyID, 'linked2project', '', $object->project); + $actionType = $object->type == 'kanban' ? 'linked2kanban' : 'linked2execution'; - $this->loadModel('action')->create('story', $storyID, $actionType, '', $objectID); + $this->action->create('story', $storyID, $actionType, '', $objectID); } else { - $this->loadModel('action')->create('story', $storyID, 'linked2project', '', $objectID); + $this->action->create('story', $storyID, 'linked2project', '', $objectID); } } @@ -499,8 +501,8 @@ class story extends control { $products = array(); foreach($mails as $story) $products[$story->storyID] = $productID; - $this->execution->linkStory($executionID, $stories, $products, $extra, $lanes); if($executionID != $this->session->project) $this->execution->linkStory($this->session->project, $stories, $products); + $this->execution->linkStory($executionID, $stories, $products, $extra, $lanes); } /* If storyID not equal zero, subdivide this story to child stories and close it. */