Skip to content

Commit

Permalink
MDL-52702 plagiarism: Improvements to base plugin class
Browse files Browse the repository at this point in the history
  • Loading branch information
micaherne committed Jan 18, 2016
1 parent e65dfd9 commit 5e43eea
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@
$string['tasklegacycron'] = 'Legacy cron processing for plugins';
$string['taskmessagingcleanup'] = 'Background processing for messaging';
$string['taskpasswordresetcleanup'] = 'Cleanup password reset attempts';
$string['taskplagiarismcron'] = 'Background processing for plagiarism plugins';
$string['taskplagiarismcron'] = 'Background processing for legacy cron in plagiarism plugins';
$string['taskportfoliocron'] = 'Background processing for portfolio plugins';
$string['taskquestioncron'] = 'Background processing for question engine';
$string['taskregistrationcron'] = 'Site registration';
Expand Down
8 changes: 5 additions & 3 deletions lib/plagiarismlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ function plagiarism_cron() {
}
$plagiarismplugins = plagiarism_load_available_plugins();
foreach($plagiarismplugins as $plugin => $dir) {
mtrace('Processing cron function for plagiarism_plugin_' . $plugin . '...', '');
cron_trace_time_and_memory();
require_once($dir.'/lib.php');
$plagiarismclass = "plagiarism_plugin_$plugin";
$plagiarismplugin = new $plagiarismclass;
$plagiarismplugin->cron();
if (method_exists($plagiarismplugin, 'cron')) {
mtrace('Processing cron function for plagiarism_plugin_' . $plugin . '...', '');
cron_trace_time_and_memory();
$plagiarismplugin->cron();
}
}
}
/**
Expand Down
24 changes: 19 additions & 5 deletions plagiarism/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* lib.php - Contains Plagiarism base class used by plugins.
*
* @since Moodle 2.0
* @package moodlecore
* @subpackage plagiarism
* @package core_plagiarism
* @copyright 2010 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -29,8 +28,16 @@
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}

//dummy class - all plugins should be based off this.
class plagiarism_plugin {

/**
* Plagiarism base class used by plugins.
*
* @since Moodle 2.0
* @package core_plagiarism
* @copyright 2010 Dan Marsden http://danmarsden.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class plagiarism_plugin {

/**
* Return the list of form element names.
Expand Down Expand Up @@ -90,10 +97,17 @@ public function print_disclosure($cmid) {
*/
public function update_status($course, $cm) {
}

/**
* hook for cron
* Deprecated cron method.
*
* This method was added by mistake in the previous versions of Moodle, do not override it since it is never called.
* To implement cron you need to register a scheduled task, see https://docs.moodle.org/dev/Task_API.
* For backward compatibility with the old cron API the method cron() from this class can also be used.
*
* @deprecated since Moodle 3.1 MDL-52702 - please use scheduled tasks instead.
*/
public function plagiarism_cron() {
debugging('plagiarism_plugin::plagiarism_cron() is deprecated. Please use scheduled tasks instead', DEBUG_DEVELOPER);
}
}
6 changes: 6 additions & 0 deletions plagiarism/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This files describes API changes for code that uses the plagiarism API.

=== 3.1 ===

1) The plagiarism_plugin::plagiarism_cron() and plagiarism_plugin::cron() methods have been deprecated.
Plugins should now use scheduled tasks.

0 comments on commit 5e43eea

Please sign in to comment.