diff options
author | Rafael de Camargo <rafacamargo123@gmail.com> | 2019-07-17 18:32:16 -0300 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2019-07-17 14:32:16 -0700 |
commit | c250f3b1b8b42652cd2f3b3f19ce36624e384ff0 (patch) | |
tree | 3018a2b8a5a7ad2fcfbc79c8f755a1e0875b67f3 /app/Model/CustomFilterModel.php | |
parent | d3be738d4f698ccc387e256dba314edcfa043e05 (diff) |
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
Diffstat (limited to 'app/Model/CustomFilterModel.php')
-rw-r--r-- | app/Model/CustomFilterModel.php | 35 |
1 files changed, 35 insertions, 0 deletions
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; + } } |