Browse files

MDL-31390 Allow data to be sorted at backup

  • Loading branch information...
1 parent cce0d9a commit d9bae60289984994368deae908648e1bcebc5da4 @andrewnicols andrewnicols committed Jan 26, 2012
View
2 backup/util/dbops/backup_structure_dbops.class.php
@@ -48,7 +48,7 @@ public static function get_iterator($element, $params, $processor) {
return new backup_array_iterator($element->get_source_array());
} else if ($element->get_source_table() !== null) { // It's one table, return recordset iterator
- return $DB->get_recordset($element->get_source_table(), self::convert_params_to_values($params, $processor));
+ return $DB->get_recordset($element->get_source_table(), self::convert_params_to_values($params, $processor), $element->get_source_table_sortby());
} else if ($element->get_source_sql() !== null) { // It's one sql, return recordset iterator
return $DB->get_recordset_sql($element->get_source_sql(), self::convert_params_to_values($params, $processor));
View
11 backup/util/structure/backup_nested_element.class.php
@@ -31,6 +31,7 @@ class backup_nested_element extends base_nested_element implements processable {
protected $var_array; // To be used in case we pass one in-memory structure
protected $table; // Table (without prefix) to fetch records from
+ protected $tablesortby; // The field to sort by when using the table methods
protected $sql; // Raw SQL to fetch records from
protected $params; // Unprocessed params as specified in the set_source() call
protected $procparams;// Processed (path resolved) params array
@@ -51,6 +52,7 @@ public function __construct($name, $attributes = null, $final_elements = null) {
parent::__construct($name, $attributes, $final_elements);
$this->var_array = null;
$this->table = null;
+ $this->tablesortby = null;
$this->sql = null;
$this->params = null;
$this->procparams= null;
@@ -191,13 +193,16 @@ public function set_source_array($arr) {
$this->var_array = $arr;
}
- public function set_source_table($table, $params) {
+ public function set_source_table($table, $params, $sortby = null) {
if (!is_array($params)) { // Check we are passing array
throw new base_element_struct_exception('setsourcerequiresarrayofparams');
}
// TODO: Only elements having final elements can set source
$this->table = $table;
$this->procparams = $this->convert_table_params($params);
+ if ($sortby) {
+ $this->tablesortby = $sortby;
+ }
}
public function set_source_sql($sql, $params) {
@@ -259,6 +264,10 @@ public function get_source_table() {
return $this->table;
}
+ public function get_source_table_sortby() {
+ return $this->tablesortby;
+ }
+
public function get_source_sql() {
return $this->sql;
}

0 comments on commit d9bae60

Please sign in to comment.