From c215b8e280ece9b37a7f0e7acd07c779342b1d5d Mon Sep 17 00:00:00 2001 From: Alexander Van der Bellen Date: Thu, 28 Nov 2024 13:43:11 +0800 Subject: [PATCH 1/3] Fix deprecated callback (Moodle 4.5 compatibility) --- classes/hook_callbacks.php | 37 +++++++++++++++++++++++++++++++++++++ db/hooks.php | 33 +++++++++++++++++++++++++++++++++ version.php | 4 ++-- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 classes/hook_callbacks.php create mode 100644 db/hooks.php diff --git a/classes/hook_callbacks.php b/classes/hook_callbacks.php new file mode 100644 index 0000000..3cd05e3 --- /dev/null +++ b/classes/hook_callbacks.php @@ -0,0 +1,37 @@ +. + +namespace mod_cms; + +/** + * Hook callbacks for tool_redirects. + * + * @package mod_cms + * @author Alexander Van der Bellen + * @copyright 2024 Catalyst IT Australia + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class hook_callbacks { + + /** + * Listener for the after_config hook. + * + * @param \core\hook\after_config $hook + */ + public static function after_config(\core\hook\after_config $hook): void { + // The original callback performs no operations, so we don't need to do anything here. + } +} diff --git a/db/hooks.php b/db/hooks.php new file mode 100644 index 0000000..617aac2 --- /dev/null +++ b/db/hooks.php @@ -0,0 +1,33 @@ +. + +/** + * Hook callbacks. + * + * @package mod_cms + * @author Alexander Van der Bellen + * @copyright 2024 Catalyst IT Australia + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$callbacks = [ + [ + 'hook' => \core\hook\after_config::class, + 'callback' => '\mod_cms\hook_callbacks::after_config', + ], +]; diff --git a/version.php b/version.php index 9f811c3..50abf48 100644 --- a/version.php +++ b/version.php @@ -25,9 +25,9 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024090305; +$plugin->version = 2024090306; $plugin->requires = 2022112800; // Moodle 4.1 and above. -$plugin->supported = [401, 401]; // Moodle 4.1. +$plugin->supported = [401, 405]; // Moodle 4.1. $plugin->component = 'mod_cms'; $plugin->maturity = MATURITY_STABLE; $plugin->release = 2023051800; From 00816a7845f0b74e313c230a9e315ed834decb59 Mon Sep 17 00:00:00 2001 From: Alexander Van der Bellen Date: Thu, 28 Nov 2024 13:50:47 +0800 Subject: [PATCH 2/3] Fix CI complaints --- classes/local/datasource/restore/fields.php | 3 +++ tests/datasource_site_test.php | 7 ++++--- tests/renderer_test.php | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/classes/local/datasource/restore/fields.php b/classes/local/datasource/restore/fields.php index de7f986..7bea0ec 100644 --- a/classes/local/datasource/restore/fields.php +++ b/classes/local/datasource/restore/fields.php @@ -32,6 +32,9 @@ class fields { /** @var \restore_cms_activity_structure_step The stepslib controlling this process. */ protected $stepslib; + /** @var array Components array */ + protected $components = []; + /** * Constructs the processor. * diff --git a/tests/datasource_site_test.php b/tests/datasource_site_test.php index 62036b7..915a743 100644 --- a/tests/datasource_site_test.php +++ b/tests/datasource_site_test.php @@ -62,9 +62,10 @@ public function test_get_data() { $ds = new dssite($cms); $data = $ds->get_data(); - $this->assertObjectHasAttribute('fullname', $data); - $this->assertObjectHasAttribute('shortname', $data); - $this->assertObjectHasAttribute('wwwroot', $data); + // Some versions of PHPUnit do not have assertObjectHasProperty(), and assertObjectHasAttribute() is deprecated. + $this->assertTrue(property_exists($data, 'fullname')); + $this->assertTrue(property_exists($data, 'shortname')); + $this->assertTrue(property_exists($data, 'wwwroot')); } /** diff --git a/tests/renderer_test.php b/tests/renderer_test.php index 426ae0d..e224e46 100644 --- a/tests/renderer_test.php +++ b/tests/renderer_test.php @@ -67,7 +67,7 @@ public function test_get_data() { foreach (dsbase::BUILTIN_DATASOURCES as $ds) { $classname = 'mod_cms\\local\\datasource\\' . $ds; $attribute = $classname::get_shortname(); - $this->assertObjectHasAttribute($attribute, $data); + $this->assertTrue(property_exists($data, $attribute)); $this->assertIsObject($data->$attribute); } } From 100dd4e10202f933b6a1fb3991c62770199649b2 Mon Sep 17 00:00:00 2001 From: Alexander Van der Bellen Date: Tue, 10 Dec 2024 10:03:50 +0800 Subject: [PATCH 3/3] Require vendor/autoload.php --- classes/hook_callbacks.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/hook_callbacks.php b/classes/hook_callbacks.php index 3cd05e3..ade4ca5 100644 --- a/classes/hook_callbacks.php +++ b/classes/hook_callbacks.php @@ -32,6 +32,8 @@ class hook_callbacks { * @param \core\hook\after_config $hook */ public static function after_config(\core\hook\after_config $hook): void { - // The original callback performs no operations, so we don't need to do anything here. + global $CFG; + + require_once($CFG->dirroot . '/vendor/autoload.php'); } }