Move Task::duplicate() to class ProjectTaskDuplicationModel
This commit is contained in:
parent
6d5577fa0b
commit
b7ac354e83
|
|
@ -86,6 +86,7 @@ use Pimple\Container;
|
|||
* @property \Kanboard\Model\ProjectGroupRoleModel $projectGroupRoleModel
|
||||
* @property \Kanboard\Model\ProjectNotificationModel $projectNotificationModel
|
||||
* @property \Kanboard\Model\ProjectNotificationTypeModel $projectNotificationTypeModel
|
||||
* @property \Kanboard\Model\ProjectTaskDuplicationModel $projectTaskDuplicationModel
|
||||
* @property \Kanboard\Model\RememberMeSessionModel $rememberMeSessionModel
|
||||
* @property \Kanboard\Model\SubtaskModel $subtaskModel
|
||||
* @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class ProjectDuplicationModel extends Base
|
|||
'swimlaneModel',
|
||||
'tagDuplicationModel',
|
||||
'projectMetadataModel',
|
||||
'taskModel',
|
||||
'projectTaskDuplicationModel',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ class ProjectDuplicationModel extends Base
|
|||
'swimlaneModel',
|
||||
'tagDuplicationModel',
|
||||
'projectMetadataModel',
|
||||
'taskModel',
|
||||
'projectTaskDuplicationModel',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,80 +17,80 @@ class TaskModel extends Base
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
const TABLE = 'tasks';
|
||||
const TABLE = 'tasks';
|
||||
|
||||
/**
|
||||
* Task status
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const STATUS_OPEN = 1;
|
||||
const STATUS_CLOSED = 0;
|
||||
const STATUS_OPEN = 1;
|
||||
const STATUS_CLOSED = 0;
|
||||
|
||||
/**
|
||||
* Events
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const EVENT_MOVE_PROJECT = 'task.move.project';
|
||||
const EVENT_MOVE_COLUMN = 'task.move.column';
|
||||
const EVENT_MOVE_POSITION = 'task.move.position';
|
||||
const EVENT_MOVE_SWIMLANE = 'task.move.swimlane';
|
||||
const EVENT_UPDATE = 'task.update';
|
||||
const EVENT_CREATE = 'task.create';
|
||||
const EVENT_CLOSE = 'task.close';
|
||||
const EVENT_OPEN = 'task.open';
|
||||
const EVENT_CREATE_UPDATE = 'task.create_update';
|
||||
const EVENT_MOVE_PROJECT = 'task.move.project';
|
||||
const EVENT_MOVE_COLUMN = 'task.move.column';
|
||||
const EVENT_MOVE_POSITION = 'task.move.position';
|
||||
const EVENT_MOVE_SWIMLANE = 'task.move.swimlane';
|
||||
const EVENT_UPDATE = 'task.update';
|
||||
const EVENT_CREATE = 'task.create';
|
||||
const EVENT_CLOSE = 'task.close';
|
||||
const EVENT_OPEN = 'task.open';
|
||||
const EVENT_CREATE_UPDATE = 'task.create_update';
|
||||
const EVENT_ASSIGNEE_CHANGE = 'task.assignee_change';
|
||||
const EVENT_OVERDUE = 'task.overdue';
|
||||
const EVENT_USER_MENTION = 'task.user.mention';
|
||||
const EVENT_DAILY_CRONJOB = 'task.cronjob.daily';
|
||||
const EVENT_OVERDUE = 'task.overdue';
|
||||
const EVENT_USER_MENTION = 'task.user.mention';
|
||||
const EVENT_DAILY_CRONJOB = 'task.cronjob.daily';
|
||||
|
||||
/**
|
||||
* Recurrence: status
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const RECURRING_STATUS_NONE = 0;
|
||||
const RECURRING_STATUS_PENDING = 1;
|
||||
const RECURRING_STATUS_PROCESSED = 2;
|
||||
const RECURRING_STATUS_NONE = 0;
|
||||
const RECURRING_STATUS_PENDING = 1;
|
||||
const RECURRING_STATUS_PROCESSED = 2;
|
||||
|
||||
/**
|
||||
* Recurrence: trigger
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const RECURRING_TRIGGER_FIRST_COLUMN = 0;
|
||||
const RECURRING_TRIGGER_LAST_COLUMN = 1;
|
||||
const RECURRING_TRIGGER_CLOSE = 2;
|
||||
const RECURRING_TRIGGER_FIRST_COLUMN = 0;
|
||||
const RECURRING_TRIGGER_LAST_COLUMN = 1;
|
||||
const RECURRING_TRIGGER_CLOSE = 2;
|
||||
|
||||
/**
|
||||
* Recurrence: timeframe
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const RECURRING_TIMEFRAME_DAYS = 0;
|
||||
const RECURRING_TIMEFRAME_MONTHS = 1;
|
||||
const RECURRING_TIMEFRAME_YEARS = 2;
|
||||
const RECURRING_TIMEFRAME_DAYS = 0;
|
||||
const RECURRING_TIMEFRAME_MONTHS = 1;
|
||||
const RECURRING_TIMEFRAME_YEARS = 2;
|
||||
|
||||
/**
|
||||
* Recurrence: base date used to calculate new due date
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const RECURRING_BASEDATE_DUEDATE = 0;
|
||||
const RECURRING_BASEDATE_TRIGGERDATE = 1;
|
||||
const RECURRING_BASEDATE_DUEDATE = 0;
|
||||
const RECURRING_BASEDATE_TRIGGERDATE = 1;
|
||||
|
||||
/**
|
||||
* Remove a task
|
||||
*
|
||||
* @access public
|
||||
* @param integer $task_id Task id
|
||||
* @param integer $task_id Task id
|
||||
* @return boolean
|
||||
*/
|
||||
public function remove($task_id)
|
||||
{
|
||||
if (! $this->taskFinderModel->exists($task_id)) {
|
||||
if (!$this->taskFinderModel->exists($task_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class TaskModel extends Base
|
|||
* Example: "Fix bug #1234" will return 1234
|
||||
*
|
||||
* @access public
|
||||
* @param string $message Text
|
||||
* @param string $message Text
|
||||
* @return integer
|
||||
*/
|
||||
public function getTaskIdFromText($message)
|
||||
|
|
@ -179,8 +179,8 @@ class TaskModel extends Base
|
|||
* Get task progress based on the column position
|
||||
*
|
||||
* @access public
|
||||
* @param array $task
|
||||
* @param array $columns
|
||||
* @param array $task
|
||||
* @param array $columns
|
||||
* @return integer
|
||||
*/
|
||||
public function getProgress(array $task, array $columns)
|
||||
|
|
@ -201,25 +201,4 @@ class TaskModel extends Base
|
|||
|
||||
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',
|
||||
'ProjectMetadataModel',
|
||||
'ProjectGroupRoleModel',
|
||||
'ProjectTaskDuplicationModel',
|
||||
'ProjectUserRoleModel',
|
||||
'RememberMeSessionModel',
|
||||
'SubtaskModel',
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
<?= $this->form->checkbox('tagDuplicationModel', t('Tags'), 1, true) ?>
|
||||
<?= $this->form->checkbox('actionModel', t('Actions'), 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 class="form-actions">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<?= $this->form->checkbox('actionModel', t('Actions'), 1, true) ?>
|
||||
<?= $this->form->checkbox('swimlaneModel', t('Swimlanes'), 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">
|
||||
<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(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
|
||||
$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(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
|
||||
$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(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);
|
||||
$this->assertCount(3, $tasks);
|
||||
|
|
|
|||
Loading…
Reference in New Issue