From 4e16f64af0a95f0968cbdb37a8f6ec79fc18bdb7 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 9 Aug 2018 12:13:06 +0200 Subject: [PATCH] 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