diff --git a/.upgradenotes/MDL-78118-2024100717482890.yml b/.upgradenotes/MDL-78118-2024100717482890.yml new file mode 100644 index 00000000000..bc53e2cb13c --- /dev/null +++ b/.upgradenotes/MDL-78118-2024100717482890.yml @@ -0,0 +1,32 @@ +issueNumber: MDL-78118 +notes: + core_reportbuilder: + - message: >- + New `get_deprecated_tables` method in base entity, to be overridden when + an entity no longer uses a table (due to column/filter re-factoring, + etc) in order to avoid breaking third-party reports + type: improved + - message: >- + The following deprecated report entity elements have been removed: + + + - `comment:context` + + - `comment:contexturl` + + - `enrolment:method` (plus enrolment formatter `enrolment_name` method) + + - 'enrolment:role` + + - `file:context` + + - `file:contexturl` + + - `instance:context` (tag) + + - `instance:contexturl` (tag) + + + Use of the `context` table is also deprecated in the `file` and + `instance` (tag) entities + type: removed diff --git a/comment/classes/reportbuilder/local/entities/comment.php b/comment/classes/reportbuilder/local/entities/comment.php index cd34cb4c8dc..4ddced0d408 100644 --- a/comment/classes/reportbuilder/local/entities/comment.php +++ b/comment/classes/reportbuilder/local/entities/comment.php @@ -20,7 +20,6 @@ namespace core_comment\reportbuilder\local\entities; use context; use context_helper; -use html_writer; use lang_string; use stdClass; use core_reportbuilder\local\entities\base; @@ -118,52 +117,6 @@ class comment extends base { return format_text($content, $comment->format, ['context' => $context]); }); - // Context. - $columns[] = (new column( - 'context', - new lang_string('context'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_TEXT) - ->add_join($this->get_context_join()) - ->add_fields("{$commentalias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias)) - // Sorting may not order alphabetically, but will at least group contexts together. - ->set_is_sortable(true) - ->set_is_deprecated('See \'context:name\' for replacement') - ->add_callback(static function($contextid, stdClass $context): string { - if ($contextid === null) { - return ''; - } - - context_helper::preload_from_record($context); - return context::instance_by_id($contextid)->get_context_name(); - }); - - // Context URL. - $columns[] = (new column( - 'contexturl', - new lang_string('contexturl'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_TEXT) - ->add_join($this->get_context_join()) - ->add_fields("{$commentalias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias)) - // Sorting may not order alphabetically, but will at least group contexts together. - ->set_is_sortable(true) - ->set_is_deprecated('See \'context:link\' for replacement') - ->add_callback(static function($contextid, stdClass $context): string { - if ($contextid === null) { - return ''; - } - - context_helper::preload_from_record($context); - $context = context::instance_by_id($contextid); - - return html_writer::link($context->get_url(), $context->get_context_name()); - }); - // Component. $columns[] = (new column( 'component', diff --git a/course/classes/reportbuilder/local/entities/enrolment.php b/course/classes/reportbuilder/local/entities/enrolment.php index b0ba4a47291..c1db0ac2e54 100644 --- a/course/classes/reportbuilder/local/entities/enrolment.php +++ b/course/classes/reportbuilder/local/entities/enrolment.php @@ -89,20 +89,6 @@ class enrolment extends base { */ protected function get_all_columns(): array { $userenrolments = $this->get_table_alias('user_enrolments'); - $enrol = $this->get_table_alias('enrol'); - - // Enrolment method column (Deprecated since Moodle 4.3, to remove in MDL-78118). - $columns[] = (new column( - 'method', - new lang_string('method', 'enrol'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_TEXT) - ->add_fields("{$enrol}.enrol, {$enrol}.id") - ->set_is_sortable(true) - ->set_is_deprecated('See \'enrol:name\' for replacement') - ->add_callback([enrolment_formatter::class, 'enrolment_name']); // Enrolment time created. $columns[] = (new column( @@ -156,33 +142,6 @@ class enrolment extends base { ->set_is_sortable(true) ->add_callback([enrolment_formatter::class, 'enrolment_status']); - // Role column (Deprecated since Moodle 4.3, to remove in MDL-78118). - $ctx = database::generate_alias(); - $ra = database::generate_alias(); - $r = database::generate_alias(); - $columns[] = (new column( - 'role', - new lang_string('role', 'moodle'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->add_join("LEFT JOIN {context} {$ctx} - ON {$ctx}.instanceid = {$enrol}.courseid AND {$ctx}.contextlevel = " . CONTEXT_COURSE) - ->add_join("LEFT JOIN {role_assignments} {$ra} - ON {$ra}.contextid = {$ctx}.id AND {$ra}.userid = {$userenrolments}.userid") - ->add_join("LEFT JOIN {role} {$r} ON {$r}.id = {$ra}.roleid") - ->set_type(column::TYPE_TEXT) - ->add_fields("{$r}.id, {$r}.name, {$r}.shortname, {$ctx}.instanceid") - ->set_is_sortable(true, ["{$r}.shortname"]) - ->set_is_deprecated('See \'role:name\' for replacement') - ->add_callback(static function(?string $value, stdClass $row): string { - if (!$row->id) { - return ''; - } - $context = context_course::instance($row->instanceid); - return role_get_name($row, $context, ROLENAME_ALIAS); - }); - return $columns; } @@ -215,24 +174,6 @@ class enrolment extends base { */ protected function get_all_filters(): array { $userenrolments = $this->get_table_alias('user_enrolments'); - $enrol = $this->get_table_alias('enrol'); - - // Enrolment method (Deprecated since Moodle 4.3, to remove in MDL-78118). - $enrolmentmethods = static function(): array { - return array_map(static function(enrol_plugin $plugin): string { - return get_string('pluginname', 'enrol_' . $plugin->get_name()); - }, enrol_get_plugins(true)); - }; - $filters[] = (new filter( - select::class, - 'method', - new lang_string('method', 'enrol'), - $this->get_entity_name(), - "{$enrol}.enrol" - )) - ->add_joins($this->get_joins()) - ->set_is_deprecated('See \'enrol:plugin\' for replacement') - ->set_options_callback($enrolmentmethods); // Enrolment time created. $filters[] = (new filter( diff --git a/course/classes/reportbuilder/local/formatters/enrolment.php b/course/classes/reportbuilder/local/formatters/enrolment.php index 9a952a40719..9b1b3914835 100644 --- a/course/classes/reportbuilder/local/formatters/enrolment.php +++ b/course/classes/reportbuilder/local/formatters/enrolment.php @@ -20,7 +20,6 @@ namespace core_course\reportbuilder\local\formatters; use core_user\output\status_field; use lang_string; -use stdClass; /** * Formatters for the course enrolment entity @@ -32,25 +31,11 @@ use stdClass; class enrolment { /** - * Return enrolment plugin instance name - * - * @param string|null $value - * @param stdClass $row - * @return string - * * @deprecated since Moodle 4.3 - please do not use this function any more (to remove in MDL-78118) */ - public static function enrolment_name(?string $value, stdClass $row): string { - global $DB; - - if (empty($value)) { - return ''; - } - - $instance = $DB->get_record('enrol', ['id' => $row->id, 'enrol' => $row->enrol], '*', MUST_EXIST); - $plugin = enrol_get_plugin($row->enrol); - - return $plugin ? $plugin->get_instance_name($instance) : '-'; + #[\core\attribute\deprecated(null, reason: 'It is no longer used', since: '4.3', mdl: 'MDL-76900', final: true)] + public static function enrolment_name(): void { + \core\deprecation::emit_deprecation_if_present([self::class, __FUNCTION__]); } /** diff --git a/files/classes/reportbuilder/local/entities/file.php b/files/classes/reportbuilder/local/entities/file.php index 5a61fdf248b..d8b8bbb4998 100644 --- a/files/classes/reportbuilder/local/entities/file.php +++ b/files/classes/reportbuilder/local/entities/file.php @@ -18,11 +18,8 @@ declare(strict_types=1); namespace core_files\reportbuilder\local\entities; -use context; -use context_helper; use core_collator; use core_filetypes; -use html_writer; use lang_string; use license_manager; use stdClass; @@ -48,6 +45,16 @@ class file extends base { protected function get_default_tables(): array { return [ 'files', + ]; + } + + /** + * Database tables that this entity no longer uses + * + * @return string[] + */ + protected function get_deprecated_tables(): array { + return [ 'context', ]; } @@ -90,7 +97,6 @@ class file extends base { */ protected function get_all_columns(): array { $filesalias = $this->get_table_alias('files'); - $contextalias = $this->get_table_alias('context'); // Name. $columns[] = (new column( @@ -220,52 +226,6 @@ class file extends base { return $licenses[$license]->fullname; }); - // Context. - $columns[] = (new column( - 'context', - new lang_string('context'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_TEXT) - ->add_join("LEFT JOIN {context} {$contextalias} ON {$contextalias}.id = {$filesalias}.contextid") - ->add_fields("{$filesalias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias)) - // Sorting may not order alphabetically, but will at least group contexts together. - ->set_is_sortable(true) - ->set_is_deprecated('See \'context:name\' for replacement') - ->add_callback(static function($contextid, stdClass $context): string { - if ($contextid === null) { - return ''; - } - - context_helper::preload_from_record($context); - return context::instance_by_id($contextid)->get_context_name(); - }); - - // Context link. - $columns[] = (new column( - 'contexturl', - new lang_string('contexturl'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_TEXT) - ->add_join("LEFT JOIN {context} {$contextalias} ON {$contextalias}.id = {$filesalias}.contextid") - ->add_fields("{$filesalias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias)) - // Sorting may not order alphabetically, but will at least group contexts together. - ->set_is_sortable(true) - ->set_is_deprecated('See \'context:link\' for replacement') - ->add_callback(static function($contextid, stdClass $context): string { - if ($contextid === null) { - return ''; - } - - context_helper::preload_from_record($context); - $context = context::instance_by_id($contextid); - - return html_writer::link($context->get_url(), $context->get_context_name()); - }); - // Content hash. $columns[] = (new column( 'contenthash', diff --git a/tag/classes/reportbuilder/local/entities/instance.php b/tag/classes/reportbuilder/local/entities/instance.php index 6e772bd4430..9c91dc1e41e 100644 --- a/tag/classes/reportbuilder/local/entities/instance.php +++ b/tag/classes/reportbuilder/local/entities/instance.php @@ -18,11 +18,8 @@ declare(strict_types=1); namespace core_tag\reportbuilder\local\entities; -use context; -use context_helper; use core_collator; use core_tag_area; -use html_writer; use lang_string; use stdClass; use core_reportbuilder\local\entities\base; @@ -47,6 +44,16 @@ class instance extends base { protected function get_default_tables(): array { return [ 'tag_instance', + ]; + } + + /** + * Database tables that this entity no longer uses + * + * @return string[] + */ + protected function get_deprecated_tables(): array { + return [ 'context', ]; } @@ -89,7 +96,6 @@ class instance extends base { */ protected function get_all_columns(): array { $instancealias = $this->get_table_alias('tag_instance'); - $contextalias = $this->get_table_alias('context'); // Area. $columns[] = (new column( @@ -109,52 +115,6 @@ class instance extends base { return (string) core_tag_area::display_name($area->component, $area->itemtype); }); - // Context. - $columns[] = (new column( - 'context', - new lang_string('context'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_TEXT) - ->add_join("LEFT JOIN {context} {$contextalias} ON {$contextalias}.id = {$instancealias}.contextid") - ->add_fields("{$instancealias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias)) - // Sorting may not order alphabetically, but will at least group contexts together. - ->set_is_sortable(true) - ->set_is_deprecated('See \'context:name\' for replacement') - ->add_callback(static function($contextid, stdClass $context): string { - if ($contextid === null) { - return ''; - } - - context_helper::preload_from_record($context); - return context::instance_by_id($contextid)->get_context_name(); - }); - - // Context URL. - $columns[] = (new column( - 'contexturl', - new lang_string('contexturl'), - $this->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_TEXT) - ->add_join("LEFT JOIN {context} {$contextalias} ON {$contextalias}.id = {$instancealias}.contextid") - ->add_fields("{$instancealias}.contextid, " . context_helper::get_preload_record_columns_sql($contextalias)) - // Sorting may not order alphabetically, but will at least group contexts together. - ->set_is_sortable(true) - ->set_is_deprecated('See \'context:link\' for replacement') - ->add_callback(static function($contextid, stdClass $context): string { - if ($contextid === null) { - return ''; - } - - context_helper::preload_from_record($context); - $context = context::instance_by_id($contextid); - - return html_writer::link($context->get_url(), $context->get_context_name()); - }); - // Component. $columns[] = (new column( 'component',