From f2745cbe673a27c5c02df5ebef6d32ce3e9a5113 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Fri, 6 Aug 2010 16:08:29 +0000 Subject: [PATCH] MDL-21432 backup - allow restore of only one itemid (instead of the whole itemname) --- backup/moodle2/restore_subplugin.class.php | 5 +++-- backup/util/dbops/restore_dbops.class.php | 6 +++++- backup/util/plan/restore_structure_step.class.php | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backup/moodle2/restore_subplugin.class.php b/backup/moodle2/restore_subplugin.class.php index 43eb56a1699..a5c8e4590b0 100644 --- a/backup/moodle2/restore_subplugin.class.php +++ b/backup/moodle2/restore_subplugin.class.php @@ -26,6 +26,7 @@ * Class implementing the subplugins support for moodle2 restore * * TODO: Finish phpdocs + * TODO: Add support for declaring decode_contents (not decode_rules) */ abstract class restore_subplugin { @@ -119,8 +120,8 @@ abstract class restore_subplugin { /** * Add all the existing file, given their component and filearea and one backup_ids itemname to match with */ - protected function add_related_files($component, $filearea, $mappingitemname, $filesctxid = null) { - $this->step->add_related_files($component, $filearea, $mappingitemname, $filesctxid); + protected function add_related_files($component, $filearea, $mappingitemname, $filesctxid = null, $olditemid = null) { + $this->step->add_related_files($component, $filearea, $mappingitemname, $filesctxid, $olditemid); } /** diff --git a/backup/util/dbops/restore_dbops.class.php b/backup/util/dbops/restore_dbops.class.php index 286960b4099..483c69244ad 100644 --- a/backup/util/dbops/restore_dbops.class.php +++ b/backup/util/dbops/restore_dbops.class.php @@ -238,7 +238,7 @@ abstract class restore_dbops { * optionally one source itemname to match itemids * put the corresponding files in the pool */ - public static function send_files_to_pool($basepath, $restoreid, $component, $filearea, $oldcontextid, $dfltuserid, $itemname = null) { + public static function send_files_to_pool($basepath, $restoreid, $component, $filearea, $oldcontextid, $dfltuserid, $itemname = null, $olditemid = null) { global $DB; // Get new context, must exist or this will fail @@ -273,6 +273,10 @@ abstract class restore_dbops { AND f.filearea = ? AND i.itemname = ?'; $params = array($restoreid, $oldcontextid, $component, $filearea, $itemname); + if ($olditemid !== null) { // Just process ONE olditemid intead of the whole itemname + $sql .= ' AND i.itemid = ?'; + $params[] = $olditemid; + } } $fs = get_file_storage(); // Get moodle file storage diff --git a/backup/util/plan/restore_structure_step.class.php b/backup/util/plan/restore_structure_step.class.php index 31ae2f4bc34..22688f64c64 100644 --- a/backup/util/plan/restore_structure_step.class.php +++ b/backup/util/plan/restore_structure_step.class.php @@ -182,10 +182,10 @@ abstract class restore_structure_step extends restore_step { /** * Add all the existing file, given their component and filearea and one backup_ids itemname to match with */ - public function add_related_files($component, $filearea, $mappingitemname, $filesctxid = null) { + public function add_related_files($component, $filearea, $mappingitemname, $filesctxid = null, $olditemid = null) { $filesctxid = is_null($filesctxid) ? $this->task->get_old_contextid() : $filesctxid; restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), $component, - $filearea, $filesctxid, $this->task->get_userid(), $mappingitemname); + $filearea, $filesctxid, $this->task->get_userid(), $mappingitemname, $olditemid); } /** -- 2.43.0