From 4e16f64af0a95f0968cbdb37a8f6ec79fc18bdb7 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 9 Aug 2018 12:13:06 +0200 Subject: [PATCH 1/5] Fix project::delete to delete children tasks before parent tasks --- htdocs/projet/class/project.class.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 5dce267d965..6710aa98ffc 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -633,9 +633,7 @@ class Project extends CommonObject $this->getLinesArray($user); // Delete tasks - foreach($this->lines as &$task) { - $task->delete($user); - } + $this->deleteTasks($this->lines); // Delete project if (! $error) @@ -711,6 +709,25 @@ class Project extends CommonObject return -1; } } + + /** + * Reoder tasks to delete children tasks first + * + * @param array $arr Array of tasks + */ + function deleteTasks($arr) + { + global $user; + + $arrParents = array(); + foreach($arr as $task) + { + if($task->hasChildren() < 0) $task->delete($user); + else $arrParents[] = $task; + } + + if (count($arrParents)) $this->deleteTasks($arrParents); + } /** * Validate a project From 3d84adbd7635e772d9d38da435a6e00c9c37d6cd Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 9 Aug 2018 12:21:48 +0200 Subject: [PATCH 2/5] fix recurcivity --- htdocs/projet/class/project.class.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 6710aa98ffc..2292487898d 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -719,14 +719,12 @@ class Project extends CommonObject { global $user; - $arrParents = array(); foreach($arr as $task) { - if($task->hasChildren() < 0) $task->delete($user); - else $arrParents[] = $task; + if($task->hasChildren() <= 0) $task->delete($user); } - - if (count($arrParents)) $this->deleteTasks($arrParents); + $this->getLinesArray($user); + if (count($this->lines)) $this->deleteTasks($this->lines); } /** From ba6f7d4b0a1daba4ab391e76fc39d30eefe84699 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Tue, 14 Aug 2018 09:32:43 +0200 Subject: [PATCH 3/5] fix infinite loop --- htdocs/projet/class/project.class.php | 32 ++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 2292487898d..4413e9b3361 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -633,7 +633,8 @@ class Project extends CommonObject $this->getLinesArray($user); // Delete tasks - $this->deleteTasks($this->lines); + $ret = $this->deleteTasks($user); + if ($ret < 0) $error++; // Delete project if (! $error) @@ -715,16 +716,31 @@ class Project extends CommonObject * * @param array $arr Array of tasks */ - function deleteTasks($arr) + function deleteTasks($user) { - global $user; - - foreach($arr as $task) - { - if($task->hasChildren() <= 0) $task->delete($user); + $countTasks = count($this->lines); + $deleted = false; + if ($countTasks){ + foreach($this->lines as $task) + { + if($task->hasChildren() <= 0) { + $deleted = true; + $ret = $task->delete($user); + if ($ret < 1) + { + $this->errors[] = $this->db->lasterror(); + return -1; + } + } + } } $this->getLinesArray($user); - if (count($this->lines)) $this->deleteTasks($this->lines); + if($deleted && count($this->lines) < $countTasks) + { + if (count($this->lines)) $this->deleteTasks($this->lines); + } + + return 1; } /** From 3523c2b3d2461fec5e223696b26e87a64e9b56fe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Aug 2018 13:09:06 +0200 Subject: [PATCH 4/5] Update project.class.php --- htdocs/projet/class/project.class.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 4413e9b3361..ebc887ccbb6 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -712,21 +712,22 @@ class Project extends CommonObject } /** - * Reoder tasks to delete children tasks first + * Delete tasks with no children first, then task with children recursively * - * @param array $arr Array of tasks + * @param int <0 if KO, 1 if OK */ function deleteTasks($user) { $countTasks = count($this->lines); $deleted = false; - if ($countTasks){ + if ($countTasks) + { foreach($this->lines as $task) { - if($task->hasChildren() <= 0) { + if ($task->hasChildren() <= 0) { // If there is no children (or error to detect them) $deleted = true; $ret = $task->delete($user); - if ($ret < 1) + if ($ret <= 0) { $this->errors[] = $this->db->lasterror(); return -1; @@ -735,7 +736,7 @@ class Project extends CommonObject } } $this->getLinesArray($user); - if($deleted && count($this->lines) < $countTasks) + if ($deleted && count($this->lines) < $countTasks) { if (count($this->lines)) $this->deleteTasks($this->lines); } From 91bfa4be6cb9022f7474cb53cc8518feeff6c4f1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Aug 2018 13:10:20 +0200 Subject: [PATCH 5/5] Update project.class.php --- htdocs/projet/class/project.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index ebc887ccbb6..59a8db62dab 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -714,14 +714,15 @@ class Project extends CommonObject /** * Delete tasks with no children first, then task with children recursively * - * @param int <0 if KO, 1 if OK + * @param User $user User + * @return int <0 if KO, 1 if OK */ function deleteTasks($user) { $countTasks = count($this->lines); $deleted = false; if ($countTasks) - { + { foreach($this->lines as $task) { if ($task->hasChildren() <= 0) { // If there is no children (or error to detect them)