Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some cron performance. Run clean-ups and send email daily on settleme…

…nt date.

an_nextmail config deleted, instead of old config new an_dailysettlement inserted into config_plugins table.
Merged from MOODLE_16_STABLE.
  • Loading branch information...
commit 9a4502dd1daf6c8ab29f9e3cd631c75b61083644 1 parent 989a0a5
ethem authored
View
10 enrol/authorize/db/mysql.php
@@ -19,7 +19,7 @@ function enrol_authorize_upgrade($oldversion=0) {
}
if ($oldversion && $oldversion < 2005071602) {
- notify("If you are using the authorize.net enrolment plugin for credit card
+ notify("If you are using the authorize.net enrolment plugin for credit card
handling, please ensure that you have turned loginhttps ON in Admin >> Variables >> Security.");
}
@@ -104,11 +104,19 @@ function enrol_authorize_upgrade($oldversion=0) {
table_column('enrol_authorize', 'transid', 'transid', 'integer', '10', 'unsigned', '0', 'not null');
}
+ if ($oldversion < 2006021501) { // delete an_nextmail record from config_plugins table
+ delete_records('config_plugins', 'name', 'an_nextmail');
+ }
+
if ($oldversion < 2006050400) { // Create transid indexes for backup & restore speed.
execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD INDEX transid(transid)", false);
execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize_refunds` ADD INDEX transid(transid)", false);
}
+ if ($oldversion < 2006060500) { // delete an_nextmail record from config_plugins table
+ delete_records('config_plugins', 'name', 'an_nextmail'); // run twice.
+ }
+
return $result;
}
View
8 enrol/authorize/db/postgres7.php
@@ -115,11 +115,19 @@ function enrol_authorize_upgrade($oldversion=0) {
table_column('enrol_authorize', 'transid', 'transid', 'integer', '10', 'unsigned', '0', 'not null');
}
+ if ($oldversion < 2006021501) { // delete an_nextmail record from config_plugins table
+ delete_records('config_plugins', 'name', 'an_nextmail');
+ }
+
if ($oldversion < 2006050400) { // Create transid indexes for backup & restore speed.
execute_sql("CREATE INDEX {$CFG->prefix}enrol_authorize_transid_idx ON {$CFG->prefix}enrol_authorize(transid);", false);
execute_sql("CREATE INDEX {$CFG->prefix}enrol_authorize_refunds_transid_idx ON {$CFG->prefix}enrol_authorize_refunds(transid);", false);
}
+ if ($oldversion < 2006060500) { // delete an_nextmail record from config_plugins table
+ delete_records('config_plugins', 'name', 'an_nextmail'); // run twice.
+ }
+
return $result;
}
View
47 enrol/authorize/enrol.php
@@ -631,40 +631,35 @@ function cron()
$oneday = 86400;
$timenow = time();
- $random100 = mt_rand(0, 100);
$timenowsettle = getsettletime($timenow);
$timediff30 = $timenowsettle - (30 * $oneday);
$mconfig = get_config('enrol/authorize');
set_config('an_lastcron', $timenow, 'enrol/authorize');
- if ($random100 < 33) {
- $select = "(status = '" .AN_STATUS_NONE. "') AND (timecreated < '$timediff30')";
+ if (intval($mconfig->an_dailysettlement) <= $timenowsettle) {
+ set_config('an_dailysettlement', $timenowsettle + $oneday, 'enrol/authorize');
+ // Some clean-up and update
+ $select = "(status='".AN_STATUS_NONE."') AND (timecreated<'$timediff30')";
delete_records_select('enrol_authorize', $select);
- }
- elseif ($random100 > 66) {
- $select = "(status = '" .AN_STATUS_AUTH. "') AND (timecreated < '$timediff30')";
- execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status = '" .AN_STATUS_EXPIRE. "' WHERE $select", false);
- }
- else {
+ $select = "(status='".AN_STATUS_AUTH."') AND (timecreated<'$timediff30')";
+ execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status='".AN_STATUS_EXPIRE."' WHERE $select", false);
$timediff60 = $timenowsettle - (60 * $oneday);
- $select = "(status = '" .AN_STATUS_EXPIRE. "') AND (timecreated < '$timediff60')";
+ $select = "(status='".AN_STATUS_EXPIRE."') AND (timecreated<'$timediff60')";
delete_records_select('enrol_authorize', $select);
- }
-
- if (!empty($CFG->an_emailexpired) && intval($mconfig->an_nextmail) < $timenowsettle) {
- set_config('an_nextmail', $timenowsettle + $oneday + 1, 'enrol/authorize');
- $timediffem = $timenowsettle - ((30 - intval($CFG->an_emailexpired)) * $oneday);
- $select = "(status = '" . AN_STATUS_AUTH . "') AND " .
- "(timecreated < '$timediffem') AND (timecreated > '$timediff30')";
- if ($count = count_records_select('enrol_authorize', $select)) {
- $a = new stdClass;
- $a->pending = $count;
- $a->days = $CFG->an_emailexpired;
- $a->enrolurl = "$CFG->wwwroot/$CFG->admin/users.php";
- $a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=".AN_STATUS_AUTH;
- $message = get_string('pendingordersemail', 'enrol_authorize', $a);
- $adminuser = get_admin();
- email_to_user($adminuser, $adminuser, "WARNING: PENDING PAYMENTS", $a);
+ // Daily warning email for expiring pending orders.
+ if (!empty($CFG->an_emailexpired)) {
+ $timediffem = $timenowsettle - ((30 - intval($CFG->an_emailexpired)) * $oneday);
+ $select = "(status='". AN_STATUS_AUTH ."') AND (timecreated<'$timediffem') AND (timecreated>'$timediff30')";
+ if ($count = count_records_select('enrol_authorize', $select)) {
+ $a = new stdClass;
+ $a->pending = $count;
+ $a->days = $CFG->an_emailexpired;
+ $a->enrolurl = "$CFG->wwwroot/$CFG->admin/users.php";
+ $a->url = $CFG->wwwroot."/enrol/authorize/index.php?status=".AN_STATUS_AUTH;
+ $message = get_string('pendingordersemail', 'enrol_authorize', $a);
+ $adminuser = get_admin();
+ email_to_user($adminuser, $adminuser, "WARNING: PENDING PAYMENTS", $a);
+ }
}
}
View
2  enrol/authorize/version.php
@@ -1,6 +1,6 @@
<?PHP // $Id$
-$plugin->version = 2006050400;
+$plugin->version = 2006060500;
$plugin->requires = 2005072200;
?>
Please sign in to comment.
Something went wrong with that request. Please try again.