Skip to content

Commit

Permalink
Merge branch 'MDL-65047-master' of git://github.com/lameze/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Mar 27, 2019
2 parents 12404fa + d8e72a6 commit 18f460e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
31 changes: 28 additions & 3 deletions lib/classes/task/portfolio_cron_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,37 @@ public function get_name() {
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
global $CFG;
global $CFG, $DB;

if ($CFG->enableportfolios) {
require_once($CFG->libdir . '/portfoliolib.php');
portfolio_cron();
require_once($CFG->libdir . '/portfolio/exporter.php');
if ($expired = $DB->get_records_select('portfolio_tempdata', 'expirytime < ?', [time()], '', 'id')) {
foreach ($expired as $tempdata) {
try {
$exporter = \portfolio_exporter::rewaken_object($tempdata->id);
$exporter->process_stage_cleanup(true);
} catch (\Exception $exception) {
mtrace('Exception thrown in portfolio cron while cleaning up ' . $tempdata->id . ': ' .
$exception->getMessage());
}
}
}

$process = $DB->get_records('portfolio_tempdata', ['queued' => 1], 'id ASC', 'id');
foreach ($process as $tempdata) {
try {
$exporter = \portfolio_exporter::rewaken_object($tempdata->id);
$exporter->process_stage_package();
$exporter->process_stage_send();
$exporter->save();
$exporter->process_stage_cleanup();
} catch (\Exception $exception) {
// 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 ' . $tempdata->id . ': ' .
$exception->getMessage());
}
}
}
}

}
34 changes: 0 additions & 34 deletions lib/portfoliolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,40 +935,6 @@ function portfolio_report_insane($insane, $instances=false, $return=false) {
echo $output;
}

/**
* Main portfolio cronjob.
* Currently just cleans up expired transfer records.
*/
function portfolio_cron() {
global $DB, $CFG;

require_once($CFG->libdir . '/portfolio/exporter.php');
if ($expired = $DB->get_records_select('portfolio_tempdata', 'expirytime < ?', array(time()), '', 'id')) {
foreach ($expired as $d) {
try {
$e = portfolio_exporter::rewaken_object($d->id);
$e->process_stage_cleanup(true);
} catch (Exception $e) {
mtrace('Exception thrown in portfolio cron while cleaning up ' . $d->id . ': ' . $e->getMessage());
}
}
}

$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());
}
}
}

/**
* Helper function to rethrow a caught portfolio_exception as an export exception.
* Used because when a portfolio_export exception is thrown the export is cancelled
Expand Down
4 changes: 4 additions & 0 deletions portfolio/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
This files describes API changes in /portfolio/ portfolio system,
information provided here is intended especially for developers.

=== 3.7 ===

* The portfolio_cron() function has been removed. Please use portfolio_cron_task scheduled task instead.

=== 3.1 ===

* The following functions, previously used (exclusively) by upgrade steps are not available
Expand Down

0 comments on commit 18f460e

Please sign in to comment.