From 0a772b3c3f581537fd77393139cf75b5d5f4f1dd Mon Sep 17 00:00:00 2001 From: Ludovic <54670129+lbr38@users.noreply.github.com> Date: Tue, 31 Dec 2024 14:19:03 +0100 Subject: [PATCH] patch --- .../Container/vars/tasks/log.vars.inc.php | 2 +- www/controllers/Task/Log/Step.php | 2 +- www/controllers/Task/Log/SubStep.php | 28 +++++++++++++++++++ www/controllers/Task/Repo/Create.php | 10 ++++--- www/controllers/Task/Repo/Delete.php | 5 ++-- www/controllers/Task/Repo/Duplicate.php | 5 ++-- www/controllers/Task/Repo/Env.php | 5 ++-- www/controllers/Task/Repo/Rebuild.php | 5 ++-- www/controllers/Task/Repo/RemoveEnv.php | 5 ++-- www/controllers/Task/Repo/Update.php | 5 ++-- 10 files changed, 54 insertions(+), 18 deletions(-) diff --git a/www/controllers/Layout/Container/vars/tasks/log.vars.inc.php b/www/controllers/Layout/Container/vars/tasks/log.vars.inc.php index b8644663..30e27314 100644 --- a/www/controllers/Layout/Container/vars/tasks/log.vars.inc.php +++ b/www/controllers/Layout/Container/vars/tasks/log.vars.inc.php @@ -104,7 +104,7 @@ if (!empty($rawParams['snap-id'])) { $snapId = $rawParams['snap-id']; } - // If the action is removeEnv, the environment has been removed, so it + // If the action is removeEnv, the environment has been removed, so it if ($rawParams['action'] != 'removeEnv') { if (!empty($rawParams['env-id'])) { $envId = $rawParams['env-id']; diff --git a/www/controllers/Task/Log/Step.php b/www/controllers/Task/Log/Step.php index 415e80d1..0e6c364d 100644 --- a/www/controllers/Task/Log/Step.php +++ b/www/controllers/Task/Log/Step.php @@ -58,7 +58,7 @@ public function completed(string $message = '') : void /** * Set the latest step as error */ - public function error(string $message) : void + public function error(string $message = '') : void { /** * Get latest step Id from database diff --git a/www/controllers/Task/Log/SubStep.php b/www/controllers/Task/Log/SubStep.php index 0d55380b..3196e4c6 100644 --- a/www/controllers/Task/Log/SubStep.php +++ b/www/controllers/Task/Log/SubStep.php @@ -99,6 +99,34 @@ public function warning(string $message) : void } } + /** + * Set the latest sub-step as error + */ + public function error(string $message) : void + { + /** + * Get latest step Id + */ + $stepId = $this->stepController->getLatestStepId($this->taskId); + + /** + * Get latest sub-step Id + */ + $substepId = $this->getLatestSubStepId($stepId); + + /** + * Add error message to output + */ + $this->output($message, 'error'); + + /** + * If there was substeps, mark latest substep as error in database + */ + if (!empty($substepId)) { + $this->model->status($substepId, 'error'); + } + } + /** * Set the latest sub-step as stopped */ diff --git a/www/controllers/Task/Repo/Create.php b/www/controllers/Task/Repo/Create.php index 225df6e0..decacf23 100644 --- a/www/controllers/Task/Repo/Create.php +++ b/www/controllers/Task/Repo/Create.php @@ -160,8 +160,9 @@ private function mirror() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set step error message - $this->taskLogStepController->error($e->getMessage()); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set task status to error $this->task->setStatus('error'); @@ -373,8 +374,9 @@ private function local() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set step error message - $this->taskLogStepController->error($e->getMessage()); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set task status to error $this->task->setStatus('error'); diff --git a/www/controllers/Task/Repo/Delete.php b/www/controllers/Task/Repo/Delete.php index c03183fd..221bdedc 100644 --- a/www/controllers/Task/Repo/Delete.php +++ b/www/controllers/Task/Repo/Delete.php @@ -145,8 +145,9 @@ public function execute() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set step error message - $this->taskLogStepController->error($e->getMessage()); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set task status to error $this->task->setStatus('error'); diff --git a/www/controllers/Task/Repo/Duplicate.php b/www/controllers/Task/Repo/Duplicate.php index a02d1a1e..9630aa04 100644 --- a/www/controllers/Task/Repo/Duplicate.php +++ b/www/controllers/Task/Repo/Duplicate.php @@ -273,8 +273,9 @@ public function execute() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set step error message - $this->taskLogStepController->error($e->getMessage()); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set task status to error $this->task->setStatus('error'); diff --git a/www/controllers/Task/Repo/Env.php b/www/controllers/Task/Repo/Env.php index 4c1a8e75..7d706f7f 100644 --- a/www/controllers/Task/Repo/Env.php +++ b/www/controllers/Task/Repo/Env.php @@ -323,8 +323,9 @@ public function execute() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set step error message - $this->taskLogStepController->error($e->getMessage()); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set task status to error $this->task->setStatus('error'); diff --git a/www/controllers/Task/Repo/Rebuild.php b/www/controllers/Task/Repo/Rebuild.php index b9484738..ce61c340 100644 --- a/www/controllers/Task/Repo/Rebuild.php +++ b/www/controllers/Task/Repo/Rebuild.php @@ -106,8 +106,9 @@ public function execute() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set snapshot metadata rebuild state in database - $this->repo->snapSetRebuild($this->repo->getSnapId(), 'failed'); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set step error message $this->taskLogStepController->error($e->getMessage()); diff --git a/www/controllers/Task/Repo/RemoveEnv.php b/www/controllers/Task/Repo/RemoveEnv.php index 5177dce1..039b2bfb 100644 --- a/www/controllers/Task/Repo/RemoveEnv.php +++ b/www/controllers/Task/Repo/RemoveEnv.php @@ -110,8 +110,9 @@ public function execute() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set step error message - $this->taskLogStepController->error($e->getMessage()); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set task status to error $this->task->setStatus('error'); diff --git a/www/controllers/Task/Repo/Update.php b/www/controllers/Task/Repo/Update.php index c72ce031..3118e15d 100644 --- a/www/controllers/Task/Repo/Update.php +++ b/www/controllers/Task/Repo/Update.php @@ -142,8 +142,9 @@ public function execute() $this->task->setStatus('done'); $this->task->updateStatus($this->task->getId(), 'done'); } catch (Exception $e) { - // Set step error message - $this->taskLogStepController->error($e->getMessage()); + // Set sub step error message and mark step as error + $this->taskLogSubStepController->error($e->getMessage()); + $this->taskLogStepController->error(); // Set task status to error $this->task->setStatus('error');