diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 846871a33d1..6affc75f3d1 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2128,45 +2128,9 @@ function message_current_user_is_involved($user1, $user2) { * Print badges on user profile page. * * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more. - * @param int $userid User ID. - * @param int $courseid Course if we need to filter badges (optional). */ function profile_display_badges($userid, $courseid = 0) { - global $CFG, $PAGE, $USER, $SITE; - require_once($CFG->dirroot . '/badges/renderer.php'); - - debugging('profile_display_badges() is deprecated.', DEBUG_DEVELOPER); - - // Determine context. - if (isloggedin()) { - $context = context_user::instance($USER->id); - } else { - $context = context_system::instance(); - } - - if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) { - $records = badges_get_user_badges($userid, $courseid, null, null, null, true); - $renderer = new core_badges_renderer($PAGE, ''); - - // Print local badges. - if ($records) { - $left = get_string('localbadgesp', 'badges', format_string($SITE->fullname)); - $right = $renderer->print_badges_list($records, $userid, true); - echo html_writer::tag('dt', $left); - echo html_writer::tag('dd', $right); - } - - // Print external badges. - if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) { - $backpack = get_backpack_settings($userid); - if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) { - $left = get_string('externalbadgesp', 'badges'); - $right = $renderer->print_badges_list($backpack->badges, $userid, true, true); - echo html_writer::tag('dt', $left); - echo html_writer::tag('dd', $right); - } - } - } + throw new coding_exception('profile_display_badges() can not be used any more.'); } /** @@ -2192,82 +2156,58 @@ function calendar_normalize_tz($tz) { * Returns a float which represents the user's timezone difference from GMT in hours * Checks various settings and picks the most dominant of those which have a value * @deprecated since Moodle 2.9 - * @param float|int|string $tz timezone user timezone - * @return float */ function get_user_timezone_offset($tz = 99) { - debugging('get_user_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER); - $tz = core_date::get_user_timezone($tz); - $date = new DateTime('now', new DateTimeZone($tz)); - return ($date->getOffset() - dst_offset_on(time(), $tz)) / (3600.0); + throw new coding_exception('get_user_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead'); + } /** * Returns an int which represents the systems's timezone difference from GMT in seconds * @deprecated since Moodle 2.9 - * @param float|int|string $tz timezone for which offset is required. - * {@link http://docs.moodle.org/dev/Time_API#Timezone} - * @return int|bool if found, false is timezone 99 or error */ function get_timezone_offset($tz) { - debugging('get_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER); - $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($tz))); - return $date->getOffset() - dst_offset_on(time(), $tz); + throw new coding_exception('get_timezone_offset() can not be used any more, please use standard PHP DateTimeZone class instead'); } /** * Returns a list of timezones in the current language. * @deprecated since Moodle 2.9 - * @return array */ function get_list_of_timezones() { - debugging('get_list_of_timezones() is deprecated, use core_date::get_list_of_timezones() instead', DEBUG_DEVELOPER); - return core_date::get_list_of_timezones(); + throw new coding_exception('get_list_of_timezones() can not be used any more, please use core_date::get_list_of_timezones() instead'); } /** * Previous internal API, it was not supposed to be used anywhere. * @deprecated since Moodle 2.9 - * @param array $timezones */ function update_timezone_records($timezones) { - debugging('update_timezone_records() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); + throw new coding_exception('update_timezone_records() can not be used any more, please use standard PHP DateTime class instead'); } /** * Previous internal API, it was not supposed to be used anywhere. * @deprecated since Moodle 2.9 - * @param int $fromyear - * @param int $toyear - * @param mixed $strtimezone - * @return bool */ function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) { - debugging('calculate_user_dst_table() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); - return false; + throw new coding_exception('calculate_user_dst_table() can not be used any more, please use standard PHP DateTime class instead'); } /** * Previous internal API, it was not supposed to be used anywhere. * @deprecated since Moodle 2.9 - * @param int|string $year - * @param mixed $timezone - * @return null */ function dst_changes_for_year($year, $timezone) { - debugging('dst_changes_for_year() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); - return null; + throw new coding_exception('dst_changes_for_year() can not be used any more, please use standard DateTime class instead'); } /** * Previous internal API, it was not supposed to be used anywhere. * @deprecated since Moodle 2.9 - * @param string $timezonename - * @return array */ function get_timezone_record($timezonename) { - debugging('get_timezone_record() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER); - return array(); + throw new coding_exception('get_timezone_record() can not be used any more, please use standard PHP DateTime class instead'); } /* === Apis deprecated since Moodle 3.0 === */ diff --git a/lib/tests/date_legacy_test.php b/lib/tests/date_legacy_test.php index a048d460bb0..09ddf026a84 100644 --- a/lib/tests/date_legacy_test.php +++ b/lib/tests/date_legacy_test.php @@ -46,20 +46,6 @@ class core_date_legacy_testcase extends advanced_testcase { $this->assertSame('99', $user->timezone); } - public function test_get_list_of_timezones() { - // Use timezones that are not problematic, this way we may test before - // and after the big tz rewrite. - $list = get_list_of_timezones(); - $this->assertDebuggingCalled(); - $this->assertArrayHasKey('Europe/London', $list); - $this->assertArrayHasKey('Pacific/Auckland', $list); - $this->assertArrayHasKey('America/New_York', $list); - $this->assertArrayHasKey('Europe/Berlin', $list); - $this->assertArrayHasKey('Europe/Prague', $list); - $this->assertArrayHasKey('Australia/Perth', $list); - $this->assertArrayHasKey('Australia/Lord_Howe', $list); - } - public function test_get_user_timezone() { global $CFG, $USER; @@ -133,44 +119,6 @@ class core_date_legacy_testcase extends advanced_testcase { $this->assertSame('Europe/Berlin', $tz); } - public function test_get_timezone_offset() { - // This is a useless function, the timezone offset may be changing! - $this->assertSame(60 * 60 * -5, get_timezone_offset('America/New_York')); - $this->assertDebuggingCalled(); - $this->assertSame(60 * 60 * -1, get_timezone_offset(-1)); - $this->assertSame(60 * 60 * 1, get_timezone_offset(1)); - $this->assertSame(60 * 60 * 1, get_timezone_offset('Europe/Prague')); - $this->assertSame(60 * 60 * 8, get_timezone_offset('Australia/Perth')); - $this->assertSame(60 * 60 * 12, get_timezone_offset('Pacific/Auckland')); - - // Known half an hour offsets. - $this->assertEquals(60 * 60 * -4.5, get_timezone_offset('-4.5')); - $this->assertEquals(60 * 60 * -4.5, get_timezone_offset('America/Caracas')); - $this->assertEquals(60 * 60 * 4.5, get_timezone_offset('4.5')); - $this->assertEquals(60 * 60 * 4.5, get_timezone_offset('Asia/Kabul')); - $this->assertEquals(60 * 60 * 5.5, get_timezone_offset('5.5')); - $this->assertEquals(60 * 60 * 5.5, get_timezone_offset('Asia/Kolkata')); - $this->assertEquals(60 * 60 * 6.5, get_timezone_offset('6.5')); - $this->assertEquals(60 * 60 * 6.5, get_timezone_offset('Asia/Rangoon')); - $this->assertEquals(60 * 60 * 9.5, get_timezone_offset('9.5')); - $this->assertEquals(60 * 60 * 9.5, get_timezone_offset('Australia/Darwin')); - - $this->resetDebugging(); - } - - public function test_get_user_timezone_offset() { - // This is a useless function, the timezone offset may be changing! - $this->assertSame(-5.0, get_user_timezone_offset('America/New_York')); - $this->assertDebuggingCalled(); - $this->assertSame(-1.0, get_user_timezone_offset(-1)); - $this->assertSame(1.0, get_user_timezone_offset(1)); - $this->assertSame(1.0, get_user_timezone_offset('Europe/Prague')); - $this->assertSame(8.0, get_user_timezone_offset('Australia/Perth')); - $this->assertSame(12.0, get_user_timezone_offset('Pacific/Auckland')); - - $this->resetDebugging(); - } - public function test_dst_offset_on() { $time = gmmktime(1, 1, 1, 3, 1, 2015); $this->assertSame(3600, dst_offset_on($time, 'Pacific/Auckland')); diff --git a/lib/tests/statslib_test.php b/lib/tests/statslib_test.php index 2e295096815..aa7a2519728 100644 --- a/lib/tests/statslib_test.php +++ b/lib/tests/statslib_test.php @@ -302,7 +302,6 @@ class core_statslib_testcase extends advanced_testcase { $dataset = $this->load_xml_data_file(__DIR__."/fixtures/statslib-test01.xml"); $DB->delete_records('log'); - // Don't ask. I don't think get_timezone_offset works correctly. $date = new DateTime('now', core_date::get_server_timezone_object()); $day = self::DAY - $date->getOffset(); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 9f608e34113..b30b7a51679 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -4,6 +4,19 @@ information provided here is intended especially for developers. === 3.1 === * The moodle/blog:associatecourse and moodle/blog:associatemodule capabilities has been removed. +* The following functions has been finally deprecated and can not be used any more: + - profile_display_badges() + - useredit_shared_definition_preferences() + - calendar_normalize_tz() + - get_user_timezone_offset() + - get_timezone_offset() + - get_list_of_timezones() + - calculate_user_dst_table() + - dst_changes_for_year() + - get_timezone_record() + - test_get_list_of_timezones() + - test_get_timezone_offset() + - test_get_user_timezone_offset() * The google api library has been updated to version 1.1.7. There was some important changes on the SSL handling. Now the SSL version will be determined by the underlying library. For more information see https://github.com/google/google-api-php-client/pull/644