if ($automation) { return -1; } } if (empty($automation)) { echo $OUTPUT->box(get_string('vmoodlesnapshot2', 'local_vmoodle')); $params = array('view' => 'management', 'what' => 'snapshot', 'step' => 2, 'wwwroot' => $wwwroot); echo $OUTPUT->continue_button(new moodle_url('/local/vmoodle/view.php', $params)); echo $OUTPUT->footer(); die; } } // End of process. // copy moodle data and protect against copy recursion. // $CFG->filedebug = 1; filesystem_copy_tree($vdatapath, $absolute_datadir, $vdatabase, array("^{$templatefoldername}\$")); // Remove Vmoodle clone session, temp and cache dir. filesystem_clear_dir($relative_datadir . $separator . 'sessions', true); filesystem_clear_dir($relative_datadir . $separator . 'temp', true); filesystem_clear_dir($relative_datadir . $separator . 'cache', true); filesystem_clear_dir($relative_datadir . $separator . 'localcache', true); // Store original hostname for further database replacements. $FILE = fopen($absolute_sqldir . $separator . 'manifest.php', 'w'); fwrite($FILE, "<?php\n "); fwrite($FILE, "\$templatewwwroot = '" . $wwwroot . "';\n"); fwrite($FILE, "\$templatevdbprefix = '" . $CFG->prefix . "';\n "); fwrite($FILE, "?>"); fclose($FILE); if (empty($automation)) { // Every step was SUCCESS. $message_object->message = get_string('successfinishedcapture', 'local_vmoodle');
/** * Dump existing files of a template. * @uses $CFG * @param string $templatename The template's name. * @param string $destpath The destination path. */ function vmoodle_dump_files_from_template($templatename, $destpath) { global $CFG; // Copies files and protects against copy recursion. $templatefilespath = $CFG->dataroot . '/vmoodle/' . $templatename . '_vmoodledata'; $destpath = str_replace('\\\\', '\\', $destpath); if (!is_dir($destpath)) { mkdir($destpath); } filesystem_copy_tree($templatefilespath, $destpath, ''); }
/** * copies recursively a subtree from a location to another * @param string $source the source path from dataroot * @param string $dest the dest path from dataroot * @param string $pathbase the base path * @return void */ function filesystem_copy_tree($source, $dest, $pathbase = null) { global $CFG; if (is_null($pathbase)) { $pathbase = $CFG->dataroot . '/'; } elseif ($pathbase === '') { $pathbase = ''; } else { $pathbase = $pathbase . '/'; } if (@$CFG->filedebug) { mtrace("copying tree <i>{$pathbase}{$source}</i> to <i>{$pathbase}{$dest}</i><br/>"); } if (file_exists($dest) && !filesystem_is_dir($dest, $pathbase)) { return; } if (!filesystem_is_dir($dest, $pathbase)) { filesystem_create_dir($dest, FS_RECURSIVE, $pathbase); } $files = array(); $files = filesystem_scan_dir($source, FS_SHOW_HIDDEN, FS_ALL_ENTRIES, $pathbase); foreach ($files as $aFile) { if ($aFile == '.' || $aFile == '..') { next; } if (filesystem_is_dir("{$source}/{$aFile}", $pathbase)) { filesystem_create_dir("{$dest}/{$aFile}", FS_NON_RECURSIVE, $pathbase); if (count(filesystem_is_dir("{$source}/{$aFile}", $pathbase)) != 0) { filesystem_copy_tree("{$source}/{$aFile}", "{$dest}/{$aFile}", $pathbase); } } else { filesystem_copy_file("{$source}/{$aFile}", "{$dest}/{$aFile}", $pathbase); } } }
$erroritem->on = 'shortname'; $errors[] = $erroritem; } else { // cannot install anything when editing data. // installing a vmoodle needs delete/add procedure // the update function is only provided for fixing // wring parameter values that have not influence upon // physical bindings. if ($form->id == '') { if (!file_exists($form->vdatapath)) { if (!filesystem_create_dir($form->vdatapath, FS_RECURSIVE, $CFG->local_vmoodle_vdatapathbase)) { $erroritem->message = get_string('couldnotcreatedataroot', 'local_vmoodle') . " " . $form->vdatapath; $erroritem->on = 'vdatapath'; $errors[] = $erroritem; } else { filesystem_copy_tree($CFG->dirroot . '/local/vmoodle/' . $v . '_vmoodledata', $vmoodle->vdatapath, ''); } } else { $done[] = 'datapath'; print_string('datapathcreated', 'local_vmoodle'); echo '<br/>'; } /// drop any previous database that could be on the way $erroritem = vmoodle_drop_database($form); if (!$erroritem) { $errors[] = $erroritem; } else { /// try to create database $vdb = vmoodle_setup_DB($form); $res = $vdb->create_database($form->vdbname); if (!$res) {
/** * copies recursively a subtree from a location to another * @param source the source path from dataroot * @param dest the dest path from dataroot * @return void */ function filesystem_copy_tree($source, $dest) { global $CFG; if ($CFG->debug > 8) { mtrace("copying tree <i>{$source}</i> to <i>{$dest}</i><br/>"); } if (file_exists($dest) && !filesystem_is_dir($dest)) { return; } if (!filesystem_is_dir($dest)) { filesystem_create_dir($dest, FS_RECURSIVE); } $files = array(); $files = filesystem_scan_dir($source); foreach ($files as $aFile) { if ($aFile == '.' || $aFile == '..') { next; } if (filesystem_is_dir("{$source}/{$aFile}")) { filesystem_create_dir("{$dest}/{$aFile}", FS_NON_RECURSIVE); if (count(filesystem_is_dir("{$source}/{$aFile}")) != 0) { filesystem_copy_tree("{$source}/{$aFile}", "{$dest}/{$aFile}"); } } else { filesystem_copy_file("{$source}/{$aFile}", "{$dest}/{$aFile}"); } } }