function webquest_upgrade($oldversion) { /// This function does anything necessary to upgrade /// older versions to match current functionality $status = true; global $CFG; if ($oldversion < 2007081222) { require_once $CFG->dirroot . '/backup/lib.php'; //make the change into each course $courses = get_records("course"); foreach ($courses as $course) { $newdir = "{$course->id}/{$CFG->moddata}/webquest"; if (make_upload_directory($newdir)) { $olddir = "{$CFG->dataroot}/{$course->id}/{$CFG->moddata}/webquest/submissions"; //chec k if the old directory exists if (is_dir($olddir)) { $status = backup_copy_file($olddir, $CFG->dataroot . "/" . $newdir); } if ($status) { fulldelete($olddir); } } } } return $status; }
function lightboxgallery_restore_files($gallery, $restore) { global $CFG; $status = true; if (is_numeric($gallery)) { $gallery = get_record('lightboxgallery', 'id', $gallery); } $newpath = $CFG->dataroot . '/' . $gallery->course . '/' . $gallery->folder; $status = check_dir_exists($newpath, true, true); if ($status) { $tmppath = $CFG->dataroot . '/temp/backup/' . $restore->backup_unique_code . '/' . $gallery->folder; if (is_dir($tmppath)) { $status = backup_copy_file($tmppath, $newpath); } } return $status; }
function backup_lightboxgallery_files_instance($bf, $preferences, $gallery) { global $CFG; $status = true; if (is_numeric($gallery)) { $gallery = get_record('lightboxgallery', 'id', $gallery); } $tmppath = $CFG->dataroot . '/temp/backup/' . $preferences->backup_unique_code . '/' . $gallery->folder; $status = check_dir_exists($tmppath, true, true); if ($status) { $oldpath = $CFG->dataroot . '/' . $preferences->backup_course . '/' . $gallery->folder; if (is_dir($oldpath)) { $status = backup_copy_file($oldpath, $tmppath); } } return $status; }
function backup_poodllpairwork_files_instance($bf, $preferences, $instanceid) { global $CFG; $status = true; //First we check to moddata exists and create it as necessary //in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/poodllpairwork/", true); //Now copy the poodllpairwork dir if ($status) { //Only if it exists !! Thanks to Daniel Miksik. if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/poodllpairwork/" . $instanceid)) { $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/poodllpairwork/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/poodllpairwork/" . $instanceid); } } return $status; }
function backup_imagegallery_files($bf, $preferences, $image) { global $CFG; $status = true; //First we check to moddata exists and create it as necessary //in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); //Now we check that moddata/glossary dir exists and create it as necessary //in temp/backup/$backup_code/moddata dir $gal_dir_to = $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $CFG->moddata . "/imagegallery"; //Let's create it as necessary $status = check_dir_exists($gal_dir_to, true); // Check imagegalleryid directory. $gal_dir_to .= '/' . $image->galleryid; $status = check_dir_exists($gal_dir_to, true); // structure for imagegallery data directory starting from moddata: // moddata // | // |- imagegallery // | // |- <imagegalleryid> // | // |- non-categorized images // |- <categoryid> // | // |- categorized images. if (!empty($image->categoryid)) { // Copy categorized image under it's directory ( create directory if necessary ). $gal_dir_to .= '/' . $image->categoryid; $status = check_dir_exists($gal_dir_to, true); $filesource = $CFG->dataroot . $image->path; $filedestin = $gal_dir_to . '/' . $image->name; if (is_dir($gal_dir_to) && file_exists($filesource)) { $status = backup_copy_file($filesource, $filedestin); } // Copy thumbnail $filesource = $CFG->dataroot . str_replace($image->name, "thumb_" . $image->name, $image->path); $filedestin = $gal_dir_to . '/thumb_' . $image->name; if (is_dir($gal_dir_to) && file_exists($filesource)) { $status = backup_copy_file($filesource, $filedestin); } } else { // Copy uncategorized image under imagegallery id. $filesource = $CFG->dataroot . $image->path; $filedestin = $gal_dir_to . '/' . $image->name; if (is_dir($gal_dir_to) && file_exists($filesource)) { $status = backup_copy_file($filesource, $filedestin); } // Copy thumbnail $filesource = $CFG->dataroot . str_replace($image->name, "thumb_" . $image->name, $image->path); $filedestin = $gal_dir_to . '/thumb_' . $image->name; if (is_dir($gal_dir_to) && file_exists($filesource)) { $status = backup_copy_file($filesource, $filedestin); } } return $status; }
function backup_exercise_student_files($bf, $preferences, $exerciseid) { global $CFG; $status = true; //First we check to moddata exists and create it as necessary //in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); if ($status) { //Now copy the submission dirs if ($submissions = get_records_select("exercise_submissions", "exerciseid = {$exerciseid}\n AND isexercise = 0")) { foreach ($submissions as $submission) { //Only if it exists !! Thanks to Daniel Miksik. if (is_dir("{$CFG->dataroot}/{$preferences->backup_course}/{$CFG->moddata}/exercise/{$submission->id}")) { $status = backup_copy_file("{$CFG->dataroot}/{$preferences->backup_course}/{$CFG->moddata}/exercise/{$submission->id}", "{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/moddata/exercise/{$submission->id}"); } } } } return $status; }
function backup_copy_dir($from_file, $to_file) { global $CFG; $status = true; // Initialize this, next code will change its value if needed if (!is_dir($to_file)) { //echo "<br />Creating ".$to_file; //Debug umask(00); $status = mkdir($to_file, $CFG->directorypermissions); } $dir = opendir($from_file); while (false !== ($file = readdir($dir))) { if ($file == "." || $file == "..") { continue; } $status = backup_copy_file("{$from_file}/{$file}", "{$to_file}/{$file}"); } closedir($dir); return $status; }
function mail_restore_files($oldmailid, $newmailid, $oldmessageid, $newmessageid, $restore) { global $CFG; $status = true; $todo = false; $moddata_path = ""; $mail_path = ""; $temp_path = ""; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id; $status = check_dir_exists($dest_dir, true); //Now, locate course's moddata directory $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; //Check it exists and create it $status = check_dir_exists($moddata_path, true); //Now, locate assignment directory if ($status) { $mail_path = $moddata_path . "/mail"; //Check it exists and create it $status = check_dir_exists($mail_path, true); } //Now locate the temp dir we are gong to restore if ($status) { $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/mail/" . $oldmailid . "/" . $oldmessageid; //Check it exists if (is_dir($temp_path)) { $todo = true; } } //If todo, we create the neccesary dirs in course moddata/mail if ($status and $todo) { //First this assignment id $this_mail_path = $mail_path . "/" . $newmailid; $status = check_dir_exists($this_mail_path, true); //Now this message id $message_mail_path = $this_mail_path . "/" . $newmessageid; //And now, copy temp_path to message_mail_path $status = backup_copy_file($temp_path, $message_mail_path); } return $status; }
function resource_restore_files($oldid, $newid, $resource, $restore) { global $CFG; $status = true; $status = check_dir_exists($CFG->dataroot . "/" . $restore->course_id, true); // we need to do anything referenced by $resource->reference and anything in moddata/resource/instance // do referenced files/dirs first. $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . '/course_files/' . $resource->reference; if (file_exists($temp_path)) { // ok, it was backed up, restore it. $new_path = $CFG->dataroot . '/' . $restore->course_id . '/' . $resource->reference; // if this is somewhere deeply nested we need to do all the structure stuff first..... $bits = explode('/', $resource->reference); $newbit = ''; for ($i = 0; $i < count($bits) - 1; $i++) { $newbit .= $bits[$i] . '/'; $status = $status && check_dir_exists($CFG->dataroot . '/' . $restore->course_id . '/' . $newbit, true); } $status = $status && backup_copy_file($temp_path, $new_path); } // and now for moddata. $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/resource/" . $oldid; if (file_exists($temp_path)) { // there's something to back up, restore it. $new_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; $status = $status && check_dir_exists($new_path, true); $new_path .= '/resource'; $status = $status && check_dir_exists($new_path, true); $new_path .= '/' . $newid; $status = $status && backup_copy_file($temp_path, $new_path); } return $status; }
/** * コースファイルのコピー * * @param object $restore * @return */ function project_restore_course_files(&$restore) { global $CFG; $status = true; $counter = 0; // 対象のコース情報の取得 if (!($course = get_record("course", "id", $restore->course_id))) { error("Course ID was incorrect (can't find it)"); } // 対象のセクション情報の取得 if (!($section = get_course_section($restore->section, $restore->course_id))) { error("Section data was incorrect (can't find it)"); } // 現在のセクションのディレクトリ名を取得 if (!($sectiontitle = project_format_get_title($course, $section->id))) { error("Section directory was incorrect"); } //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id . '/' . $restore->newdirectoryname; $status = check_dir_exists($dest_dir, true); //Now, we iterate over "course_files" records to check if that file/dir must be //copied to the "dest_dir" dir. $rootdir = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/course_files/" . $restore->olddirectoryname; // ディレクトリをまるごとコピーする if (is_dir($rootdir)) { $status = backup_copy_file($rootdir, $dest_dir); } return $status; }
function flv_backup_files($bf, $preferences, $flv) { global $CFG; $status = true; if (!file_exists($CFG->dataroot . '/' . $preferences->backup_course . '/' . $flv->flvfile)) { return true; // doesn't exist but we don't want to halt the entire process so still return true. } $status = $status && check_and_create_course_files_dir($preferences->backup_unique_code); // if this is somewhere deeply nested we need to do all the structure stuff first..... $bits = explode('/', $flv->flvfile); $newbit = ''; for ($i = 0; $i < count($bits) - 1; $i++) { $newbit .= $bits[$i] . '/'; $status = $status && check_dir_exists($CFG->dataroot . '/temp/backup/' . $preferences->backup_unique_code . '/course_files/' . $newbit, true); } if ($flv->flvfile === '') { $status = $status && backup_copy_course_files($preferences); // copy while ignoring backupdata and moddata!!! } else { if (strpos($flv->flvfile, 'backupdata') === 0 or strpos($flv->flvfile, $CFG->moddata) === 0) { // no copying - these directories must not be shared anyway! } else { $status = $status && backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $flv->flvfile, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/course_files/" . $flv->flvfile); } } // now, just in case we check moddata ( going forwards, flvs should use this ) $status = $status && check_and_create_moddata_dir($preferences->backup_unique_code); $status = $status && check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $CFG->moddata . "/flv/", true); if ($status) { //Only if it exists !! Thanks to Daniel Miksik. $instanceid = $flv->id; if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/flv/" . $instanceid)) { $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/flv/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/flv/" . $instanceid); } } return $status; }
function taoresource_backup_files($bf, $preferences, $taoresource_entry) { global $CFG; require_once "{$CFG->dirroot}/mod/taoresource/lib.php"; $status = true; if (empty($taoresource_entry->file)) { return true; } $filename = $CFG->dataroot . TAORESOURCE_RESOURCEPATH . $taoresource_entry->file; if (!file_exists($filename)) { return true; // doesn't exist but we don't want to halt the entire process so still return true. } $status = $status && check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . TAORESOURCE_RESOURCEPATH, true); // if this is somewhere deeply nested we need to do all the structure stuff first..... $status = $status && backup_copy_file($filename, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . TAORESOURCE_RESOURCEPATH . $taoresource_entry->file); return $status; }
function backup_wiki_files($bf, $preferences) { global $CFG; $status = true; //First we check to moddata exists and create it as necessary //in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); //Now copy the forum dir if ($status) { //Only if it exists !! Thanks to Daniel Miksik. if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki")) { $handle = opendir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki"); while (false !== ($item = readdir($handle))) { if ($item != '.' && $item != '..' && is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki/" . $item) && array_key_exists($item, $preferences->mods['wiki']->instances) && !empty($preferences->mods['wiki']->instances[$item]->backup)) { $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/wiki/" . $item, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/wiki/", $item); } } } } return $status; }
function backup_turnitintool_files_instance($bf, $preferences, $instanceid) { global $CFG; $status = true; $status = check_and_create_moddata_dir($preferences->backup_unique_code); $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/turnitintool/", true); if ($status) { if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/turnitintool/" . $instanceid)) { $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/turnitintool/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/turnitintool/" . $instanceid); } } return $status; }
function copy_zip_to_course_dir($preferences) { global $CFG, $DB; $status = true; //Define zip location (from) $from_zip_file = $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $preferences->backup_name; //Initialise $to_zip_file $to_zip_file = ""; //If $preferences->backup_destination isn't empty, then copy to custom directory if (!empty($preferences->backup_destination)) { $to_zip_file = $preferences->backup_destination . "/" . $preferences->backup_name; //Copy zip file if ($status) { $status = backup_copy_file($from_zip_file, $to_zip_file); } } else { //Define zip destination (course dir) $context = get_context_instance(CONTEXT_COURSE, $preferences->backup_course); $fs = get_file_storage(); $file_record = array('contextid' => $context->id, 'filearea' => 'course_backup', 'itemid' => 0, 'filepath' => '/', 'filename' => $preferences->backup_name, 'timecreated' => time(), 'timemodified' => time()); $fs->create_file_from_pathname($file_record, $from_zip_file); } return $status; }
//Backup podcast files because we've selected to backup user info //and files are user info's level function backup_podcast_files_instance($bf, $preferences, $instanceid) { global $CFG; $status = true; // MEDIA // in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/", true); if ($status) { // Copie des fichiers multim�dia if (is_dir($CFG->dirroot . "/mod/podcast/media/" . $preferences->backup_course . "/" . $instanceid)) { $status = backup_copy_file($CFG->dirroot . "/mod/podcast/media/" . $preferences->backup_course . "/" . $instanceid, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/media/" . $instanceid); } } // XML // in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); $status = check_dir_exists($CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/", true); if ($status) { // Copie des fichiers rss if (is_dir($CFG->dirroot . "/mod/podcast/media/" . $preferences->backup_course . "/" . $instanceid)) { $status = backup_copy_file($CFG->dirroot . "/mod/podcast/publication/" . $preferences->backup_course, $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/podcast/publication/"); } }
} /// Ensure it's empty if (!delete_dir_contents($resourcedir)) { print_error('errorcleaningdirectory', 'error', '', $resourcedir); } /// Copy files $origin = $CFG->dataroot . '/' . $courseid . '/' . $file; if (!is_file($origin)) { print_error('filenotfound', 'error', '', $file); } $mimetype = mimeinfo("type", $file); if ($mimetype != "application/zip") { print_error('invalidfiletype', 'error', '', $file); } $resourcefile = $resourcedir . '/' . basename($origin); if (!backup_copy_file($origin, $resourcefile)) { print_error('errorcopyingfiles', 'error'); } /// Unzip files if (!unzip_file($resourcefile, '', false)) { print_error('errorunzippingfiles', 'error'); } /// Check for imsmanifest if (!file_exists($resourcedir . '/imsmanifest.xml')) { print_error('filenotfound', 'error', '', 'imsmanifest.xml'); } /// Load imsmanifest to memory (instead of using a full parser, /// we are going to use xmlize intensively (because files aren't too big) if (!($imsmanifest = ims_file2var($resourcedir . '/imsmanifest.xml'))) { print_error('errorreadingfile', 'error', '', 'imsmanifest.xml'); }
function wiki_restore_files($oldwikiid, $newwikiid, $oldentryid, $newentryid, $restore) { global $CFG; $status = true; $todo = false; $moddata_path = ""; $forum_path = ""; $temp_path = ""; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id; $status = check_dir_exists($dest_dir, true); //First, locate course's moddata directory $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; //Check it exists and create it $status = check_dir_exists($moddata_path, true); //Now, locate wiki directory if ($status) { $wiki_path = $moddata_path . "/wiki"; //Check it exists and create it $status = check_dir_exists($wiki_path, true); } //Now locate the temp dir we are restoring from if ($status) { $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/wiki/" . $oldwikiid . "/" . $oldentryid; //Check it exists if (is_dir($temp_path)) { $todo = true; } } //If todo, we create the neccesary dirs in course moddata/wiki if ($status and $todo) { //First this wiki id $this_wiki_path = $wiki_path . "/" . $newwikiid; $status = check_dir_exists($this_wiki_path, true); //Now this entry id $entry_wiki_path = $this_wiki_path . "/" . $newentryid; //And now, copy temp_path to entry_wiki_path $status = backup_copy_file($temp_path, $entry_wiki_path); } return $status; }
function poodllpairwork_restore_files($oldpairworkid, $newpairworkid, $restore) { global $CFG; $status = true; $todo = false; $moddata_path = ""; $poodllpairwork_path = ""; $temp_path = ""; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id; $status = check_dir_exists($dest_dir, true); //First, locate course's moddata directory $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; //Check it exists and create it $status = check_dir_exists($moddata_path, true); //Now, locate forum directory if ($status) { $poodllpairwork_path = $moddata_path . "/poodllpairwork"; //Check if exists and create it $status = check_dir_exists($poodllpairwork_path, true); } //Now locate the temp dir we are restoring from if ($status) { $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/poodllpairwork/" . $oldpairworkid; //Check it exists if (is_dir($temp_path)) { $todo = true; } } //If todo, we create the neccesary dirs in course moddata/forum if ($status and $todo) { //First this poodllpairwork id $this_poodllpairwork_path = $poodllpairwork_path . "/" . $newpairworkid; $status = check_dir_exists($this_poodllpairwork_path, true); //And now, copy temp_path to poodllpairwork_path $status = backup_copy_file($temp_path, $this_poodllpairwork_path); } return $status; }
function copy_zip_to_course_dir($preferences) { global $CFG; $status = true; //Define zip location (from) $from_zip_file = $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $preferences->backup_name; //Initialise $to_zip_file $to_zip_file = ""; //If $preferences->backup_destination isn't empty, then copy to custom directory if (!empty($preferences->backup_destination)) { $to_zip_file = $preferences->backup_destination . "/" . $preferences->backup_name; } else { //Define zip destination (course dir) $to_zip_file = $CFG->dataroot . "/" . $preferences->backup_course; //echo "<p>From: ".$from_zip_file."<br />"; //Debug //echo "<p>Checking: ".$to_zip_file."<br />"; //Debug //Checks course dir exists $status = check_dir_exists($to_zip_file, true); //Define zip destination (backup dir) $to_zip_file = $to_zip_file . "/backupdata"; //echo "<p>Checking: ".$to_zip_file."<br />"; //Debug //Checks backup dir exists $status = check_dir_exists($to_zip_file, true); //Define zip destination (zip file) $to_zip_file = $to_zip_file . "/" . $preferences->backup_name; } //echo "<p>To: ".$to_zip_file."<br />"; //Debug //Copy zip file if ($status) { $status = backup_copy_file($from_zip_file, $to_zip_file); } return $status; }
function backup_scorm_files($bf, $preferences) { global $CFG; $status = true; //First we check to moddata exists and create it as necessary //in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); //Now copy the scorm dir if ($status) { if (is_dir($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm')) { $handle = opendir($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm'); while (false !== ($item = readdir($handle))) { if ($item != '.' && $item != '..' && is_dir($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm/' . $item) && array_key_exists($item, $preferences->mods['scorm']->instances) && !empty($preferences->mods['scorm']->instances[$item]->backup)) { $status = backup_copy_file($CFG->dataroot . '/' . $preferences->backup_course . '/' . $CFG->moddata . '/scorm/' . $item, $CFG->dataroot . '/temp/backup/' . $preferences->backup_unique_code . '/moddata/scorm/', $item); } } } } return $status; }
function taoresource_restore_files($oldid, $newid, $taoresource_entry, $restore) { global $CFG; // need a file to do anything ... if (empty($taoresource_entry->file)) { return true; } $status = true; // course directory exists $status = check_dir_exists($CFG->dataroot . "/" . $restore->course_id, true); //TAO Resource shared repository exists $status = $status && check_dir_exists($CFG->dataroot . TAORESOURCE_RESOURCEPATH, true); // we need to do anything referenced by $resource->reference and anything in moddata/resource/instance // do referenced files/dirs first. $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . TAORESOURCE_RESOURCEPATH . $taoresource_entry->file; if (file_exists($temp_path)) { // ok, it was backed up, restore it. $new_path = $CFG->dataroot . TAORESOURCE_RESOURCEPATH . $taoresource_entry->file; $status = $status && backup_copy_file($temp_path, $new_path); } return $status; }
/** * @param string $errorstr passed by reference, if silent is true, * errorstr will be populated and this function will return false rather than calling error() or notify() * @param boolean $noredirect (optional) if this is passed, this function will not print continue, or * redirect to the next step in the restore process, instead will return $backup_unique_code */ function restore_precheck($id, $file, &$errorstr, $noredirect = false) { global $CFG, $SESSION; //Prepend dataroot to variable to have the absolute path $file = $CFG->dataroot . "/" . $file; if (!defined('RESTORE_SILENTLY')) { //Start the main table echo "<table cellpadding=\"5\">"; echo "<tr><td>"; //Start the mail ul echo "<ul>"; } //Check the file exists if (!is_file($file)) { if (!defined('RESTORE_SILENTLY')) { error("File not exists ({$file})"); } else { $errorstr = "File not exists ({$file})"; return false; } } //Check the file name ends with .zip if (!substr($file, -4) == ".zip") { if (!defined('RESTORE_SILENTLY')) { error("File has an incorrect extension"); } else { $errorstr = 'File has an incorrect extension'; return false; } } //Now calculate the unique_code for this restore $backup_unique_code = time(); //Now check and create the backup dir (if it doesn't exist) if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("creatingtemporarystructures") . '</li>'; } $status = check_and_create_backup_dir($backup_unique_code); //Empty dir if ($status) { $status = clear_backup_dir($backup_unique_code); } //Now delete old data and directories under dataroot/temp/backup if ($status) { if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("deletingolddata") . '</li>'; } $status = backup_delete_old_data(); } //Now copy he zip file to dataroot/temp/backup/backup_unique_code if ($status) { if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("copyingzipfile") . '</li>'; } if (!($status = backup_copy_file($file, $CFG->dataroot . "/temp/backup/" . $backup_unique_code . "/" . basename($file)))) { if (!defined('RESTORE_SILENTLY')) { notify("Error copying backup file. Invalid name or bad perms."); } else { $errorstr = "Error copying backup file. Invalid name or bad perms"; return false; } } } //Now unzip the file if ($status) { if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("unzippingbackup") . '</li>'; } if (!($status = restore_unzip($CFG->dataroot . "/temp/backup/" . $backup_unique_code . "/" . basename($file)))) { if (!defined('RESTORE_SILENTLY')) { notify("Error unzipping backup file. Invalid zip file."); } else { $errorstr = "Error unzipping backup file. Invalid zip file."; return false; } } } //Check for Blackboard backups and convert if ($status) { require_once "{$CFG->dirroot}/backup/bb/restore_bb.php"; if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("checkingforbbexport") . '</li>'; } $status = blackboard_convert($CFG->dataroot . "/temp/backup/" . $backup_unique_code); } //Now check for the moodle.xml file if ($status) { $xml_file = $CFG->dataroot . "/temp/backup/" . $backup_unique_code . "/moodle.xml"; if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("checkingbackup") . '</li>'; } if (!($status = restore_check_moodle_file($xml_file))) { if (!is_file($xml_file)) { $errorstr = 'Error checking backup file. moodle.xml not found at root level of zip file.'; } else { $errorstr = 'Error checking backup file. moodle.xml is incorrect or corrupted.'; } if (!defined('RESTORE_SILENTLY')) { notify($errorstr); } else { return false; } } } $info = ""; $course_header = ""; //Now read the info tag (all) if ($status) { if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("readinginfofrombackup") . '</li>'; } //Reading info from file $info = restore_read_xml_info($xml_file); //Reading course_header from file $course_header = restore_read_xml_course_header($xml_file); if (!is_object($course_header)) { // ensure we fail if there is no course header $course_header = false; } } if (!defined('RESTORE_SILENTLY')) { //End the main ul echo "</ul>\n"; //End the main table echo "</td></tr>"; echo "</table>"; } //We compare Moodle's versions if ($CFG->version < $info->backup_moodle_version && $status) { $message = new object(); $message->serverversion = $CFG->version; $message->serverrelease = $CFG->release; $message->backupversion = $info->backup_moodle_version; $message->backuprelease = $info->backup_moodle_release; print_simple_box(get_string('noticenewerbackup', '', $message), "center", "70%", '', "20", "noticebox"); } //Now we print in other table, the backup and the course it contains info if ($info and $course_header and $status) { //First, the course info if (!defined('RESTORE_SILENTLY')) { $status = restore_print_course_header($course_header); } //Now, the backup info if ($status) { if (!defined('RESTORE_SILENTLY')) { $status = restore_print_info($info); } } } //Save course header and info into php session if ($status) { $SESSION->info = $info; $SESSION->course_header = $course_header; } //Finally, a little form to continue //with some hidden fields if ($status) { if (!defined('RESTORE_SILENTLY')) { echo "<br /><div style='text-align:center'>"; $hidden["backup_unique_code"] = $backup_unique_code; $hidden["launch"] = "form"; $hidden["file"] = $file; $hidden["id"] = $id; print_single_button("restore.php", $hidden, get_string("continue"), "post"); echo "</div>"; } else { if (empty($noredirect)) { // in 2.0 we must not print "Continue" redirect link here, because ppl click on it and the execution gets interrupted on next page!!! // imo RESTORE_SILENTLY is an ugly hack :-P $sillystr = get_string('donotclickcontinue'); redirect($CFG->wwwroot . '/backup/restore.php?backup_unique_code=' . $backup_unique_code . '&launch=form&file=' . $file . '&id=' . $id, $sillystr, 0); } else { return $backup_unique_code; } } } if (!$status) { if (!defined('RESTORE_SILENTLY')) { error("An error has ocurred"); } else { $errorstr = "An error has occured"; // helpful! :P return false; } } return true; }
function backup_glossary_files($bf, $preferences, $glossary, $entry) { global $CFG; $status = true; //First we check to moddata exists and create it as necessary //in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); //Now we check that moddata/glossary dir exists and create it as necessary //in temp/backup/$backup_code/moddata dir $glo_dir_to = $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/" . $CFG->moddata . "/glossary"; //Let's create it as necessary $status = check_dir_exists($glo_dir_to, true); //Now we check that the moddata/glossary/$glossary dir exists and create it as necessary //in temp/backup/$backup_code/moddata/glossary $status = check_dir_exists($glo_dir_to . "/" . $glossary, true); //Now copy the moddata/glossary/$glossary/$entry to //temp/backup/$backup_code/moddata/glossary/$glossary/$entry if ($status) { //Calculate moddata/glossary dir $glo_dir_from = $CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/glossary"; //Only if it exists !! if (is_dir($glo_dir_from . "/" . $glossary . "/" . $entry)) { $status = backup_copy_file($glo_dir_from . "/" . $glossary . "/" . $entry, $glo_dir_to . "/" . $glossary . "/" . $entry); } } return $status; }
function backup_blended_files($bf, $preferences) { global $CFG; $status = true; //First we check to moddata exists and create it as necessary //in temp/backup/$backup_code dir $status = check_and_create_moddata_dir($preferences->backup_unique_code); //Now copy the questournament dir if ($status) { if (is_dir($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/blended")) { $dir = "{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/moddata/blended"; check_dir_exists($dir, true); $status = backup_copy_file($CFG->dataroot . "/" . $preferences->backup_course . "/" . $CFG->moddata . "/blended", $CFG->dataroot . "/temp/backup/" . $preferences->backup_unique_code . "/moddata/blended"); } } return $status; }
/** * Copies a file into backup area. * @param string $source Full path of source file * @param string $target Target path relative to the backup folder (e.g. 'moddata/frog/myfile.txt') * @throws Exception if file copy fails */ public function copy_file($source, $target) { global $CFG; $basefolder = $CFG->dataroot . '/temp/backup/' . $this->uniquecode . '/'; $targetfolder = dirname($basefolder . $target); if (!@mkdir_recursive($targetfolder)) { throw new Exception("Failed to create folder for backup file ({$targetfolder})", EXN_LOCAL_BACKUPFOLDER); } if (!@backup_copy_file($source, $basefolder . $target)) { throw new Exception("Failed to copy file for backup ({$source})", EXN_LOCAL_BACKUPCOPY); } }
function exercise_restore_files($oldsubmiss, $newsubmiss, $restore) { global $CFG; $status = true; $todo = false; $moddata_path = ""; $exercise_path = ""; $temp_path = ""; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id; $status = check_dir_exists($dest_dir, true); //Now, locate course's moddata directory $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; //Check it exists and create it $status = check_dir_exists($moddata_path, true); //Now, locate exercise directory if ($status) { $exercise_path = $moddata_path . "/exercise"; //Check it exists and create it $status = check_dir_exists($exercise_path, true); } //Now locate the temp dir we are gong to restore if ($status) { $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/exercise/" . $oldsubmiss; //Check it exists if (is_dir($temp_path)) { $todo = true; } } //If todo, we create the neccesary dirs in course moddata/exercise if ($status and $todo) { //First this exercise id $this_exercise_path = $exercise_path . "/" . $newsubmiss; $status = check_dir_exists($this_exercise_path, true); //And now, copy temp_path to this_exercise_path $status = backup_copy_file($temp_path, $this_exercise_path); } return $status; }
function scorm_restore_files($package, $restore) { global $CFG; $status = true; $todo = false; $moddata_path = ""; $scorm_path = ""; $temp_path = ""; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id; $status = check_dir_exists($dest_dir, true); //First, locate course's moddata directory $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; //Check it exists and create it $status = check_dir_exists($moddata_path, true); //Now, locate scorm directory if ($status) { $scorm_path = $moddata_path . "/scorm"; //Check it exists and create it $status = check_dir_exists($scorm_path, true); } //Now locate the temp dir we are restoring from if ($status) { $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/scorm/" . $package->datadir; //Check it exists if (is_dir($temp_path)) { $todo = true; } } //If todo, we create the neccesary dirs in course moddata/scorm if ($status and $todo) { //Make scorm package directory path $this_scorm_path = $scorm_path . "/" . $package->id; $status = backup_copy_file($temp_path, $this_scorm_path); } return $status; }
function data_restore_files($old_data_id, $new_data_id, $old_field_id, $new_field_id, $old_record_id, $new_record_id, $recinfo, $restore) { global $CFG, $db; $status = true; $todo = false; $moddata_path = ""; $data_path = ""; $temp_path = ""; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id; $status = check_dir_exists($dest_dir, true); //Now, locate course's moddata directory $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; //Check it exists and create it $status = check_dir_exists($moddata_path, true); //Now, locate data directory if ($status) { $data_path = $moddata_path . "/data"; //Check it exists and create it $status = check_dir_exists($data_path, true); } //Now locate the temp dir we are gong to restore if ($status) { $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/data/" . $old_data_id . "/" . $old_field_id . "/" . $old_record_id; $todo = check_dir_exists($temp_path); } //If todo, we create the neccesary dirs in course moddata/data if ($status and $todo) { //First this data id $this_data_path = $data_path . "/" . $new_data_id; $status = check_dir_exists($this_data_path, true); //Now this user id $this_field_path = $this_data_path . "/" . $new_field_id; $status = check_dir_exists($this_field_path, true); $this_record_path = $this_field_path = $this_field_path . "/" . $new_record_id; $status = check_dir_exists($this_record_path, true); //And now, copy temp_path to user_data_path $status = @backup_copy_file($temp_path, $this_record_path); } return $status; }
function webquestscorm_restore_files($oldassid, $newassid, $olduserid, $newuserid, $restore) { global $CFG; $status = true; $todo = false; $moddata_path = ""; $webquestscorm_path = ""; $temp_path = ""; //First, we check to "course_id" exists and create is as necessary //in CFG->dataroot $dest_dir = $CFG->dataroot . "/" . $restore->course_id; $status = check_dir_exists($dest_dir, true); //Now, locate course's moddata directory $moddata_path = $CFG->dataroot . "/" . $restore->course_id . "/" . $CFG->moddata; //Check it exists and create it $status = check_dir_exists($moddata_path, true); //Now, locate webquestscorm directory if ($status) { $webquestscorm_path = $moddata_path . "/webquestscorm"; //Check it exists and create it $status = check_dir_exists($webquestscorm_path, true); } //Now locate the temp dir we are gong to restore if ($status) { $temp_path = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/moddata/webquestscorm/" . $oldassid . "/" . $olduserid; //Check it exists if (is_dir($temp_path)) { $todo = true; } } //If todo, we create the neccesary dirs in course moddata/webquestscorm if ($status and $todo) { //First this webquestscorm id $this_webquestscorm_path = $webquestscorm_path . "/" . $newassid; $status = check_dir_exists($this_webquestscorm_path, true); //Now this user id $user_webquestscorm_path = $this_webquestscorm_path . "/" . $newuserid; //And now, copy temp_path to user_webquestscorm_path $status = backup_copy_file($temp_path, $user_webquestscorm_path); } return $status; }