function backup_zip($preferences) { global $CFG; $status = true; //Base dir where everything happens $basedir = cleardoubleslashes($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code); //Backup zip file name $name = $preferences->backup_name; //List of files and directories $filelist = list_directories_and_files($basedir); //Convert them to full paths $files = array(); foreach ($filelist as $file) { $files[] = "{$basedir}/{$file}"; } $status = zip_files($files, "{$basedir}/{$name}"); //echo "<br/>Status: ".$status; //Debug return $status; }
function wiki_export_html(&$WS) { global $CFG; check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/html", true); check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}", true); check_dir_exists("{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}", true); //export contents wiki_export_html_content($WS); //export attached files $flist = list_directories_and_files("{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}"); if ($flist != null) { foreach ($flist as $fil) { $from_file = "{$CFG->dataroot}/{$WS->dfwiki->course}/moddata/dfwiki{$WS->cm->id}/{$fil}"; $to_file = "{$CFG->dataroot}/temp/html/dfwiki{$WS->cm->id}/atachments/{$fil}"; copy($from_file, $to_file); } } //zip file name $times = time(); $name = $WS->dfwiki->name . '-' . $times . '.zip'; $cleanzipname = clean_filename($name); //List of files and directories $filelist = list_directories_and_files("{$CFG->dataroot}/temp/html"); //Convert them to full paths $files = array(); if ($filelist != null) { foreach ($filelist as $file) { $files[] = "{$CFG->dataroot}/temp/html/{$file}"; } } check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}", true); check_dir_exists("{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml", true); $destination = "{$CFG->dataroot}/{$WS->dfwiki->course}/exportedhtml/{$cleanzipname}"; $status = zip_files($files, $destination); //delete the folder created in temp $filelist2 = list_directories_and_files("{$CFG->dataroot}/temp/html"); if ($filelist2 != null) { $del = delete_dir_contents("{$CFG->dataroot}/temp/html"); } //show it all to be albe to download the file $prop = null; $prop->class = "textcenter"; wiki_div_start($prop); wiki_size_text(get_string("exporthtmlcorrectly", "wiki"), 2); wiki_div_end(); $prop = null; $prop->border = "0"; $prop->class = "boxaligncenter"; $prop->classtd = "nwikileftnow"; wiki_table_start($prop); $wdir = '/exportedhtml'; $fileurl = "{$wdir}/{$cleanzipname}"; $ffurl = "/file.php?file=/{$WS->cm->course}{$fileurl}"; $icon = mimeinfo("icon", $cleanzipname); link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" height=\"16\" width=\"16\" alt=\"File\" />", 480, 640); echo "\n" . ' '; link_to_popup_window($ffurl, "display", htmlspecialchars($cleanzipname), 480, 640); $prop = null; $prop->class = "nwikileftnow"; wiki_change_row($prop); echo ' '; wiki_table_end(); $prop = null; $prop->border = "0"; $prop->class = "boxaligncenter"; $prop->classtd = "nwikileftnow"; wiki_table_start($prop); $prop = null; $prop->id = "form"; $prop->method = "post"; $prop->action = '../xml/index.php?id=' . $WS->dfwiki->course . '&wdir=/exportedhtml'; wiki_form_start($prop); wiki_div_start(); $prop = null; $prop->name = "dfform[viewexported]"; $prop->value = get_string('viewexported', 'wiki'); wiki_input_submit($prop); wiki_div_end(); wiki_form_end(); wiki_change_column(); print_continue("{$CFG->wwwroot}/mod/wiki/view.php?id={$WS->cm->id}"); wiki_table_end(); }
if ($c > 0) { $xmlcontentfnewtext .= "<QUESTION_CATEGORY>" . $xmlcontentfnew_; } else { $xmlcontentfnewtext .= $xmlcontentfnew_; } $c++; } } $xml_file = $CFG->dataroot . $dirq . '/moodle.xml'; $restoreq->file = $CFG->dataroot . $dirq . '/moodle.zip'; $fp = fopen($xml_file, "w+"); fwrite($fp, $xmlcontentfnewtext); if (!($statusbackup = backup_zip($restoreq))) { print_error('Can\'t create backup zip file.'); } $filelist = list_directories_and_files($CFG->dataroot . $dirq); $xmlarray = xmlize($xmlcontentfnewtext); //---------------Check images ----------------// $checkimagesarr = $xmlarray['MOODLE_BACKUP']['#']['COURSE']['0']['#']['QUESTION_CATEGORIES']['0']['#']['QUESTION_CATEGORY']; while (list($key, $value) = each($checkimagesarr)) { if (@is_array($value['#']['QUESTIONS']['0']['#']['QUESTION'])) { $dataquestarr = $value['#']['QUESTIONS']['0']['#']['QUESTION']; while (list($key2, $value2) = each($dataquestarr)) { if ($value2['#']['IMAGE']['0']['#']) { //Upload Image-------// $imglinks = explode("/", $value2['#']['IMAGE']['0']['#']); end($imglinks); unset($imglinks[key($imglinks)]); $imglinks = implode("/", $imglinks); make_upload_directory('reader/images'); $image = file_get_contents($readercfg->reader_serverlink . '/getfile_quiz_image.php?imagelink=' . urlencode($value2['#']['IMAGE']['0']['#']));
function restore_site_files($restore) { global $CFG; $status = true; $counter = 0; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . SITEID; $status = check_dir_exists($dest_dir, true); //Now, we iterate over "site_files" files to check if that file/dir must be //copied to the "dest_dir" dir. $rootdir = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/site_files"; //Check if directory exists if (is_dir($rootdir)) { $list = list_directories_and_files($rootdir); if ($list) { //Iterate $counter = 0; foreach ($list as $dir) { //Avoid copying maintenance.html. MDL-18594 if ($dir == 'maintenance.html') { continue; } //Copy the dir to its new location //Only if destination file/dir doesn exists if (!file_exists($dest_dir . "/" . $dir)) { $status = backup_copy_file($rootdir . "/" . $dir, $dest_dir . "/" . $dir, true); $counter++; } //Do some output if ($counter % 2 == 0) { if (!defined('RESTORE_SILENTLY')) { echo "."; if ($counter % 40 == 0) { echo "<br />"; } } backup_flush(300); } } } } //If status is ok and whe have dirs created, returns counter to inform if ($status and $counter) { return $counter; } else { return $status; } }
function backup_wiki_files($bf, $preferences, $id) { global $CFG; $status = true; $modul = get_record("modules", "name", 'wiki'); if (!($cm = get_record("course_modules", "instance", $id, "module", $modul->id))) { error("Course Module ID was incorrect"); } check_dir_exists("{$CFG->dataroot}/{$preferences->backup_course}", true); check_dir_exists("{$CFG->dataroot}/{$preferences->backup_course}/{$CFG->moddata}", true); check_dir_exists("{$CFG->dataroot}/{$preferences->backup_course}/{$CFG->moddata}/wiki{$cm->id}", true); $moddata_path = $CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki" . $cm->id; check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/backup", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/moddata", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/moddata/wiki", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/moddata/wiki/wiki{$id}", true); $temp_path = $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/wiki/wiki" . $id; //get all attachments $list = null; $list = list_directories_and_files($moddata_path); if ($list != null) { foreach ($list as $file) { $from_file = "{$moddata_path}/{$file}"; $to_file = "{$temp_path}/{$file}"; copy($from_file, $to_file); } } return $status; }
function wiki_copy_attachments($wikiid, $course, $coursemodule, $oldentryid) { global $CFG; //create the dir where attached dfwiki files are stored check_dir_exists("{$CFG->dataroot}/{$course}", true); check_dir_exists("{$CFG->dataroot}/{$course}/moddata", true); check_dir_exists("{$CFG->dataroot}/{$course}/moddata/dfwiki{$coursemodule}", true); check_dir_exists("{$CFG->dataroot}/{$course}/moddata", true); check_dir_exists("{$CFG->dataroot}/{$course}/moddata/wiki", true); check_dir_exists("{$CFG->dataroot}/{$course}/moddata/wiki/{$wikiid}", true); check_dir_exists("{$CFG->dataroot}/{$course}/moddata/wiki/{$wikiid}/{$oldentryid}", true); $files = list_directories_and_files("{$CFG->dataroot}/{$course}/moddata/wiki/{$wikiid}/{$oldentryid}"); //get every attached file if ($files != null) { foreach ($files as $fil) { //in case it's not a directory if (!is_dir("{$CFG->dataroot}/{$course}/moddata/wiki/{$wikiid}/{$oldentryid}/{$fil}")) { $to_file = "{$CFG->dataroot}/{$course}/moddata/dfwiki{$coursemodule}/{$fil}"; $from_file = "{$CFG->dataroot}/{$course}/moddata/wiki/{$wikiid}/{$oldentryid}/{$fil}"; copy($from_file, $to_file); } else { //get every single attached file $files2 = list_directories_and_files("{$CFG->dataroot}/{$course}/moddata/wiki/{$wikiid}/{$oldentryid}/{$fil}"); if ($files2 != null) { foreach ($files2 as $fil2) { $to_file = "{$CFG->dataroot}/{$course}/moddata/dfwiki{$coursemodule}/{$fil2}"; $from_file = "{$CFG->dataroot}/{$course}/moddata/wiki/{$wikiid}/{$oldentryid}/{$fil}/{$fil2}"; copy($from_file, $to_file); } } } } } }
function get_ewikis($zip) { global $CFG; $listewikis = null; //unpack the .zip check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/ewikis", true); $destination = "{$CFG->dataroot}/temp/ewikis"; unzip_file($zip, $destination, false); //take the .xml $filelist = list_directories_and_files("{$CFG->dataroot}/temp/ewikis"); if ($filelist == null) { return $listewikis; } foreach ($filelist as $file) { $extension = explode(".", $file); $num = count($extension) - 1; if ($extension[$num] == "xml") { $goodfile = $file; } } $newfile = "{$CFG->dataroot}/temp/ewikis/{$goodfile}"; $info = restore_read_xml_bis($newfile); if ($info != null) { foreach ($info as $mod) { if ($mod->modtype == 'wiki' || $mod->modtype == 'dfwiki') { $listewikis[] = $mod; } } } //delete the folder created in temp $filelist2 = list_directories_and_files("{$CFG->dataroot}/temp/ewikis"); if ($filelist2 != null) { $del = delete_dir_contents("{$CFG->dataroot}/temp/ewikis"); } return $listewikis; }
function xmldb_wiki_upgrade($oldversion = 0) { global $CFG, $db; $result = true; // Checks if the current version installed in the system is old wiki (ewiki) or is new wiki (nwiki) // We can distinguish ewiki from nwiki checking wiki_synonymous table existence. //Initialy we asume we aren't upgrading from old wiki $fromoldwiki = false; $table = new XMLDBTable('wiki_synonymous'); if (!table_exists($table)) { //New wiki isn't installed yet $fromoldwiki = true; //We are upgrading from old wiki. // Upgrading ewiki to last version using XMLDB functions. require_once $CFG->dirroot . '/mod/wiki/wikimigrate/ewiki_upgrade.php'; $result = xmldb_ewiki_upgrade($oldversion); // We have an upgraded ewiki at this point of process. // Migration can start. require_once $CFG->dirroot . '/mod/wiki/wikimigrate/ewiki_migrate.php'; wiki_migrate_ewiki(); $oldversion = 0; } if ($result && $oldversion < 2006042900) { //Delete previous log_display records for wiki for safety delete_records('log_display', 'module', 'wiki'); //Add new log_display_records $record->module = 'wiki'; $record->action = 'add'; $record->mtable = 'wiki'; $record->field = 'name'; $result = insert_record('log_display', $record); $record->action = 'update'; $result = $result && insert_record('log_display', $record); $record->action = 'view'; $result = $result && insert_record('log_display', $record); $record->action = 'view all'; $result = $result && insert_record('log_display', $record); $record->mtable = 'wiki_pages'; $record->field = 'pagename'; $record->action = 'view page'; $result = $result && insert_record('log_display', $record); $record->action = 'edit page'; $result = $result && insert_record('log_display', $record); $record->action = 'save page'; $result = $result && insert_record('log_display', $record); $record->action = 'info page'; $result = $result && insert_record('log_display', $record); // OLD SENTENCES // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'add', 'wiki', 'name') "); // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'update', 'wiki', 'name') "); // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'view', 'wiki', 'name') "); // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'view all', 'wiki', 'name') "); // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'view page', 'wiki_pages', 'pagename') "); // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'edit page', 'wiki_pages', 'pagename') "); // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'save page', 'wiki_pages', 'pagename') "); // execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('wiki', 'info page', 'wiki_pages', 'pagename') "); } if ($result && $oldversion < 2006050301) { $result = table_column('wiki_synonymous', '', 'userid', 'int', '10', 'unsigned', '0', 'not null', 'groupid'); if (empty($fromoldwiki)) { //Only if we aren't migrating from old wiki, because it creates these columns and fills them! $result = $result && table_column('wiki', '', 'intro', 'text', '', '', '', 'not null', 'name'); $result = $result && table_column('wiki', '', 'introformat', 'tinyint', '2', 'unsigned', '0', 'not null', 'intro'); //add colums $result = $result && table_column('wiki_pages', '', 'userid', 'int', '10', 'unsigned', '0', 'not null', 'author'); $result = $result && table_column('wiki_synonymous', '', 'userid', 'int', '10', 'unsigned', '0', 'not null', 'groupid'); //set userid via author values $authors = get_records_select('wiki_pages', null, null, 'distinct author'); // OLD SENTENCE // $authors = get_records_sql('SELECT DISTINCT author, author FROM '.$CFG->prefix.'wiki_pages'); foreach ($authors as $author) { if ($user = get_record('user', 'username', $author->author)) { $result = $result && set_field('wiki_pages', 'userid', $user->id, 'author', $author->author); } } } } if ($result && $oldversion < 2006050500) { //droping and regenerating some indexes to normalize everything //(some of them could not exist, but for safety...) $table = new XMLDBTable('wiki'); $index = new XMLDBIndex('course'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course')); $result = drop_index($table, $index); $index = new XMLDBIndex('course'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course')); $result = $result && add_index($table, $index); $table = new XMLDBTable('wiki_pages'); $key = new XMLDBKey('dfwiki_pages_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid')); $result = $result && drop_key($table, $key); $key = new XMLDBKey('wiki_pages_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid')); $result = $result && drop_key($table, $key); $key = new XMLDBKey('wiki_pages_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid', 'ownerid')); $result = $result && add_key($table, $key); $table = new XMLDBTable('wiki_synonymous'); $key = new XMLDBKey('dfwiki_synonymous_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('syn', 'dfwiki', 'groupid', 'userid')); $result = drop_key($table, $key); $key = new XMLDBKey('wiki_synonymous_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('syn', 'dfwiki', 'groupid', 'userid')); $result = drop_key($table, $key); $key = new XMLDBKey('wiki_synonymous_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('syn', 'dfwiki', 'groupid', 'userid')); $result = $result && add_key($table, $key); // OLD SENTENCES //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki DROP KEY course;",false); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki ADD KEY course (course);",false); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_pages DROP KEY dfwiki_pages_uk;",false); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_pages DROP KEY wiki_pages_uk;",false); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_pages ADD UNIQUE KEY wiki_pages_uk (pagename, version, dfwiki, groupid, userid);",false); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous DROP KEY dfwiki_synonymous_uk;",false); // execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous DROP KEY wiki_synonymous_uk;",false); // execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous ADD UNIQUE KEY wiki_synonymous_uk (syn,dfwiki,groupid, userid);",false); } if ($result && $oldversion < 2006051800) { $table = new XMLDBTable('wiki_pages'); $field = new XMLDBField('highlight'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', 'editable'); $result = add_field($table, $field); // OLD SENTECE // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_pages` ADD `highlight` tinyint(1) NOT NULL default 0 AFTER `editable`'); } if ($result && $oldversion < 2006053000) { if (empty($fromoldwiki)) { //Only if we aren't migrating from old wiki, because it creates this column! $table = new XMLDBTable('wiki_pages'); $field = new XMLDBField('votes'); $field->setAttributes(XMLDB_TYPE_INTEGER, null, XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'hits'); $result = add_field($table, $field); // OLD SENTENCE // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_pages` ADD `votes` INTEGER UNSIGNED NOT NULL default 0 AFTER `hits`'); } } if ($result && $oldversion < 2006060701) { if (empty($fromoldwiki)) { $table = new XMLDBTable('wiki'); $field = new XMLDBField('studentmode'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', null); $result = add_field($table, $field); $field = new XMLDBField('teacherdiscussion'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', null); $result = $result && add_field($table, $field); $field = new XMLDBField('studentdiscussion'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', null); $result = $result && add_field($table, $field); $field = new XMLDBField('editanothergroup'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', null); $result = $result && add_field($table, $field); $field = new XMLDBField('editanotherstudent'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', null); $result = $result && add_field($table, $field); $table = new XMLDBTable('wiki_pages'); $field = new XMLDBField('evaluation'); $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, '', 'groupid'); $result = add_field($table, $field); // OLD SENTENCES // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `studentmode` tinyint(1) NOT NULL default 0'); // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `teacherdiscussion` int(1) NOT NULL default 0'); // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `studentdiscussion` int(1) NOT NULL default 0'); // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `editanothergroup` tinyint(1) not null default 0'); // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `editanotherstudent` tinyint(1) not null default 0'); // // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_pages` ADD `evaluation` MEDIUMTEXT default NULL AFTER `groupid`'); } else { $table = new XMLDBTable('wiki_pages'); $field = new XMLDBField('evaluation'); $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, '', 'ownerid'); $result = add_field($table, $field); // OLD SENTENCE // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_pages` ADD `evaluation` MEDIUMTEXT default NULL AFTER `ownerid`'); } $table = new XMLDBTable('wiki'); $field = new XMLDBField('evaluation'); $field->setAttributes(XMLDB_TYPE_CHAR, '40', null, null, null, null, null, 'noeval', 'studentdiscussion'); $result = $result && add_field($table, $field); $field = new XMLDBField('notetype'); $field->setAttributes(XMLDB_TYPE_CHAR, '40', null, null, null, null, null, 'quant', 'evaluation'); $result = $result && add_field($table, $field); // OLD SENTECES // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `evaluation` varchar(40) default "noeval" AFTER `studentdiscussion`'); // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `notetype` varchar(40) default "quant" AFTER `evaluation`'); } if ($result && $oldversion < 2006060702 && empty($fromoldwiki)) { //make sure we don't have ownerid in the DB (backward compatibility) $table = new XMLDBTable('wiki_pages'); $field = $table->findFieldInArray('ownerid'); if (empty($field)) { $field = new XMLDBField('ownerid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupid'); $result = add_field($table, $field); $key = new XMLDBKey('wiki_pages_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid')); $result = $result && drop_key($table, $key); $key = new XMLDBKey('wiki_pages_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid', 'ownerid')); $result = $result && add_key($table, $key); $table = new XMLDBTable('wiki_synonymous'); $field = new XMLDBField('userid'); $result = $result && drop_field($table, $field); $field = new XMLDBField('ownerid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null); $result = $result && add_field($table, $field); $key = new XMLDBKey('wiki_synonymous_uk'); $result = $result && drop_key($table, $key); $key = new XMLDBKey('wiki_synonymous_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('syn', 'dfwiki', 'groupid', 'ownerid')); $result = $result && add_key($table, $key); // OLD SENTENCES // //make sure we don't have ownerid in the DB (backward compatibility) // if(!get_records_sql('SELECT ownerid FROM '.$CFG->prefix.'wiki_pages LIMIT 0 , 30')){ // //adding new ownerid replacing userid //- execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_pages` ADD `ownerid` int(10) unsigned not null default 0 AFTER `groupid`'); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous DROP userid;",false); //- execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_synonymous` ADD `ownerid` int(10) unsigned not null default 0'); // //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_pages DROP KEY wiki_pages_uk;",false); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_pages ADD UNIQUE KEY wiki_pages_uk (pagename, version, dfwiki, groupid, userid, ownerid);",false); // //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous DROP KEY wiki_synonymous_uk;",false); //- execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous ADD UNIQUE KEY wiki_synonymous_uk (syn,dfwiki,groupid,ownerid);",false); // //now ownerid is the old userid, and userid is the author's id $quer = 'UPDATE ' . $CFG->prefix . 'wiki_pages SET ownerid = userid'; $result = $result && execute_sql($quer); // It can't be translated to XMLDB functions $authors = get_records_select('wiki_pages', null, null, 'distinct author'); foreach ($authors as $author) { if ($user = get_record('user', 'username', $author->author)) { //set userid corrrectly set_field('wiki_pages', 'userid', $user->id, 'author', $author->author); } // OLD SENTENCES // //now ownerid is the old userid, and userid is the author's id // $quer = 'UPDATE '.$CFG->prefix.'wiki_pages // SET ownerid = userid'; // execute_sql($quer); // // //set userid via author values // $authors = get_records_sql('SELECT DISTINCT author, author FROM '.$CFG->prefix.'wiki_pages'); // foreach($authors as $author) { // if ($user = get_record('user', 'username', $author->author)) { // //set userid corrrectly // set_field ('wiki_pages', 'userid', $user->id, 'author', $author->author); // } // } } } } if ($result && $oldversion < 2006060702 && $fromoldwiki) { $table = new XMLDBTable('wiki_pages'); $field = new XMLDBField('destacar'); $result = drop_field($table, $field); $key = new XMLDBKey('wiki_pages_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid')); $result = $result && drop_key($table, $key); $key = new XMLDBKey('wiki_pages_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('pagename', 'version', 'dfwiki', 'groupid', 'userid', 'ownerid')); $result = $result && add_key($table, $key); $table = new XMLDBTable('wiki_synonymous'); $field = new XMLDBField('userid'); $result = $result && drop_field($table, $field); $key = new XMLDBKey('wiki_synonymous_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('syn', 'dfwiki', 'groupid', 'userid', 'ownerid')); $result = $result && drop_key($table, $key); $key = new XMLDBKey('wiki_synonymous_uk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('syn', 'dfwiki', 'groupid', 'ownerid')); $result = $result && add_key($table, $key); // OLD SENTENCES // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_pages` DROP `destacar`'); // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_synonymous` DROP `userid`'); // // execute_sql(" ALTER TABLE {$CFG->prefix}wiki_pages DROP KEY wiki_pages_uk;",false); // execute_sql(" ALTER TABLE {$CFG->prefix}wiki_pages ADD UNIQUE KEY wiki_pages_uk (pagename, version, dfwiki, groupid, userid, ownerid);",false); // // execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous DROP KEY wiki_synonymous_uk;",false); // execute_sql(" ALTER TABLE {$CFG->prefix}wiki_synonymous ADD UNIQUE KEY wiki_synonymous_uk (syn,dfwiki,groupid,ownerid);",false); $authors = get_records_select('wiki_pages', null, null, 'author'); if (!empty($authors)) { foreach ($authors as $author) { if ($user = get_record('user', 'username', $author->author)) { //set userid corrrectly set_field('wiki_pages', 'userid', $user->id, 'author', $author->author); } } } //OLD SENTENCES // //set userid via author values // $authors = get_records_sql('SELECT DISTINCT author, author FROM '.$CFG->prefix.'wiki_pages'); // foreach($authors as $author) { // if ($user = get_record('user', 'username', $author->author)) { // //set userid corrrectly // set_field ('wiki_pages', 'userid', $user->id, 'author', $author->author); // } // } } //Actualizamos la newwiki independientemenre de si hemos utilizado //una dfwiki instalada y actualizada o una dfwiki temporal if ($result && $oldversion < 2006070700) { $table = new XMLDBTable('wiki'); $field = new XMLDBField('votemode'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', null); $result = add_field($table, $field); // OLD SENTENCE // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `votemode` tinyint(1) NOT NULL default 0'); } if ($result && $oldversion < 2006070703) { $table = new XMLDBTable('wiki_votes'); $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); $table->addFieldInfo('pagename', XMLDB_TYPE_CHAR, '160', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('version', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, '0', null); $table->addFieldInfo('dfwiki', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, '0', null); $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, null, null); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $result = create_table($table); // OLD SENTENCE // execute_sql('CREATE TABLE `'.$CFG->prefix.'wiki_votes` (`id` int(10) unsigned NOT NULL auto_increment, // `pagename` varchar(160) NOT NULL, // `version` int(10) unsigned NOT NULL default 0, // `dfwiki` int(10) unsigned NOT NULL, // `username` varchar(100) NOT NULL, // PRIMARY KEY (`id`))'); } if ($result && $oldversion < 2006071402) { $table = new XMLDBTable('wiki'); $field = new XMLDBField('listofteachers'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0', null); $result = add_field($table, $field); // OLD SENTENCE // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `listofteachers` tinyint(1) NOT NULL default 0'); } if ($result && $oldversion < 2006072401) { $table = new XMLDBTable('wiki_pages'); $field = new XMLDBField('votes'); $result = drop_field($table, $field); // OLD VERSION // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki_pages` DROP `votes`'); } // correct version error if ($result && $oldversion == 2006271001) { $oldversion = 2006102701; $result = set_field('modules', 'version', '2006102701', 'name', 'wiki'); // OLD SENTENCE // execute_sql('UPDATE `'.$CFG->prefix.'modules` SET `version`= 2006102701 WHERE `name` = wiki'); } if ($result && $oldversion < 2006112101) { $table = new XMLDBTable('wiki'); $field = $table->findFieldInArray('editorrows'); if (empty($field)) { $field = new XMLDBField('editorrows'); $field->setAttributes(XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null, null, '40', null); $result = add_field($table, $field); } $field = $table->findFieldInArray('editorcols'); if (empty($field)) { $field = new XMLDBField('editorcols'); $field->setAttributes(XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null, null, '60', null); $result = $result && add_field($table, $field); } // OLD SENTENCES // if (!get_records_sql('SHOW COLUMNS FROM '.$CFG->prefix.'wiki WHERE Field=\'editorrows\'')){ // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `editorrows` integer NOT NULL DEFAULT 40'); // } // // if (!get_records_sql('SHOW COLUMNS FROM '.$CFG->prefix.'wiki WHERE Field=\'editorcols\'')){ // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `editorcols` integer NOT NULL DEFAULT 60'); // } } if ($result && $oldversion < 2006112502) { $table = new XMLDBTable('wiki'); $field = new XMLDBField('wikicourse'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null); $result = add_field($table, $field); // OLD SENTENCE // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `wikicourse` int(10) unsigned NOT NULL DEFAULT 0'); if ($wikicourses = get_records('course', 'format', 'wiki')) { $wikimod = get_record('modules', 'name', 'wiki'); foreach ($wikicourses as $wikicourse) { $min = get_record_select('course_module', 'course = ' . $wikicourse->id . ' AND module = ' . $wikimod->id, 'min(id) as minim'); // OLD SENTENCE // $min = get_record_sql('SELECT MIN(`id`) AS minim FROM '.$CFG->prefix.'course_modules WHERE `course`=\''.$wikicourse->id.'\' AND `module`=\''.$wikimod->id.'\''); $cm = get_record('course_modules', 'id', $min->minim); $result = $result && set_field('wiki', 'wikicourse', $wikicourse->id, 'id', $cm->instance); } } } if ($result && $oldversion < 2007022707) { // Moving archives to the new directory (from dfwikiX to wikiX) require_once $CFG->dirroot . '/lib/uploadlib.php'; require_once $CFG->dirroot . '/backup/lib.php'; $wikimod = get_record("modules", "name", "wiki"); $wikis = get_records("wiki"); if (!empty($wikis)) { foreach ($wikis as $wiki) { $cm = get_record("course_modules", "course", $wiki->course, "instance", $wiki->id, "module", $wikimod->id); if (check_dir_exists($CFG->dataroot . "/" . $wiki->course . "/moddata/dfwiki" . $cm->id)) { check_dir_exists($CFG->dataroot . "/" . $wiki->course . "/moddata/wiki" . $cm->id, true, true); $flist = list_directories_and_files($CFG->dataroot . "/" . $wiki->course . "/moddata/dfwiki" . $cm->id); foreach ($flist as $file) { $result = $result && copy($CFG->dataroot . "/" . $wiki->course . "/moddata/dfwiki" . $cm->id . "/" . $file, $CFG->dataroot . "/" . $wiki->course . "/moddata/wiki" . $cm->id . "/" . $file); } $result = $result && remove_dir($CFG->dataroot . "/" . $wiki->course . "/moddata/dfwiki" . $cm->id); } } } } if ($result && $oldversion < 2007030301) { // Adding filetemplate file to database $table = new XMLDBTable('wiki'); $field = new XMLDBField('filetemplate'); $field->setAttributes(XMLDB_TYPE_CHAR, '60', null, null, null, null, null, null, null); $result = add_field($table, $field); // OLD SENTENCE // execute_sql('ALTER TABLE `'.$CFG->prefix.'wiki` ADD `filetemplate` VARCHAR(60) NULL DEFAULT NULL'); } if ($result && $oldversion < 2007060701) { $table = new XMLDBTable('wiki_locks'); if (!table_exists($table)) { // Adding wiki_locks table to admin wiki pages lock system $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); $table->addFieldInfo('wikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('pagename', XMLDB_TYPE_CHAR, '160', null, XMLDB_NOTNULL, null, null, '', null); $table->addFieldInfo('lockedby', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 0, null); $table->addFieldInfo('lockedsince', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, '0', null); $table->addFieldInfo('lockedseen', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, '0', null); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('wiki_locks_uk', XMLDB_KEY_UNIQUE, array('wikiid', 'pagename')); $table->addIndexInfo('wiki_locks_ix', XMLDB_INDEX_NOTUNIQUE, array('lockedseen')); $result = $result && create_table($table); } // OLD SENTENCE // modify_database(""," // CREATE TABLE prefix_wiki_locks // ( // id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, // wikiid INT(10) UNSIGNED NOT NULL, // pagename VARCHAR(160) NOT NULL DEFAULT '', // lockedby INT(10) NOT NULL DEFAULT 0, // lockedsince INT(10) NOT NULL DEFAULT 0, // lockedseen INT(10) NOT NULL DEFAULT 0, // PRIMARY KEY(id), // UNIQUE INDEX wiki_locks_uk(wikiid,pagename), // INDEX wiki_locks_ix(lockedseen) // );"); } if ($result && $oldversion < 2007072301) { //////////////////////////// // Fixing some old errors // //////////////////////////// // Old mysql.php created this field as intergers: int(11) // They must be smallint(3) // // I'm going to change defaults too. $table = new XMLDBTable('wiki'); $field = new XMLDBField('editorrows'); $field->setAttributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '30', null); $result = change_field_precision($table, $field); $result = $result && change_field_default($table, $field); $field = new XMLDBField('editorcols'); $field->setAttributes(XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '120', null); $result = $result && change_field_precision($table, $field); $result = $result && change_field_default($table, $field); // Changing wikicourse to bigint $field = new XMLDBField('wikicourse'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null); if (!field_exists($table, $field)) { $result = $result && add_field($table, $field); } else { $result = $result && change_field_precision($table, $field); } // Renaming key 'course' $key = new XMLDBIndex('course'); $key->setAttributes(XMLDB_INDEX_UNIQUE, array('course')); $result = $result && drop_index($table, $key); $key = new XMLDBIndex('wiki_cou_ix'); $key->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('course')); $result = $result && add_index($table, $key); /* // Changing some field in wiki_pages $table = new XMLDBTable('wiki_pages'); $field = new XMLDBField('evaluation'); $field->setAttributes(XMLDB_TYPE_TEXT,'medium' , null, XMLDB_NOTNULL, null, null, null, "", 'ownerid'); $result = $result && change_field_default($table, $field); $result = $result && change_field_notnull($table, $field); */ } // Add groupid and ownerid fields to the wiki_locks table if ($result && $oldversion < 2007121701) { $table = new XMLDBTable('wiki_locks'); $field = new XMLDBField('groupid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, 0, null); $result = add_field($table, $field); $field = new XMLDBField('ownerid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, 0, null); $result = $result && add_field($table, $field); } if ($result && $oldversion < 2008013105) { // To create a new tables: wiki_evaluation and wiki_evaluation_edition /////////// WIKI_EVALUATION //////////////////////////////// $table = new XMLDBTable('wiki'); $field = new XMLDBField('evaluation'); $field->setAttributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'studentdiscussion'); $result = $result && add_field($table, $field); $field = new XMLDBField('notetype'); $field->setAttributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'evaluation'); $result = $result && add_field($table, $field); /// Define field id to be added to wiki_evaluation $table = new XMLDBTable('wiki_evaluation'); if (!table_exists($table)) { // Adding wiki_evaluation table $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null); $table->addFieldInfo('pagename', XMLDB_TYPE_CHAR, '160', null, XMLDB_NOTNULL, null, null, null, null, 'id'); $table->addFieldInfo('wikiid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'pagename'); $table->addFieldInfo('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'wikiid'); $table->addFieldInfo('ownerid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupid'); $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'ownerid'); $table->addFieldInfo('wikigrade', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'userid'); $table->addFieldInfo('wikigrade_initial', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'wikigrade'); $table->addFieldInfo('comment', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'wikigrade_initial'); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('key_uinique', XMLDB_KEY_UNIQUE, array('pagename', 'wikiid', 'groupid', 'ownerid', 'userid')); $table->addKeyInfo('foreign_key_user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $result = $result && create_table($table); } /////////// WIKI_EVALUATION_EDITION //////////////////////////////// /// Define field id to be added to wiki_evaluation_edition $table = new XMLDBTable('wiki_evaluation_edition'); if (!table_exists($table)) { // Adding wiki_evaluation table $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null, null); $table->addFieldInfo('wiki_pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id'); $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'wiki_pageid'); $table->addFieldInfo('valoration', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null, 'userid'); $table->addFieldInfo('feedback', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'valoration'); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('key_unique_edition', XMLDB_KEY_UNIQUE, array('wiki_pageid', 'userid')); $table->addKeyInfo('foreign_key_user', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); $table->addKeyInfo('foreign_key_wikipage', XMLDB_KEY_FOREIGN, array('wiki_pageid'), 'wiki_pages', array('id')); /// Create the table wiki_evaluation_edition $result = $result && create_table($table); } } if ($result && $oldversion < 2008080401) { $table = new XMLDBTable('wiki'); $field = new XMLDBField('evaluation'); $field->setAttributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'studentdiscussion'); $result = $result && change_field_type($table, $field); $field = new XMLDBField('notetype'); $field->setAttributes(XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'evaluation'); $result = $result && change_field_type($table, $field); } return $result; }
function wiki_restore_files($olddfwikiid, $restore, $order, $e_wiki) { global $CFG; $status = true; $moddata_path = ""; $temp_path = ""; //get wiki $cm->id we're restoring //get the latest wiki $cm->id to restore $modul = get_record("modules", "name", 'wiki'); $newdfwikiid = get_record_sql('SELECT MAX(id) AS maxim FROM ' . $CFG->prefix . 'course_modules WHERE module=' . $modul->id . ' AND course=' . $restore->course_id); //necessary data is available to proceed $num = wiki_count_position($newdfwikiid->maxim, $restore->course_id, $order); if (isset($e_wiki['oldid'])) { $oldcourseid = $e_wiki['oldid']; } else { $oldcourseid = ''; } if (isset($e_wiki['oldentryid'])) { $oldentryid = $e_wiki['oldentryid']; } else { $oldentryid = ''; } check_dir_exists("{$CFG->dataroot}/{$restore->course_id}", true); check_dir_exists("{$CFG->dataroot}/{$restore->course_id}/{$CFG->moddata}", true); check_dir_exists("{$CFG->dataroot}/{$restore->course_id}/{$CFG->moddata}/wiki{$num}", true); $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata . "/wiki" . $num; if ($oldcourseid == '' && $oldentryid == '') { check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/backup", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}/moddata", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}/moddata/wiki", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}/moddata/wiki/wiki{$olddfwikiid}", true); $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/wiki/wiki" . $olddfwikiid; } else { check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/backup", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}/moddata", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}/moddata/wiki", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}/moddata/wiki/{$oldcourseid}", true); check_dir_exists("{$CFG->dataroot}/temp/backup/{$restore->backup_unique_code}/moddata/wiki/{$oldcourseid}/{$oldentryid}", true); $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/wiki/{$oldcourseid}/{$oldentryid}"; } //get the attached files $list = null; $list = list_directories_and_files($temp_path); if ($list != null) { foreach ($list as $file) { //if isn't a directory if (!is_dir("{$temp_path}/{$file}")) { $to_file = "{$moddata_path}/{$file}"; $from_file = "{$temp_path}/{$file}"; copy($from_file, $to_file); } else { //one by one $temp_path = "{$temp_path}/{$file}"; $files2 = list_directories_and_files($temp_path); if ($files2 != null) { foreach ($files2 as $file2) { $to_file = "{$moddata_path}/{$file2}"; $from_file = "{$temp_path}/{$file2}"; copy($from_file, $to_file); } } } } } }
function get_ewikis_bis($zip, $ewiki) { global $CFG; $listewikis = null; //unpack the .zip check_dir_exists("{$CFG->dataroot}/temp", true); check_dir_exists("{$CFG->dataroot}/temp/ewikis", true); $destination = "{$CFG->dataroot}/temp/ewikis"; unzip_file($zip, $destination, false); //take the .xml $filelist = list_directories_and_files("{$CFG->dataroot}/temp/ewikis"); if ($filelist == null) { return $listewikis; } foreach ($filelist as $file) { $extension = explode(".", $file); $num = count($extension) - 1; if ($extension[$num] == "xml") { $goodfile = $file; } } $newfile = "{$CFG->dataroot}/temp/ewikis/{$goodfile}"; $info = restore_read_xml_bis_bis($newfile, $ewiki); return $info; }
function wiki_search_rest() { global $CFG; $rest = "1/exportedfiles/a0"; $listmoodledata = list_directories_and_files("{$CFG->dataroot}"); foreach ($listmoodledata as $filemoodledata) { if (check_dir_exists("{$CFG->dataroot}/{$filemoodledata}/exportedfiles", false) && $filemoodledata != temp) { $exporteddfwikis = list_directories_and_files("{$CFG->dataroot}/{$filemoodledata}/exportedfiles"); if ($exporteddfwikis != null) { foreach ($exporteddfwikis as $exporteddfwiki) { $xmllist = list_directories_and_files("{$CFG->dataroot}/{$filemoodledata}/exportedfiles/{$exporteddfwiki}"); if ($xmllist != null) { foreach ($xmllist as $filexml) { $rest = "{$filemoodledata}/exportedfiles/{$exporteddfwiki}"; } } } } } } return $rest; }
/** * Private function. * * This function moves file or directori $from to $to * * @TODO: Move this function * * @param string $from. File path to be moved * @param string $to. Destination path. * * @return boolean. true in success or false in error */ function wiki_move_file($from, $to) { $result = true; if (is_dir($from)) { $files = list_directories_and_files($from); foreach ($files as $file) { $from_file = $from . '/' . $file; if (is_dir($from_file)) { $to_file = $to; } else { $to_file = $to . '/' . $file; } $result = $result && wiki_move_file($from_file, $to_file); } rmdir($from); } else { $result = copy($from, $to); unlink($from); } return $result; }
function webwork_codecheck($data, $wwquestionid, $questioncopy) { //codechecklevel $codechecklevel = $data['codecheck']; //here we construct a temp question object $question = new stdClass(); $question->code = base64_encode(stripslashes($data['code'])); $question->seed = $data['seed']; $question->trials = $data['trials']; //handle the new question from old functionality if ($questioncopy) { webwork_make_tmp_dir(); $path = webwork_get_wwquestion_path_full($wwquestionid); $filelist = list_directories_and_files($path); //copy everthing but derivations folder into tmp folder foreach ($filelist as $file) { if ($file != 'derivations') { webwork_copy_file("{$path}/{$file}", webwork_get_tmp_path_full() . '/' . $file); } } } //should we look in tmp or in wwquestion dir to find stuff if (!isset($wwquestionid)) { $path = webwork_get_tmp_path_full(); $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_tmp_path() . '/'; } else { $path = webwork_get_wwquestion_path_full($this->question->webworkid); $urlpath = webwork_get_filehandler_path() . '/' . webwork_get_wwquestion_path($this->question->webworkid) . '/'; } $filelist = list_directories_and_files($path); $filearray = array(); //files that need to be pushed foreach ($filelist as $file) { if (!is_dir($path . '/' . $file)) { $encode = base64_encode($urlpath . '/' . $file); array_push($filearray, $encode); } } $question->files = $filearray; //one call to the server will return response for this code and keep it static in the function $results = webwork_get_derivations($question); //filter errors and warnings $errorresults = array(); $noerrorresults = array(); $warningresults = array(); $goodresults = array(); foreach ($results as $record) { if (isset($record['errors']) && $record['errors'] != '' && $record['errors'] != null) { array_push($errorresults, $record); } else { array_push($noerrorresults, $record); } } foreach ($noerrorresults as $record) { if (isset($record['warnings']) && $record['warnings'] != '' && $record['warnings'] != null) { array_push($warningresults, $record); } else { array_push($goodresults, $record); } } switch ($codechecklevel) { //No code check case 0: webwork_qtype::_derivations($results); return true; break; //reject seeds with errors //reject seeds with errors case 1: if (count($noerrorresults) > 0) { webwork_qtype::_derivations($noerrorresults); return true; } break; //reject if errors //reject if errors case 2: if (count($noerrorresults) == count($results)) { webwork_qtype::_derivations($results); return true; } break; //reject seeds with errors or warnings //reject seeds with errors or warnings case 3: if (count($goodresults) > 0) { webwork_qtype::_derivations($goodresults); return true; } break; //reject if errors or warnings //reject if errors or warnings case 4: if (count($goodresults) == count($results)) { webwork_qtype::_derivations($results); return true; } break; } $errormsgs = array(); $warningmsgs = array(); //at this point we are going to be invalid //this correlates seeds with certain error messages for better output //ERRORS foreach ($errorresults as $record) { $found = 0; $candidate = $record['errors'] . "<br>"; $candidateseed = $record['seed']; for ($i = 0; $i < count($errormsgs); $i++) { if ($candidate == $errormsgs[$i]['errors']) { $found = 1; $errormsgs[$i]['seeds'][] = $candidateseed; } } if ($found == 0) { //new error message $msg = array(); $msg['errors'] = $candidate; $msg['seeds'] = array(); $msg['seeds'][] = $candidateseed; $errormsgs[] = $msg; } } //WARNINGS foreach ($warningresults as $record) { $found = 0; $candidate = $record['warnings'] . "<br>"; $candidateseed = $record['seed']; for ($i = 0; $i < count($warningmsgs); $i++) { if ($candidate == $warningmsgs[$i]['errors']) { $found = 1; $warningmsgs[$i]['seeds'][] = $candidateseed; } } if ($found == 0) { //new error message $msg = array(); $msg['warnings'] = $candidate; $msg['seeds'] = array(); $msg['seeds'][] = $candidateseed; $warningmsgs[] = $msg; } } $output = "Errors in PG Code on: " . count($errorresults) . " out of " . count($results) . " seeds tried:<br>"; //construct error statement $counter = 1; foreach ($errormsgs as $msg) { $output .= "{$counter}) "; $output .= "Seeds ("; foreach ($msg['seeds'] as $seed) { $output .= $seed . " "; } $output .= ") gave Errors:" . $msg['errors'] . "<br><br>"; $counter++; } $output .= "Warnings in PG Code on: " . count($warningresults) . " out of " . count($results) . " seeds tried:<br>"; $counter = 1; foreach ($warningmsgs as $msg) { $output .= "{$counter}) "; $output .= "Seeds ("; foreach ($msg['seeds'] as $seed) { $output .= $seed . " "; } $output .= ") gave Warnings:" . $msg['warnings'] . "<br><br>"; $counter++; } $returner = array(); $returner['code'] = $output; return $returner; }