From c250f3b1b8b42652cd2f3b3f19ce36624e384ff0 Mon Sep 17 00:00:00 2001 From: Rafael de Camargo Date: Wed, 17 Jul 2019 18:32:16 -0300 Subject: Add option to clone filters on project duplication * Fixed missing metadata option from project "create from" * Added option to clone project custom filters * Added append option to custom field tests * Added a test that uses the "append" option * Fixed disabled swimlane duplication error with Postgresql --- app/Model/CustomFilterModel.php | 35 ++++++++++++++++++++++++++++++++ app/Model/ProjectDuplicationModel.php | 2 ++ app/Model/SwimlaneModel.php | 2 +- app/Template/project_creation/create.php | 2 ++ app/Template/project_view/duplicate.php | 1 + 5 files changed, 41 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/Model/CustomFilterModel.php b/app/Model/CustomFilterModel.php index a4c23b5c..7eb02a01 100644 --- a/app/Model/CustomFilterModel.php +++ b/app/Model/CustomFilterModel.php @@ -101,4 +101,39 @@ class CustomFilterModel extends Base { return $this->db->table(self::TABLE)->eq('id', $filter_id)->remove(); } + + /** + * Duplicate custom filters from a project to another one, must be executed inside a transaction + * + * @param integer $src_project_id Source project id + * @param integer $dst_project_id Destination project id + * @return boolean + */ + public function duplicate($src_project_id, $dst_project_id) + { + $filters = $this->db + ->table(self::TABLE) + ->columns( + self::TABLE.'.user_id', + self::TABLE.'.filter', + self::TABLE.'.name', + self::TABLE.'.is_shared', + self::TABLE.'.append' + ) + ->eq('project_id', $src_project_id) + ->findAll(); + + foreach ($filters as $filter) { + $filter['project_id'] = $dst_project_id; + // Avoid SQL error with Postgres + $filter['is_shared'] = $filter['is_shared'] ?: 0; + $filter['append'] = $filter['append'] ?: 0; + + if (! $this->db->table(self::TABLE)->save($filter)) { + return false; + } + } + + return true; + } } diff --git a/app/Model/ProjectDuplicationModel.php b/app/Model/ProjectDuplicationModel.php index a8f57709..90a9f03d 100644 --- a/app/Model/ProjectDuplicationModel.php +++ b/app/Model/ProjectDuplicationModel.php @@ -28,6 +28,7 @@ class ProjectDuplicationModel extends Base 'projectPermissionModel', 'actionModel', 'tagDuplicationModel', + 'customFilterModel', 'projectMetadataModel', 'projectTaskDuplicationModel', ); @@ -50,6 +51,7 @@ class ProjectDuplicationModel extends Base 'actionModel', 'swimlaneModel', 'tagDuplicationModel', + 'customFilterModel', 'projectMetadataModel', 'projectTaskDuplicationModel', ); diff --git a/app/Model/SwimlaneModel.php b/app/Model/SwimlaneModel.php index 2b3be912..0d204ae2 100644 --- a/app/Model/SwimlaneModel.php +++ b/app/Model/SwimlaneModel.php @@ -443,7 +443,7 @@ class SwimlaneModel extends Base 'name' => $swimlane['name'], 'description' => $swimlane['description'], 'position' => $swimlane['position'], - 'is_active' => $swimlane['is_active'], + 'is_active' => $swimlane['is_active'] ? self::ACTIVE : self::INACTIVE, // Avoid SQL error with Postgres 'project_id' => $projectDstId, ); diff --git a/app/Template/project_creation/create.php b/app/Template/project_creation/create.php index 01952f14..12eb3215 100644 --- a/app/Template/project_creation/create.php +++ b/app/Template/project_creation/create.php @@ -30,6 +30,8 @@ form->checkbox('categoryModel', t('Categories'), 1, true) ?> form->checkbox('tagDuplicationModel', t('Tags'), 1, true) ?> form->checkbox('actionModel', t('Actions'), 1, true) ?> + form->checkbox('customFilterModel', t('Custom filters'), 1, true) ?> + form->checkbox('projectMetadataModel', t('Metadata'), 1, false) ?> form->checkbox('projectTaskDuplicationModel', t('Tasks'), 1, false) ?> diff --git a/app/Template/project_view/duplicate.php b/app/Template/project_view/duplicate.php index e2f3677c..f0268f6b 100644 --- a/app/Template/project_view/duplicate.php +++ b/app/Template/project_view/duplicate.php @@ -18,6 +18,7 @@ form->checkbox('categoryModel', t('Categories'), 1, true) ?> form->checkbox('tagDuplicationModel', t('Tags'), 1, true) ?> form->checkbox('actionModel', t('Actions'), 1, true) ?> + form->checkbox('customFilterModel', t('Custom filters'), 1, true) ?> form->checkbox('projectMetadataModel', t('Metadata'), 1, false) ?> form->checkbox('projectTaskDuplicationModel', t('Tasks'), 1, false) ?> -- cgit v1.2.3