From ff8734f21d9c313f3100288a4a16a143a6ae6206 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mudr=C3=A1k?= Date: Fri, 15 Jun 2012 16:46:08 +0200 Subject: [PATCH] MDL-33430 Give tasks an access to their current plan's results This in turn provides access to the plan's results for both structure and execution steps so they can register something useful there. --- backup/util/plan/base_plan.class.php | 17 +++++++++++++++++ backup/util/plan/base_task.class.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/backup/util/plan/base_plan.class.php b/backup/util/plan/base_plan.class.php index eab1869d6d3..d8c4b4d7c98 100644 --- a/backup/util/plan/base_plan.class.php +++ b/backup/util/plan/base_plan.class.php @@ -75,10 +75,27 @@ abstract class base_plan implements checksumable, executable { return $this->tasks; } + /** + * Add the passed info to the plan results + * + * At the moment we expect an associative array structure to be merged into + * the current results. In the future, some sort of base_result class may + * be introduced. + * + * @param array $result associative array describing a result of a task/step + */ public function add_result($result) { + if (!is_array($result)) { + throw new coding_exception('Associative array is expected as a parameter of add_result()'); + } $this->results = array_merge($this->results, $result); } + /** + * Return the results collected via {@link self::add_result()} method + * + * @return array + */ public function get_results() { return $this->results; } diff --git a/backup/util/plan/base_task.class.php b/backup/util/plan/base_task.class.php index 1527634713f..440521b54de 100644 --- a/backup/util/plan/base_task.class.php +++ b/backup/util/plan/base_task.class.php @@ -154,7 +154,7 @@ abstract class base_task implements checksumable, executable, loggable { // If step returns array, it will be forwarded to plan // (TODO: shouldn't be array but proper result object) if (is_array($result) and !empty($result)) { - $this->plan->add_result($result); + $this->add_result($result); } } // Mark as executed if any step has been executed @@ -191,6 +191,34 @@ abstract class base_task implements checksumable, executable, loggable { backup_general_helper::array_checksum_recursive($this->steps)); } + /** + * Add the given info to the current plan's results. + * + * @see base_plan::add_result() + * @param array $result associative array describing a result of a task/step + */ + public function add_result($result) { + if (!is_null($this->plan)) { + $this->plan->add_result($result); + } else { + debugging('Attempting to add a result of a task not binded with a plan', DEBUG_DEVELOPER); + } + } + + /** + * Return the current plan's results + * + * @return array|null + */ + public function get_results() { + if (!is_null($this->plan)) { + return $this->plan->get_results(); + } else { + debugging('Attempting to get results of a task not binded with a plan', DEBUG_DEVELOPER); + return null; + } + } + // Protected API starts here /** -- 2.11.4.GIT