]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12500 Fixed restore conversion for links in database templates
authorsam_marshall <sam_marshall>
Fri, 7 Dec 2007 16:26:32 +0000 (16:26 +0000)
committersam_marshall <sam_marshall>
Fri, 7 Dec 2007 16:26:32 +0000 (16:26 +0000)
mod/data/restorelib.php

index 3ac837bda754cca942988ae67798782013fe2bda..fcd95220bac01dd4ac1c89695d8488a00268f1ef 100644 (file)
@@ -563,27 +563,46 @@ function data_decode_content_links_caller($restore) {
     global $CFG;
     $status = true;
 
-/// Process every DATA (intro) in the course
-    if ($datas = get_records_sql ("SELECT d.id, d.intro
+/// Process every DATA (intro, all HTML templates) in the course
+/// Supported fields for main table:
+    $supportedfields = array('intro','singletemplate','listtemplate',
+        'listtemplateheader','addtemplate','rsstemplate','rsstitletemplate');
+    if ($datas = get_records_sql ("SELECT d.id, ".implode(',',$supportedfields)."
                                   FROM {$CFG->prefix}data d
                                   WHERE d.course = $restore->course_id")) {
-    /// Iterate over each data->intro
+    /// Iterate over each data
         $i = 0;   //Counter to send some output to the browser to avoid timeouts
         foreach ($datas as $data) {
         /// Increment counter
             $i++;
-            $content = $data->intro;
-            $result = restore_decode_content_links_worker($content,$restore);
-            if ($result != $content) {
-            /// Update record
-                $data->intro = addslashes($result);
-                $status = update_record("data",$data);
-                if (debugging()) {
-                    if (!defined('RESTORE_SILENTLY')) {
-                        echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
+
+        /// Make a new copy of the data object with nothing in, to use if
+        /// changes are necessary (allows us to do update_record without
+        /// worrying about every single field being included and needing
+        /// slashes).
+            $newdata = new stdClass;
+            $newdata->id=$data->id;
+
+        /// Loop through handling each supported field
+            $changed = false;
+            foreach($supportedfields as $field) {
+                $result = restore_decode_content_links_worker($data->{$field},$restore);
+                if ($result != $data->{$field}) {
+                    $newdata->{$field} = addslashes($result);
+                    $changed = true;
+                    if (debugging()) {
+                        if (!defined('RESTORE_SILENTLY')) {
+                            echo '<br /><hr />'.s($data->{$field}).'<br />changed to<br />'.s($result).'<hr /><br />';
+                        }
                     }
                 }
             }
+
+        /// Update record if any field changed
+            if($changed) {
+                $status = update_record("data",$newdata);
+            }
+
         /// Do some output
             if (($i+1) % 5 == 0) {
                 if (!defined('RESTORE_SILENTLY')) {