mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-35603-import-limit' of git://github.com/rlorenzo/moodle
This commit is contained in:
commit
92d1453bcb
@ -135,6 +135,11 @@ if ($hassiteconfig
|
||||
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), array('value'=>0, 'locked'=>0)));
|
||||
$ADMIN->add('backups', $temp);
|
||||
|
||||
// Create a page for general import configuration and defaults.
|
||||
$temp = new admin_settingpage('importgeneralsettings', new lang_string('importgeneralsettings', 'backup'), 'moodle/backup:backupcourse');
|
||||
$temp->add(new admin_setting_configtext('backup/import_general_maxresults', new lang_string('importgeneralmaxresults', 'backup'), new lang_string('importgeneralmaxresults_desc', 'backup'), 10));
|
||||
$ADMIN->add('backups', $temp);
|
||||
|
||||
// Create a page for automated backups configuration and defaults.
|
||||
$temp = new admin_settingpage('automated', new lang_string('automatedsetup','backup'), 'moodle/backup:backupcourse');
|
||||
|
||||
|
@ -590,8 +590,14 @@ class core_backup_renderer extends plugin_renderer_base {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_count()), array('class'=>'ics-totalresults'));
|
||||
$count_str = '';
|
||||
if ($component->has_more_results()) {
|
||||
$count_str = get_string('morecoursesearchresults', 'backup', $component->get_count());
|
||||
} else {
|
||||
$count_str = get_string('totalcoursesearchresults', 'backup', $component->get_count());
|
||||
}
|
||||
|
||||
$output .= html_writer::tag('div', $count_str, array('class'=>'ics-totalresults'));
|
||||
$output .= html_writer::start_tag('div', array('class' => 'ics-results'));
|
||||
|
||||
$table = new html_table();
|
||||
@ -610,6 +616,14 @@ class core_backup_renderer extends plugin_renderer_base {
|
||||
);
|
||||
$table->data[] = $row;
|
||||
}
|
||||
if ($component->has_more_results()) {
|
||||
$cell = new html_table_cell(get_string('moreresults', 'backup'));
|
||||
$cell->colspan = 3;
|
||||
$cell->attributes['class'] = 'notifyproblem';
|
||||
$row = new html_table_row(array($cell));
|
||||
$row->attributes['class'] = 'rcs-course';
|
||||
$table->data[] = $row;
|
||||
}
|
||||
$output .= html_writer::table($table);
|
||||
$output .= html_writer::end_tag('div');
|
||||
|
||||
|
@ -39,7 +39,6 @@ abstract class restore_search_base implements renderable {
|
||||
*/
|
||||
static $VAR_SEARCH = 'search';
|
||||
|
||||
static $MAXRESULTS = 10;
|
||||
/**
|
||||
* The current search string
|
||||
* @var string|null
|
||||
@ -65,6 +64,16 @@ abstract class restore_search_base implements renderable {
|
||||
* @var array
|
||||
*/
|
||||
private $requiredcapabilities = array();
|
||||
/**
|
||||
* Max number of courses to return in a search.
|
||||
* @var int
|
||||
*/
|
||||
private $maxresults = null;
|
||||
/**
|
||||
* Indicates if we have more than maxresults found.
|
||||
* @var boolean
|
||||
*/
|
||||
private $has_more_results = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -73,6 +82,7 @@ abstract class restore_search_base implements renderable {
|
||||
public function __construct(array $config=array()) {
|
||||
|
||||
$this->search = optional_param($this->get_varsearch(), self::DEFAULT_SEARCH, PARAM_NOTAGS);
|
||||
$this->maxresults = get_config('backup', 'import_general_maxresults');
|
||||
|
||||
foreach ($config as $name=>$value) {
|
||||
$method = 'set_'.$name;
|
||||
@ -177,8 +187,8 @@ abstract class restore_search_base implements renderable {
|
||||
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) {
|
||||
// Iterate while we have records and haven't reached $this->maxresults.
|
||||
while ($totalcourses > $offs and $this->totalcount < $this->maxresults) {
|
||||
$resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
|
||||
foreach ($resultset as $result) {
|
||||
context_instance_preload($result);
|
||||
@ -189,11 +199,14 @@ abstract class restore_search_base implements renderable {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$this->results[$result->id] = $result;
|
||||
$this->totalcount++;
|
||||
if ($this->totalcount >= self::$MAXRESULTS) {
|
||||
// Check if we are over the limit.
|
||||
if ($this->totalcount+1 > $this->maxresults) {
|
||||
$this->has_more_results = true;
|
||||
break;
|
||||
}
|
||||
// If not, then continue.
|
||||
$this->totalcount++;
|
||||
$this->results[$result->id] = $result;
|
||||
}
|
||||
$offs += $blocksz;
|
||||
}
|
||||
@ -202,7 +215,10 @@ abstract class restore_search_base implements renderable {
|
||||
}
|
||||
|
||||
final public function has_more_results() {
|
||||
return $this->get_count() >= self::$MAXRESULTS;
|
||||
if ($this->results === null) {
|
||||
$this->search();
|
||||
}
|
||||
return $this->has_more_results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,6 +138,9 @@ $string['generalroleassignments'] = 'Include role assignments';
|
||||
$string['generalsettings'] = 'General backup settings';
|
||||
$string['generaluserscompletion'] = 'Include user completion information';
|
||||
$string['generalusers'] = 'Include users';
|
||||
$string['importgeneralsettings'] = 'General import defaults';
|
||||
$string['importgeneralmaxresults'] = 'Maximum number of courses listed for import';
|
||||
$string['importgeneralmaxresults_desc'] = 'This controls the number of courses that are listed during the first step of the import process';
|
||||
$string['importfile'] = 'Import a backup file';
|
||||
$string['importbackupstage1action'] = 'Next';
|
||||
$string['importbackupstage2action'] = 'Next';
|
||||
@ -246,3 +249,4 @@ $string['skipmodifprev'] = 'Skip courses not modified since previous backup';
|
||||
$string['skipmodifprevhelp'] = 'Choose whether or not to skip courses that have not been modified since previous backup';
|
||||
$string['totalcategorysearchresults'] = 'Total categories: {$a}';
|
||||
$string['totalcoursesearchresults'] = 'Total courses: {$a}';
|
||||
$string['morecoursesearchresults'] = 'More than {$a} courses found, showing first {$a} results';
|
||||
|
Loading…
x
Reference in New Issue
Block a user