Skip to content

Commit

Permalink
Merge pull request #9226 from atm-greg/Fix_project_delete_tasks
Browse files Browse the repository at this point in the history
Fix project delete tasks
  • Loading branch information
eldy committed Aug 21, 2018
2 parents e88b68f + 91bfa4b commit 009424c
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions htdocs/projet/class/project.class.php
Expand Up @@ -633,9 +633,8 @@ function delete($user, $notrigger=0)
$this->getLinesArray($user);

// Delete tasks
foreach($this->lines as &$task) {
$task->delete($user);
}
$ret = $this->deleteTasks($user);
if ($ret < 0) $error++;

// Delete project
if (! $error)
Expand Down Expand Up @@ -711,6 +710,40 @@ function delete($user, $notrigger=0)
return -1;
}
}

/**
* Delete tasks with no children first, then task with children recursively
*
* @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)
$deleted = true;
$ret = $task->delete($user);
if ($ret <= 0)
{
$this->errors[] = $this->db->lasterror();
return -1;
}
}
}
}
$this->getLinesArray($user);
if ($deleted && count($this->lines) < $countTasks)
{
if (count($this->lines)) $this->deleteTasks($this->lines);
}

return 1;
}

/**
* Validate a project
Expand Down

0 comments on commit 009424c

Please sign in to comment.