This commit is contained in:
shenshulong
2023-05-06 01:47:52 +00:00
4 changed files with 70 additions and 76 deletions
+2 -2
View File
@@ -149,7 +149,7 @@ class programplan extends control
if($_POST)
{
$formData = form::data($this->config->programplan->create->form);
$this->programplan->create($formData, $projectID, $this->productID, $planID);
$this->programplan->create($formData, $projectID, $productID, $planID);
if(dao::isError())
{
$errors = dao::getError();
@@ -173,7 +173,7 @@ class programplan extends control
$this->view->position[] = $this->lang->programplan->create;
$executions = !empty($planID) ? $this->loadModel('execution')->getChildExecutions($planID, 'order_asc') : array();
$plans = $this->programplan->getStage($planID ? $planID : $projectID, $this->productID, 'parent', 'order_asc');
$plans = $this->programplan->getStage($planID ? $planID : $projectID, $productID, 'parent', 'order_asc');
if(!empty($planID) and !empty($plans) and $project->model == 'waterfallplus')
{
$executionType = 'stage';
+52 -54
View File
@@ -767,12 +767,14 @@ class programplanModel extends model
$plans[] = $plan;
}
/* Set dao error and return false if the programplan has no name. */
if(empty($plans))
{
dao::$errors['message'][] = sprintf($this->lang->error->notempty, $this->lang->programplan->name);
return false;
}
/* Check every plan is valid. */
$totalPercent = 0;
$milestone = 0;
foreach($plans as $index => $plan)
@@ -861,7 +863,7 @@ class programplanModel extends model
{
$orderIndex = empty($orders) ? 0 : count($orders);
$lastID = $this->dao->select('id')->from(TABLE_EXECUTION)->orderBy('id_desc')->fetch('id');
for($i = $orderIndex; $i < count($datas); $i ++)
for($i = $orderIndex; $i < count($plans); $i ++)
{
$lastID ++;
$orders[$i] = $lastID * 5;
@@ -881,33 +883,29 @@ class programplanModel extends model
$linkProducts = array_keys($productList);
foreach($linkProducts as $index => $productID) $linkBranches[$index] = $productList[$productID]->branches;
}
$this->post->set('products', $linkProducts);
$this->post->set('branch', $linkBranches);
foreach($datas as $data)
foreach($plans as $plan)
{
/* Set planDuration and realDuration. */
if($this->config->edition == 'max')
{
$data->planDuration = $this->getDuration($data->begin, $data->end);
$data->realDuration = $this->getDuration($data->realBegan, $data->realEnd);
$plan->planDuration = $this->getDuration($plan->begin, $plan->end);
$plan->realDuration = $this->getDuration($plan->realBegan, $plan->realEnd);
}
$projectChanged = false;
$data->days = helper::diffDate($data->end, $data->begin) + 1;
$data->order = current($orders);
$plan->days = helper::diffDate($plan->end, $plan->begin) + 1;
$plan->order = current($orders);
if($data->id)
if($plan->id)
{
$stageID = $data->id;
unset($data->id, $data->type);
$stageID = $plan->id;
unset($plan->id, $plan->type);
$oldStage = $this->getByID($stageID);
$planChanged = ($oldStage->name != $data->name || $oldStage->milestone != $data->milestone || $oldStage->begin != $data->begin || $oldStage->end != $data->end);
$planChanged = ($oldStage->name != $plan->name || $oldStage->milestone != $plan->milestone || $oldStage->begin != $plan->begin || $oldStage->end != $plan->end);
if($planChanged) $data->version = $oldStage->version + 1;
$this->dao->update(TABLE_PROJECT)->data($data)
if($planChanged) $plan->version = $oldStage->version + 1;
$this->dao->update(TABLE_PROJECT)->data($plan)
->autoCheck()
->batchCheck($this->config->programplan->edit->requiredFields, 'notempty')
->checkIF($plan->percent != '' and $setPercent, 'percent', 'float')
@@ -915,56 +913,56 @@ class programplanModel extends model
->exec();
/* Add PM to stage teams and project teams. */
if(!empty($data->PM))
if(!empty($plan->PM))
{
$team = $this->user->getTeamMemberPairs($stageID, 'execution');
if(isset($team[$data->PM])) continue;
if(isset($team[$plan->PM])) continue;
$roles = $this->user->getUserRoles($data->PM);
$roles = $this->user->getUserRoles($plan->PM);
$member = new stdclass();
$member->root = $stageID;
$member->account = $data->PM;
$member->role = zget($roles, $data->PM, '');
$member->account = $plan->PM;
$member->role = zget($roles, $plan->PM, '');
$member->join = $now;
$member->type = 'execution';
$member->days = $data->days;
$member->days = $plan->days;
$member->hours = $this->config->execution->defaultWorkhours;
$this->dao->insert(TABLE_TEAM)->data($member)->exec();
$this->execution->addProjectMembers($data->project, array($data->PM => $member));
$this->execution->addProjectMembers($plan->project, array($plan->PM => $member));
}
if($data->acl != 'open') $this->user->updateUserView($stageID, 'sprint');
if($plan->acl != 'open') $this->user->updateUserView($stageID, 'sprint');
/* Record version change information. */
if($planChanged)
{
$spec = new stdclass();
$spec->project = $stageID;
$spec->version = $data->version;
$spec->name = $data->name;
$spec->milestone = $data->milestone;
$spec->begin = $data->begin;
$spec->end = $data->end;
$spec->version = $plan->version;
$spec->name = $plan->name;
$spec->milestone = $plan->milestone;
$spec->begin = $plan->begin;
$spec->end = $plan->end;
$this->dao->insert(TABLE_PROJECTSPEC)->data($spec)->exec();
}
$changes = common::createChanges($oldStage, $data);
$changes = common::createChanges($oldStage, $plan);
$actionID = $this->action->create('execution', $stageID, 'edited');
$this->action->logHistory($actionID, $changes);
}
else
{
unset($data->id);
$data->status = 'wait';
$data->division = $project->division;
$data->version = 1;
$data->parentVersion = $data->parent == 0 ? 0 : $this->dao->findByID($data->parent)->from(TABLE_PROJECT)->fetch('version');
$data->team = substr($data->name,0, 30);
$data->openedBy = $account;
$data->openedDate = $now;
$data->openedVersion = $this->config->version;
if(!isset($data->acl)) $data->acl = $this->dao->findByID($data->parent)->from(TABLE_PROJECT)->fetch('acl');
$this->dao->insert(TABLE_PROJECT)->data($data)
unset($plan->id);
$plan->status = 'wait';
$plan->division = $project->division;
$plan->version = 1;
$plan->parentVersion = $plan->parent == 0 ? 0 : $this->dao->findByID($plan->parent)->from(TABLE_PROJECT)->fetch('version');
$plan->team = substr($plan->name,0, 30);
$plan->openedBy = $account;
$plan->openedDate = $now;
$plan->openedVersion = $this->config->version;
if(!isset($plan->acl)) $plan->acl = $this->dao->findByID($plan->parent)->from(TABLE_PROJECT)->fetch('acl');
$this->dao->insert(TABLE_PROJECT)->data($plan)
->autoCheck()
->batchCheck($this->config->programplan->create->requiredFields, 'notempty')
->checkIF($plan->percent != '' and $setPercent, 'percent', 'float')
@@ -973,13 +971,13 @@ class programplanModel extends model
if(!dao::isError())
{
$stageID = $this->dao->lastInsertID();
if($data->type == 'kanban')
if($plan->type == 'kanban')
{
$execution = $this->execution->getByID($stageID);
$this->loadModel('kanban')->createRDKanban($execution);
}
if($data->acl != 'open') $this->user->updateUserView($stageID, 'sprint');
if($plan->acl != 'open') $this->user->updateUserView($stageID, 'sprint');
/* Create doc lib. */
$lib = new stdclass();
@@ -995,7 +993,7 @@ class programplanModel extends model
/* Add creators and PM to stage teams and project teams. */
$teamMembers = array();
$members = array($this->app->user->account, $data->PM);
$members = array($this->app->user->account, $plan->PM);
$roles = $this->user->getUserRoles(array_values($members));
$team = $this->user->getTeamMemberPairs($stageID, 'execution');
foreach($members as $teamMember)
@@ -1008,29 +1006,29 @@ class programplanModel extends model
$member->role = zget($roles, $teamMember, '');
$member->join = $now;
$member->type = 'execution';
$member->days = $data->days;
$member->days = $plan->days;
$member->hours = $this->config->execution->defaultWorkhours;
$this->dao->insert(TABLE_TEAM)->data($member)->exec();
$teamMembers[$teamMember] = $member;
}
$this->execution->addProjectMembers($data->project, $teamMembers);
$this->execution->addProjectMembers($plan->project, $teamMembers);
$this->setTreePath($stageID);
if($data->acl != 'open') $this->user->updateUserView($stageID, 'sprint');
if($plan->acl != 'open') $this->user->updateUserView($stageID, 'sprint');
/* Record version change information. */
$spec = new stdclass();
$spec->project = $stageID;
$spec->version = $data->version;
$spec->name = $data->name;
$spec->milestone = $data->milestone;
$spec->begin = $data->begin;
$spec->end = $data->end;
$spec->version = $plan->version;
$spec->name = $plan->name;
$spec->milestone = $plan->milestone;
$spec->begin = $plan->begin;
$spec->end = $plan->end;
$this->dao->insert(TABLE_PROJECTSPEC)->data($spec)->exec();
if($project->hasProduct)
if($project->hasProduct and !empty($linkProducts))
{
$this->action->create('execution', $stageID, 'opened', '', join(',', $_POST['products']));
$this->action->create('execution', $stageID, 'opened', '', implode(',', $linkProducts));
}
else
{
+14 -17
View File
@@ -11,13 +11,13 @@ title=测试 todoModel->create();
timeout=0
cid=1
- 执行todoTest模块的createTest方法,参数是$todoWithoutName, $formData @0
- 执行todoTest模块的createTest方法,参数是$todoWithoutName @0
- 执行todoTest模块的createTest方法,参数是$todoInvalidEnd, $formData @0
- 执行todoTest模块的createTest方法,参数是$todoInvalidObjectID @0
- 执行todoTest模块的createTest方法,参数是$todo, $formData @2
- 执行todoTest模块的createTest方法,参数是$todo @6
- 执行todoTest模块的createTest方法,参数是$todoWithCycle, $formData @3
- 执行todoTest模块的createTest方法,参数是$todoWithCycle @7
*/
@@ -27,10 +27,6 @@ $tester->loadModel('todo');
zdTable('todo')->config('create')->gen(5);
$today = date('Y-m-d');
$formData = new stdClass;
$formData->rawdata = new stdclass;
$formData->rawdata->uid = '';
$todo = new stdclass;
$todo->name = 'TODO Create Test';
$todo->account = 'admin';
@@ -45,19 +41,20 @@ $todo->assignedDate = $today;
$todoWithoutName = clone $todo;
$todoWithoutName->name = '';
$todoInvalidEnd = clone $todo;
$todoInvalidEnd->name = 'todoInvalidDate';
$todoInvalidEnd->begin = '1000';
$todoInvalidEnd->end = '0800';
$todoInvalidObjectID = clone $todo;
$randModuleKey = array_rand($tester->config->todo->moduleList, 1);
$todoInvalidObjectID->name = 'todoInvalidObjectID';
$todoInvalidObjectID->type = $tester->config->todo->moduleList[$randModuleKey];
$todoInvalidObjectID->objectID = 0;
$todoWithCycle = clone $todo;
$todoWithCycle->type = 'cycle';
$todoWithCycle->cycle = 1;
$todoWithCycle->config = array('day' => 1, 'specify' => array('month' => 0, 'day' => 1), 'type' => 'day', 'beforeDays' => 1, 'end' => '');
$todoWithCycle->config = json_encode(array('day' => 1, 'specify' => array('month' => 0, 'day' => 1), 'type' => 'day', 'beforeDays' => 1, 'end' => ''));
$todoWithCycle->objectID = 0;
$todoTest = new todoTest();
r($todoTest->createTest($todoWithoutName, $formData)) && p() && e('0');
r($todoTest->createTest($todoInvalidEnd, $formData)) && p() && e('0');
r($todoTest->createTest($todo, $formData)) && p() && e('6');
r($todoTest->createTest($todoWithCycle, $formData)) && p() && e('7');
r($todoTest->createTest($todoWithoutName)) && p() && e('0');
r($todoTest->createTest($todoInvalidObjectID)) && p() && e('0');
r($todoTest->createTest($todo)) && p() && e('6');
r($todoTest->createTest($todoWithCycle)) && p() && e('7');
+2 -3
View File
@@ -13,13 +13,12 @@ class todoTest
* Test create a todo.
*
* @param object $todoData
* @param object $formData
* @access public
* @return int
*/
public function createTest($todoData, $formData)
public function createTest($todoData)
{
$objectID = $this->objectModel->create($todoData, $formData);
$objectID = $this->objectModel->create($todoData);
return $objectID ?: 0;
}