Skip to content

Commit 33f92e8

Browse files
committed
Removed legacy cron function and deprecated cron_trace_time_and_memory
In Moodle 4.2, cron_trace_time_and_memory has been replaced by a different function in a namespaced location, and you get deprecation warnings for including cronlib.php as well as for calling the function. This change removes the old cron function in lib.php, and changes the code that calls cron_trace_time_and_memory so that it uses the old method prior to 4.2, and the new one after.
1 parent c7c7584 commit 33f92e8

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

classes/task/delete_local_empty_directories.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
defined('MOODLE_INTERNAL') || die();
3232

33-
require_once($CFG->libdir.'/cronlib.php');
34-
3533
class delete_local_empty_directories extends task {
3634

3735
/** @var string $stringname */
@@ -42,6 +40,8 @@ class delete_local_empty_directories extends task {
4240
* @throws coding_exception
4341
*/
4442
public function execute() {
43+
global $CFG;
44+
4545
if (!$this->enabled_tasks()) {
4646
return;
4747
}
@@ -51,7 +51,13 @@ public function execute() {
5151
return;
5252
}
5353
$filesystem = new $this->config->filesystem();
54-
cron_trace_time_and_memory();
54+
if ($CFG->version < 2023042400) {
55+
// This function and library was deprecated in Moodle 4.2.
56+
require_once($CFG->libdir . '/cronlib.php');
57+
cron_trace_time_and_memory();
58+
} else {
59+
\core\cron::trace_time_and_memory();
60+
}
5561
$filesystem->delete_empty_dirs();
5662
}
5763
}

lib.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,6 @@
6969
define('TOOL_OBJECTFS_DELETE_EXTERNAL_TRASH', 1);
7070
define('TOOL_OBJECTFS_DELETE_EXTERNAL_FULL', 2);
7171

72-
// Legacy cron function.
73-
function tool_objectfs_cron() {
74-
mtrace('RUNNING legacy cron objectfs');
75-
global $CFG;
76-
if ($CFG->branch <= 26) {
77-
// Unlike the task system, we do not get fine grained control over
78-
// when tasks/manipulators run. Every cron we just run all the manipulators.
79-
(new manipulator_builder())->execute_all();
80-
81-
\tool_objectfs\local\report\objectfs_report::cleanup_reports();
82-
\tool_objectfs\local\report\objectfs_report::generate_status_report();
83-
}
84-
85-
return true;
86-
}
87-
8872
/**
8973
* Sends a plugin file to the browser.
9074
* @param $course

tests/local/tasks_test.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ protected function tearDown(): void {
3232
ob_end_clean();
3333
}
3434

35-
public function test_run_legacy_cron() {
36-
$config = manager::get_objectfs_config();
37-
$config->enabletasks = true;
38-
manager::set_objectfs_config($config);
39-
$this->assertTrue(tool_objectfs_cron());
40-
}
41-
4235
public function test_run_scheduled_tasks() {
4336
global $CFG;
4437
// If tasks not implemented.

0 commit comments

Comments
 (0)