Merge pull request #9226 from atm-greg/Fix_project_delete_tasks
Fix project delete tasks
This commit is contained in:
commit
009424cd67
@ -633,9 +633,8 @@ class Project extends CommonObject
|
|||||||
$this->getLinesArray($user);
|
$this->getLinesArray($user);
|
||||||
|
|
||||||
// Delete tasks
|
// Delete tasks
|
||||||
foreach($this->lines as &$task) {
|
$ret = $this->deleteTasks($user);
|
||||||
$task->delete($user);
|
if ($ret < 0) $error++;
|
||||||
}
|
|
||||||
|
|
||||||
// Delete project
|
// Delete project
|
||||||
if (! $error)
|
if (! $error)
|
||||||
@ -711,6 +710,40 @@ class Project extends CommonObject
|
|||||||
return -1;
|
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
|
* Validate a project
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user