FIX : we can't update task if closed project because of wrong test with PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE conf

This commit is contained in:
Gauthier PC portable 024 2021-04-06 16:59:00 +02:00
parent 10fb793fb1
commit 04cb8453f0

View File

@ -402,20 +402,23 @@ class Task extends CommonObject
if (!$error && !empty($conf->global->PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE)) { if (!$error && !empty($conf->global->PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE)) {
// Close the parent project if it is open (validated) and its tasks are 100% completed // Close the parent project if it is open (validated) and its tasks are 100% completed
$project = new Project($this->db); $project = new Project($this->db);
if ($project->fetch($this->fk_project) > 0 && $project->statut == Project::STATUS_VALIDATED) { if ($project->fetch($this->fk_project) > 0) {
$project->getLinesArray(null); // this method does not return <= 0 if fails if($project->statut == Project::STATUS_VALIDATED) {
$projectCompleted = array_reduce( $project->getLinesArray(null); // this method does not return <= 0 if fails
$project->lines, $projectCompleted = array_reduce(
function ($allTasksCompleted, $task) { $project->lines,
return $allTasksCompleted && $task->progress >= 100; function ($allTasksCompleted, $task) {
}, return $allTasksCompleted && $task->progress >= 100;
},
1 1
); );
if ($projectCompleted) { if ($projectCompleted) {
if ($project->setClose($user) <= 0) { if ($project->setClose($user) <= 0) {
$error++; $error++;
}
} }
} }
} else { } else {
$error++; $error++;
} }