diff --git a/admin/tool/log/classes/log/manager.php b/admin/tool/log/classes/log/manager.php index 894fe94e7de..4bffed0d3ca 100644 --- a/admin/tool/log/classes/log/manager.php +++ b/admin/tool/log/classes/log/manager.php @@ -134,16 +134,6 @@ class manager implements \core\log\manager { $this->writers = null; } - /** - * Execute cron actions. - */ - public function cron() { - $this->init(); - foreach ($this->stores as $store) { - $store->cron(); - } - } - /** * Legacy add_to_log() redirection. * diff --git a/admin/tool/log/classes/log/store.php b/admin/tool/log/classes/log/store.php index 1e402655d07..5a5726dea28 100644 --- a/admin/tool/log/classes/log/store.php +++ b/admin/tool/log/classes/log/store.php @@ -40,10 +40,4 @@ interface store { * @return void */ public function dispose(); - - /** - * Execute cron actions. - * @return void - */ - public function cron(); } diff --git a/admin/tool/log/store/database/classes/log/store.php b/admin/tool/log/store/database/classes/log/store.php index 9ab22f7b831..f64ccac89fc 100644 --- a/admin/tool/log/store/database/classes/log/store.php +++ b/admin/tool/log/store/database/classes/log/store.php @@ -209,9 +209,6 @@ class store implements \tool_log\log\writer, \core\log\sql_select_reader { return $this->extdb->count_records_select($dbtable, $selectwhere, $params); } - public function cron() { - } - /** * Are the new events appearing in the reader? * diff --git a/admin/tool/log/store/legacy/classes/log/store.php b/admin/tool/log/store/legacy/classes/log/store.php index d69851a3900..2436e7ebb2f 100644 --- a/admin/tool/log/store/legacy/classes/log/store.php +++ b/admin/tool/log/store/legacy/classes/log/store.php @@ -91,17 +91,6 @@ class store implements \tool_log\log\store, \core\log\sql_select_reader { } } - public function cron() { - global $CFG, $DB; - - // Delete old logs to save space (this might need a timer to slow it down...). - if (!empty($CFG->loglifetime)) { // Value in days. - $loglifetime = time(0) - ($CFG->loglifetime * 3600 * 24); - $DB->delete_records_select("log", "time < ?", array($loglifetime)); - mtrace(" Deleted old log records"); - } - } - /** * Are the new events appearing in the reader? * diff --git a/admin/tool/log/store/legacy/classes/task/cleanup_task.php b/admin/tool/log/store/legacy/classes/task/cleanup_task.php new file mode 100644 index 00000000000..474604b4a74 --- /dev/null +++ b/admin/tool/log/store/legacy/classes/task/cleanup_task.php @@ -0,0 +1,54 @@ +. + +/** + * Legacy log reader. + * + * @package logstore_legacy + * @copyright 2014 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace logstore_legacy\task; + +defined('MOODLE_INTERNAL') || die(); + +class cleanup_task extends \core\task\scheduled_task { + + /** + * Get a descriptive name for this task (shown to admins). + * + * @return string + */ + public function get_name() { + return get_string('taskcleanup', 'logstore_legacy'); + } + + /** + * Do the job. + * Throw exceptions on errors (the job will be retried). + */ + public function execute() { + global $CFG, $DB; + + // Delete old logs to save space (this might need a timer to slow it down...). + if (!empty($CFG->loglifetime)) { // Value in days. + $loglifetime = time(0) - ($CFG->loglifetime * 3600 * 24); + $DB->delete_records_select("log", "time < ?", array($loglifetime)); + mtrace(" Deleted old legacy log records"); + } + } +} diff --git a/admin/tool/log/lib.php b/admin/tool/log/store/legacy/db/tasks.php similarity index 67% rename from admin/tool/log/lib.php rename to admin/tool/log/store/legacy/db/tasks.php index 9db2ee3945f..24522d95703 100644 --- a/admin/tool/log/lib.php +++ b/admin/tool/log/store/legacy/db/tasks.php @@ -15,23 +15,23 @@ // along with Moodle. If not, see . /** - * Log tool API. + * Legacy log reader cron task. * - * @package tool_log - * @copyright 2014 Petr Skoda {@link http://skodak.org/} + * @package logstore_legacy + * @copyright 2014 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -/** - * Execute cron actions. - */ -function tool_log_cron() { - // Execute cron only if this log manager used. - $logmanager = get_log_manager(); - if (get_class($logmanager) === 'tool_log\log\manager') { - /** @var \tool_log\log\manager $logmanager */ - $logmanager->cron(); - } -} +$tasks = array( + array( + 'classname' => '\logstore_legacy\task\cleanup_task', + 'blocking' => 0, + 'minute' => '*', + 'hour' => '5', + 'day' => '*', + 'dayofweek' => '*', + 'month' => '*' + ), +); \ No newline at end of file diff --git a/admin/tool/log/store/legacy/lang/en/logstore_legacy.php b/admin/tool/log/store/legacy/lang/en/logstore_legacy.php index 4cf386218ab..58a54d4172f 100644 --- a/admin/tool/log/store/legacy/lang/en/logstore_legacy.php +++ b/admin/tool/log/store/legacy/lang/en/logstore_legacy.php @@ -27,4 +27,5 @@ $string['legacy:read'] = 'Read logs'; $string['loglegacy'] = 'Log legacy data'; $string['loglegacy_help'] = 'This plugin records log data to the legacy log table (mdl_log). This functionality has been replaced by newer, richer and more efficient logging plugins, so you should only run this plugin if you have old custom reports that directly query the old log table. Writing to the legacy logs will increase load, so it is recommended that you disable this plugin for performance reasons when it is not needed.'; $string['pluginname'] = 'Legacy log'; -$string['pluginname_desc'] = 'A log plugin that stores log entries in the legacy log table.'; \ No newline at end of file +$string['pluginname_desc'] = 'A log plugin that stores log entries in the legacy log table.'; +$string['taskcleanup'] = 'Legacy log table cleanup'; diff --git a/admin/tool/log/store/legacy/version.php b/admin/tool/log/store/legacy/version.php index c00663c98af..95f1d426822 100644 --- a/admin/tool/log/store/legacy/version.php +++ b/admin/tool/log/store/legacy/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2014011300; // The current plugin version (Date: YYYYMMDDXX). -$plugin->requires = 2014011000; // Requires this Moodle version. +$plugin->version = 2014031300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2014031200; // Requires this Moodle version. $plugin->component = 'logstore_legacy'; // Full name of the plugin (used for diagnostics). diff --git a/admin/tool/log/store/standard/classes/log/store.php b/admin/tool/log/store/standard/classes/log/store.php index 5f8e433b4ef..a05794e96c2 100644 --- a/admin/tool/log/store/standard/classes/log/store.php +++ b/admin/tool/log/store/standard/classes/log/store.php @@ -100,19 +100,6 @@ class store implements \tool_log\log\writer, \core\log\sql_internal_reader { return 'logstore_standard_log'; } - public function cron() { - global $DB; - $loglifetime = $this->get_config('loglifetime', 0); - - // NOTE: we should do this only once a day, new cron will deal with this. - - if ($loglifetime > 0) { - $loglifetime = time() - ($loglifetime * 3600 * 24); // Value in days. - $DB->delete_records_select("logstore_standard_log", "timecreated < ?", array($loglifetime)); - mtrace(" Deleted old log records from standard store."); - } - } - /** * Are the new events appearing in the reader? * diff --git a/admin/tool/log/store/standard/classes/task/cleanup_task.php b/admin/tool/log/store/standard/classes/task/cleanup_task.php new file mode 100644 index 00000000000..cc27b1fa091 --- /dev/null +++ b/admin/tool/log/store/standard/classes/task/cleanup_task.php @@ -0,0 +1,54 @@ +. + +/** + * Standard log reader/writer. + * + * @package logstore_standard + * @copyright 2014 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace logstore_standard\task; + +defined('MOODLE_INTERNAL') || die(); + +class cleanup_task extends \core\task\scheduled_task { + + /** + * Get a descriptive name for this task (shown to admins). + * + * @return string + */ + public function get_name() { + return get_string('taskcleanup', 'logstore_standard'); + } + + /** + * Do the job. + * Throw exceptions on errors (the job will be retried). + */ + public function execute() { + global $DB; + $loglifetime = (int)get_config('logstore_standard', 'loglifetime'); + + if ($loglifetime > 0) { + $loglifetime = time() - ($loglifetime * 3600 * 24); // Value in days. + $DB->delete_records_select("logstore_standard_log", "timecreated < ?", array($loglifetime)); + mtrace(" Deleted old log records from standard store."); + } + } +} diff --git a/admin/tool/log/store/standard/db/tasks.php b/admin/tool/log/store/standard/db/tasks.php new file mode 100644 index 00000000000..f51c812367d --- /dev/null +++ b/admin/tool/log/store/standard/db/tasks.php @@ -0,0 +1,37 @@ +. + +/** + * Standard log reader/writer cron task. + * + * @package logstore_standard + * @copyright 2014 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$tasks = array( + array( + 'classname' => '\logstore_standard\task\cleanup_task', + 'blocking' => 0, + 'minute' => '*', + 'hour' => '4', + 'day' => '*', + 'dayofweek' => '*', + 'month' => '*' + ), +); \ No newline at end of file diff --git a/admin/tool/log/store/standard/lang/en/logstore_standard.php b/admin/tool/log/store/standard/lang/en/logstore_standard.php index 4276fa7a680..c81fac541cd 100644 --- a/admin/tool/log/store/standard/lang/en/logstore_standard.php +++ b/admin/tool/log/store/standard/lang/en/logstore_standard.php @@ -26,3 +26,4 @@ $string['buffersize'] = 'Write buffer size'; $string['pluginname'] = 'Standard log'; $string['pluginname_desc'] = 'A log plugin stores log entries in a Moodle database table.'; $string['standard:read'] = 'Read logs'; +$string['taskcleanup'] = 'Log table cleanup'; diff --git a/admin/tool/log/store/standard/version.php b/admin/tool/log/store/standard/version.php index ae201daab0c..60a98ef2232 100644 --- a/admin/tool/log/store/standard/version.php +++ b/admin/tool/log/store/standard/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2014021100; // The current plugin version (Date: YYYYMMDDXX). -$plugin->requires = 2014012400; // Requires this Moodle version. +$plugin->version = 2014031300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2014031200; // Requires this Moodle version. $plugin->component = 'logstore_standard'; // Full name of the plugin (used for diagnostics).