MDL-15095 towards restore lib dml conversion
authorskodak <skodak>
Tue, 3 Jun 2008 23:35:50 +0000 (23:35 +0000)
committerskodak <skodak>
Tue, 3 Jun 2008 23:35:50 +0000 (23:35 +0000)
16 files changed:
backup/restorelib.php
mod/assignment/restorelib.php
mod/chat/restorelib.php
mod/choice/restorelib.php
mod/data/restorelib.php
mod/forum/restorelib.php
mod/glossary/restorelib.php
mod/hotpot/restorelib.php
mod/label/restorelib.php
mod/lesson/restorelib.php
mod/quiz/restorelib.php
mod/resource/restorelib.php
mod/scorm/restorelib.php
mod/survey/restorelib.php
mod/wiki/restorelib.php
question/restorelib.php

index d09b305848eefb46bfbdd3031148fa570703244d..b6da844a9db443adb5b60fb1565e82709d07f762 100644 (file)
@@ -3268,7 +3268,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
 
                 //Now search if that group exists (by name and description field) in
                 //restore->course_id course
-                //Going to compare LOB columns so, use the cross-db sql_compare_text() in both sides.
+                //Going to compare LOB columns so, use the cross-db $DB->sql_compare_text() in both sides.
                 $description_clause = '';
                 $params = array('courseid'=>$restore->course_id, 'grname'=>$gro->name);
                 if (!empty($gro->description)) { /// Only for groups having a description
index af89d2c9bf0ae06a5fdb30974bf640e23220245c..3939800778c434f2530685874e62ecf69377a39a 100644 (file)
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function assignment_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
 
-        if ($assignments = get_records_sql ("SELECT a.id, a.description
-                                   FROM {$CFG->prefix}assignment a
-                                   WHERE a.course = $restore->course_id")) {
+        if ($assignments = $DB->get_records('assignment', array('course'=>$restore->course_id), '', "id,description")) {
             //Iterate over each assignment->description
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($assignments as $assignment) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $assignment->description = addslashes($result);
-                    $status = update_record("assignment",$assignment);
+                    $assignment->description = $result;
+                    $status = $DB->update_record("assignment",$assignment);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
     //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
     //some texts in the module
     function assignment_restore_wiki2markdown ($restore) {
-    
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
         //Convert assignment->description
-        if ($records = get_records_sql ("SELECT a.id, a.description, a.format
-                                         FROM {$CFG->prefix}assignment a,
-                                              {$CFG->prefix}backup_ids b
-                                         WHERE a.course = $restore->course_id AND
+        if ($records = $DB->get_records_sql ("SELECT a.id, a.description, a.format
+                                                FROM {assignment} a, {backup_ids} b
+                                               WHERE a.course = ? AND
                                                a.format = ".FORMAT_WIKI. " AND
-                                               b.backup_code = $restore->backup_unique_code AND
+                                               b.backup_code = ? AND
                                                b.table_name = 'assignment' AND
-                                               b.new_id = a.id")) {
+                                               b.new_id = a.id", array($restore->course_id, $restore->backup_unique_code))) {
             foreach ($records as $record) {
                 //Rebuild wiki links
                 $record->description = restore_decode_wiki_content($record->description, $restore);
                 $wtm = new WikiToMarkdown();
                 $record->description = $wtm->convert($record->description, $restore->course_id);
                 $record->format = FORMAT_MARKDOWN;
-                $status = update_record('assignment', addslashes_object($record));
+                $status = $DB->update_record('assignment', $record);
                 //Do some output
                 $i++;
                 if (($i+1) % 1 == 0) {
index f3429a4503bb3fa9878eea5a0bee1a02980900ce..587caef52df9410f38b97b2222f420d7016456d3 100644 (file)
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function chat_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
         
-        if ($chats = get_records_sql ("SELECT c.id, c.intro
-                                   FROM {$CFG->prefix}chat c
-                                   WHERE c.course = $restore->course_id")) {
+        if ($chats = $DB->get_records('chat', array('course'=>$restore->course_id), '', "id,intro")) {
                                                //Iterate over each chat->intro
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($chats as $chat) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $chat->intro = addslashes($result);
-                    $status = update_record("chat",$chat);
+                    $chat->intro = $result;
+                    $status = $DB->update_record("chat",$chat);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
index 9974c8ab3468bba7d55edf3c44fea8ec7315f11f..dee6829016cb8b0a7ccbcfc8b40140cd61d3cf80 100644 (file)
     }
 
 function choice_options_restore_mods($choiceid,$info,$restore) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
@@ -169,7 +168,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
             $option->timemodified = backup_todb($opt_info['#']['TIMEMODIFIED']['0']['#']);
 
             //The structure is equal to the db, so insert the choice_options
-            $newid = insert_record ("choice_options",$option);
+            $newid = $DB->insert_record ("choice_options",$option);
 
             //Do some output
             if (($i+1) % 50 == 0) {
@@ -196,8 +195,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
 
     //This function restores the choice_answers
     function choice_answers_restore_mods($choiceid,$info,$restore) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
@@ -239,7 +237,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
             }
 
             //The structure is equal to the db, so insert the choice_answers
-            $newid = insert_record ("choice_answers",$answer);
+            $newid = $DB->insert_record ("choice_answers",$answer);
 
             //Do some output
             if (($i+1) % 50 == 0) {
@@ -336,9 +334,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
         global $CFG;
         $status = true;
         
-        if ($choices = get_records_sql ("SELECT c.id, c.text
-                                   FROM {$CFG->prefix}choice c
-                                   WHERE c.course = $restore->course_id")) {
+        if ($choices = $DB->get_records('chat', array('course'=>$restore->course_id), '', "id,text")) {
                                                //Iterate over each choice->text
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($choices as $choice) {
@@ -348,8 +344,8 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $choice->text = addslashes($result);
-                    $status = update_record("choice",$choice);
+                    $choice->text = $result;
+                    $status = $DB->update_record("choice",$choice);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@@ -375,20 +371,18 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
     //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
     //some texts in the module
     function choice_restore_wiki2markdown ($restore) {
-    
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
         //Convert choice->text
-        if ($records = get_records_sql ("SELECT c.id, c.text, c.format
-                                         FROM {$CFG->prefix}choice c,
-                                              {$CFG->prefix}backup_ids b
-                                         WHERE c.course = $restore->course_id AND
-                                               c.format = ".FORMAT_WIKI. " AND
-                                               b.backup_code = $restore->backup_unique_code AND
-                                               b.table_name = 'choice' AND
-                                               b.new_id = c.id")) {
+        if ($records = $DB->get_records_sql("SELECT c.id, c.text, c.format
+                                               FROM {choice} c, {backup_ids} b
+                                              WHERE c.course = ? AND
+                                                    c.format = ".FORMAT_WIKI. " AND
+                                                    b.backup_code = ? AND
+                                                    b.table_name = 'choice' AND
+                                                    b.new_id = c.id", array($restore->course_id, $restore->backup_unique_code))) {
             foreach ($records as $record) {
                 //Rebuild wiki links
                 $record->text = restore_decode_wiki_content($record->text, $restore);
@@ -396,7 +390,7 @@ function choice_options_restore_mods($choiceid,$info,$restore) {
                 $wtm = new WikiToMarkdown();
                 $record->text = $wtm->convert($record->text, $restore->course_id);
                 $record->format = FORMAT_MARKDOWN;
-                $status = update_record('choice', addslashes_object($record));
+                $status = $DB->update_record('choice', $record);
                 //Do some output
                 $i++;
                 if (($i+1) % 1 == 0) {
index 63dd62b7c1955d964ece9b0724565ef19a81d765..44c4fc4dab5b042c5b2ba76ed42cb5546cb25059 100644 (file)
@@ -555,17 +555,17 @@ function data_decode_content_links ($content,$restore) {
  * @return boolean status of the execution
  */
 function data_decode_content_links_caller($restore) {
+    global $CFG, $DB;
 
-    global $CFG;
     $status = true;
 
 /// 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")) {
+    if ($datas = $DB->get_records_sql ("SELECT d.id, ".implode(',',$supportedfields)."
+                                          FROM {data} d
+                                         WHERE d.course = ?", array($restore->course_id))) {
     /// Iterate over each data
         $i = 0;   //Counter to send some output to the browser to avoid timeouts
         foreach ($datas as $data) {
@@ -573,7 +573,7 @@ function data_decode_content_links_caller($restore) {
             $i++;
 
         /// Make a new copy of the data object with nothing in, to use if
-        /// changes are necessary (allows us to do update_record without
+        /// changes are necessary (allows us to do $DB->update_record without
         /// worrying about every single field being included and needing
         /// slashes).
             $newdata = new stdClass;
@@ -584,7 +584,7 @@ function data_decode_content_links_caller($restore) {
             foreach($supportedfields as $field) {
                 $result = restore_decode_content_links_worker($data->{$field},$restore);
                 if ($result != $data->{$field}) {
-                    $newdata->{$field} = addslashes($result);
+                    $newdata->{$field} = $result;
                     $changed = true;
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
@@ -596,7 +596,7 @@ function data_decode_content_links_caller($restore) {
 
         /// Update record if any field changed
             if($changed) {
-                $status = update_record("data",$newdata);
+                $status = $DB->update_record("data",$newdata);
             }
 
         /// Do some output
@@ -613,13 +613,13 @@ function data_decode_content_links_caller($restore) {
     }
 
 /// Process every COMMENT (content) in the course
-    if ($comments = get_records_sql ("SELECT dc.id, dc.content
-                                      FROM {$CFG->prefix}data d,
-                                           {$CFG->prefix}data_records dr,
-                                           {$CFG->prefix}data_comments dc
-                                      WHERE d.course = $restore->course_id
-                                        AND dr.dataid = d.id
-                                        AND dc.recordid = dr.id")) {
+    if ($comments = $DB->get_records_sql ("SELECT dc.id, dc.content
+                                             FROM {data} d,
+                                                  {data_records} dr,
+                                                  {data_comments} dc
+                                            WHERE d.course = ?
+                                                  AND dr.dataid = d.id
+                                                  AND dc.recordid = dr.id", array($restore->course_id))) {
     /// Iterate over each data_comments->content
         $i = 0;   //Counter to send some output to the browser to avoid timeouts
         foreach ($comments as $comment) {
@@ -629,8 +629,8 @@ function data_decode_content_links_caller($restore) {
             $result = restore_decode_content_links_worker($content,$restore);
             if ($result != $content) {
             /// Update record
-                $comment->content = addslashes($result);
-                $status = update_record("data_comments",$comment);
+                $comment->content = $result;
+                $status = $DB->update_record("data_comments",$comment);
                 if (debugging()) {
                     if (!defined('RESTORE_SILENTLY')) {
                         echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
@@ -651,13 +651,13 @@ function data_decode_content_links_caller($restore) {
     }
 
 /// Process every CONTENT (content, content1, content2, content3, content4) in the course
-    if ($contents = get_records_sql ("SELECT dc.id, dc.content, dc.content1, dc.content2, dc.content3, dc.content4
-                                      FROM {$CFG->prefix}data d,
-                                           {$CFG->prefix}data_records dr,
-                                           {$CFG->prefix}data_content dc
-                                      WHERE d.course = $restore->course_id
-                                        AND dr.dataid = d.id
-                                        AND dc.recordid = dr.id")) {
+    if ($contents = $DB->get_records_sql("SELECT dc.id, dc.content, dc.content1, dc.content2, dc.content3, dc.content4
+                                            FROM {data} d,
+                                                 {data_records} dr,
+                                                 {data_content} dc
+                                           WHERE d.course = ?
+                                                 AND dr.dataid = d.id
+                                                 AND dc.recordid = dr.id", array($restore->course_id))) {
     /// Iterate over each data_content->content, content1, content2, content3 and content4
         $i = 0;   //Counter to send some output to the browser to avoid timeouts
         foreach ($contents as $cnt) {
@@ -683,22 +683,22 @@ function data_decode_content_links_caller($restore) {
                 unset($cnt->content4);
             /// Conditionally set the fields
                 if ($result != $content) {
-                    $cnt->content = addslashes($result);
+                    $cnt->content = $result;
                 }
                 if ($result1 != $content1) {
-                    $cnt->content1 = addslashes($result1);
+                    $cnt->content1 = $result1;
                 }
                 if ($result2 != $content2) {
-                    $cnt->content2 = addslashes($result2);
+                    $cnt->content2 = $result2;
                 }
                 if ($result3 != $content3) {
-                    $cnt->content3 = addslashes($result3);
+                    $cnt->content3 = $result3;
                 }
                 if ($result4 != $content4) {
-                    $cnt->content4 = addslashes($result4);
+                    $cnt->content4 = $result4;
                 }
             /// Update record with the changed fields
-                $status = update_record("data_content",$cnt);
+                $status = $DB->update_record("data_content",$cnt);
                 if (debugging()) {
                     if (!defined('RESTORE_SILENTLY')) {
                         echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
index b7665c7dc9b6a0dba12a93db3ffdaa1c0841b9e8..a8c7659890e9b97eabd8972882e73f0822a975f2 100644 (file)
     //This function returns a log record with all the necessay transformations
     //done. It's used by restore_log_module() to restore modules log.
     function forum_restore_logs($restore,$log) {
+        global $DB;
 
         $status = false;
 
                 $pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
                 if ($pos) {
                     //Get the post record from database
-                    $dbpos = get_record("forum_posts","id","$pos->new_id");
+                    $dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
                     if ($dbpos) {
                         $log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id;
                         $log->info = $pos->new_id;
                 $pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
                 if ($pos) {
                     //Get the post record from database
-                    $dbpos = get_record("forum_posts","id","$pos->new_id");
+                    $dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
                     if ($dbpos) {
                         $log->url = "discuss.php?d=".$dbpos->discussion;
                         $log->info = $pos->new_id;
                 $pos = backup_getid($restore->backup_unique_code,"forum_posts",$log->info);
                 if ($pos) {
                     //Get the post record from database
-                    $dbpos = get_record("forum_posts","id","$pos->new_id");
+                    $dbpos = $DB->get_record("forum_posts", array("id"=>$pos->new_id));
                     if ($dbpos) {
                         $log->url = "discuss.php?d=".$dbpos->discussion."&parent=".$pos->new_id;
                         $log->info = $pos->new_id;
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function forum_decode_content_links_caller($restore) {
-        global $CFG, $DB;
+        global $CFG, $DB, $DB;
         $status = true;
         
         //Process every POST (message) in the course
-        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")) {
+        if ($posts = $DB->get_records_sql("SELECT p.id, p.message
+                                             FROM {forum_posts} p,
+                                                  {forum_discussions} d
+                                            WHERE d.course = ? AND
+                                                  p.discussion = d.id", array($restore->course_id))) {
             //Iterate over each post->message
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($posts as $post) {
         }
 
         //Process every FORUM (intro) in the course
-        if ($forums = get_records_sql ("SELECT f.id, f.intro
-                                   FROM {$CFG->prefix}forum f
-                                   WHERE f.course = $restore->course_id")) {
+        if ($forums = $DB->get_records('forum', array('course'=>$restore->course_id), '', "id,intro")) {
             //Iterate over each forum->intro
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($forums as $forum) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $forum->intro = addslashes($result);
-                    $status = update_record("forum",$forum);
+                    $forum->intro = $result;
+                    $status = $DB->update_record("forum",$forum);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
index 93e291b27b558306b5e578a0f474fbb627bd2526..f432b037c18b01d43627293019a9228cf848f9df 100644 (file)
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function glossary_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
         
         //Process every glossary ENTRY in the course
-        if ($entries = get_records_sql ("SELECT e.id, e.definition
-                                   FROM {$CFG->prefix}glossary_entries e,
-                                        {$CFG->prefix}glossary g
-                                   WHERE g.course = $restore->course_id AND
-                                         e.glossaryid = g.id")) {
+        if ($entries = $DB->get_records_sql("SELECT e.id, e.definition
+                                               FROM {glossary_entries} e,
+                                                    {glossary} g
+                                              WHERE g.course = ? AND
+                                                    e.glossaryid = g.id", array($restore->course_id))) {
             //Iterate over each post->message
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($entries as $entry) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $entry->definition = addslashes($result);
-                    $status = update_record("glossary_entries",$entry);
+                    $entry->definition = $result;
+                    $status = $DB->update_record("glossary_entries",$entry);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
         }
 
         //Process every glossary (intro) in the course
-        if ($glossarys = get_records_sql ("SELECT g.id, g.intro
-                                   FROM {$CFG->prefix}glossary g
-                                   WHERE g.course = $restore->course_id")) {
+        if ($glossarys = $DB->get_records('glossary', array('course'=>$restore->course_id), '', "id,intro")) {
             //Iterate over each glossary->intro
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($glossarys as $glossary) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $glossary->intro = addslashes($result);
-                    $status = update_record("glossary",$glossary);
+                    $glossary->intro = $result;
+                    $status = $DB->update_record("glossary",$glossary);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
     //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
     //some texts in the module
     function glossary_restore_wiki2markdown ($restore) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
         //Convert glossary_comments->entrycomment
-        if ($records = get_records_sql ("SELECT c.id, c.entrycomment, c.format
-                                         FROM {$CFG->prefix}glossary_comments c,
-                                              {$CFG->prefix}glossary_entries e,
-                                              {$CFG->prefix}glossary g,
-                                              {$CFG->prefix}backup_ids b
-                                         WHERE e.id = c.entryid AND
-                                               g.id = e.glossaryid AND
-                                               g.course = $restore->course_id AND
-                                               c.format = ".FORMAT_WIKI. " AND
-                                               b.backup_code = $restore->backup_unique_code AND
-                                               b.table_name = 'glossary_comments' AND
-                                               b.new_id = c.id")) {
+        if ($records = $DB->get_records_sql("SELECT c.id, c.entrycomment, c.format
+                                               FROM {glossary_comments} c,
+                                                    {glossary_entries} e,
+                                                    {glossary} g,
+                                                    {backup_ids} b
+                                              WHERE e.id = c.entryid AND
+                                                    g.id = e.glossaryid AND
+                                                    g.course = ? AND
+                                                    c.format = ".FORMAT_WIKI. " AND
+                                                    b.backup_code = ? AND
+                                                    b.table_name = 'glossary_comments' AND
+                                                    b.new_id = c.id", array($restore->course_id, $restore->backup_unique_code))) {
             foreach ($records as $record) {
                 //Rebuild wiki links
                 $record->entrycomment = restore_decode_wiki_content($record->entrycomment, $restore);
                 $wtm = new WikiToMarkdown();
                 $record->entrycomment = $wtm->convert($record->entrycomment, $restore->course_id);
                 $record->format = FORMAT_MARKDOWN;
-                $status = update_record('glossary_comments', addslashes_object($record));
+                $status = $DB->update_record('glossary_comments', $record);
                 //Do some output
                 $i++;
                 if (($i+1) % 1 == 0) {
         }
 
         //Convert glossary_entries->definition
-        if ($records = get_records_sql ("SELECT e.id, e.definition, e.format
-                                         FROM {$CFG->prefix}glossary_entries e,
-                                              {$CFG->prefix}glossary g,
-                                              {$CFG->prefix}backup_ids b
-                                         WHERE g.id = e.glossaryid AND
-                                               g.course = $restore->course_id AND
-                                               e.format = ".FORMAT_WIKI. " AND
-                                               b.backup_code = $restore->backup_unique_code AND
-                                               b.table_name = 'glossary_entries' AND
-                                               b.new_id = e.id")) {
+        if ($records = $DB->get_records_sql("SELECT e.id, e.definition, e.format
+                                               FROM {glossary_entries} e,
+                                                    {glossary} g,
+                                                    {backup_ids} b
+                                              WHERE g.id = e.glossaryid AND
+                                                    g.course = ? AND
+                                                    e.format = ".FORMAT_WIKI. " AND
+                                                    b.backup_code = ? AND
+                                                    b.table_name = 'glossary_entries' AND
+                                                    b.new_id = e.id", array($restore->course_id, $restore->backup_unique_code))) {
             foreach ($records as $record) {
                 //Rebuild wiki links
                 $record->definition = restore_decode_wiki_content($record->definition, $restore);
                 $wtm = new WikiToMarkdown();
                 $record->definition = $wtm->convert($record->definition, $restore->course_id);
                 $record->format = FORMAT_MARKDOWN;
-                $status = update_record('glossary_entries', addslashes_object($record));
+                $status = $DB->update_record('glossary_entries', $record);
                 //Do some output
                 $i++;
                 if (($i+1) % 1 == 0) {
index 844818dd909eb50d0b1df00809635c0d5d3303a5..36940419e842ffae7829aa59a8e5bd121104c083 100644 (file)
@@ -212,6 +212,7 @@ function hotpot_restore_responses(&$restore, $status, &$xml, &$record) {
     );
 }
 function hotpot_restore_details(&$restore, $status, &$xml, &$record) {
+    global $DB;
     // $xml is an XML tree for an attempt record
     // $record is the newly added attempt record
     if (empty($record->details)) {
@@ -220,7 +221,7 @@ function hotpot_restore_details(&$restore, $status, &$xml, &$record) {
         $details = new stdClass();
         $details->attempt = $record->id;
         $details->details = $record->details;
-        if (insert_record('hotpot_details', $details)) {
+        if ($DB->insert_record('hotpot_details', $details)) {
             $status = true;
         } else {
             if (!defined('RESTORE_SILENTLY')) {
index 6bbe35295030505943592bf738a46b1ae15b75f4..99536593e2478d8c8c3de291c3e248542a082aaa 100644 (file)
     }
 
     function label_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
 
-        if ($labels = get_records_sql ("SELECT l.id, l.content
-                                   FROM {$CFG->prefix}label l
-                                   WHERE l.course = $restore->course_id")) {
+        if ($labels = $DB->get_records('label', array('course'=>$restore->course_id), '', "id,content")) {
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($labels as $label) {
                 //Increment counter
@@ -78,8 +76,8 @@
 
                 if ($result != $content) {
                     //Update record
-                    $label->content = addslashes($result);
-                    $status = update_record("label", $label);
+                    $label->content = $result;
+                    $status = $DB->update_record("label", $label);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
index 6e2c8c9225b5250582e97982e0887338d53672f6..99fe4b9c61ac7bae0deec08b9ebda3b9ae0f9028 100644 (file)
             // pre moodle 1.5.  Matching questions need two answer fields designated
             // for correct and wrong responses before the rest of the answer fields.
             if ($restore->backup_version <= 2004083124) {  // Backup version for 1.4.5+
-                if ($ismatching = get_record('lesson_pages', 'id', $pageid)) {  // get the page we just inserted
+                if ($ismatching = $DB->get_record('lesson_pages', array('id'=>$pageid))) {  // get the page we just inserted
                     if ($ismatching->qtype == 5) { // check to make sure it is a matching question
                         $time = time();  // this may need to be changed
                         // make our 2 response answers
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function lesson_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
         
         //Process every lesson PAGE in the course
-        if ($pages = get_records_sql ("SELECT p.id, p.contents
-                                   FROM {$CFG->prefix}lesson_pages p,
-                                        {$CFG->prefix}lesson l
-                                   WHERE l.course = $restore->course_id AND
-                                         p.lessonid = l.id")) {
+        if ($pages = $DB->get_records_sql("SELECT p.id, p.contents
+                                             FROM {lesson_pages} p,
+                                                  {lesson} l
+                                            WHERE l.course = ? AND
+                                                  p.lessonid = l.id", array($restore->course_id))) {
             //Iterate over each page->message
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($pages as $page) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $page->contents = addslashes($result);
-                    $status = update_record("lesson_pages",$page);
+                    $page->contents = $result;
+                    $status = $DB->update_record("lesson_pages",$page);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
         }
 
         // Remap activity links
-        if ($lessons = get_records_select('lesson', "activitylink != 0 AND course = $restore->course_id", '', 'id, activitylink')) {
+        if ($lessons = $DB->get_records_select('lesson', "activitylink <> 0 AND course = ?", array($restore->course_id), '', 'id, activitylink')) {
             foreach ($lessons as $lesson) {
                 if ($newcmid = backup_getid($restore->backup_unique_code, 'course_modules', $lesson->activitylink)) {
-                    $status = $status and set_field('lesson', 'activitylink', $newcmid->new_id, 'id', $lesson->id);
+                    $status = $status and $DB->set_field('lesson', 'activitylink', $newcmid->new_id, array('id'=>$lesson->id));
                 }
             }
         }
index 0952290ac94bf793d41a83ba40243cbfae6ae510..f5ed71eb8767299df0c48ae0ca0b419a5a2185f6 100644 (file)
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function quiz_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
         
-        if ($quizs = get_records_sql ("SELECT q.id, q.intro
-                                   FROM {$CFG->prefix}quiz q
-                                   WHERE q.course = $restore->course_id")) {
+        if ($quizs = $DB->get_records('quiz', array('course'=>$restore->course_id), '', "id,intro")) {
                                                //Iterate over each quiz->intro
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($quizs as $quiz) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $quiz->intro = addslashes($result);
-                    $status = update_record("quiz",$quiz);
+                    $quiz->intro = $result;
+                    $status = $DB->update_record("quiz",$quiz);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
     //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
     //some texts in the module
     function quiz_restore_wiki2markdown ($restore) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
         //Convert question->questiontext
-        if ($records = get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat
-                                         FROM {$CFG->prefix}question q,
-                                              {$CFG->prefix}backup_ids b
-                                         WHERE b.backup_code = $restore->backup_unique_code AND
-                                               b.table_name = 'question' AND
-                                               q.id = b.new_id AND
-                                               q.questiontextformat = ".FORMAT_WIKI)) {
+        if ($records = $DB->get_records_sql("SELECT q.id, q.questiontext, q.questiontextformat
+                                               FROM {question} q,
+                                                    {backup_ids} b
+                                              WHERE b.backup_code = ? AND
+                                                    b.table_name = 'question' AND
+                                                    q.id = b.new_id AND
+                                                    q.questiontextformat = ".FORMAT_WIKI, array($restore->backup_unique_code))) {
             $i = 0;
             foreach ($records as $record) {
                 //Rebuild wiki links
                 $wtm = new WikiToMarkdown();
                 $record->questiontext = $wtm->convert($record->questiontext, $restore->course_id);
                 $record->questiontextformat = FORMAT_MARKDOWN;
-                $status = update_record('question', addslashes_object($record));
+                $status = $DB->update_record('question', $record);
                 //Do some output
                 $i++;
                 if (($i+1) % 1 == 0) {
index 0862c22b90460ddfc9c195066ca42ccbf8a96f5e..5c382e27e868101fa11d04ab381e23cedaf5c880 100644 (file)
     //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;
+        global $CFG, $DB;
         $status = true;
 
-        if ($resources = get_records_sql ("SELECT r.id, r.alltext, r.summary, r.reference
-                                   FROM {$CFG->prefix}resource r
-                                   WHERE r.course = $restore->course_id")) {
+        if ($resources = $DB->get_records('resource', array('course'=>$restore->course_id), '', "id, alltext, summary, reference")) {
 
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($resources as $resource) {
 
                 if ($result1 != $content1 || $result2 != $content2 ||  $result3 != $content3) {
                     //Update record
-                    $resource->alltext = addslashes($result1);
-                    $resource->summary = addslashes($result2);
-                    $resource->reference = addslashes($result3);
-                    $status = update_record("resource",$resource);
+                    $resource->alltext = $result1;
+                    $resource->summary = $result2;
+                    $resource->reference = $result3;
+                    $status = $DB->update_record("resource",$resource);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content1).'<br />changed to<br />'.s($result1).'<hr /><br />';
     //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
     //some texts in the module
     function resource_restore_wiki2markdown ($restore) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
         //Convert resource->alltext
-        if ($records = get_records_sql ("SELECT r.id, r.alltext, r.options
-                                         FROM {$CFG->prefix}resource r,
-                                              {$CFG->prefix}backup_ids b
-                                         WHERE r.course = $restore->course_id AND
-                                               options = ".FORMAT_WIKI. " AND
-                                               b.backup_code = $restore->backup_unique_code AND
-                                               b.table_name = 'resource' AND
-                                               b.new_id = r.id")) {
+        if ($records = $DB->get_records_sql("SELECT r.id, r.alltext, r.options
+                                               FROM {resource} r,
+                                                    {backup_ids} b
+                                              WHERE r.course = ? AND
+                                                    options = ".FORMAT_WIKI. " AND
+                                                    b.backup_code = ? AND
+                                                    b.table_name = 'resource' AND
+                                                    b.new_id = r.id", array($restore->course_id, $restore->backup_unique_code))) {
             foreach ($records as $record) {
                 //Rebuild wiki links
                 $record->alltext = restore_decode_wiki_content($record->alltext, $restore);
                 $wtm = new WikiToMarkdown();
                 $record->alltext = $wtm->convert($record->alltext, $restore->course_id);
                 $record->options = FORMAT_MARKDOWN;
-                $status = update_record('resource', addslashes_object($record));
+                $status = $DB->update_record('resource', $record);
                 //Do some output
                 $i++;
                 if (($i+1) % 1 == 0) {
index 2ad7b344698fa8c5c4530feb47eed916fc08e5d7..5f800f7982411c52304a01208d8bb62d6b620033 100755 (executable)
         global $CFG;
         $status = true;
 
-        if ($scorms = get_records_sql ("SELECT s.id, s.summary
-                                   FROM {$CFG->prefix}scorm s
-                                   WHERE s.course = $restore->course_id")) {
+        if ($scorms = $DB->get_records('scorm', array('course'=>$restore->course_id), '', "id,summary")) {
 
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($scorms as $scorm) {
 
                 if ($result != $content) {
                     //Update record
-                    $scorm->summary = addslashes($result);
-                    $status = update_record("scorm",$scorm);
+                    $scorm->summary = $result;
+                    $status = $DB->update_record("scorm",$scorm);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
-                            echo '<br /><hr />'.htmlentities($content).'<br />changed to<br />'.htmlentities($result).'<hr /><br />';
+                            echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
                         }
                     }
                 }
index 47aa03891d54e93a50886e9fdab3e39abef4c1a6..9c2a253738a6b7d16a8764efb544124d80016a4c 100644 (file)
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function survey_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
         
-        if ($surveys = get_records_sql ("SELECT s.id, s.intro
-                                   FROM {$CFG->prefix}survey s
-                                   WHERE s.course = $restore->course_id")) {
+        if ($surveys = $DB->get_records('survey', array('course'=>$restore->course_id), '', "id,intro")) {
                                                //Iterate over each survey->intro
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($surveys as $survey) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $survey->intro = addslashes($result);
-                    $status = update_record("survey",$survey);
+                    $survey->intro = $result;
+                    $status = $DB->update_record("survey",$survey);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
index f34531d6ca315b1f13c9ad395304a8f6aef21551..43dbe15b06ee1974de4d4d86519985deac022eab 100644 (file)
     //working in the backup/restore process. It's called from restore_decode_content_links()
     //function in restore process
     function wiki_decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
         
         //Process every wiki PAGE in the course
-        if ($pages = get_records_sql ("SELECT p.id, p.content
-                                   FROM {$CFG->prefix}wiki_pages p,
-                                        {$CFG->prefix}wiki w
-                                   WHERE w.course = $restore->course_id AND
-                                         p.wiki = w.id")) {
+        if ($pages = $DB->get_records_sql("SELECT p.id, p.content
+                                             FROM {wiki_pages} p, {wiki} w
+                                            WHERE w.course = ? AND
+                                                  p.wiki = w.id", array($restore->course_id))) {
             //Iterate over each post->message
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($pages as $page) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $page->content = addslashes($result);
-                    $status = update_record("wiki_pages",$page);
+                    $page->content = $result;
+                    $status = $DB->update_record("wiki_pages",$page);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
         }
 
         //Process every wiki (summary) in the course
-        if ($wikis = get_records_sql ("SELECT w.id, w.summary
-                                   FROM {$CFG->prefix}wiki w
-                                   WHERE w.course = $restore->course_id")) {
+        if ($wikis = $DB->get_records('wiki', array('course'=>$restore->course_id), '', "id,summary")) {
             //Iterate over each wiki->summary
             $i = 0;   //Counter to send some output to the browser to avoid timeouts
             foreach ($wikis as $wiki) {
                 $result = restore_decode_content_links_worker($content,$restore);
                 if ($result != $content) {
                     //Update record
-                    $wiki->summary = addslashes($result);
-                    $status = update_record("wiki",$wiki);
+                    $wiki->summary = $result;
+                    $status = $DB->update_record("wiki",$wiki);
                     if (debugging()) {
                         if (!defined('RESTORE_SILENTLY')) {
                             echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
index bd2317f0189c7b92f946dbf094b9197fd8d1d03f..9128a932f90baa2916c35de74e59b9713a680522 100644 (file)
@@ -94,6 +94,8 @@
     * @return object best context instance for this category to be in
     */
     function restore_question_get_best_category_context($restore, $contextinfo) {
+        global $DB;
+
         switch ($contextinfo['LEVEL'][0]['#']) {
             case 'module':
                 if (!$instanceinfo = backup_getid($restore->backup_unique_code, 'course_modules', $contextinfo['INSTANCE'][0]['#'])){
                 //search COURSECATEGORYLEVEL steps up the course cat tree or
                 //to the top of the tree if steps are exhausted.
                 $catno = $contextinfo['COURSECATEGORYLEVEL'][0]['#'];
-                $catid = get_field('course', 'category', 'id', $restore->course_id);
+                $catid = $DB->get_field('course', 'category', array('id'=>$restore->course_id));
                 while ($catno > 1){
-                    $nextcatid = get_field('course_categories', 'parent', 'id', $catid);
+                    $nextcatid = $DB->get_field('course_categories', 'parent', array('id'=>$catid));
                     if ($nextcatid == 0){
                         break;
                     }
                     }
                     $question_cat->contextid = $tocontext->id;
                     if (!$fcat = $DB->get_record('question_categories', array('contextid'=>$question_cat->contextid, 'stamp'=>$question_cat->stamp))) {
-                        $question_cat->id = insert_record ("question_categories", $question_cat);
+                        $question_cat->id = $DB->insert_record ("question_categories", $question_cat);
                     } else {
                         $question_cat = $fcat;
                     }
     }
 
     function restore_recode_category_parents($restore){
-        global $CFG;
+        global $CFG, $DB;
         $status = true;
         //Now we have to recode the parent field of each restored category
-        $categories = get_records_sql("SELECT old_id, new_id
-                                       FROM {$CFG->prefix}backup_ids
-                                       WHERE backup_code = $restore->backup_unique_code AND
-                                             table_name = 'question_categories'");
+        $categories = $DB->get_records_sql("SELECT old_id, new_id
+                                              FROM {backup_ids}
+                                             WHERE backup_code = ? AND
+                                                   table_name = 'question_categories'", array($restore->backup_unique_code));
         if ($categories) {
             //recode all parents to point at their old parent cats no matter what context the parent is now in
             foreach ($categories as $category) {
-                $restoredcategory = get_record('question_categories','id',$category->new_id);
+                $restoredcategory = $DB->get_record('question_categories', array('id'=>$category->new_id));
                 if ($restoredcategory && $restoredcategory->parent != 0) {
                     $updateobj = new object();
                     $updateobj->id = $restoredcategory->id;
                     } else {
                         $updateobj->parent = 0;
                     }
-                    $status = $status && update_record('question_categories', $updateobj);
+                    $status = $status && $DB->update_record('question_categories', $updateobj);
                 }
             }
             //now we have recoded all parents, check through all parents and set parent to be
             //or else set parent to 0 (top level category).
             $toupdate = array();
             foreach ($categories as $category) {
-                $restoredcategory = get_record('question_categories','id',$category->new_id);
+                $restoredcategory = $DB->get_record('question_categories', array('id'=>$category->new_id));
                 if ($restoredcategory && $restoredcategory->parent != 0) {
                     $nextparentid = $restoredcategory->parent;
                     do {
-                        if (!$parent = get_record('question_categories', 'id', $nextparentid)){
+                        if (!$parent = $DB->get_record('question_categories', array('id'=>$nextparentid))) {
                             if (!defined('RESTORE_SILENTLY')) {
                                 echo 'Could not find parent for question category '. $category->id.' recoding as top category item.<br />';
                             }
                 $updateobj = new object();
                 $updateobj->id = $id;
                 $updateobj->parent = $parent;
-                $status = $status && update_record('question_categories', $updateobj);
+                $status = $status && $DB->update_record('question_categories', $updateobj);
             }
         }
         return $status;
                     }
                     $question->category = $course_question_cat->id;
                     //does question already exist in course cat
-                    $existingquestion = get_record ("question", "category", $question->category, "stamp", $question->stamp, "version", $question->version);
+                    $existingquestion = $DB->get_record("question", array("category"=>$question->category, "stamp"=>$question->stamp, "version"=>$question->version));
                 } else {
                     //permissions ok, restore to best cat
                     $question->category = $best_question_cat->id;
      * @return boolean whether the operation succeeded.
      */
     function question_decode_content_links_caller($restore) {
-        global $CFG, $QTYPES;
+        global $CFG, $QTYPES, $DB;
         $status = true;
         $i = 1;   //Counter to send some output to the browser to avoid timeouts
 
         $coursemodulecontexts = array();
         $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
         $coursemodulecontexts[] = $context->id;
-        $cms = get_records('course_modules', 'course', $restore->course_id, '', 'id');
+        $cms = $DB->get_records('course_modules', array('course'=>$restore->course_id), '', 'id');
         if ($cms){
             foreach ($cms as $cm){
                 $context =  get_context_instance(CONTEXT_MODULE, $cm->id);
         }
         $coursemodulecontextslist = join($coursemodulecontexts, ',');
         // Decode links in questions.
-        if ($questions = get_records_sql('SELECT q.id, q.qtype, q.questiontext, q.generalfeedback '.
-                 'FROM ' . $CFG->prefix . 'question q, '.
-                 $CFG->prefix . 'question_categories qc '.
-                 'WHERE q.category = qc.id '.
-                 'AND qc.contextid IN (' .$coursemodulecontextslist.')')) {
+        if ($questions = $DB->get_records_sql('SELECT q.id, q.qtype, q.questiontext, q.generalfeedback
+                                                 FROM {question} q, {question_categories} qc
+                                                WHERE q.category = qc.id
+                                                      AND qc.contextid IN (' .$coursemodulecontextslist.')')) {
 
             foreach ($questions as $question) {
                 $questiontext = restore_decode_content_links_worker($question->questiontext, $restore);
                 $generalfeedback = restore_decode_content_links_worker($question->generalfeedback, $restore);
                 if ($questiontext != $question->questiontext || $generalfeedback != $question->generalfeedback) {
-                    $question->questiontext = addslashes($questiontext);
-                    $question->generalfeedback = addslashes($generalfeedback);
-                    if (!update_record('question', $question)) {
+                    $question->questiontext = $questiontext;
+                    $question->generalfeedback = $generalfeedback;
+                    if (!$DB->update_record('question', $question)) {
                         $status = false;
                     }
                 }
         }
 
         // Decode links in answers.
-        if ($answers = get_records_sql('SELECT qa.id, qa.answer, qa.feedback, q.qtype
-               FROM ' . $CFG->prefix . 'question_answers qa,
-                    ' . $CFG->prefix . 'question q,
-                    ' . $CFG->prefix . 'question_categories qc
-               WHERE qa.question = q.id
-                 AND q.category = qc.id '.
-                 'AND qc.contextid IN ('.$coursemodulecontextslist.')')) {
+        if ($answers = $DB->get_records_sql('SELECT qa.id, qa.answer, qa.feedback, q.qtype
+                                               FROM {question_answers} qa, {question} q, {question_categories} qc
+                                              WHERE qa.question = q.id
+                                                    AND q.category = qc.id
+                                                    AND qc.contextid IN ('.$coursemodulecontextslist.')')) {
 
             foreach ($answers as $answer) {
                 $feedback = restore_decode_content_links_worker($answer->feedback, $restore);
                 }
                 if ($feedback != $answer->feedback || $answertext != $answer->answer) {
                     unset($answer->qtype);
-                    $answer->feedback = addslashes($feedback);
-                    $answer->answer = addslashes($answertext);
-                    if (!update_record('question_answers', $answer)) {
+                    $answer->feedback = $feedback;
+                    $answer->answer = $answertext;
+                    if (!$DB->update_record('question_answers', $answer)) {
                         $status = false;
                     }
                 }