From: ethem Date: Fri, 21 Mar 2008 11:47:17 +0000 (+0000) Subject: get_recordset() for performance X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b37fa3d55364d543bb1114b36f11c2b5f3c8acc4;p=moodle.git get_recordset() for performance --- diff --git a/enrol/authorize/localfuncs.php b/enrol/authorize/localfuncs.php index bbd4536dc7..1965001518 100644 --- a/enrol/authorize/localfuncs.php +++ b/enrol/authorize/localfuncs.php @@ -1,4 +1,4 @@ -fullname: Authorize.net ERROR", $message); } - function send_welcome_messages($orderdata) { global $CFG, $SITE; @@ -131,43 +130,49 @@ function send_welcome_messages($orderdata) $orderdata = array($orderdata); } - $select = "SELECT e.id, e.courseid, e.userid, c.fullname - FROM {$CFG->prefix}enrol_authorize e - INNER JOIN {$CFG->prefix}course c ON c.id = e.courseid - WHERE e.id IN(" . implode(',', $orderdata) . ") - ORDER BY e.userid"; - - $emailinfo = get_records_sql($select); - if (1 == count($emailinfo)) { - $ei = reset($emailinfo); - $context = get_context_instance(CONTEXT_COURSE, $ei->courseid); - $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1'); - $sender = array_shift($paymentmanagers); - } - else { - $sender = get_admin(); - } + $sql = "SELECT e.id, e.courseid, e.userid, c.fullname + FROM {$CFG->prefix}enrol_authorize e + INNER JOIN {$CFG->prefix}course c ON c.id = e.courseid + WHERE e.id IN(" . implode(',', $orderdata) . ") + ORDER BY e.userid"; - for($ei = reset($emailinfo); $ei !== false; ) { - $usercourses = array(); - $lastuserid = $ei->userid; - for($current = $ei; $current !== false && $current->userid == $lastuserid; $current = next($emailinfo)) { - $usercourses[] = $current->fullname; + if (($rs = get_recordset_sql($sql)) && ($ei = rs_fetch_next_record($rs))) + { + if (1 < count($orderdata)) { + $sender = get_admin(); } - $ei = $current; - if ($user = get_record('user', 'id', $lastuserid)) { - $a = new stdClass; - $a->name = $user->firstname; - $a->courses = implode("\n", $usercourses); - $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid"; - $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid"; - $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a); - @email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage); + else { + $context = get_context_instance(CONTEXT_COURSE, $ei->courseid); + $paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments', '', '', '0', '1'); + $sender = array_shift($paymentmanagers); } + + do + { + $usercourses = array(); + $lastuserid = $ei->userid; + + while ($ei && $ei->userid == $lastuserid) { + $usercourses[] = $ei->fullname; + $ei = rs_fetch_next_record($rs); + } + + if (($user = get_record('user', 'id', $lastuserid))) { + $a = new stdClass; + $a->name = $user->firstname; + $a->courses = implode("\n", $usercourses); + $a->profileurl = "$CFG->wwwroot/user/view.php?id=$lastuserid"; + $a->paymenturl = "$CFG->wwwroot/enrol/authorize/index.php?user=$lastuserid"; + $emailmessage = get_string('welcometocoursesemail', 'enrol_authorize', $a); + @email_to_user($user, $sender, get_string("enrolmentnew", '', $SITE->shortname), $emailmessage); + } + } + while ($ei); + + rs_close($rs); } } - function check_curl_available() { return function_exists('curl_init') && @@ -175,11 +180,10 @@ function check_curl_available() in_array('https', stream_get_wrappers()); } - function authorize_verify_account() { global $CFG, $USER, $SITE; - require_once('authorizenetlib.php'); + require_once('authorizenet.class.php'); $CFG->an_test = 1; // Test mode @@ -210,7 +214,8 @@ function authorize_verify_account() $extra->x_invoice_num = $order->id; $extra->x_description = 'Verify Account'; - if (AN_APPROVED == authorize_action($order, $message, $extra, AN_ACTION_AUTH_CAPTURE, 'vis')) { + $message = ''; + if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_AUTH_CAPTURE)) { return get_string('verifyaccountresult', 'enrol_authorize', get_string('success')); } else {