diff --git a/.upgradenotes/MDL-86997-2025102314343463.yml b/.upgradenotes/MDL-86997-2025102314343463.yml new file mode 100644 index 00000000000..d555f502ffe --- /dev/null +++ b/.upgradenotes/MDL-86997-2025102314343463.yml @@ -0,0 +1,10 @@ +issueNumber: MDL-86997 +notes: + core_reportbuilder: + - message: | + The following `user_filter_manager` methods have been deprecated: + + * `reset_all()` - to be replaced by new `reset()` method + * `reset_single()` + * `merge()` + type: deprecated diff --git a/public/reportbuilder/classes/external/filters/reset.php b/public/reportbuilder/classes/external/filters/reset.php index b999e4d0879..fba7623e0bf 100644 --- a/public/reportbuilder/classes/external/filters/reset.php +++ b/public/reportbuilder/classes/external/filters/reset.php @@ -33,7 +33,6 @@ use core_reportbuilder\local\helpers\user_filter_manager; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class reset extends external_api { - /** * External method parameters * @@ -72,7 +71,7 @@ class reset extends external_api { permission::require_can_view_report($persistent); } - return user_filter_manager::reset_all($reportid); + return user_filter_manager::reset($reportid); } /** diff --git a/public/reportbuilder/classes/local/helpers/user_filter_manager.php b/public/reportbuilder/classes/local/helpers/user_filter_manager.php index f3030eb168c..cdcd366a733 100644 --- a/public/reportbuilder/classes/local/helpers/user_filter_manager.php +++ b/public/reportbuilder/classes/local/helpers/user_filter_manager.php @@ -29,7 +29,6 @@ use core_text; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class user_filter_manager { - /** * Set user filters for given report * @@ -84,8 +83,13 @@ class user_filter_manager { * @param array $values * @param int|null $userid * @return bool + * + * @deprecated since Moodle 5.2 - please do not use this function any more */ + #[\core\attribute\deprecated(reason: 'It is no longer used', mdl: 'MDL-86997', since: '5.2')] public static function merge(int $reportid, array $values, ?int $userid = null): bool { + \core\deprecation::emit_deprecation([self::class, __FUNCTION__]); + $existing = static::get($reportid, $userid); return static::set($reportid, array_merge($existing, $values), $userid); @@ -96,10 +100,9 @@ class user_filter_manager { * * @param int $reportid * @param int|null $userid - * @param int $index Unused * @return bool */ - public static function reset_all(int $reportid, ?int $userid = null, int $index = 0): bool { + public static function reset(int $reportid, ?int $userid = null): bool { global $DB, $USER; $userid ??= $USER->id; @@ -107,6 +110,23 @@ class user_filter_manager { return $DB->delete_records(user_filter::TABLE, ['reportid' => $reportid, 'usercreated' => $userid]); } + /** + * Reset all user filters for given report + * + * @param int $reportid + * @param int|null $userid + * @param int $index Unused + * @return bool + * + * @deprecated since Moodle 5.2 - please use {@see reset} instead + */ + #[\core\attribute\deprecated('::reset', mdl: 'MDL-86997', since: '5.2')] + public static function reset_all(int $reportid, ?int $userid = null, int $index = 0): bool { + \core\deprecation::emit_deprecation([self::class, __FUNCTION__]); + + return static::reset($reportid, $userid); + } + /** * Reset single user filter for given report * @@ -114,12 +134,17 @@ class user_filter_manager { * @param string $uniqueidentifier * @param int|null $userid * @return bool + * + * @deprecated since Moodle 5.2 - please do not use this function any more */ + #[\core\attribute\deprecated(reason: 'It is no longer used', mdl: 'MDL-86997', since: '5.2')] public static function reset_single(int $reportid, string $uniqueidentifier, ?int $userid = null): bool { + \core\deprecation::emit_deprecation([self::class, __FUNCTION__]); + $originalvalues = static::get($reportid, $userid); // Remove any filters whose name is prefixed by given identifier. - $values = array_filter($originalvalues, static function(string $filterkey) use ($uniqueidentifier): bool { + $values = array_filter($originalvalues, static function (string $filterkey) use ($uniqueidentifier): bool { return core_text::strpos($filterkey, $uniqueidentifier) !== 0; }, ARRAY_FILTER_USE_KEY); diff --git a/public/reportbuilder/tests/local/helpers/user_filter_manager_test.php b/public/reportbuilder/tests/local/helpers/user_filter_manager_test.php index a9893794e4f..8ecf0e8290d 100644 --- a/public/reportbuilder/tests/local/helpers/user_filter_manager_test.php +++ b/public/reportbuilder/tests/local/helpers/user_filter_manager_test.php @@ -32,17 +32,6 @@ use core_user\reportbuilder\datasource\users; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class user_filter_manager_test extends advanced_testcase { - /** - * Helper method to return all user preferences for filters - based on the current storage backend using the same - * - * @return array - */ - private function get_filter_preferences(): array { - return array_filter(get_user_preferences(), static function(string $key): bool { - return strpos($key, 'reportbuilder-report-') === 0; - }, ARRAY_FILTER_USE_KEY); - } - /** * Data provider for {@see test_get} * @@ -93,11 +82,11 @@ final class user_filter_manager_test extends advanced_testcase { } /** - * Data provider for {@see test_reset_all} + * Data provider for {@see test_reset} * * @return array */ - public static function reset_all_provider(): array { + public static function reset_provider(): array { return [ 'Small value' => ['foo'], 'Large value' => [str_repeat('A', 4000)], @@ -110,9 +99,9 @@ final class user_filter_manager_test extends advanced_testcase { * * @param string $value * - * @dataProvider reset_all_provider + * @dataProvider reset_provider */ - public function test_reset_all(string $value): void { + public function test_reset(string $value): void { $this->resetAfterTest(); /** @var core_reportbuilder_generator $generator */ @@ -123,7 +112,7 @@ final class user_filter_manager_test extends advanced_testcase { 'entity:filter_name' => $value, ]); - $reset = user_filter_manager::reset_all($report->get('id')); + $reset = user_filter_manager::reset($report->get('id')); $this->assertTrue($reset); // We should get an empty array back. @@ -151,6 +140,7 @@ final class user_filter_manager_test extends advanced_testcase { ]); $reset = user_filter_manager::reset_single($report->get('id'), 'entity:other'); + $this->assertDebuggingCalled(); $this->assertTrue($reset); $this->assertEquals([ @@ -181,7 +171,7 @@ final class user_filter_manager_test extends advanced_testcase { 'entity:filter_name' => 'twotimesfoo', 'entity:filter_value' => 'twotimesbar', ]); - + $this->assertDebuggingCalled(); $this->assertEqualsCanonicalizing([ 'entity:filter_name' => 'twotimesfoo', 'entity:filter_value' => 'twotimesbar',