]> git.mjollnir.org Git - moodle.git/commitdiff
Now every link to forums (from resources and forums) and every link
authorstronk7 <stronk7>
Sat, 8 May 2004 18:30:30 +0000 (18:30 +0000)
committerstronk7 <stronk7>
Sat, 8 May 2004 18:30:30 +0000 (18:30 +0000)
to resources (from resources and forums) are re-encoded in backup/restore.

I could reduce the code size but for now I prefer to have it this looong
form to clarify what it's doing.

Please, test, test and test...

backup/STATUS.txt
backup/version.php
mod/forum/restorelib.php
mod/resource/backuplib.php
mod/resource/restorelib.php

index 6af982b3ce0f8d4d7eb08f1da47fd73400ed9a9a..5fe7caffd17a276550d208bb93b31a4c52a0c344 100644 (file)
@@ -126,9 +126,9 @@ Backup Details:
       - Modify the backup frontend..............................NOT EXISTS
       - Modify the backup of course_sections and course_modules.NOT EXISTS
       - Modify every module backuplib to work properly..........NOT EXISTS
-   - Encode every possible internal link........................IN PROGRESS
+   - Encode every possible internal link........................DONE
       - Links to forums.........................................DONE
-      - Links to resources......................................NOT EXISTS
+      - Links to resources......................................DONE
 Restore Details:
 ===============
    - Delete old entries at restore start........................DONE
@@ -245,11 +245,17 @@ Restore Details:
       - From database...........................................DONE
       - From filesystem.........................................DONE
    - Upload backup files........................................DONE
-   - Decode every possible internal link........................IN PROGRESS
-      - Links to forums.........................................IN PROGRESS
+   - Decode every possible internal link........................DONE
+      - Links to forums.........................................DONE
+         - From forums (post->message)..........................DONE
+         - From forums (forum->intro)...........................DONE
+         - From resources (resource->summary)...................DONE
+         - From resources (resource->alltext)...................DONE
+      - Links to resources......................................DONE
          - From forums (post->message)..........................DONE
+         - From forums (forum->intro)...........................DONE
+         - From resources (resource->summary)...................DONE
          - From resources (resource->alltext)...................DONE
-      - Links to resources......................................NOT EXISTS
 
 ========== ========== ========== =========== =========== =========== ===
 
index e9799d1fa7aa2d20ba6be1de0b1d065641cdfe93..b17aa23813a7685f10f7d7a699c496f8eff99c31 100644 (file)
@@ -5,6 +5,6 @@
 // database (backup_version) to determine whether upgrades should
 // be performed (see db/backup_*.php)
 
-$backup_version = 2004050800;   // The current version is a date (YYYYMMDDXX)
+$backup_version = 2004050801;   // The current version is a date (YYYYMMDDXX)
 
 $backup_release = "1.3 development";  // User-friendly version number
index 234a45927ab7a9f6f8cc11d9d999abf35be643e6..d09764a377d46a05ecbfce3129068f05294d85ea 100644 (file)
             }
         }
 
+        //RESOURCE: Decode every RESOURCE (summary) in the coure
+
+        //Check we are restoring resources
+        if ($restore->mods['resource']->restore == 1) {
+            //Get all course resources
+            if ($resources = get_records_sql ("SELECT r.id, r.summary
+                                       FROM {$CFG->prefix}resource r
+                                       WHERE r.course = $restore->course_id")) {
+                //Iterate over each resource->summary
+                $i = 0;   //Counter to send some output to the browser to avoid timeouts
+                foreach ($resources as $resource) {
+                    //Increment counter
+                    $i++;
+                    $content = $resource->summary;
+                    $result = forum_decode_content_links($content,$restore);
+                    if ($result != $content) {
+                        //Update record
+                        $resource->summary = addslashes($result);
+                        $status = update_record("resource",$resource);
+                        if ($CFG->debug>7) {
+                            echo "<br><hr>".$content."<br>changed to</br>".$result."<hr><br>";
+                        }
+                    }
+                    //Do some output
+                    if (($i+1) % 5 == 0) {
+                        echo ".";
+                        if (($i+1) % 100 == 0) {
+                            echo "<br>";
+                        }
+                        backup_flush(300);
+                    }
+                }
+            }
+        }
+
         echo "</ul>";
         return $status;
     }
index 61e63b5a18bb81e6e8d3d6cf48b997de82df00b0..fb8c8e5dce10b94e80e2072337ac45f49deb7e03 100644 (file)
         return $info;
     }
 
+    //Return a content encoded to support interactivities linking. Every module
+    //should have its own. They are called automatically from the backup procedure.
+    function resource_encode_content_links ($content,$preferences) {
 
+        global $CFG;
+
+        $base = preg_quote($CFG->wwwroot,"/");
 
+        //Link to the list of resources
+        $buscar="/(".$base."\/mod\/resource\/index.php\?id\=)([0-9]+)/";
+        $result= preg_replace($buscar,'$@RESOURCEINDEX*$2@$',$content);
 
+        //Link to resource view by moduleid
+        $buscar="/(".$base."\/mod\/resource\/view.php\?id\=)([0-9]+)/";
+        $result= preg_replace($buscar,'$@RESOURCEVIEWBYID*$2@$',$result);
 
+        return $result;
+    }
 
     // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
 
index f57296e1dd87b415c9a9c65f7083315a2cfc7d05..f80a6bd60cd502b4f2788d2f80705f5a45ef9f5c 100644 (file)
         return $status;
     }
 
+    //Return a content decoded to support interactivities linking. Every module
+    //should have its own. They are called automatically from
+    //resource_decode_content_links_caller() function in each module
+    //in the restore process
+    function resource_decode_content_links ($content,$restore) {
+            
+        global $CFG;
+            
+        $result = $content;
+                
+        //Link to the list of resources
+                
+        $searchstring='/\$@(RESOURCEINDEX)\*([0-9]+)@\$/';
+        //We look for it
+        preg_match_all($searchstring,$content,$foundset);
+        //If found, then we are going to look for its new id (in backup tables)
+        if ($foundset[0]) {
+            //print_object($foundset);                                     //Debug
+            //Iterate over foundset[2]. They are the old_ids
+            foreach($foundset[2] as $old_id) {
+                //We get the needed variables here (course id)
+                $rec = backup_getid($restore->backup_unique_code,"course",$old_id);
+                //Personalize the searchstring
+                $searchstring='/\$@(RESOURCEINDEX)\*('.$old_id.')@\$/';
+                //If it is a link to this course, update the link to its new location
+                if($rec->new_id) {
+                    //Now replace it
+                    $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/resource/index.php?id='.$rec->new_id,$result);
+                } else { 
+                    //It's a foreign link so leave it as original
+                    $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/resource/index.php?id='.$old_id,$result);
+                }
+            }
+        }
+
+        //Link to resource view by moduleid
+
+        $searchstring='/\$@(RESOURCEVIEWBYID)\*([0-9]+)@\$/';
+        //We look for it
+        preg_match_all($searchstring,$result,$foundset);
+        //If found, then we are going to look for its new id (in backup tables)
+        if ($foundset[0]) {
+            //print_object($foundset);                                     //Debug
+            //Iterate over foundset[2]. They are the old_ids
+            foreach($foundset[2] as $old_id) {
+                //We get the needed variables here (course_modules id)
+                $rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id);
+                //Personalize the searchstring
+                $searchstring='/\$@(RESOURCEVIEWBYID)\*('.$old_id.')@\$/';
+                //If it is a link to this course, update the link to its new location
+                if($rec->new_id) {
+                    //Now replace it
+                    $result= preg_replace($searchstring,$CFG->wwwroot.'/mod/resource/view.php?id='.$rec->new_id,$result);
+                } else {
+                    //It's a foreign link so leave it as original
+                    $result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/resource/view.php?id='.$old_id,$result);
+                }
+            }
+        }
+
+        return $result;
+    }
+
+    //This function makes all the necessary calls to xxxx_decode_content_links()
+    //function in each module, passing them the desired contents to be decoded
+    //from backup format to destination site/course in order to mantain inter-activities
+    //working in the backup/restore process. It's called from restore_decode_content_links()
+    //function in restore process
+    function resource_decode_content_links_caller($restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        echo "<ul>";
+        //FORUM: Decode every POST (message) in the coure
+
+        //Check we are restoring forums
+        if ($restore->mods['forum']->restore == 1) {
+            echo "<li>".get_string("from")." ".get_string("modulenameplural","forum");
+            //Get all course posts
+            if ($posts = get_records_sql ("SELECT p.id, p.message
+                                       FROM {$CFG->prefix}forum_posts p,
+                                            {$CFG->prefix}forum_discussions d
+                                       WHERE d.course = $restore->course_id AND
+                                             p.discussion = d.id")) {
+                //Iterate over each post->message
+                $i = 0;   //Counter to send some output to the browser to avoid timeouts
+                foreach ($posts as $post) {
+                    //Increment counter
+                    $i++;
+                    $content = $post->message;
+                    $result = resource_decode_content_links($content,$restore);
+                    if ($result != $content) {
+                        //Update record
+                        $post->message = addslashes($result);
+                        $status = update_record("forum_posts",$post);
+                        if ($CFG->debug>7) {
+                            echo "<br><hr>".$content."<br>changed to</br>".$result."<hr><br>";
+                        }
+                    }
+                    //Do some output
+                    if (($i+1) % 5 == 0) {
+                        echo ".";
+                        if (($i+1) % 100 == 0) {
+                            echo "<br>";
+                        }
+                        backup_flush(300);
+                    }
+                }
+            }
+        }
+
+        //FORUM: Decode every FORUM (intro) in the coure
+
+        //Check we are restoring forums
+        if ($restore->mods['forum']->restore == 1) {
+            //Get all course forums
+            if ($forums = get_records_sql ("SELECT f.id, f.intro
+                                       FROM {$CFG->prefix}forum f
+                                       WHERE f.course = $restore->course_id")) {
+                //Iterate over each forum->intro
+                $i = 0;   //Counter to send some output to the browser to avoid timeouts
+                foreach ($forums as $forum) {
+                    //Increment counter
+                    $i++;
+                    $content = $forum->intro;
+                    $result = resource_decode_content_links($content,$restore);
+                    if ($result != $content) {
+                        //Update record
+                        $forum->intro = addslashes($result);
+                        $status = update_record("forum",$forum);
+                        if ($CFG->debug>7) {
+                            echo "<br><hr>".$content."<br>changed to</br>".$result."<hr><br>";
+                        }
+                    }
+                    //Do some output
+                    if (($i+1) % 5 == 0) {
+                        echo ".";
+                        if (($i+1) % 100 == 0) {
+                            echo "<br>";
+                        }
+                        backup_flush(300);
+                    }
+                }
+            }
+        }
+
+        //RESOURCE: Decode every RESOURCE (alltext) in the coure
+
+        //Check we are restoring resources
+        if ($restore->mods['resource']->restore == 1) {
+            echo "<li>".get_string("from")." ".get_string("modulenameplural","resource");
+            //Get all course resources
+            if ($resources = get_records_sql ("SELECT r.id, r.alltext
+                                       FROM {$CFG->prefix}resource r
+                                       WHERE r.course = $restore->course_id")) {
+                //Iterate over each resource->alltext
+                $i = 0;   //Counter to send some output to the browser to avoid timeouts
+                foreach ($resources as $resource) {
+                    //Increment counter
+                    $i++;
+                    $content = $resource->alltext;
+                    $result = resource_decode_content_links($content,$restore);
+                    if ($result != $content) {
+                        //Update record
+                        $resource->alltext = addslashes($result);
+                        $status = update_record("resource",$resource);
+                        if ($CFG->debug>7) {
+                            echo "<br><hr>".$content."<br>changed to</br>".$result."<hr><br>";
+                        }
+                    }
+                    //Do some output
+                    if (($i+1) % 5 == 0) {
+                        echo ".";
+                        if (($i+1) % 100 == 0) {
+                            echo "<br>";
+                        }
+                        backup_flush(300);
+                    }
+                }
+            }
+        }
+
+        //RESOURCE: Decode every RESOURCE (summary) in the coure
+
+        //Check we are restoring resources
+        if ($restore->mods['resource']->restore == 1) {
+            //Get all course resources
+            if ($resources = get_records_sql ("SELECT r.id, r.summary
+                                       FROM {$CFG->prefix}resource r
+                                       WHERE r.course = $restore->course_id")) {
+                //Iterate over each resource->summary
+                $i = 0;   //Counter to send some output to the browser to avoid timeouts
+                foreach ($resources as $resource) {
+                    //Increment counter
+                    $i++;
+                    $content = $resource->summary;
+                    $result = resource_decode_content_links($content,$restore);
+                    if ($result != $content) {
+                        //Update record
+                        $resource->summary = addslashes($result);
+                        $status = update_record("resource",$resource);
+                        if ($CFG->debug>7) {
+                            echo "<br><hr>".$content."<br>changed to</br>".$result."<hr><br>";
+                        }
+                    }
+                    //Do some output
+                    if (($i+1) % 5 == 0) {
+                        echo ".";
+                        if (($i+1) % 100 == 0) {
+                            echo "<br>";
+                        }
+                        backup_flush(300);
+                    }
+                }
+            }
+        }
+
+        echo "</ul>";
+        return $status;
+    }
+
+
     //This function returns a log record with all the necessay transformations
     //done. It's used by restore_log_module() to restore modules log.
     function resource_restore_logs($restore,$log) {