From 1fc6d69e2e25d6e4feaa38fe03dab98c75cfb36c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 25 Jan 2015 18:08:28 -0500 Subject: Fix bug duplicate project with a too long name --- app/Model/Base.php | 1 + app/Model/Project.php | 59 -------------------------- app/Model/ProjectDuplication.php | 89 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 59 deletions(-) create mode 100644 app/Model/ProjectDuplication.php (limited to 'app/Model') diff --git a/app/Model/Base.php b/app/Model/Base.php index a6333144..785785a7 100644 --- a/app/Model/Base.php +++ b/app/Model/Base.php @@ -27,6 +27,7 @@ use Pimple\Container; * @property \Model\LastLogin $lastLogin * @property \Model\Notification $notification * @property \Model\Project $project + * @property \Model\ProjectDuplication $projectDuplication * @property \Model\ProjectPermission $projectPermission * @property \Model\SubTask $subTask * @property \Model\SubtaskHistory $subtaskHistory diff --git a/app/Model/Project.php b/app/Model/Project.php index a072a5c1..f802e4ed 100644 --- a/app/Model/Project.php +++ b/app/Model/Project.php @@ -261,65 +261,6 @@ class Project extends Base ->filter(array($this, 'applyColumnStats')); } - /** - * Create a project from another one. - * - * @author Antonio Rabelo - * @param integer $project_id Project Id - * @return integer Cloned Project Id - */ - public function createProjectFromAnotherProject($project_id) - { - $project = $this->getById($project_id); - - $values = array( - 'name' => $project['name'].' ('.t('Clone').')', - 'is_active' => true, - 'last_modified' => 0, - 'token' => '', - 'is_public' => 0, - 'is_private' => empty($project['is_private']) ? 0 : 1, - ); - - if (! $this->db->table(self::TABLE)->save($values)) { - return 0; - } - - return $this->db->getConnection()->getLastId(); - } - - /** - * Clone a project - * - * @author Antonio Rabelo - * @param integer $project_id Project Id - * @return integer Cloned Project Id - */ - public function duplicate($project_id) - { - $this->db->startTransaction(); - - // Get the cloned project Id - $clone_project_id = $this->createProjectFromAnotherProject($project_id); - - if (! $clone_project_id) { - $this->db->cancelTransaction(); - return false; - } - - foreach (array('board', 'category', 'projectPermission', 'action') as $model) { - - if (! $this->$model->duplicate($project_id, $clone_project_id)) { - $this->db->cancelTransaction(); - return false; - } - } - - $this->db->closeTransaction(); - - return (int) $clone_project_id; - } - /** * Create a project * diff --git a/app/Model/ProjectDuplication.php b/app/Model/ProjectDuplication.php new file mode 100644 index 00000000..11a606d7 --- /dev/null +++ b/app/Model/ProjectDuplication.php @@ -0,0 +1,89 @@ + 50) { + $name = substr($name, 0, 50 - strlen($suffix)); + } + + return $name.$suffix; + } + + /** + * Create a project from another one + * + * @param integer $project_id Project Id + * @return integer Cloned Project Id + */ + public function copy($project_id) + { + $project = $this->project->getById($project_id); + + $values = array( + 'name' => $this->getClonedProjectName($project['name']), + 'is_active' => true, + 'last_modified' => 0, + 'token' => '', + 'is_public' => 0, + 'is_private' => empty($project['is_private']) ? 0 : 1, + ); + + if (! $this->db->table(Project::TABLE)->save($values)) { + return 0; + } + + return $this->db->getConnection()->getLastId(); + } + + /** + * Clone a project with all settings + * + * @param integer $project_id Project Id + * @return integer Cloned Project Id + */ + public function duplicate($project_id) + { + $this->db->startTransaction(); + + // Get the cloned project Id + $clone_project_id = $this->copy($project_id); + + if (! $clone_project_id) { + $this->db->cancelTransaction(); + return false; + } + + foreach (array('board', 'category', 'projectPermission', 'action') as $model) { + + if (! $this->$model->duplicate($project_id, $clone_project_id)) { + $this->db->cancelTransaction(); + return false; + } + } + + $this->db->closeTransaction(); + + return (int) $clone_project_id; + } +} -- cgit v1.2.3