Skip to content

Commit 5e43eea

Browse files
committed
MDL-52702 plagiarism: Improvements to base plugin class
1 parent e65dfd9 commit 5e43eea

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

lang/en/admin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@
10321032
$string['tasklegacycron'] = 'Legacy cron processing for plugins';
10331033
$string['taskmessagingcleanup'] = 'Background processing for messaging';
10341034
$string['taskpasswordresetcleanup'] = 'Cleanup password reset attempts';
1035-
$string['taskplagiarismcron'] = 'Background processing for plagiarism plugins';
1035+
$string['taskplagiarismcron'] = 'Background processing for legacy cron in plagiarism plugins';
10361036
$string['taskportfoliocron'] = 'Background processing for portfolio plugins';
10371037
$string['taskquestioncron'] = 'Background processing for question engine';
10381038
$string['taskregistrationcron'] = 'Site registration';

lib/plagiarismlib.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,14 @@ function plagiarism_cron() {
171171
}
172172
$plagiarismplugins = plagiarism_load_available_plugins();
173173
foreach($plagiarismplugins as $plugin => $dir) {
174-
mtrace('Processing cron function for plagiarism_plugin_' . $plugin . '...', '');
175-
cron_trace_time_and_memory();
176174
require_once($dir.'/lib.php');
177175
$plagiarismclass = "plagiarism_plugin_$plugin";
178176
$plagiarismplugin = new $plagiarismclass;
179-
$plagiarismplugin->cron();
177+
if (method_exists($plagiarismplugin, 'cron')) {
178+
mtrace('Processing cron function for plagiarism_plugin_' . $plugin . '...', '');
179+
cron_trace_time_and_memory();
180+
$plagiarismplugin->cron();
181+
}
180182
}
181183
}
182184
/**

plagiarism/lib.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
* lib.php - Contains Plagiarism base class used by plugins.
2020
*
2121
* @since Moodle 2.0
22-
* @package moodlecore
23-
* @subpackage plagiarism
22+
* @package core_plagiarism
2423
* @copyright 2010 Dan Marsden http://danmarsden.com
2524
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2625
*/
@@ -29,8 +28,16 @@
2928
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
3029
}
3130

32-
//dummy class - all plugins should be based off this.
33-
class plagiarism_plugin {
31+
32+
/**
33+
* Plagiarism base class used by plugins.
34+
*
35+
* @since Moodle 2.0
36+
* @package core_plagiarism
37+
* @copyright 2010 Dan Marsden http://danmarsden.com
38+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39+
*/
40+
abstract class plagiarism_plugin {
3441

3542
/**
3643
* Return the list of form element names.
@@ -90,10 +97,17 @@ public function print_disclosure($cmid) {
9097
*/
9198
public function update_status($course, $cm) {
9299
}
100+
93101
/**
94-
* hook for cron
102+
* Deprecated cron method.
103+
*
104+
* This method was added by mistake in the previous versions of Moodle, do not override it since it is never called.
105+
* To implement cron you need to register a scheduled task, see https://docs.moodle.org/dev/Task_API.
106+
* For backward compatibility with the old cron API the method cron() from this class can also be used.
95107
*
108+
* @deprecated since Moodle 3.1 MDL-52702 - please use scheduled tasks instead.
96109
*/
97110
public function plagiarism_cron() {
111+
debugging('plagiarism_plugin::plagiarism_cron() is deprecated. Please use scheduled tasks instead', DEBUG_DEVELOPER);
98112
}
99113
}

plagiarism/upgrade.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This files describes API changes for code that uses the plagiarism API.
2+
3+
=== 3.1 ===
4+
5+
1) The plagiarism_plugin::plagiarism_cron() and plagiarism_plugin::cron() methods have been deprecated.
6+
Plugins should now use scheduled tasks.

0 commit comments

Comments
 (0)