コード例 #1
0
function wiki_restore_mods($mod, $restore)
{
    global $CFG, $COURSE;
    $status = true;
    $ewiki = false;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    $info = $data->info;
    //Now check if the mod is a ewiki or a newwiki mod, an create the
    //array $data with the info with the same format in both cases.
    if (isset($info["MOD"]["#"]["ENTRIES"])) {
        $data = wiki_read_xml_ewiki($info["MOD"]["#"], $restore);
        $ewiki = true;
        //Use this later.
    } else {
        $data = wiki_read_xml_wiki($info["MOD"]["#"], $restore->course_id);
    }
    if (!isset($data)) {
        $status = false;
    } else {
        $schema = wiki_create_schema();
        $wiki = wiki_validate($data['wiki'], $schema['wiki']);
        $wiki->course = $restore->course_id;
        $id = get_record_sql('SELECT id
					FROM ' . $CFG->prefix . 'wiki WHERE wikicourse=' . addslashes($wiki->course));
        if (empty($id->id) && $wiki->wikicourse != '0') {
            //The course is a wiki format course, then set the correct wikicourse id
            $wiki->wikicourse = $wiki->course;
        } else {
            $wiki->wikicourse = 0;
        }
        //Now insert the wiki record
        $newid = insert_record("wiki", $wiki);
        //Do some output
        echo "<li>" . get_string("modulename", 'wiki') . " \"" . format_string(stripslashes($wiki->name), true) . "\"</li>";
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now check if want to restore user data and do it.
            if ($restore->mods['wiki']->userinfo) {
                $oldid = backup_todb($info['MOD']['#']['ID']['0']['#']);
                $order = backup_todb($info['MOD']['#']['ORDER']['0']['#']);
                //Now, build the wiki record structure
                $schemapages = $schema['wiki_pages'];
                $datapages = $data['wiki_pages'];
                $numpages = count($datapages);
                for ($i = 0; $i < $numpages; $i++) {
                    //$page=wiki_validate_page($datapages[$i],$schemapages);
                    $page = wiki_validate($datapages[$i], $schemapages);
                    $page->dfwiki = $newid;
                    //We have to recode the userid field
                    $user = backup_getid($restore->backup_unique_code, "user", $page->userid);
                    if ($user) {
                        $page->userid = $user->new_id;
                    }
                    //We have to recode the ownerid field
                    if ($ewiki) {
                        if ($wiki->studentmode != '0') {
                            $page->ownerid = $page->userid;
                        }
                    }
                    $owner = backup_getid($restore->backup_unique_code, "owner", $page->ownerid);
                    if ($owner) {
                        $page->ownerid = $owner->new_id;
                    }
                    //We have to recode the groupid field
                    $group = backup_getid($restore->backup_unique_code, "group", $page->groupid);
                    if ($group) {
                        $page->groupid = $group->new_id;
                    }
                    //The structure is equal to the db
                    $oldpageid = $page->id;
                    $newpageid = insert_record("wiki_pages", $page);
                    $page->id = $oldpageid;
                    //Do some output
                    if (($i + 1) % 50 == 0) {
                        echo ".";
                        if (($i + 1) % 1000 == 0) {
                            echo "<br />";
                        }
                        backup_flush(300);
                    }
                    if ($newpageid) {
                        //We have the newid, update backup_ids
                        //$page->id is now the page old id
                        backup_putid($restore->backup_unique_code, "wiki_pages", $page->id, $newpageid);
                    } else {
                        $status = false;
                    }
                }
                //Restore synonymous for the newwiki mod
                if (!$ewiki && isset($data['wiki_synonymous'])) {
                    $schemasyn = $schema['wiki_synonymous'];
                    $datasyns = $data['wiki_synonymous'];
                    $numsyns = count($datasyns);
                    for ($i = 0; $i < $numsyns; $i++) {
                        $syn = wiki_validate($datasyns[$i], $schemasyn);
                        $syn->dfwiki = $newid;
                        //We have to recode the userid field
                        $owner = backup_getid($restore->backup_unique_code, "owner", $syn->ownerid);
                        if ($owner) {
                            $syn->ownerid = $owner->new_id;
                        }
                        $group = backup_getid($restore->backup_unique_code, "group", $syn->groupid);
                        if ($group) {
                            $syn->groupid = $group->new_id;
                        }
                        //The structure is equal to the db
                        $newsynid = insert_record("wiki_synonymous", $syn);
                        //Do some output
                        if (($i + 1) % 50 == 0) {
                            echo ".";
                            if (($i + 1) % 1000 == 0) {
                                echo "<br />";
                            }
                            backup_flush(300);
                        }
                        if ($newsynid) {
                            //We have the newid, update backup_ids
                            backup_putid($restore->backup_unique_code, "wiki_synonymous", $syn->id, $newsynid);
                        } else {
                            $status = false;
                        }
                    }
                }
                //Now copy moddata associated files
                $e_wiki = $data['wiki_pages'][0];
                wiki_restore_files($oldid, $restore, $order, $e_wiki);
            }
        } else {
            $status = false;
        }
    }
    return $status;
}
コード例 #2
0
 function EndElementModule($parser, $tagName)
 {
     //Check if we are into MODULES zone
     if ($this->tree[3] == "MODULES") {
         //Acumulate data to info (content + close tag)
         //Reconvert: strip htmlchars again and trim to generate xml data
         if (!isset($this->temp)) {
             $this->temp = "";
         }
         $this->temp .= htmlspecialchars(trim($this->content)) . "</" . $tagName . ">";
         //If we've finished a mod, xmlize it an save to array $data
         if ($this->level == 4 and $tagName == "MOD") {
             //Prepend XML standard header to info gathered
             $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $this->temp;
             //Call to xmlize for this portion of xml data (one MOD)
             $data = xmlize($xml_data, 0);
             $name = $data["MOD"]["#"]["NAME"]["0"]["#"];
             if (isset($data["MOD"]["#"]["ENTRIES"]) && $name == $this->ewiki) {
                 $this->info[] = wiki_read_xml_ewiki($data["MOD"]["#"]);
             } else {
                 if ($name == $this->ewiki) {
                     $this->info[] = wiki_read_xml_wiki($data["MOD"]["#"]);
                 }
             }
             //Only if we've selected to restore it
             //Reset temp
             unset($this->temp);
         }
     }
     //Stop parsing if todo = MODULES and tagName = MODULES (en of the tag, of course)
     //Speed up a lot (avoid parse all)
     if ($tagName == "MODULES" and $this->level == 3) {
         $this->finished = true;
     }
     //Clear things
     $this->tree[$this->level] = "";
     $this->level--;
     $this->content = "";
 }