Skip to content

Commit

Permalink
MDL-54988 core: Final deprecation for lib/modinfolib methods
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
junpataleta committed Jul 25, 2016
1 parent 90a8bdb commit 7a07d34
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 85 deletions.
62 changes: 19 additions & 43 deletions lib/modinfolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,22 +531,14 @@ public function __construct($course, $userid) {
}

/**
* 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.');
}

/**
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -1841,18 +1826,15 @@ private function get_available() {
}

/**
* 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.');
}

/**
Expand Down Expand Up @@ -1897,20 +1879,14 @@ private function update_user_visible() {
}

/**
* 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.');
}

/**
Expand Down
42 changes: 0 additions & 42 deletions lib/tests/modinfolib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ public function test_cm_info_properties() {
$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);
Expand Down Expand Up @@ -470,44 +466,6 @@ public function test_is_user_access_restricted_by_capability() {
$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()
*/
Expand Down
14 changes: 14 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===

Expand Down

0 comments on commit 7a07d34

Please sign in to comment.