コード例 #1
0
function forumng_backup_one_mod($bf, $preferences, $forumng)
{
    global $CFG;
    try {
        if (is_numeric($forumng)) {
            $forumng = forum_utils::get_record('forumng', 'id', $forumng);
        }
        $xb = new xml_backup($bf, $preferences, 3);
        $xb->tag_start('MOD');
        // Required bits
        $xb->tag_full('ID', $forumng->id);
        $xb->tag_full('MODTYPE', 'forumng');
        $xb->tag_full('NAME', $forumng->name);
        // Backup versioning
        require dirname(__FILE__) . '/version.php';
        $xb->tag_full('FORUMNG_VERSION', $module->version);
        // Are we doing user data?
        $userdata = backup_userdata_selected($preferences, 'forumng', $forumng->id);
        // ForumNG-specific
        $xb->tag_full_notnull('TYPE', $forumng->type);
        $xb->tag_full_notnull('INTRO', $forumng->intro);
        $xb->tag_full('RATINGSCALE', $forumng->ratingscale);
        $xb->tag_full('RATINGFROM', $forumng->ratingfrom);
        $xb->tag_full('RATINGUNTIL', $forumng->ratinguntil);
        $xb->tag_full('RATINGTHRESHOLD', $forumng->ratingthreshold);
        $xb->tag_full('GRADING', $forumng->grading);
        $xb->tag_full('ATTACHMENTMAXBYTES', $forumng->attachmentmaxbytes);
        $xb->tag_full('REPORTINGEMAIL', $forumng->reportingemail);
        $xb->tag_full('SUBSCRIPTION', $forumng->subscription);
        $xb->tag_full('FEEDTYPE', $forumng->feedtype);
        $xb->tag_full('FEEDITEMS', $forumng->feeditems);
        $xb->tag_full('MAXPOSTSPERIOD', $forumng->maxpostsperiod);
        $xb->tag_full('MAXPOSTSBLOCK', $forumng->maxpostsblock);
        $xb->tag_full('POSTINGFROM', $forumng->postingfrom);
        $xb->tag_full('POSTINGUNTIL', $forumng->postinguntil);
        $xb->tag_full_notnull('TYPEDATA', $forumng->typedata);
        $xb->tag_full('MAGICNUMBER', $forumng->magicnumber);
        $xb->tag_full('COMPLETIONDISCUSSIONS', $forumng->completiondiscussions);
        $xb->tag_full('COMPLETIONREPLIES', $forumng->completionreplies);
        $xb->tag_full('COMPLETIONPOSTS', $forumng->completionposts);
        $xb->tag_full('REMOVEAFTER', $forumng->removeafter);
        $xb->tag_full('REMOVETO', $forumng->removeto);
        $xb->tag_full('SHARED', $forumng->shared);
        // When this is a clone forum, we store the idnumber of the original
        // forum so that it can be found afterward; this makes sense rather
        // than using the normal cmid mapping because it might be on a different
        // course or something, also idnumber is shown in the interface.
        if ($forumng->originalcmid) {
            $idnumber = get_field('course_modules', 'idnumber', 'id', $forumng->originalcmid);
            if ($idnumber) {
                $xb->tag_full('ORIGINALCMIDNUMBER', $idnumber);
            }
        }
        // We only back up most content when 'user data' is turned on
        if ($userdata) {
            $xb->tag_start('DISCUSSIONS');
            $rs = forum_utils::get_recordset('forumng_discussions', 'forumid', $forumng->id);
            while ($discussion = rs_fetch_next_record($rs)) {
                forumng_backup_discussion($xb, $discussion);
            }
            rs_close($rs);
            $xb->tag_end('DISCUSSIONS');
            $xb->tag_start('SUBSCRIPTIONS');
            $rs = forum_utils::get_recordset('forumng_subscriptions', 'forumid', $forumng->id);
            while ($subscription = rs_fetch_next_record($rs)) {
                forumng_backup_subscription($xb, $subscription);
            }
            rs_close($rs);
            $xb->tag_end('SUBSCRIPTIONS');
            forumng_backup_files($bf, $preferences, $forumng->id);
        }
        $xb->tag_end('MOD');
        return true;
    } catch (Exception $e) {
        forum_utils::handle_backup_exception($e);
        return false;
    }
}
コード例 #2
0
function forumng_decode_content_links_caller($restore)
{
    // Get all the items that might have links in, from the relevant new course
    try {
        global $CFG, $db;
        // 1. Intros
        if ($intros = get_records_select('forumng', 'course=' . $restore->course_id . ' AND intro IS NOT NULL', '', 'id, intro, name')) {
            foreach ($intros as $intro) {
                $newintro = $intro->intro;
                // Special behaviour hidden in intro
                $matches = array();
                if (preg_match('~%%CMIDNUMBER:([^%]+)%%$~', $newintro, $matches)) {
                    $newintro = substr($newintro, 0, -strlen($matches[0]));
                    $idnumber = $matches[1];
                    $cm = forum::get_shared_cm_from_idnumber($idnumber);
                    if ($cm) {
                        set_field('forumng', 'originalcmid', $cm->id, 'id', $intro->id);
                    } else {
                        // The original forum cannot be found, so restore
                        // this as not shared
                        if (!defined('RESTORE_SILENTLY')) {
                            $a = (object) array('name' => s($intro->name), 'idnumber' => s($idnumber));
                            print '<br />' . get_string('error_nosharedforum', 'forumng', $a) . '<br />';
                        }
                    }
                }
                if (preg_match('~%%REMOVETHIS%%$~', $newintro)) {
                    $newintro = substr($newintro, 0, -14);
                }
                $newintro = restore_decode_content_links_worker($newintro, $restore);
                if ($newintro != $intro->intro) {
                    if (!set_field('forumng', 'intro', addslashes($newintro), 'id', $intro->id)) {
                        throw new forum_exception("Failed to set intro for forum {$intro->id}: " . $db->ErrorMsg());
                    }
                }
            }
        }
        // 2. Post content
        $rs = get_recordset_sql("\nSELECT\n    fp.id, fp.message, fp.format\nFROM\n    {$CFG->prefix}forumng f\n    INNER JOIN {$CFG->prefix}forumng_discussions d ON d.forumid = f.id\n    INNER JOIN {$CFG->prefix}forumng_posts fp ON fp.discussionid = d.id\nWHERE\n    f.course={$restore->course_id}\n");
        if (!$rs) {
            throw new forum_exception("Failed to query for forum data: " . $db->ErrorMsg());
        }
        while ($rec = rs_fetch_next_record($rs)) {
            $newcontent = restore_decode_content_links_worker($rec->message, $restore);
            if ($newcontent != $rec->message) {
                if (!set_field('forumng_posts', 'message', addslashes($newcontent), 'id', $rec->id)) {
                    throw new forum_exception("Failed to update content {$ec->id}: " . $db->ErrorMsg());
                }
            }
        }
        rs_close($rs);
        // 3. Update search data (note this is not actually do with content
        //    links, but it has to be done here because we need a course-module
        //    id.
        if (forum::search_installed()) {
            forumng_ousearch_update_all(false, $restore->course_id);
        }
        return true;
    } catch (Exception $e) {
        forum_utils::handle_backup_exception($e, 'restore');
        return false;
    }
}