Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-26037 restore: fixes for mssql, php 5.4 and small improvs

  • Loading branch information...
commit 3b63a42387b365fad515d7071fda91317cf18281 1 parent 5c625be
@stronk7 stronk7 authored
Showing with 18 additions and 7 deletions.
  1. +18 −7 backup/util/ui/restore_ui_components.php
View
25 backup/util/ui/restore_ui_components.php
@@ -166,21 +166,32 @@ public function __construct(array $config=array()) {
list($sql, $params) = $this->get_searchsql();
$blocksz = 5000;
$offs = 0;
- while ($resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz)){
+ // Get total number, to avoid some incorrect iterations
+ $countsql = preg_replace('/ORDER BY.*/', '', $sql);
+ $totalcourses = $DB->count_records_sql("SELECT COUNT(*) FROM ($countsql) sel", $params);
+ // User to be checked is always the same (usually null, get it form first element)
+ $firstcap = reset($this->requiredcapabilities);
+ $userid = isset($firstcap['user']) ? $firstcap['user'] : null;
+ // Extract caps to check, this saves us a bunch of iterations
+ $requiredcaps = array();
+ foreach ($this->requiredcapabilities as $cap) {
+ $requiredcaps[] = $cap['capability'];
+ }
+ // Iterate while we have records and haven't reached MAXRESULTS
+ while ($totalcourses > $offs and $this->totalcount < self::$MAXRESULTS) {
+ $resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
foreach ($resultset as $result) {
context_instance_preload($result);
$context = get_context_instance($contextlevel, $result->id);
- if (count($this->requiredcapabilities) > 0) {
- foreach ($this->requiredcapabilities as $cap) {
- if (!has_capability($cap['capability'], $context, $cap['user'])) {
- continue 2;
- }
+ if (count($requiredcaps) > 0) {
+ if (!has_all_capabilities($requiredcaps, $context, $userid)) {
+ continue;
}
}
$this->results[$result->id] = $result;
$this->totalcount++;
if ($this->totalcount >= self::$MAXRESULTS) {
- break 2;
+ break;
}
}
$offs += $blocksz;
Please sign in to comment.
Something went wrong with that request. Please try again.