mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-42541 stop using events for porfolion cron
This commit is contained in:
parent
900b1bf7d1
commit
fd0e019286
@ -342,17 +342,6 @@ function cron_run() {
|
||||
mtrace('done');
|
||||
}
|
||||
|
||||
|
||||
if ($CFG->enableportfolios) {
|
||||
// Portfolio cron
|
||||
mtrace('Starting the portfolio cron...');
|
||||
cron_trace_time_and_memory();
|
||||
require_once($CFG->libdir . '/portfoliolib.php');
|
||||
portfolio_cron();
|
||||
mtrace('done');
|
||||
}
|
||||
|
||||
|
||||
//now do plagiarism checks
|
||||
require_once($CFG->libdir.'/plagiarismlib.php');
|
||||
plagiarism_cron();
|
||||
@ -463,6 +452,15 @@ function cron_run() {
|
||||
cache_helper::cron();
|
||||
mtrace('done.');
|
||||
|
||||
// Portfolio cron - this needs to be close to the end because it may take a long time.
|
||||
if ($CFG->enableportfolios) {
|
||||
mtrace('Starting the portfolio cron...');
|
||||
cron_trace_time_and_memory();
|
||||
require_once($CFG->libdir . '/portfoliolib.php');
|
||||
portfolio_cron();
|
||||
mtrace('done');
|
||||
}
|
||||
|
||||
// Run automated backups if required - these may take a long time to execute
|
||||
require_once($CFG->dirroot.'/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot.'/backup/util/helper/backup_cron_helper.class.php');
|
||||
|
@ -36,22 +36,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
/* List of legacy event handlers */
|
||||
|
||||
$handlers = array(
|
||||
/*
|
||||
* portfolio queued event - for non interactive file transfers
|
||||
* NOTE: this is a HACK, please do not add any more things like this here
|
||||
* (it is just abusing cron to do very time consuming things which is wrong any way)
|
||||
*
|
||||
* TODO: this has to be moved into separate queueing framework....
|
||||
* TODO: MDL-25508, MDL-41541
|
||||
*/
|
||||
'portfolio_send' => array (
|
||||
'handlerfile' => '/lib/portfoliolib.php',
|
||||
'handlerfunction' => 'portfolio_handle_event', // argument to call_user_func(), could be an array
|
||||
'schedule' => 'cron',
|
||||
'internal' => 0,
|
||||
),
|
||||
|
||||
/* no more here please, core should not consume any events!!!!!!! */
|
||||
/* No more old events! */
|
||||
);
|
||||
|
||||
$observers = array(
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20140115" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20140213" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -2357,6 +2357,7 @@
|
||||
<FIELD NAME="expirytime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="time this record will expire (used for cron cleanups) - the start of export + 24 hours"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="psuedo fk to user. this is stored in the serialised data structure in the data field, but added here for ease of lookups."/>
|
||||
<FIELD NAME="instance" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="which portfolio plugin instance is being used"/>
|
||||
<FIELD NAME="queued" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Value 1 means the entry should be processed in cron."/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
@ -3084,4 +3085,4 @@
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
</XMLDB>
|
@ -2996,5 +2996,20 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2014020500.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2014020700.02) {
|
||||
|
||||
// Define field queued to be added to portfolio_tempdata.
|
||||
$table = new xmldb_table('portfolio_tempdata');
|
||||
$field = new xmldb_field('queued', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'instance');
|
||||
|
||||
// Conditionally launch add field queued.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2014020700.02);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -434,10 +434,11 @@ class portfolio_exporter {
|
||||
* @return bool whether or not to process the next stage. this is important as the control function is called recursively.
|
||||
*/
|
||||
public function process_stage_queueorwait() {
|
||||
global $DB;
|
||||
|
||||
$wait = $this->instance->get_export_config('wait');
|
||||
if (empty($wait)) {
|
||||
// TODO MDL-42541 Removing usage of events_trigger().
|
||||
events_trigger_legacy('portfolio_send', $this->id);
|
||||
$DB->set_field('portfolio_tempdata', 'queued', 1, array('id' => $this->id));
|
||||
$this->queued = true;
|
||||
return $this->process_stage_finished(true);
|
||||
}
|
||||
|
@ -930,30 +930,9 @@ function portfolio_report_insane($insane, $instances=false, $return=false) {
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Event handler for the portfolio_send event
|
||||
*
|
||||
* @param int $eventdata event id
|
||||
* @return bool
|
||||
*/
|
||||
function portfolio_handle_event($eventdata) {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->libdir . '/portfolio/exporter.php');
|
||||
$exporter = portfolio_exporter::rewaken_object($eventdata);
|
||||
$exporter->process_stage_package();
|
||||
$exporter->process_stage_send();
|
||||
$exporter->save();
|
||||
$exporter->process_stage_cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main portfolio cronjob.
|
||||
* Currently just cleans up expired transfer records.
|
||||
*
|
||||
* @todo - MDL-15997 - Add hooks in the plugins - either per instance or per plugin
|
||||
*/
|
||||
function portfolio_cron() {
|
||||
global $DB, $CFG;
|
||||
@ -969,6 +948,20 @@ function portfolio_cron() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$process = $DB->get_records('portfolio_tempdata', array('queued' => 1), 'id ASC', 'id');
|
||||
foreach ($process as $d) {
|
||||
try {
|
||||
$exporter = portfolio_exporter::rewaken_object($d->id);
|
||||
$exporter->process_stage_package();
|
||||
$exporter->process_stage_send();
|
||||
$exporter->save();
|
||||
$exporter->process_stage_cleanup();
|
||||
} catch (Exception $e) {
|
||||
// This will get probably retried in the next cron until it is discarded by the code above.
|
||||
mtrace('Exception thrown in portfolio cron while processing ' . $d->id . ': ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2014020700.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2014020700.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user