예제 #1
0
 public static function restore_data($data, $restore)
 {
     $linknamestatus = $linkurlstatus = false;
     foreach ($data as $datum) {
         switch ($datum->name) {
             case 'linkname':
                 // We just want to know that it is there
                 $linknamestatus = true;
                 break;
             case 'linkurl':
                 $content = $datum->value;
                 $result = restore_decode_content_links_worker($content, $restore);
                 if ($result != $content) {
                     $datum->value = addslashes($result);
                     if (debugging() and !defined('RESTORE_SILENTLY')) {
                         echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                     }
                     $linkurlstatus = update_record('pagemenu_link_data', $datum);
                 } else {
                     $linkurlstatus = true;
                 }
                 break;
             default:
                 debugging('Deleting unknown data type: ' . $datum->name);
                 // Not recognized
                 delete_records('pagemenu_link_data', 'id', $datum->id);
                 break;
         }
     }
     return $linkurlstatus and $linknamestatus;
 }
예제 #2
0
 /**
  * This function makes all the necessary calls to {@link restore_decode_content_links_worker()}
  * function in order to decode contents of this block from the backup
  * format to destination site/course in order to mantain inter-activities
  * working in the backup/restore process.
  *
  * This is called from {@link restore_decode_content_links()} function in the restore process.
  *
  * NOTE: There is no block instance when this method is called.
  *
  * @param object $restore Standard restore object
  * @return boolean
  **/
 function decode_content_links_caller($restore)
 {
     global $CFG;
     if ($restored_blocks = get_records_select("backup_ids", "table_name = 'block_instance' AND backup_code = {$restore->backup_unique_code} AND new_id > 0", "", "new_id")) {
         $restored_blocks = implode(',', array_keys($restored_blocks));
         $sql = "SELECT bi.*\n                      FROM {$CFG->prefix}block_instance bi\n                           JOIN {$CFG->prefix}block b ON b.id = bi.blockid\n                     WHERE b.name = 'html' AND bi.id IN ({$restored_blocks})";
         if ($instances = get_records_sql($sql)) {
             foreach ($instances as $instance) {
                 $blockobject = block_instance('featured', $instance);
                 $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text);
                 $blockobject->config->text = restore_decode_content_links_worker($blockobject->config->text, $restore);
                 $blockobject->instance_config_commit($blockobject->pinned);
             }
         }
     }
     return true;
 }
예제 #3
0
function customlabel_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    $sql = "\r\n            SELECT \r\n                l.id, \r\n                l.content\r\n            FROM \r\n                {$CFG->prefix}customlabel l\r\n            WHERE \r\n                l.course = {$restore->course_id}\r\n        ";
    if ($customlabels = get_records_sql($sql)) {
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($customlabels as $customlabel) {
            //Increment counter
            $i++;
            $content = $customlabel->content;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $customlabel->content = addslashes($result);
                $status = update_record("customlabel", $customlabel);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function groupselect_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($groupselects = get_records_sql("SELECT l.id, l.intro\n                                   FROM {$CFG->prefix}groupselect l\n                                   WHERE l.course = {$restore->course_id}")) {
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($groupselects as $groupselect) {
            //Increment counter
            $i++;
            $intro = $groupselect->intro;
            $result = restore_decode_content_links_worker($intro, $restore);
            if ($result != $intro) {
                //Update record
                $groupselect->intro = addslashes($result);
                $status = update_record("groupselect", $groupselect);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($intro) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function skype_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($skypes = get_records_sql("SELECT l.id, l.participants\n                                   FROM {$CFG->prefix}skype l\n                                   WHERE l.course = {$restore->course_id}")) {
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($skypes as $skype) {
            //Increment counter
            $i++;
            $participants = $skype->participants;
            $result = restore_decode_content_links_worker($participants, $restore);
            if ($result != $participants) {
                //Update record
                $skype->participants = addslashes($result);
                $status = update_record("skype", $skype);
                if ($CFG->debug > 7) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #6
0
function label_decode_content_links_caller($restore)
{
    global $CFG, $DB;
    $status = true;
    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
            $i++;
            $content = $label->intro;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $label->intro = $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 />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function lightboxgallery_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($galleries = get_records_sql("SELECT l.id, l.description FROM {$CFG->prefix}lightboxgallery l WHERE l.course = {$restore->course_id}")) {
        $i = 0;
        foreach ($galleries as $gallery) {
            $i++;
            $content = $gallery->description;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($content != $result) {
                $gallery->description = addslashes($result);
                $status = update_record('lightboxgallery', $gallery);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            if (($i + 1) % 50 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo '.';
                    if (($i + 1) % 1000 == 0) {
                        echo '<br />';
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #8
0
function restore_decode_content_links($restore)
{
    global $CFG, $DB;
    $status = true;
    if (!defined('RESTORE_SILENTLY')) {
        echo "<ul>";
    }
    // Recode links in the course summary.
    if (!defined('RESTORE_SILENTLY')) {
        echo '<li>' . get_string('from') . ' ' . get_string('course');
    }
    $course = $DB->get_record('course', array('id' => $restore->course_id), 'id,summary');
    $coursesummary = restore_decode_content_links_worker($course->summary, $restore);
    if ($coursesummary != $course->summary) {
        $course->summary = addslashes($coursesummary);
        if (!update_record('course', $course)) {
            $status = false;
        }
    }
    if (!defined('RESTORE_SILENTLY')) {
        echo '</li>';
    }
    // Recode links in section summaries.
    $sections = $DB->get_records('course_sections', array('course', $restore->course_id), 'id,summary');
    if ($sections) {
        if (!defined('RESTORE_SILENTLY')) {
            echo '<li>' . get_string('from') . ' ' . get_string('sections');
        }
        foreach ($sections as $section) {
            $sectionsummary = restore_decode_content_links_worker($section->summary, $restore);
            if ($sectionsummary != $section->summary) {
                $section->summary = addslashes($sectionsummary);
                if (!update_record('course_sections', $section)) {
                    $status = false;
                }
            }
        }
        if (!defined('RESTORE_SILENTLY')) {
            echo '</li>';
        }
    }
    // Restore links in modules.
    foreach ($restore->mods as $name => $info) {
        //If the module is being restored
        if (isset($info->restore) && $info->restore == 1) {
            //Check if the xxxx_decode_content_links_caller exists
            include_once "{$CFG->dirroot}/mod/{$name}/restorelib.php";
            $function_name = $name . "_decode_content_links_caller";
            if (function_exists($function_name)) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo "<li>" . get_string("from") . " " . get_string("modulenameplural", $name);
                }
                $status = $function_name($restore) && $status;
                if (!defined('RESTORE_SILENTLY')) {
                    echo '</li>';
                }
            }
        }
    }
    // Process all html text also in blocks too
    if (!defined('RESTORE_SILENTLY')) {
        echo '<li>' . get_string('from') . ' ' . get_string('blocks');
    }
    if ($blocks = $DB->get_records('block', array('visible' => 1))) {
        foreach ($blocks as $block) {
            if ($blockobject = block_instance($block->name)) {
                $blockobject->decode_content_links_caller($restore);
            }
        }
    }
    if (!defined('RESTORE_SILENTLY')) {
        echo '</li>';
    }
    // Restore links in questions.
    require_once "{$CFG->dirroot}/question/restorelib.php";
    if (!defined('RESTORE_SILENTLY')) {
        echo '<li>' . get_string('from') . ' ' . get_string('questions', 'quiz');
    }
    $status = question_decode_content_links_caller($restore) && $status;
    if (!defined('RESTORE_SILENTLY')) {
        echo '</li>';
    }
    if (!defined('RESTORE_SILENTLY')) {
        echo "</ul>";
    }
    return $status;
}
예제 #9
0
function mail_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    //Process every Mail in the course
    if ($mails = get_records_sql("SELECT m.id, m.summary\r\n                                   FROM {$CFG->prefix}mail m\r\n                                   WHERE m.course = {$restore->course_id}")) {
        //Iterate over each forum->intro
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($mails as $mail) {
            //Increment counter
            $i++;
            $content_summary = $mail->summary;
            $result_summary = restore_decode_content_links_worker($content_summary, $restore);
            if ($result_summary != $content_summary) {
                //Update record
                $mail->summary = addslashes($result_summary);
                $status = update_record("mail", $mail);
                if ($CFG->debug > 7) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content_summary) . '<br />changed to<br />' . s($result_summary) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #10
0
function wiki_decode_content_links_caller($restore)
{
    global $CFG, $DB;
    $status = true;
    //Process every wiki PAGE in the course
    if ($pages = $DB->get_records_sql("SELECT p.id, p.content\n                                             FROM {wiki_pages} p, {wiki} w\n                                            WHERE w.course = ? AND\n                                                  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) {
            //Increment counter
            $i++;
            $content = $page->definition;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $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 />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    //Process every wiki (summary) in the course
    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) {
            //Increment counter
            $i++;
            $content = $wiki->summary;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $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 />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function econsole_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($econsoles = get_records_sql("SELECT e.id, e.content, e.url1, e.url2, e.url3, e.url4, e.url5, e.url6 \r\n                                   FROM {$CFG->prefix}econsole e\r\n                                   WHERE e.course = {$restore->course_id}")) {
        //Iterate over each econsole->intro
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($econsoles as $econsole) {
            //Increment counter
            $i++;
            $content1 = $econsole->content;
            $content2 = $econsole->url1;
            $content3 = $econsole->url2;
            $content4 = $econsole->url3;
            $content5 = $econsole->url4;
            $content6 = $econsole->url5;
            $content7 = $econsole->url6;
            $result1 = restore_decode_content_links_worker($content1, $restore);
            $result2 = restore_decode_content_links_worker($content2, $restore);
            $result3 = restore_decode_content_links_worker($content3, $restore);
            $result4 = restore_decode_content_links_worker($content4, $restore);
            $result5 = restore_decode_content_links_worker($content5, $restore);
            $result6 = restore_decode_content_links_worker($content6, $restore);
            $result7 = restore_decode_content_links_worker($content7, $restore);
            if ($result1 != $content1 || $result2 != $content2 || $result3 != $content3 || $result4 != $content4 || $result5 != $content5 || $result6 != $content6 || $result7 != $content7) {
                //Update record
                $econsole->content = addslashes($result1);
                $econsole->url1 = addslashes($result2);
                $econsole->url2 = addslashes($result3);
                $econsole->url3 = addslashes($result4);
                $econsole->url4 = addslashes($result5);
                $econsole->url5 = addslashes($result6);
                $econsole->url6 = addslashes($result7);
                $status = update_record("econsole", $econsole);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content1) . '<br />changed to<br />' . s($result1) . '<hr /><br />';
                        echo '<br /><hr />' . s($content2) . '<br />changed to<br />' . s($result2) . '<hr /><br />';
                        echo '<br /><hr />' . s($content3) . '<br />changed to<br />' . s($result3) . '<hr /><br />';
                        echo '<br /><hr />' . s($content4) . '<br />changed to<br />' . s($result4) . '<hr /><br />';
                        echo '<br /><hr />' . s($content5) . '<br />changed to<br />' . s($result5) . '<hr /><br />';
                        echo '<br /><hr />' . s($content6) . '<br />changed to<br />' . s($result6) . '<hr /><br />';
                        echo '<br /><hr />' . s($content7) . '<br />changed to<br />' . s($result7) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #12
0
 /**
  * Decode links in question type specific tables.
  * @return bool success or failure.
  */
 function decode_content_links_caller($questionids, $restore, &$i)
 {
     $status = true;
     // Decode links in the question_multichoice table.
     if ($multichoices = get_records_list('question_multichoice', 'question', implode(',', $questionids), '', 'id, correctfeedback, partiallycorrectfeedback, incorrectfeedback')) {
         foreach ($multichoices as $multichoice) {
             $correctfeedback = restore_decode_content_links_worker($multichoice->correctfeedback, $restore);
             $partiallycorrectfeedback = restore_decode_content_links_worker($multichoice->partiallycorrectfeedback, $restore);
             $incorrectfeedback = restore_decode_content_links_worker($multichoice->incorrectfeedback, $restore);
             if ($correctfeedback != $multichoice->correctfeedback || $partiallycorrectfeedback != $multichoice->partiallycorrectfeedback || $incorrectfeedback != $multichoice->incorrectfeedback) {
                 $subquestion->correctfeedback = addslashes($correctfeedback);
                 $subquestion->partiallycorrectfeedback = addslashes($partiallycorrectfeedback);
                 $subquestion->incorrectfeedback = addslashes($incorrectfeedback);
                 if (!update_record('question_multichoice', $multichoice)) {
                     $status = false;
                 }
             }
             // Do some output.
             if (++$i % 5 == 0 && !defined('RESTORE_SILENTLY')) {
                 echo ".";
                 if ($i % 100 == 0) {
                     echo "<br />";
                 }
                 backup_flush(300);
             }
         }
     }
     return $status;
 }
예제 #13
0
function forum_decode_content_links_caller($restore)
{
    global $CFG, $DB, $DB;
    $status = true;
    //Process every POST (message) in the course
    if ($posts = $DB->get_records_sql("SELECT p.id, p.message\n                                             FROM {forum_posts} p,\n                                                  {forum_discussions} d\n                                            WHERE d.course = ? AND\n                                                  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) {
            //Increment counter
            $i++;
            $content = $post->message;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $post->message = $result;
                $status = $DB->update_record("forum_posts", $post);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    //Process every FORUM (intro) in the course
    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) {
            //Increment counter
            $i++;
            $content = $forum->intro;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $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 />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #14
0
function glossary_decode_content_links_caller($restore)
{
    global $CFG, $DB;
    $status = true;
    //Process every glossary ENTRY in the course
    if ($entries = $DB->get_records_sql("SELECT e.id, e.definition\n                                               FROM {glossary_entries} e,\n                                                    {glossary} g\n                                              WHERE g.course = ? AND\n                                                    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) {
            //Increment counter
            $i++;
            $content = $entry->definition;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $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 />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    //Process every glossary (intro) in the course
    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) {
            //Increment counter
            $i++;
            $content = $glossary->intro;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $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 />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function webquest_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    //Process every description,process,taskdescription,conclussion from WEBQUEST
    if ($webquests = get_records_sql("SELECT *\n                                           FROM {$CFG->prefix}webquest w\n                                           WHERE w.course = {$restore->course_id}")) {
        $i = 0;
        foreach ($webquests as $webquest) {
            $i++;
            $todo = false;
            $content = $webquest->description;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                $webquest->description = addslashes($result);
                if ($CFG->debug > 7) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
                $todo = true;
            }
            $content = $webquest->process;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                $webquest->process = addslashes($result);
                if ($CFG->debug > 7) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
                $todo = true;
            }
            $content = $webquest->conclussion;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                $webquest->process = addslashes($result);
                if ($CFG->debug > 7) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
                $todo = true;
            }
            $content = $webquest->taskdescription;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                $webquest->process = addslashes($result);
                if ($CFG->debug > 7) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
                $todo = true;
            }
            if ($todo) {
                $status = update_record("webquest", $webquest);
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function scorm_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($scorms = get_records_sql("SELECT s.id, s.summary\n                                   FROM {$CFG->prefix}scorm s\n                                   WHERE s.course = {$restore->course_id}")) {
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($scorms as $scorm) {
            //Increment counter
            $i++;
            $content = $scorm->summary;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $scorm->summary = addslashes_js($result);
                $status = update_record("scorm", $scorm);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . htmlentities($content) . '<br />changed to<br />' . htmlentities($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #17
0
function turnitintool_decode_content_links_caller($restore)
{
    global $CFG, $DB;
    $status = true;
    //Convert turnitintool->description, check for DB type
    if (is_callable(array($DB, 'get_records_sql'))) {
        $turnitintools = $DB->get_records_sql("SELECT t.id, t.intro\n                               FROM {$CFG->prefix}turnitintool t\n                               WHERE t.course = {$restore->course_id}");
    } else {
        $turnitintools = get_records_sql("SELECT t.id, t.intro\n                               FROM {$CFG->prefix}turnitintool t\n                               WHERE t.course = {$restore->course_id}");
    }
    if ($turnitintools) {
        //Iterate over each turnitintool->intro
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($turnitintools as $turnitintool) {
            //Increment counter
            $i++;
            $content = $turnitintool->intro;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $turnitintool->intro = addslashes($result);
                $status = update_record("turnitintool", $turnitintool);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #18
0
function lesson_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    //Process every lesson PAGE in the course
    if ($pages = get_records_sql("SELECT p.id, p.contents\n                                   FROM {$CFG->prefix}lesson_pages p,\n                                        {$CFG->prefix}lesson l\n                                   WHERE l.course = {$restore->course_id} AND\n                                         p.lessonid = l.id")) {
        //Iterate over each page->message
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($pages as $page) {
            //Increment counter
            $i++;
            $content = $page->contents;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $page->contents = addslashes($result);
                $status = update_record("lesson_pages", $page);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    // Remap activity links
    if ($lessons = get_records_select('lesson', "activitylink != 0 AND course = {$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);
            }
        }
    }
    return $status;
}
예제 #19
0
function mplayer_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    //
    if ($mplayers = get_records_sql("SELECT f.id, f.configxml, f.mplayerfile, f.hdfile, f.livestreamstreamer, f.audiodescriptionfile, f.image, f.link, f.skin, f.logoboxfile, f.logoboxlink, f.logofile, f.logolink, f.streamer, f.captionsfile, f.notes, f.searchbarscript, f.snapshotscript\n                                   FROM {$CFG->prefix}mplayer f\n                                   WHERE f.course = {$restore->course_id}")) {
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($mplayers as $mplayer) {
            //Increment counter
            $i++;
            //
            $configxml = $mplayer->configxml;
            $mplayerfile = $mplayer->mplayerfile;
            $hdfile = $mplayer->hdfile;
            $livestreamstreamer = $mplayer->livestreamstreamer;
            $audiodescriptionfile = $mplayer->audiodescriptionfile;
            $image = $mplayer->image;
            $link = $mplayer->link;
            $skin = $mplayer->skin;
            $logoboxfile = $mplayer->logoboxfile;
            $logoboxlink = $mplayer->logoboxlink;
            $logofile = $mplayer->logofile;
            $logolink = $mplayer->logolink;
            $streamer = $mplayer->streamer;
            $captionsfile = $mplayer->captionsfile;
            $notes = $mplayer->notes;
            $searchbarscript = $mplayer->searchbarscript;
            $snapshotscript = $mplayer->snapshotscript;
            //
            $r_configxml = restore_decode_content_links_worker($configxml, $restore);
            $r_mplayerfile = restore_decode_content_links_worker($mplayerfile, $restore);
            $r_hdfile = restore_decode_content_links_worker($hdfile, $restore);
            $r_livestreamstreamer = restore_decode_content_links_worker($livestreamstreamer, $restore);
            $r_audiodescriptionfile = restore_decode_content_links_worker($audiodescriptionfile, $restore);
            $r_image = restore_decode_content_links_worker($image, $restore);
            $r_link = restore_decode_content_links_worker($link, $restore);
            $r_skin = restore_decode_content_links_worker($skin, $restore);
            $r_logoboxfile = restore_decode_content_links_worker($logoboxfile, $restore);
            $r_logoboxlink = restore_decode_content_links_worker($logoboxlink, $restore);
            $r_logofile = restore_decode_content_links_worker($logofile, $restore);
            $r_logolink = restore_decode_content_links_worker($logolink, $restore);
            $r_streamer = restore_decode_content_links_worker($streamer, $restore);
            $r_captionsfile = restore_decode_content_links_worker($captionsfile, $restore);
            $r_notes = restore_decode_content_links_worker($notes, $restore);
            $r_searchbarscript = restore_decode_content_links_worker($searchbarscript, $restore);
            $r_snapshotscript = restore_decode_content_links_worker($snapshotscript, $restore);
            //
            if ($r_configxml != $configxml || $r_mplayerfile != $mplayerfile || $r_hdfile != $hdfile || $r_livestreamstreamer != $livestreamstreamer || $r_audiodescriptionfile != $audiodescriptionfile || $r_image != $image || $r_link != $link || $r_skin != $skin || $r_logoboxfile != $logoboxfile || $r_logoboxlink != $logoboxlink || $r_logofile != $logofile || $r_logolink != $logolink || $r_streamer != $streamer || $r_captionsfile != $captionsfile || $r_notes != $notes || $r_searchbarscript != $searchbarscript || $r_snapshotscript != $snapshotscript) {
                //Update record
                $mplayer->configxml = addslashes($r_configxml);
                $mplayer->mplayerfile = addslashes($r_mplayerfile);
                $mplayer->hdfile = addslashes($r_hdfile);
                $mplayer->livestreamstreamer = addslashes($r_livestreamstreamer);
                $mplayer->audiodescriptionfile = addslashes($r_audiodescriptionfile);
                $mplayer->image = addslashes($r_image);
                $mplayer->link = addslashes($r_link);
                $mplayer->skin = addslashes($r_skin);
                $mplayer->logoboxfile = addslashes($r_logoboxfile);
                $mplayer->logoboxlink = addslashes($r_logoboxlink);
                $mplayer->logofile = addslashes($r_logofile);
                $mplayer->logolink = addslashes($r_logolink);
                $mplayer->streamer = addslashes($r_streamer);
                $mplayer->captionsfile = addslashes($r_captionsfile);
                $mplayer->notes = addslashes($r_notes);
                $mplayer->searchbarscript = addslashes($r_searchbarscript);
                $mplayer->snapshotscript = addslashes($r_snapshotscript);
                //
                $status = update_record("mplayer", $mplayer);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($configxml) . '<br />changed to<br />' . s($r_configxml) . '<hr /><br />';
                        echo '<br /><hr />' . s($mplayerfile) . '<br />changed to<br />' . s($r_mplayerfile) . '<hr /><br />';
                        echo '<br /><hr />' . s($hdfile) . '<br />changed to<br />' . s($r_hdfile) . '<hr /><br />';
                        echo '<br /><hr />' . s($livestreamstreamer) . '<br />changed to<br />' . s($r_livestreamstreamer) . '<hr /><br />';
                        echo '<br /><hr />' . s($audiodescriptionfile) . '<br />changed to<br />' . s($r_audiodescriptionfile) . '<hr /><br />';
                        echo '<br /><hr />' . s($image) . '<br />changed to<br />' . s($r_image) . '<hr /><br />';
                        echo '<br /><hr />' . s($link) . '<br />changed to<br />' . s($r_link) . '<hr /><br />';
                        echo '<br /><hr />' . s($skin) . '<br />changed to<br />' . s($r_skin) . '<hr /><br />';
                        echo '<br /><hr />' . s($logoboxfile) . '<br />changed to<br />' . s($r_logoboxfile) . '<hr /><br />';
                        echo '<br /><hr />' . s($logoboxlink) . '<br />changed to<br />' . s($r_logoboxlink) . '<hr /><br />';
                        echo '<br /><hr />' . s($logofile) . '<br />changed to<br />' . s($r_logofile) . '<hr /><br />';
                        echo '<br /><hr />' . s($logolink) . '<br />changed to<br />' . s($r_logolink) . '<hr /><br />';
                        echo '<br /><hr />' . s($abouttext) . '<br />changed to<br />' . s($r_abouttext) . '<hr /><br />';
                        echo '<br /><hr />' . s($aboutlink) . '<br />changed to<br />' . s($r_aboutlink) . '<hr /><br />';
                        echo '<br /><hr />' . s($streamer) . '<br />changed to<br />' . s($r_streamer) . '<hr /><br />';
                        echo '<br /><hr />' . s($captionsfile) . '<br />changed to<br />' . s($r_captionsfile) . '<hr /><br />';
                        echo '<br /><hr />' . s($notes) . '<br />changed to<br />' . s($r_notes) . '<hr /><br />';
                        echo '<br /><hr />' . s($searchbarscript) . '<br />changed to<br />' . s($r_searchbarscript) . '<hr /><br />';
                        echo '<br /><hr />' . s($snapshotscript) . '<br />changed to<br />' . s($r_snapshotscript) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function booking_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($bookings = get_records_sql("SELECT c.id, c.text\n                                   FROM {$CFG->prefix}booking c\n                                   WHERE c.course = {$restore->course_id}")) {
        //Iterate over each booking->text
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($bookings as $booking) {
            //Increment counter
            $i++;
            $content = $booking->text;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $booking->text = addslashes($result);
                $status = update_record("booking", $booking);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #21
0
 /**
  * Decode links in question type specific tables.
  * @return bool success or failure.
  */
 function decode_content_links_caller($questionids, $restore, &$i)
 {
     global $DB;
     $status = true;
     // Decode links in the question_match_sub table.
     if ($subquestions = $DB->get_records_list('question_match_sub', 'question', $questionids, '', 'id, questiontext')) {
         foreach ($subquestions as $subquestion) {
             $questiontext = restore_decode_content_links_worker($subquestion->questiontext, $restore);
             if ($questiontext != $subquestion->questiontext) {
                 $subquestion->questiontext = $questiontext;
                 $DB->update_record('question_match_sub', $subquestion);
             }
             // Do some output.
             if (++$i % 5 == 0 && !defined('RESTORE_SILENTLY')) {
                 echo ".";
                 if ($i % 100 == 0) {
                     echo "<br />";
                 }
                 backup_flush(300);
             }
         }
     }
     return $status;
 }
예제 #22
0
파일: restorelib.php 프로젝트: r007/PMoodle
/**
 * Recode content links in question texts.
 * @param object $restore the restore metadata object.
 * @return boolean whether the operation succeeded.
 */
function question_decode_content_links_caller($restore)
{
    global $CFG, $QTYPES;
    $status = true;
    $i = 1;
    //Counter to send some output to the browser to avoid timeouts
    // Get a list of which question types have custom field that will need decoding.
    $qtypeswithextrafields = array();
    $qtypeswithhtmlanswers = array();
    foreach ($QTYPES as $qtype => $qtypeclass) {
        $qtypeswithextrafields[$qtype] = method_exists($qtypeclass, 'decode_content_links_caller');
        $qtypeswithhtmlanswers[$qtype] = $qtypeclass->has_html_answers();
    }
    $extraprocessing = array();
    $coursemodulecontexts = array();
    $context = get_context_instance(CONTEXT_COURSE, $restore->course_id);
    $coursemodulecontexts[] = $context->id;
    $cms = get_records('course_modules', 'course', $restore->course_id, '', 'id');
    if ($cms) {
        foreach ($cms as $cm) {
            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
            $coursemodulecontexts[] = $context->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 . ')')) {
        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)) {
                    $status = false;
                }
            }
            // Do some output.
            if (++$i % 5 == 0 && !defined('RESTORE_SILENTLY')) {
                echo ".";
                if ($i % 100 == 0) {
                    echo "<br />";
                }
                backup_flush(300);
            }
            // Decode any questiontype specific fields.
            if ($qtypeswithextrafields[$question->qtype]) {
                if (!array_key_exists($question->qtype, $extraprocessing)) {
                    $extraprocessing[$question->qtype] = array();
                }
                $extraprocessing[$question->qtype][] = $question->id;
            }
        }
    }
    // 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 . ')')) {
        foreach ($answers as $answer) {
            $feedback = restore_decode_content_links_worker($answer->feedback, $restore);
            if ($qtypeswithhtmlanswers[$answer->qtype]) {
                $answertext = restore_decode_content_links_worker($answer->answer, $restore);
            } else {
                $answertext = $answer->answer;
            }
            if ($feedback != $answer->feedback || $answertext != $answer->answer) {
                unset($answer->qtype);
                $answer->feedback = addslashes($feedback);
                $answer->answer = addslashes($answertext);
                if (!update_record('question_answers', $answer)) {
                    $status = false;
                }
            }
            // Do some output.
            if (++$i % 5 == 0 && !defined('RESTORE_SILENTLY')) {
                echo ".";
                if ($i % 100 == 0) {
                    echo "<br />";
                }
                backup_flush(300);
            }
        }
    }
    // Do extra work for certain question types.
    foreach ($extraprocessing as $qtype => $questionids) {
        if (!$QTYPES[$qtype]->decode_content_links_caller($questionids, $restore, $i)) {
            $status = false;
        }
    }
    return $status;
}
예제 #23
0
function quiz_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($quizs = get_records_sql("SELECT q.id, q.intro\n                                   FROM {$CFG->prefix}quiz q\n                                   WHERE q.course = {$restore->course_id}")) {
        //Iterate over each quiz->intro
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($quizs as $quiz) {
            //Increment counter
            $i++;
            $content = $quiz->intro;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $quiz->intro = addslashes($result);
                $status = update_record("quiz", $quiz);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
function kaltura_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    return $status;
    if ($resources = get_records_sql("SELECT r.id, r.alltext, r.summary, r.reference\n                                   FROM {$CFG->prefix}resource r\n                                   WHERE r.course = {$restore->course_id}")) {
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($resources as $resource) {
            //Increment counter
            $i++;
            $content1 = $resource->alltext;
            $content2 = $resource->summary;
            $content3 = $resource->reference;
            $result1 = restore_decode_content_links_worker($content1, $restore);
            $result2 = restore_decode_content_links_worker($content2, $restore);
            $result3 = restore_decode_content_links_worker($content3, $restore);
            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);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content1) . '<br />changed to<br />' . s($result1) . '<hr /><br />';
                        echo '<br /><hr />' . s($content2) . '<br />changed to<br />' . s($result2) . '<hr /><br />';
                        echo '<br /><hr />' . s($content3) . '<br />changed to<br />' . s($result3) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #25
0
function assignment_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    if ($assignments = get_records_sql("SELECT a.id, a.description\n                                   FROM {$CFG->prefix}assignment a\n                                   WHERE a.course = {$restore->course_id}")) {
        //Iterate over each assignment->description
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($assignments as $assignment) {
            //Increment counter
            $i++;
            $content = $assignment->description;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $assignment->description = addslashes($result);
                $status = update_record("assignment", $assignment);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #26
0
function podcaster_decode_content_links_caller($restore)
{
    $properties = get_podcaster_channel_properties();
    $itemprops = get_podcaster_item_properties();
    $i = 0;
    if ($podcasters = get_records('podcaster', 'course', $restore->course_id, 'id')) {
        foreach ($podcasters as $podcast) {
            // TODO: optimization. We dont really have to process all the fields
            foreach ($properties as $p) {
                $podcast->{$p} = restore_decode_content_links_worker($podcast->{$p}, $restore);
            }
            $status = update_record('podcaster', $podcast);
            if ($items = get_records('podcaster_item', 'channel', $podcast->id, 'id')) {
                foreach ($items as $item) {
                    // TODO: optimization. We dont really have to process all the fields
                    foreach ($itemprops as $p) {
                        $item->{$p} = restore_decode_content_links_worker($item->{$p}, $restore);
                    }
                    $status = update_record('podcaster_item', $item);
                }
            }
        }
        //Do some output
        if (($i + 1) % 5 == 0) {
            if (!defined('RESTORE_SILENTLY')) {
                echo '.';
                if (($i + 1) % 100 == 0) {
                    echo '<br />';
                }
            }
            backup_flush(300);
        }
    }
    return $status;
}
예제 #27
0
function restore_decode_content_links($restore)
{
    global $CFG;
    $status = true;
    if (!defined('RESTORE_SILENTLY')) {
        echo "<ul>";
    }
    // Recode links in the course summary.
    if (!defined('RESTORE_SILENTLY')) {
        echo '<li>' . get_string('from') . ' ' . get_string('course');
    }
    $course = get_record('course', 'id', $restore->course_id, '', '', '', '', 'id,summary');
    $coursesummary = backup_todb($course->summary, false);
    // Exception: Process FILEPHP (not available when restored) MDL-18222
    $coursesummary = restore_decode_content_links_worker($coursesummary, $restore);
    if ($coursesummary != $course->summary) {
        $course->summary = addslashes($coursesummary);
        if (!update_record('course', $course)) {
            $status = false;
        }
    }
    if (!defined('RESTORE_SILENTLY')) {
        echo '</li>';
    }
    // Recode links in section summaries.
    $sections = get_records('course_sections', 'course', $restore->course_id, 'id', 'id,summary');
    if ($sections) {
        if (!defined('RESTORE_SILENTLY')) {
            echo '<li>' . get_string('from') . ' ' . get_string('sections');
        }
        foreach ($sections as $section) {
            $sectionsummary = restore_decode_content_links_worker($section->summary, $restore);
            if ($sectionsummary != $section->summary) {
                $section->summary = addslashes($sectionsummary);
                if (!update_record('course_sections', $section)) {
                    $status = false;
                }
            }
        }
        if (!defined('RESTORE_SILENTLY')) {
            echo '</li>';
        }
    }
    // Restore links in modules.
    foreach ($restore->mods as $name => $info) {
        //If the module is being restored
        if (isset($info->restore) && $info->restore == 1) {
            //Check if the xxxx_decode_content_links_caller exists
            include_once "{$CFG->dirroot}/mod/{$name}/restorelib.php";
            $function_name = $name . "_decode_content_links_caller";
            if (function_exists($function_name)) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo "<li>" . get_string("from") . " " . get_string("modulenameplural", $name);
                }
                $status = $function_name($restore) && $status;
                if (!defined('RESTORE_SILENTLY')) {
                    echo '</li>';
                }
            }
        }
    }
    // For the course format call its decode_content_links method (if it exists)
    $format = get_field('course', 'format', 'id', $restore->course_id);
    if (file_exists("{$CFG->dirroot}/course/format/{$format}/restorelib.php")) {
        include_once "{$CFG->dirroot}/course/format/{$format}/restorelib.php";
        $function_name = $format . '_decode_format_content_links_caller';
        if (function_exists($function_name)) {
            if (!defined('RESTORE_SILENTLY')) {
                echo "<li>" . get_string("from") . " " . get_string("format") . ' ' . $format;
            }
            $status = $function_name($restore);
            if (!defined('RESTORE_SILENTLY')) {
                echo '</li>';
            }
        }
    }
    // Process all html text also in blocks too
    if (!defined('RESTORE_SILENTLY')) {
        echo '<li>' . get_string('from') . ' ' . get_string('blocks');
    }
    if ($blocks = get_records('block', 'visible', 1)) {
        foreach ($blocks as $block) {
            if ($blockobject = block_instance($block->name)) {
                $blockobject->decode_content_links_caller($restore);
            }
        }
    }
    if (!defined('RESTORE_SILENTLY')) {
        echo '</li>';
    }
    // Restore links in questions.
    require_once "{$CFG->dirroot}/question/restorelib.php";
    if (!defined('RESTORE_SILENTLY')) {
        echo '<li>' . get_string('from') . ' ' . get_string('questions', 'quiz');
    }
    $status = question_decode_content_links_caller($restore) && $status;
    if (!defined('RESTORE_SILENTLY')) {
        echo '</li>';
    }
    if (!defined('RESTORE_SILENTLY')) {
        echo "</ul>";
    }
    return $status;
}
예제 #28
0
function workshop_decode_content_links_caller($restore)
{
    global $CFG;
    $status = true;
    //Process every WORKSHOP (description) in the course
    if ($workshops = get_records_sql("SELECT w.id, w.description\n                                           FROM {$CFG->prefix}workshop w\n                                           WHERE w.course = {$restore->course_id}")) {
        //Iterate over each workshop->description
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($workshops as $workshop) {
            //Increment counter
            $i++;
            $content = $workshop->description;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                //Update record
                $workshop->description = addslashes($result);
                $status = update_record("workshop", $workshop);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            //Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #29
0
/**
 * 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
 *
 * @param object $restore the preferences used in restore
 * @return boolean status of the execution
 */
function data_decode_content_links_caller($restore)
{
    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) . "\n                                  FROM {$CFG->prefix}data d\n                                  WHERE d.course = {$restore->course_id}")) {
        /// Iterate over each data
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($datas as $data) {
            /// Increment counter
            $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
            /// 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')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    /// Process every COMMENT (content) in the course
    if ($comments = get_records_sql("SELECT dc.id, dc.content\n                                      FROM {$CFG->prefix}data d,\n                                           {$CFG->prefix}data_records dr,\n                                           {$CFG->prefix}data_comments dc\n                                      WHERE d.course = {$restore->course_id}\n                                        AND dr.dataid = d.id\n                                        AND dc.recordid = dr.id")) {
        /// Iterate over each data_comments->content
        $i = 0;
        //Counter to send some output to the browser to avoid timeouts
        foreach ($comments as $comment) {
            /// Increment counter
            $i++;
            $content = $comment->content;
            $result = restore_decode_content_links_worker($content, $restore);
            if ($result != $content) {
                /// Update record
                $comment->content = addslashes($result);
                $status = update_record("data_comments", $comment);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            /// Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    /// 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\n                                      FROM {$CFG->prefix}data d,\n                                           {$CFG->prefix}data_records dr,\n                                           {$CFG->prefix}data_content dc\n                                      WHERE d.course = {$restore->course_id}\n                                        AND dr.dataid = d.id\n                                        AND dc.recordid = dr.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) {
            /// Increment counter
            $i++;
            $content = $cnt->content;
            $content1 = $cnt->content1;
            $content2 = $cnt->content2;
            $content3 = $cnt->content3;
            $content4 = $cnt->content4;
            $result = restore_decode_content_links_worker($content, $restore);
            $result1 = restore_decode_content_links_worker($content1, $restore);
            $result2 = restore_decode_content_links_worker($content2, $restore);
            $result3 = restore_decode_content_links_worker($content3, $restore);
            $result4 = restore_decode_content_links_worker($content4, $restore);
            if ($result != $content || $result1 != $content1 || $result2 != $content2 || $result3 != $content3 || $result4 != $content4) {
                /// Unset fields to update only the necessary ones
                unset($cnt->content);
                unset($cnt->content1);
                unset($cnt->content2);
                unset($cnt->content3);
                unset($cnt->content4);
                /// Conditionally set the fields
                if ($result != $content) {
                    $cnt->content = addslashes($result);
                }
                if ($result1 != $content1) {
                    $cnt->content1 = addslashes($result1);
                }
                if ($result2 != $content2) {
                    $cnt->content2 = addslashes($result2);
                }
                if ($result3 != $content3) {
                    $cnt->content3 = addslashes($result3);
                }
                if ($result4 != $content4) {
                    $cnt->content4 = addslashes($result4);
                }
                /// Update record with the changed fields
                $status = update_record("data_content", $cnt);
                if (debugging()) {
                    if (!defined('RESTORE_SILENTLY')) {
                        echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                    }
                }
            }
            /// Do some output
            if (($i + 1) % 5 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 100 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
        }
    }
    return $status;
}
예제 #30
0
 /**
  * Assistant to decode_content_links_caller
  *
  * @return boolean
  **/
 function decode_content_links_worker($restore)
 {
     global $CFG;
     $status = true;
     $i = 0;
     // Counter to send some output to the browser to avoid timeouts
     foreach ($this->tasks as $task) {
         //Increment counter
         $i++;
         $content = $task->name;
         $result = restore_decode_content_links_worker($content, $restore);
         if ($result != $content) {
             // Changed, so update record
             $update = new stdClass();
             $update->id = $task->id;
             $update->name = addslashes($result);
             $status = update_record('block_task_list', $update);
             if (debugging()) {
                 if (!defined('RESTORE_SILENTLY')) {
                     echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
                 }
             }
         }
         //Do some output
         if (($i + 1) % 5 == 0) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo ".";
                 if (($i + 1) % 100 == 0) {
                     echo "<br />";
                 }
             }
             backup_flush(300);
         }
     }
     return $status;
 }