Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-26037_21' of git://github.com/stronk7/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
commit 36bad5bfcdc6c716715c74effcb8324601e5b1d3 2 parents 33bd4e0 + 3b63a42
@samhemelryk samhemelryk authored
View
6 backup/util/ui/renderer.php
@@ -570,6 +570,12 @@ public function render_import_course_search(import_course_search $component) {
$output = html_writer::start_tag('div', array('class' => 'import-course-search'));
if ($component->get_count() === 0) {
$output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
+
+ $output .= html_writer::start_tag('div', array('class'=>'ics-search'));
+ $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
+ $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
+ $output .= html_writer::end_tag('div');
+
$output .= html_writer::end_tag('div');
return $output;
}
View
41 backup/util/ui/restore_ui_components.php
@@ -164,22 +164,37 @@ public function __construct(array $config=array()) {
$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;
+ // 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($requiredcaps) > 0) {
+ if (!has_all_capabilities($requiredcaps, $context, $userid)) {
+ continue;
}
}
+ $this->results[$result->id] = $result;
+ $this->totalcount++;
+ if ($this->totalcount >= self::$MAXRESULTS) {
+ break;
+ }
}
- $this->results[$result->id] = $result;
- $this->totalcount++;
- if ($this->totalcount >= self::$MAXRESULTS) {
- break;
- }
+ $offs += $blocksz;
}
return $this->totalcount;
Please sign in to comment.
Something went wrong with that request. Please try again.