From 7a07d34db8ead47d4946aaa364f41e163fe98486 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 12 Jul 2016 17:22:27 +0800 Subject: [PATCH] MDL-54988 core: Final deprecation for lib/modinfolib methods Final deprecation of the following methods: - course_modinfo::build_section_cache() - cm_info::get_deprecated_group_members_only() - cm_info::is_user_access_restricted_by_group() Plus throw coding exception for direct calls of the following: - cm_info::get_url() - cm_info::get_content() - cm_info::get_extra_classes() - cm_info::get_on_click() - cm_info::get_custom_data() - cm_info::get_after_link() - cm_info::get_after_edit_icons() - cm_info::obtain_dynamic_data() --- lib/modinfolib.php | 62 +++++++++++------------------------ lib/tests/modinfolib_test.php | 42 ------------------------ lib/upgrade.txt | 14 ++++++++ 3 files changed, 33 insertions(+), 85 deletions(-) diff --git a/lib/modinfolib.php b/lib/modinfolib.php index 23aeb8e73cb..d8d3c1ec484 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -531,22 +531,14 @@ class course_modinfo { } /** - * Builds a list of information about sections on a course to be stored in - * the course cache. (Does not include information that is already cached - * in some other way.) - * - * This function will be removed in 2.7 + * This method can not be used anymore. * + * @see course_modinfo::build_course_cache() * @deprecated since 2.6 - * @param int $courseid Course ID - * @return array Information about sections, indexed by section number (not id) */ public static function build_section_cache($courseid) { - global $DB; - debugging('Function course_modinfo::build_section_cache() is deprecated. It can only be used internally to build course cache.'); - $course = $DB->get_record('course', array('id' => $course->id), - array_merge(array('id'), self::$cachedfields), MUST_EXIST); - return self::build_course_section_cache($course); + throw new coding_exception('Function course_modinfo::build_section_cache() can not be used anymore.' . + ' Please use course_modinfo::build_course_cache() whenever applicable.'); } /** @@ -1124,28 +1116,21 @@ class cm_info implements IteratorAggregate { ); /** - * Magic method to call functions that are now declared as private now but - * were public in Moodle before 2.6. Developers can access them without - * any warnings but they are not listed in the class methods list. + * Magic method to call functions that are now declared as private but were public in Moodle before 2.6. + * These private methods can not be used anymore. * * @param string $name * @param array $arguments * @return mixed + * @throws coding_exception */ public function __call($name, $arguments) { - global $CFG; - if (in_array($name, self::$standardmethods)) { - if ($CFG->debugdeveloper) { - if ($alternative = array_search($name, self::$standardproperties)) { - // All standard methods do not have arguments anyway. - debugging("cm_info::$name() is deprecated, please use the property cm_info->$alternative instead.", DEBUG_DEVELOPER); - } else { - debugging("cm_info::$name() is deprecated and should not be used.", DEBUG_DEVELOPER); - } + $message = "cm_info::$name() can not be used anymore."; + if ($alternative = array_search($name, self::$standardproperties)) { + $message .= " Please use the property cm_info->$alternative instead."; } - // All standard methods do not have arguments anyway. - return $this->$name(); + throw new coding_exception($message); } throw new coding_exception("Method cm_info::{$name}() does not exist"); } @@ -1841,18 +1826,15 @@ class cm_info implements IteratorAggregate { } /** - * Getter method for $availablefrom and $availableuntil. Just returns zero - * as these are no longer supported. + * This method can not be used anymore. * - * @return int Zero + * @see \core_availability\info_module::filter_user_list() * @deprecated Since Moodle 2.8 */ private function get_deprecated_group_members_only() { - debugging('$cm->groupmembersonly has been deprecated and always returns zero. ' . + throw new coding_exception('$cm->groupmembersonly can not be used anymore. ' . 'If used to restrict a list of enrolled users to only those who can ' . - 'access the module, consider \core_availability\info_module::filter_user_list.', - DEBUG_DEVELOPER); - return 0; + 'access the module, consider \core_availability\info_module::filter_user_list.'); } /** @@ -1897,20 +1879,14 @@ class cm_info implements IteratorAggregate { } /** - * Checks whether the module's group settings restrict the current user's - * access. This function is not necessary now that all access restrictions - * are handled by the availability API. You can use $cm->uservisible to - * find out if the current user can access an activity, or $cm->availableinfo - * to get information about why not. + * This method has been deprecated and should not be used. * - * @return bool False + * @see $uservisible * @deprecated Since Moodle 2.8 */ public function is_user_access_restricted_by_group() { - debugging('cm_info::is_user_access_restricted_by_group() ' . - 'is deprecated and always returns false; use $cm->uservisible ' . - 'to decide whether the current user can access an activity', DEBUG_DEVELOPER); - return false; + throw new coding_exception('cm_info::is_user_access_restricted_by_group() can not be used any more.' . + ' Use $cm->uservisible to decide whether the current user can access an activity.'); } /** diff --git a/lib/tests/modinfolib_test.php b/lib/tests/modinfolib_test.php index 938366db6ea..50e0f228b6c 100644 --- a/lib/tests/modinfolib_test.php +++ b/lib/tests/modinfolib_test.php @@ -201,10 +201,6 @@ class core_modinfolib_testcase extends advanced_testcase { $this->assertEquals(new moodle_url('/mod/assign/view.php', array('id' => $moduledb->id)), $cm->url); $this->assertEquals($cachedcminfo->customdata, $cm->customdata); - // Deprecated field. - $this->assertEquals(0, $cm->groupmembersonly); - $this->assertDebuggingCalled(); - // Dynamic fields, just test that they can be retrieved (must be carefully tested in each activity type). $this->assertNotEmpty($cm->availableinfo); // Lists all unmet availability conditions. $this->assertEquals(0, $cm->uservisible); @@ -470,44 +466,6 @@ class core_modinfolib_testcase extends advanced_testcase { $this->assertTrue($cm->is_user_access_restricted_by_capability()); } - /** - * Tests that various deprecated cm_info methods are throwing debuggign messages - */ - public function test_cm_info_property_deprecations() { - global $DB, $CFG; - - $this->resetAfterTest(); - - $course = $this->getDataGenerator()->create_course( array('format' => 'topics', 'numsections' => 3), - array('createsections' => true)); - $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id)); - $cm = get_fast_modinfo($course->id)->instances['forum'][$forum->id]; - - $cm->get_url(); - $this->assertDebuggingCalled('cm_info::get_url() is deprecated, please use the property cm_info->url instead.'); - - $cm->get_content(); - $this->assertDebuggingCalled('cm_info::get_content() is deprecated, please use the property cm_info->content instead.'); - - $cm->get_extra_classes(); - $this->assertDebuggingCalled('cm_info::get_extra_classes() is deprecated, please use the property cm_info->extraclasses instead.'); - - $cm->get_on_click(); - $this->assertDebuggingCalled('cm_info::get_on_click() is deprecated, please use the property cm_info->onclick instead.'); - - $cm->get_custom_data(); - $this->assertDebuggingCalled('cm_info::get_custom_data() is deprecated, please use the property cm_info->customdata instead.'); - - $cm->get_after_link(); - $this->assertDebuggingCalled('cm_info::get_after_link() is deprecated, please use the property cm_info->afterlink instead.'); - - $cm->get_after_edit_icons(); - $this->assertDebuggingCalled('cm_info::get_after_edit_icons() is deprecated, please use the property cm_info->afterediticons instead.'); - - $cm->obtain_dynamic_data(); - $this->assertDebuggingCalled('cm_info::obtain_dynamic_data() is deprecated and should not be used.'); - } - /** * Tests for function cm_info::get_course_module_record() */ diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 4f353de0571..07446a0b252 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -26,6 +26,20 @@ information provided here is intended especially for developers. - get_records_csv() Please use csv_import_reader::load_csv_content() instead. - put_records_csv() Please use download_as_dataformat (lib/dataformatlib.php) instead. * The password_compat library was removed as it is no longer required. +* The following methods have been finally deprecated and should no longer be used: + - course_modinfo::build_section_cache() + - cm_info::get_deprecated_group_members_only() + - cm_info::is_user_access_restricted_by_group() +* The following methods in cm_info::standardmethods have also been finally deprecated and should no longer be used: + - cm_info::get_after_edit_icons() + - cm_info::get_after_link() + - cm_info::get_content() + - cm_info::get_custom_data() + - cm_info::get_extra_classes() + - cm_info::get_on_click() + - cm_info::get_url() + - cm_info::obtain_dynamic_data() + Calling them through the magic method __call() will throw a coding exception. === 3.1 ===