Merge branch 'MDL-26037_21' of git://github.com/stronk7/moodle into MOODLE_21_STABLE
This commit is contained in:
@@ -570,6 +570,12 @@ class core_backup_renderer extends plugin_renderer_base {
|
||||
$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;
|
||||
}
|
||||
|
||||
@@ -164,22 +164,37 @@ 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;
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user