From becd11a84a69fbd3092ad7c3fea4056552c4a2e5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 20 Feb 2024 10:54:12 +0800 Subject: [PATCH 1/2] MDL-80862 testing: Reset task manager between behat tests --- lib/behat/classes/util.php | 3 +++ lib/classes/task/manager.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/behat/classes/util.php b/lib/behat/classes/util.php index 8237f6013ce..1b15f106ab8 100644 --- a/lib/behat/classes/util.php +++ b/lib/behat/classes/util.php @@ -435,6 +435,9 @@ class behat_util extends testing_util { // Inform data generator. self::get_data_generator()->reset(); + // Reset the task manager. + \core\task\manager::reset_state(); + // Initialise $CFG with default values. This is needed for behat cli process, so we don't have modified // $CFG values from the old run. @see set_config. self::remove_added_config(); diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php index 4b56f81438f..657d47e272c 100644 --- a/lib/classes/task/manager.php +++ b/lib/classes/task/manager.php @@ -75,6 +75,15 @@ class manager { */ public static $mode; + /** + * Reset the state of the task manager. + */ + public static function reset_state(): void { + self::$miniqueue = null; + self::$numtasks = null; + self::$mode = null; + } + /** * Given a component name, will load the list of tasks in the db/tasks.php file for that component. * From 8ebd9f08e4ce5d152da9f576a9d2977bd62c3be5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 20 Feb 2024 11:13:44 +0800 Subject: [PATCH 2/2] MDL-80862 core: Tidy up state vars in task manager --- lib/classes/task/manager.php | 12 ++++++------ lib/upgrade.txt | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php index 657d47e272c..d839eedac75 100644 --- a/lib/classes/task/manager.php +++ b/lib/classes/task/manager.php @@ -63,24 +63,24 @@ class manager { /** * @var array A cached queue of adhoc tasks */ - public static $miniqueue; + protected static array $miniqueue = []; /** * @var int The last recorded number of unique adhoc tasks. */ - public static $numtasks; + protected static int $numtasks = 0; /** - * @var string Used to determine if the adhoc task queue is distributing or filling capacity. + * @var null|int Used to determine if the adhoc task queue is distributing or filling capacity. */ - public static $mode; + protected static ?int $mode = null; /** * Reset the state of the task manager. */ public static function reset_state(): void { - self::$miniqueue = null; - self::$numtasks = null; + self::$miniqueue = []; + self::$numtasks = 0; self::$mode = null; } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index a5f2a492698..0a8c4aa9baf 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -55,6 +55,10 @@ information provided here is intended especially for developers. * The nocache option for format_text has been removed. It was deprecated in Moodle 2.3. * The set_heading() method has a new parameter, $clean, to define whether the heading should be cleaned or not when no formatting is applied. +* Visibility of internal properties of the \core\task\manager have been changed from public to protected. These should not have been accessible. + - $miniqueue + - $numtasks + - $mode === 4.3 ===