diff --git a/module/story/model.php b/module/story/model.php index 99467df8f3..08046f7cba 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1841,18 +1841,20 @@ class storyModel extends model if($oldStory->branch) $story->plan = $planID; /* Append the plan id to plan field if product is multi and story is all branch. */ - if($this->session->currentProductType != 'normal' and empty($story->branch) and $planID != 0) + if($this->session->currentProductType != 'normal' and empty($story->branch)) { $branchPlanPairs = $this->dao->select('branch, id as plan')->from(TABLE_PRODUCTPLAN) ->where('product')->eq($oldStory->product) ->andWhere('id')->in($oldStory->plan) ->fetchPairs(); - if(!empty($oldStory->plan) and isset($branchPlanPairs[$plan->branch]) and $branchPlanPairs[$plan->branch] != $planID) $unlinkPlans[$branchPlanPairs[$plan->branch]] = empty($unlinkPlans[$branchPlanPairs[$plan->branch]]) ? $storyID : "{$unlinkPlans[$branchPlanPairs[$plan->branch]]},$storyID"; - if(isset($branchPlanPairs[$plan->branch])) $branchPlanPairs[$plan->branch] = $planID; - - - $story->plan = $oldStory->plan ? ',' . implode(',', $branchPlanPairs) : ",$planID"; - if($story->plan != $oldStory->plan and !empty($story->plan)) $link2Plans[$planID] = empty($link2Plans[$planID]) ? $storyID : "{$link2Plans[$planID]},$storyID"; + if($planID == 0 and !empty($oldStory->plan) and isset($branchPlanPairs[0]) and $branchPlanPairs[0] != $planID) $unlinkPlans[$branchPlanPairs[0]] = empty($unlinkPlans[$branchPlanPairs[0]]) ? $storyID : "{$unlinkPlans[$branchPlanPairs[0]]},$storyID"; + if($planID != 0) + { + if(!empty($oldStory->plan) and isset($branchPlanPairs[$plan->branch]) and $branchPlanPairs[$plan->branch] != $planID) $unlinkPlans[$branchPlanPairs[$plan->branch]] = empty($unlinkPlans[$branchPlanPairs[$plan->branch]]) ? $storyID : "{$unlinkPlans[$branchPlanPairs[$plan->branch]]},$storyID"; + if(isset($branchPlanPairs[$plan->branch])) $branchPlanPairs[$plan->branch] = $planID; + $story->plan = $oldStory->plan ? ',' . implode(',', $branchPlanPairs) : ",$planID"; + if($story->plan != $oldStory->plan and !empty($planID)) $link2Plans[$planID] = empty($link2Plans[$planID]) ? $storyID : "{$link2Plans[$planID]},$storyID"; + } } /* Change stage. */