MDL-26037: restore/import: check through all courses instead of only first 250
authorTony Levi <tony.levi@netspot.com.au>
Fri, 6 Jan 2012 05:26:45 +0000 (15:56 +1030)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 1 Mar 2012 12:18:45 +0000 (13:18 +0100)
backup/util/ui/restore_ui_components.php

index adae38a..744fafc 100644 (file)
@@ -164,22 +164,26 @@ abstract class restore_search_base implements renderable {
         $this->totalcount = 0;
         $contextlevel = $this->get_itemcontextlevel();
         list($sql, $params) = $this->get_searchsql();
-        $resultset = $DB->get_recordset_sql($sql, $params, 0, 250);
-        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;
+        $blocksz = 5000;
+        $offs = 0;
+        while ($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;
+                        }
                     }
                 }
+                $this->results[$result->id] = $result;
+                $this->totalcount++;
+                if ($this->totalcount >= self::$MAXRESULTS) {
+                    break 2;
+                }
             }
-            $this->results[$result->id] = $result;
-            $this->totalcount++;
-            if ($this->totalcount >= self::$MAXRESULTS) {
-                break;
-            }
+            $offs += $blocksz;
         }
 
         return $this->totalcount;