diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 442179f8700..bf2f8fa8f90 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -230,237 +230,124 @@ function print_course_request_buttons() { } /** - * Execute cron tasks - * - * @param int|null $keepalive The keepalive time for this cron run. * @deprecated since 4.2 Use \core\cron::run_main_process() instead. */ -function cron_run(?int $keepalive = null): void { - debugging( - 'The cron_run() function is deprecated. Please use \core\cron::run_main_process() instead.', - DEBUG_DEVELOPER - ); - \core\cron::run_main_process($keepalive); +#[\core\attribute\deprecated('\core\cron::run_main_process()', since: '4.2', mdl: 'MDL-77186', final: true)] +function cron_run() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Execute all queued scheduled tasks, applying necessary concurrency limits and time limits. - * - * @param int $timenow The time this process started. * @deprecated since 4.2 Use \core\cron::run_scheduled_tasks() instead. */ -function cron_run_scheduled_tasks(int $timenow) { - debugging( - 'The cron_run_scheduled_tasks() function is deprecated. Please use \core\cron::run_scheduled_tasks() instead.', - DEBUG_DEVELOPER - ); - \core\cron::run_scheduled_tasks($timenow); +#[\core\attribute\deprecated('\core\cron::run_scheduled_tasks()', since: '4.2', mdl: 'MDL-77186', final: true)] +function cron_run_scheduled_tasks() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Execute all queued adhoc tasks, applying necessary concurrency limits and time limits. - * - * @param int $timenow The time this process started. - * @param int $keepalive Keep this function alive for N seconds and poll for new adhoc tasks. - * @param bool $checklimits Should we check limits? * @deprecated since 4.2 Use \core\cron::run_adhoc_tasks() instead. */ -function cron_run_adhoc_tasks(int $timenow, $keepalive = 0, $checklimits = true) { - debugging( - 'The cron_run_adhoc_tasks() function is deprecated. Please use \core\cron::run_adhoc_tasks() instead.', - DEBUG_DEVELOPER - ); - \core\cron::run_adhoc_tasks($timenow, $keepalive, $checklimits); +#[\core\attribute\deprecated('\core\cron::run_adhoc_tasks()', since: '4.2', mdl: 'MDL-77186', final: true)] +function cron_run_adhoc_tasks() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Shared code that handles running of a single scheduled task within the cron. - * - * Not intended for calling directly outside of this library! - * - * @param \core\task\task_base $task * @deprecated since 4.2 Use \core\cron::run_inner_scheduled_task() instead. */ -function cron_run_inner_scheduled_task(\core\task\task_base $task) { - debugging( - 'The cron_run_inner_scheduled_task() function is deprecated. Please use \core\cron::run_inner_scheduled_task() instead.', - DEBUG_DEVELOPER - ); - \core\cron::run_inner_scheduled_task($task); +#[\core\attribute\deprecated('\core\cron::run_inner_scheduled_task()', since: '4.2', mdl: 'MDL-77186', final: true)] +function cron_run_inner_scheduled_task() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Shared code that handles running of a single adhoc task within the cron. - * - * @param \core\task\adhoc_task $task * @deprecated since 4.2 Use \core\cron::run_inner_adhoc_task() instead. */ -function cron_run_inner_adhoc_task(\core\task\adhoc_task $task) { - debugging( - 'The cron_run_inner_adhoc_task() function is deprecated. Please use \core\cron::run_inner_adhoc_task() instead.', - DEBUG_DEVELOPER - ); - \core\cron::run_inner_adhoc_task($task); +#[\core\attribute\deprecated('\core\cron::run_inner_adhoc_task()', since: '4.2', mdl: 'MDL-77186', final: true)] +function cron_run_inner_adhoc_task() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Sets the process title - * - * This makes it very easy for a sysadmin to immediately see what task - * a cron process is running at any given moment. - * - * @param string $title process status title + * @deprecated since 4.2 Use \core\cron::set_process_title() instead. */ -function cron_set_process_title(string $title) { - debugging( - 'The cron_set_process_title() function is deprecated. Please use \core\cron::set_process_title() instead.', - DEBUG_DEVELOPER - ); - \core\cron::set_process_title($title); +#[\core\attribute\deprecated('\core\cron::set_process_title()', since: '4.2', mdl: 'MDL-77186', final: true)] +function cron_set_process_title() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Output some standard information during cron runs. Specifically current time - * and memory usage. This method also does gc_collect_cycles() (before displaying - * memory usage) to try to help PHP manage memory better. - * * @deprecated since 4.2 Use \core\cron::trace_time_and_memory() instead. */ +#[\core\attribute\deprecated('\core\cron::trace_time_and_memory()', since: '4.2', mdl: 'MDL-77186', final: true)] function cron_trace_time_and_memory() { - debugging( - 'The cron_trace_time_and_memory() function is deprecated. Please use \core\cron::trace_time_and_memory() instead.', - DEBUG_DEVELOPER - ); - \core\cron::trace_time_and_memory(); + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Prepare the output renderer for the cron run. - * - * This involves creating a new $PAGE, and $OUTPUT fresh for each task and prevents any one task from influencing - * any other. - * - * @param bool $restore Whether to restore the original PAGE and OUTPUT * @deprecated since 4.2 Use \core\cron::prepare_core_renderer() instead. */ -function cron_prepare_core_renderer($restore = false) { - debugging( - 'The cron_prepare_core_renderer() function is deprecated. Please use \core\cron::prepare_core_renderer() instead.', - DEBUG_DEVELOPER - ); - \core\cron::prepare_core_renderer($restore); +#[\core\attribute\deprecated('\core\cron::prepare_core_renderer()', since: '4.2', mdl: 'MDL-77186', final: true)] +function cron_prepare_core_renderer() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Sets up current user and course environment (lang, etc.) in cron. - * Do not use outside of cron script! - * - * @param stdClass $user full user object, null means default cron user (admin), - * value 'reset' means reset internal static caches. - * @param stdClass $course full course record, null means $SITE - * @param bool $leavepagealone If specified, stops it messing with global page object - * @deprecated since 4.2. Use \core\core::setup_user() instead. - * @return void + * @deprecated since 4.2. Use \core\cron::setup_user() instead. */ -function cron_setup_user($user = null, $course = null, $leavepagealone = false) { - debugging( - 'The cron_setup_user() function is deprecated. ' . - 'Please use \core\cron::setup_user() and reset_user_cache() as appropriate instead.', - DEBUG_DEVELOPER - ); - - if ($user === 'reset') { - \core\cron::reset_user_cache(); - return; - } - - \core\cron::setup_user($user, $course, $leavepagealone); +#[\core\attribute\deprecated('\core\cron::setup_user()', since: '4.2', mdl: 'MDL-77837', final: true)] +function cron_setup_user() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Get OAuth2 services for the external backpack. - * - * @return array - * @throws coding_exception * @deprecated since 4.3. */ +#[\core\attribute\deprecated(since: '4.3', mdl: 'MDL-77837', final: true)] function badges_get_oauth2_service_options() { - debugging( - 'badges_get_oauth2_service_options() is deprecated. Don\'t use it.', - DEBUG_DEVELOPER - ); - global $DB; - - $issuers = core\oauth2\api::get_all_issuers(); - $options = ['' => 'None']; - foreach ($issuers as $issuer) { - $options[$issuer->get('id')] = $issuer->get('name'); - } - - return $options; + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Checks if the given device has a theme defined in config.php. - * - * @param string $device The device * @deprecated since 4.3. - * @return bool */ -function theme_is_device_locked($device) { - debugging( - __FUNCTION__ . '() is deprecated.' . - 'All functions associated with device specific themes are being removed.', - DEBUG_DEVELOPER - ); - global $CFG; - $themeconfigname = core_useragent::get_device_type_cfg_var_name($device); - return isset($CFG->config_php_settings[$themeconfigname]); +#[\core\attribute\deprecated( + since: '4.3', + reason: 'All functions associated with device specific themes are being removed', + mdl: 'MDL-77793', + final: true, +)] +function theme_is_device_locked() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Returns the theme named defined in config.php for the given device. - * - * @param string $device The device * @deprecated since 4.3. - * @return string or null */ -function theme_get_locked_theme_for_device($device) { - debugging( - __FUNCTION__ . '() is deprecated.' . - 'All functions associated with device specific themes are being removed.', - DEBUG_DEVELOPER - ); - global $CFG; - - if (!theme_is_device_locked($device)) { - return null; - } - - $themeconfigname = core_useragent::get_device_type_cfg_var_name($device); - return $CFG->config_php_settings[$themeconfigname]; +#[\core\attribute\deprecated( + since: '4.3', + reason: 'All functions associated with device specific themes are being removed', + mdl: 'MDL-77793', + final: true, +)] +function theme_get_locked_theme_for_device() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** - * Try to generate cryptographically secure pseudo-random bytes. - * - * Note this is achieved by fallbacking between: - * - PHP 7 random_bytes(). - * - OpenSSL openssl_random_pseudo_bytes(). - * - In house random generator getting its entropy from various, hard to guess, pseudo-random sources. - * - * @param int $length requested length in bytes * @deprecated since 4.3. - * @return string binary data */ -function random_bytes_emulate($length) { - debugging( - __FUNCTION__ . '() is deprecated.' . - 'Please use random_bytes instead.', - DEBUG_DEVELOPER - ); - return random_bytes($length); +#[\core\attribute\deprecated( + 'random_bytes()', + since: '4.3', + reason: 'Since PHP 7.0 the random_bytes() is natively available and Moodle LMS requires greater than PHP 7.', + mdl: 'MDL-78698', + final: true, +)] +function random_bytes_emulate() { + \core\deprecation::emit_deprecation_if_present(__FUNCTION__); } /** diff --git a/lib/tests/sessionlib_test.php b/lib/tests/sessionlib_test.php index 75324deb115..74d97293f1f 100644 --- a/lib/tests/sessionlib_test.php +++ b/lib/tests/sessionlib_test.php @@ -27,143 +27,6 @@ namespace core; */ final class sessionlib_test extends \advanced_testcase { - /** - * @covers ::cron_setup_user - */ - public function test_cron_setup_user(): void { - // This function uses the $GLOBALS super global. Disable the VariableNameLowerCase sniff for this function. - // phpcs:disable moodle.NamingConventions.ValidVariableName.VariableNameLowerCase - - global $PAGE, $USER, $SESSION, $SITE, $CFG; - $this->resetAfterTest(); - - // NOTE: this function contains some static caches, let's reset first. - cron_setup_user('reset'); - $this->assertDebuggingCalledCount(1); - - $admin = get_admin(); - $user1 = $this->getDataGenerator()->create_user(); - $user2 = $this->getDataGenerator()->create_user(); - $course = $this->getDataGenerator()->create_course(); - - cron_setup_user(); - $this->assertDebuggingCalledCount(1); - $this->assertSame($admin->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($SITE->id)); - $this->assertSame($CFG->timezone, $USER->timezone); - $this->assertSame('', $USER->lang); - $this->assertSame('', $USER->theme); - $SESSION->test1 = true; - $adminsession = $SESSION; - $adminuser = $USER; - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user(null, $course); - $this->assertDebuggingCalledCount(1); - $this->assertSame($admin->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($course->id)); - $this->assertSame($adminsession, $SESSION); - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user($user1); - $this->assertDebuggingCalledCount(1); - $this->assertSame($user1->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($SITE->id)); - $this->assertNotSame($adminsession, $SESSION); - $this->assertObjectNotHasProperty('test1', $SESSION); - $this->assertEmpty((array)$SESSION); - $usersession1 = $SESSION; - $SESSION->test2 = true; - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user($user1); - $this->assertDebuggingCalledCount(1); - $this->assertSame($user1->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($SITE->id)); - $this->assertNotSame($adminsession, $SESSION); - $this->assertSame($usersession1, $SESSION); - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user($user2); - $this->assertDebuggingCalledCount(1); - $this->assertSame($user2->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($SITE->id)); - $this->assertNotSame($adminsession, $SESSION); - $this->assertNotSame($usersession1, $SESSION); - $this->assertEmpty((array)$SESSION); - $usersession2 = $SESSION; - $usersession2->test3 = true; - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user($user2, $course); - $this->assertDebuggingCalledCount(1); - $this->assertSame($user2->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($course->id)); - $this->assertNotSame($adminsession, $SESSION); - $this->assertNotSame($usersession1, $SESSION); - $this->assertSame($usersession2, $SESSION); - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user($user1); - $this->assertDebuggingCalledCount(1); - $this->assertSame($user1->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($SITE->id)); - $this->assertNotSame($adminsession, $SESSION); - $this->assertNotSame($usersession1, $SESSION); - $this->assertEmpty((array)$SESSION); - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user(); - $this->assertDebuggingCalledCount(1); - $this->assertSame($admin->id, $USER->id); - $this->assertSame($PAGE->context, \context_course::instance($SITE->id)); - $this->assertSame($adminsession, $SESSION); - $this->assertSame($adminuser, $USER); - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user('reset'); - $this->assertDebuggingCalledCount(1); - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - cron_setup_user(); - $this->assertDebuggingCalledCount(1); - $this->assertNotSame($adminsession, $SESSION); - $this->assertNotSame($adminuser, $USER); - $this->assertSame($GLOBALS['SESSION'], $_SESSION['SESSION']); - $this->assertSame($GLOBALS['SESSION'], $SESSION); - $this->assertSame($GLOBALS['USER'], $_SESSION['USER']); - $this->assertSame($GLOBALS['USER'], $USER); - - // phpcs:enable - } - /** * Test provided for secure cookie *