Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Very small change. A little performance for cron if admin enabled sen…

…ding email for pending orders expiring.

1- If dailysettlement is 00:05 and cron executes at this time, nothing will occur. If it is executes at 00:10 it works. I think "<" works faster then "<=" :))
2- Don't compare course->ids by authorize->courseid, because courses are grouped by courseid. We sure each line is unique.
3- Only get pendingorderexpiring strings for sending email if course teachers exist.
  • Loading branch information...
commit 552f0e47dc9123f27426c044869ae8289e57a474 1 parent 84331e0
ethem authored

Showing 1 changed file with 18 additions and 20 deletions. Show diff stats Hide diff stats

  1. +18 20 enrol/authorize/enrol.php
38 enrol/authorize/enrol.php
@@ -635,24 +635,24 @@ function cron()
635 635
636 636 $oneday = 86400;
637 637 $timenow = time();
638   - $timenowsettle = getsettletime($timenow);
639   - $timediff30 = $timenowsettle - (30 * $oneday);
  638 + $settlementtime = getsettletime($timenow);
  639 + $timediff30 = $settlementtime - (30 * $oneday);
640 640 $mconfig = get_config('enrol/authorize');
641 641 set_config('an_lastcron', $timenow, 'enrol/authorize');
642 642
643   - if (intval($mconfig->an_dailysettlement) <= $timenowsettle) {
644   - set_config('an_dailysettlement', $timenowsettle + $oneday, 'enrol/authorize');
  643 + if (intval($mconfig->an_dailysettlement) < $settlementtime) {
  644 + set_config('an_dailysettlement', $settlementtime, 'enrol/authorize');
645 645 // Some clean-up and update
646 646 $select = "(status='".AN_STATUS_NONE."') AND (timecreated<'$timediff30')";
647 647 delete_records_select('enrol_authorize', $select);
648 648 $select = "(status='".AN_STATUS_AUTH."') AND (timecreated<'$timediff30')";
649 649 execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status='".AN_STATUS_EXPIRE."' WHERE $select", false);
650   - $timediff60 = $timenowsettle - (60 * $oneday);
  650 + $timediff60 = $settlementtime - (60 * $oneday);
651 651 $select = "(status='".AN_STATUS_EXPIRE."') AND (timecreated<'$timediff60')";
652 652 delete_records_select('enrol_authorize', $select);
653 653 // Daily warning email for expiring pending orders.
654 654 if (!empty($CFG->an_emailexpired)) {
655   - $timediffem = $timenowsettle - ((30 - intval($CFG->an_emailexpired)) * $oneday);
  655 + $timediffem = $settlementtime - ((30 - intval($CFG->an_emailexpired)) * $oneday);
656 656 $select = "(status='". AN_STATUS_AUTH ."') AND (timecreated<'$timediffem') AND (timecreated>'$timediff30')";
657 657 if ($count = count_records_select('enrol_authorize', $select)) {
658 658 $a = new stdClass;
@@ -677,26 +677,24 @@ function cron()
677 677 "INNER JOIN {$CFG->prefix}course C ON C.id = E.courseid " .
678 678 "WHERE $select GROUP BY E.courseid ORDER BY $sorttype DESC";
679 679 $message = ''; $subject = ''; $lastcourse = 0;
680   - $courseidandcounts = get_records_sql($sql);
681   - foreach($courseidandcounts as $courseidandcount) {
682   - if ($lastcourse != $courseidandcount->courseid) {
683   - $lastcourse = $courseidandcount->courseid;
  680 + $coursesandcounts = get_records_sql($sql);
  681 + foreach($coursesandcounts as $courseandcount) {
  682 + $lastcourse = $courseandcount->courseid;
  683 + if ($teachers = get_course_teachers($lastcourse)) {
684 684 $a = new stdClass;
685   - $a->course = $courseidandcount->shortname;
686   - $a->pending = $courseidandcount->cnt;
  685 + $a->course = $courseandcount->shortname;
  686 + $a->pending = $courseandcount->cnt;
687 687 $a->days = $CFG->an_emailexpired;
688 688 $subject = get_string('pendingorderssubject', 'enrol_authorize', $a);
689 689 $a = new stdClass;
690   - $a->course = $courseidandcount->fullname;
691   - $a->pending = $courseidandcount->cnt;
692   - $a->currency = $courseidandcount->currency;
693   - $a->sumcost = $courseidandcount->ttl;
  690 + $a->course = $courseandcount->fullname;
  691 + $a->pending = $courseandcount->cnt;
  692 + $a->currency = $courseandcount->currency;
  693 + $a->sumcost = $courseandcount->ttl;
694 694 $a->days = $CFG->an_emailexpired;
695 695 $a->url = $CFG->wwwroot.'/enrol/authorize/index.php?course='.
696   - $lastcourse.'&amp;status='.AN_STATUS_AUTH;
  696 + $lastcourse.'&amp;status='.AN_STATUS_AUTH;
697 697 $message = get_string('pendingordersemailteacher', 'enrol_authorize', $a);
698   - }
699   - if ($teachers = get_course_teachers($lastcourse)) {
700 698 foreach ($teachers as $teacher) {
701 699 email_to_user($teacher, $adminuser, $subject, $message);
702 700 }
@@ -712,7 +710,7 @@ function cron()
712 710 return;
713 711 }
714 712
715   - $timediffcnf = $timenowsettle - (intval($CFG->an_capture_day) * $oneday);
  713 + $timediffcnf = $settlementtime - (intval($CFG->an_capture_day) * $oneday);
716 714 $sql = "SELECT E.*, C.fullname, C.enrolperiod " .
717 715 "FROM {$CFG->prefix}enrol_authorize E " .
718 716 "INNER JOIN {$CFG->prefix}course C ON C.id = E.courseid " .

0 comments on commit 552f0e4

Please sign in to comment.
Something went wrong with that request. Please try again.