Move Task::duplicate() to class ProjectTaskDuplicationModel
This commit is contained in:
@@ -86,6 +86,7 @@ use Pimple\Container;
|
|||||||
* @property \Kanboard\Model\ProjectGroupRoleModel $projectGroupRoleModel
|
* @property \Kanboard\Model\ProjectGroupRoleModel $projectGroupRoleModel
|
||||||
* @property \Kanboard\Model\ProjectNotificationModel $projectNotificationModel
|
* @property \Kanboard\Model\ProjectNotificationModel $projectNotificationModel
|
||||||
* @property \Kanboard\Model\ProjectNotificationTypeModel $projectNotificationTypeModel
|
* @property \Kanboard\Model\ProjectNotificationTypeModel $projectNotificationTypeModel
|
||||||
|
* @property \Kanboard\Model\ProjectTaskDuplicationModel $projectTaskDuplicationModel
|
||||||
* @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel
|
* @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel
|
||||||
* @property \Kanboard\Model\SubtaskModel $subtaskModel
|
* @property \Kanboard\Model\SubtaskModel $subtaskModel
|
||||||
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
|
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class ProjectDuplicationModel extends Base
|
|||||||
'swimlaneModel',
|
'swimlaneModel',
|
||||||
'tagDuplicationModel',
|
'tagDuplicationModel',
|
||||||
'projectMetadataModel',
|
'projectMetadataModel',
|
||||||
'taskModel',
|
'projectTaskDuplicationModel',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ class ProjectDuplicationModel extends Base
|
|||||||
'swimlaneModel',
|
'swimlaneModel',
|
||||||
'tagDuplicationModel',
|
'tagDuplicationModel',
|
||||||
'projectMetadataModel',
|
'projectMetadataModel',
|
||||||
'taskModel',
|
'projectTaskDuplicationModel',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
35
app/Model/ProjectTaskDuplicationModel.php
Normal file
35
app/Model/ProjectTaskDuplicationModel.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Kanboard\Model;
|
||||||
|
|
||||||
|
use Kanboard\Core\Base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project Task Duplication Model
|
||||||
|
*
|
||||||
|
* @package Kanboard\Model
|
||||||
|
* @author Frederic Guillot
|
||||||
|
*/
|
||||||
|
class ProjectTaskDuplicationModel extends Base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Duplicate all tasks to another project
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param integer $src_project_id
|
||||||
|
* @param integer $dst_project_id
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function duplicate($src_project_id, $dst_project_id)
|
||||||
|
{
|
||||||
|
$task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED));
|
||||||
|
|
||||||
|
foreach ($task_ids as $task_id) {
|
||||||
|
if (! $this->taskProjectDuplicationModel->duplicateToProject($task_id, $dst_project_id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -201,25 +201,4 @@ class TaskModel extends Base
|
|||||||
|
|
||||||
return round(($position * 100) / count($columns), 1);
|
return round(($position * 100) / count($columns), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to duplicate all tasks to another project
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @param integer $src_project_id
|
|
||||||
* @param integer $dst_project_id
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function duplicate($src_project_id, $dst_project_id)
|
|
||||||
{
|
|
||||||
$task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED));
|
|
||||||
|
|
||||||
foreach ($task_ids as $task_id) {
|
|
||||||
if (! $this->taskProjectDuplicationModel->duplicateToProject($task_id, $dst_project_id)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class ClassProvider implements ServiceProviderInterface
|
|||||||
'ProjectNotificationModel',
|
'ProjectNotificationModel',
|
||||||
'ProjectMetadataModel',
|
'ProjectMetadataModel',
|
||||||
'ProjectGroupRoleModel',
|
'ProjectGroupRoleModel',
|
||||||
|
'ProjectTaskDuplicationModel',
|
||||||
'ProjectUserRoleModel',
|
'ProjectUserRoleModel',
|
||||||
'RememberMeSessionModel',
|
'RememberMeSessionModel',
|
||||||
'SubtaskModel',
|
'SubtaskModel',
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<?= $this->form->checkbox('tagDuplicationModel', t('Tags'), 1, true) ?>
|
<?= $this->form->checkbox('tagDuplicationModel', t('Tags'), 1, true) ?>
|
||||||
<?= $this->form->checkbox('actionModel', t('Actions'), 1, true) ?>
|
<?= $this->form->checkbox('actionModel', t('Actions'), 1, true) ?>
|
||||||
<?= $this->form->checkbox('swimlaneModel', t('Swimlanes'), 1, true) ?>
|
<?= $this->form->checkbox('swimlaneModel', t('Swimlanes'), 1, true) ?>
|
||||||
<?= $this->form->checkbox('taskModel', t('Tasks'), 1, false) ?>
|
<?= $this->form->checkbox('projectTaskDuplicationModel', t('Tasks'), 1, false) ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<?= $this->form->checkbox('actionModel', t('Actions'), 1, true) ?>
|
<?= $this->form->checkbox('actionModel', t('Actions'), 1, true) ?>
|
||||||
<?= $this->form->checkbox('swimlaneModel', t('Swimlanes'), 1, false) ?>
|
<?= $this->form->checkbox('swimlaneModel', t('Swimlanes'), 1, false) ?>
|
||||||
<?= $this->form->checkbox('projectMetadataModel', t('Metadata'), 1, false) ?>
|
<?= $this->form->checkbox('projectMetadataModel', t('Metadata'), 1, false) ?>
|
||||||
<?= $this->form->checkbox('taskModel', t('Tasks'), 1, false) ?>
|
<?= $this->form->checkbox('projectTaskDuplicationModel', t('Tasks'), 1, false) ?>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button type="submit" class="btn btn-red"><?= t('Duplicate') ?></button>
|
<button type="submit" class="btn btn-red"><?= t('Duplicate') ?></button>
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ class ProjectDuplicationModelTest extends Base
|
|||||||
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2)));
|
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2)));
|
||||||
$this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3)));
|
$this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3)));
|
||||||
|
|
||||||
$this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'taskModel')));
|
$this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'projectTaskDuplicationModel')));
|
||||||
|
|
||||||
// Check if Tasks have been duplicated
|
// Check if Tasks have been duplicated
|
||||||
$tasks = $taskFinderModel->getAll(2);
|
$tasks = $taskFinderModel->getAll(2);
|
||||||
@@ -458,7 +458,7 @@ class ProjectDuplicationModelTest extends Base
|
|||||||
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
|
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
|
||||||
$this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
$this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
|
||||||
|
|
||||||
$this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'taskModel')));
|
$this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'projectTaskDuplicationModel')));
|
||||||
|
|
||||||
// Check if Swimlanes have been duplicated
|
// Check if Swimlanes have been duplicated
|
||||||
$swimlanes = $swimlaneModel->getAll(2);
|
$swimlanes = $swimlaneModel->getAll(2);
|
||||||
@@ -496,7 +496,7 @@ class ProjectDuplicationModelTest extends Base
|
|||||||
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'tags' => array('A', 'B'))));
|
$this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'tags' => array('A', 'B'))));
|
||||||
$this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'tags' => array('C'))));
|
$this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'tags' => array('C'))));
|
||||||
|
|
||||||
$this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'taskModel')));
|
$this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'projectTaskDuplicationModel')));
|
||||||
|
|
||||||
$tasks = $taskFinderModel->getAll(2);
|
$tasks = $taskFinderModel->getAll(2);
|
||||||
$this->assertCount(3, $tasks);
|
$this->assertCount(3, $tasks);
|
||||||
|
|||||||
Reference in New Issue
Block a user