mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-60923 backup: Added $CFG->backuptempdir
The new setting will allow to host the temporary backup files into a specific target directory. Defaults to '$CFG->tempdir/backup'. Calling make_backup_temp_directory() checks that the required sub-directory will be properly created under the new target directory.
This commit is contained in:
parent
20bf0c45ff
commit
ef844148a9
@ -442,6 +442,7 @@ if ($interactive) {
|
||||
}
|
||||
}
|
||||
$CFG->tempdir = $CFG->dataroot.'/temp';
|
||||
$CFG->backuptempdir = $CFG->tempdir.'/backup';
|
||||
$CFG->cachedir = $CFG->dataroot.'/cache';
|
||||
$CFG->localcachedir = $CFG->dataroot.'/localcache';
|
||||
|
||||
|
@ -207,9 +207,9 @@ class category_bin extends base_bin {
|
||||
// Get the backup file.
|
||||
$file = reset($files);
|
||||
|
||||
// Get a temp directory name and create it.
|
||||
// Get a backup temp directory name and create it.
|
||||
$tempdir = \restore_controller::get_tempdir_name($context->id, $user->id);
|
||||
$fulltempdir = make_temp_directory('/backup/' . $tempdir);
|
||||
$fulltempdir = make_backup_temp_directory($tempdir);
|
||||
|
||||
// Extract the backup to tmpdir.
|
||||
$fb = get_file_packer('application/vnd.moodle.backup');
|
||||
|
@ -211,9 +211,9 @@ class course_bin extends base_bin {
|
||||
// Get the backup file.
|
||||
$file = reset($files);
|
||||
|
||||
// Get a temp directory name and create it.
|
||||
// Get a backup temp directory name and create it.
|
||||
$tempdir = \restore_controller::get_tempdir_name($context->id, $user->id);
|
||||
$fulltempdir = make_temp_directory('/backup/' . $tempdir);
|
||||
$fulltempdir = make_backup_temp_directory($tempdir);
|
||||
|
||||
// Extract the backup to tempdir.
|
||||
$fb = get_file_packer('application/vnd.moodle.backup');
|
||||
|
@ -347,7 +347,7 @@ class tool_uploadcourse_course {
|
||||
/**
|
||||
* Get the directory of the object to restore.
|
||||
*
|
||||
* @return string|false|null subdirectory in $CFG->tempdir/backup/..., false when an error occured
|
||||
* @return string|false|null subdirectory in $CFG->backuptempdir/..., false when an error occured
|
||||
* and null when there is simply nothing.
|
||||
*/
|
||||
protected function get_restore_content_dir() {
|
||||
|
@ -227,7 +227,7 @@ class tool_uploadcourse_helper {
|
||||
}
|
||||
|
||||
// If we don't use the cache, or if we do and not set, or the directory doesn't exist any more.
|
||||
if (!$usecache || (($backupid = $cache->get($cachekey)) === false || !is_dir("$CFG->tempdir/backup/$backupid"))) {
|
||||
if (!$usecache || (($backupid = $cache->get($cachekey)) === false || !is_dir(get_backup_temp_directory($backupid)))) {
|
||||
|
||||
// Use null instead of false because it would consider that the cache key has not been set.
|
||||
$backupid = null;
|
||||
@ -236,7 +236,7 @@ class tool_uploadcourse_helper {
|
||||
// Extracting the backup file.
|
||||
$packer = get_file_packer('application/vnd.moodle.backup');
|
||||
$backupid = restore_controller::get_tempdir_name(SITEID, $USER->id);
|
||||
$path = "$CFG->tempdir/backup/$backupid/";
|
||||
$path = make_backup_temp_directory($backupid, false);
|
||||
$result = $packer->extract_to_pathname($backupfile, $path);
|
||||
if (!$result) {
|
||||
$errors['invalidbackupfile'] = new lang_string('invalidbackupfile', 'tool_uploadcourse');
|
||||
|
@ -259,7 +259,7 @@ class tool_uploadcourse_processor {
|
||||
/**
|
||||
* Get the directory of the object to restore.
|
||||
*
|
||||
* @return string subdirectory in $CFG->tempdir/backup/...
|
||||
* @return string subdirectory in $CFG->backuptempdir/...
|
||||
*/
|
||||
protected function get_restore_content_dir() {
|
||||
$backupfile = null;
|
||||
|
@ -32,7 +32,7 @@
|
||||
*/
|
||||
class restore_controller extends base_controller {
|
||||
|
||||
protected $tempdir; // Directory under tempdir/backup awaiting restore
|
||||
protected $tempdir; // Directory under $CFG->backuptempdir awaiting restore
|
||||
protected $restoreid; // Unique identificator for this restore
|
||||
|
||||
protected $courseid; // courseid where restore is going to happen
|
||||
@ -68,7 +68,7 @@ class restore_controller extends base_controller {
|
||||
* while loading the plan, as well as for future use. (You can change it
|
||||
* for a different one later using set_progress.)
|
||||
*
|
||||
* @param string $tempdir Directory under tempdir/backup awaiting restore
|
||||
* @param string $tempdir Directory under $CFG->backuptempdir awaiting restore
|
||||
* @param int $courseid Course id where restore is going to happen
|
||||
* @param bool $interactive backup::INTERACTIVE_YES[true] or backup::INTERACTIVE_NO[false]
|
||||
* @param int $mode backup::MODE_[ GENERAL | HUB | IMPORT | SAMESITE ]
|
||||
|
@ -110,7 +110,7 @@ class core_backup_controller_testcase extends advanced_testcase {
|
||||
global $CFG;
|
||||
|
||||
// Make a backup.
|
||||
check_dir_exists($CFG->tempdir . '/backup');
|
||||
make_backup_temp_directory('');
|
||||
$bc = new backup_controller(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE,
|
||||
backup::INTERACTIVE_NO, backup::MODE_IMPORT, $this->userid);
|
||||
$backupid = $bc->get_backupid();
|
||||
@ -159,7 +159,7 @@ class core_backup_controller_testcase extends advanced_testcase {
|
||||
|
||||
$foldername = 'deadlock';
|
||||
$fp = get_file_packer('application/vnd.moodle.backup');
|
||||
$tempdir = $CFG->dataroot . '/temp/backup/' . $foldername;
|
||||
$tempdir = make_backup_temp_directory($foldername);
|
||||
$files = $fp->extract_to_pathname($CFG->dirroot . '/backup/controller/tests/fixtures/deadlock.mbz', $tempdir);
|
||||
|
||||
$this->setAdminUser();
|
||||
|
@ -148,7 +148,7 @@ abstract class base_converter implements loggable {
|
||||
public function get_workdir_path() {
|
||||
global $CFG;
|
||||
|
||||
return "$CFG->tempdir/backup/$this->workdir";
|
||||
return make_backup_temp_directory($this->workdir);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,7 +157,7 @@ abstract class base_converter implements loggable {
|
||||
public function get_tempdir_path() {
|
||||
global $CFG;
|
||||
|
||||
return "$CFG->tempdir/backup/$this->tempdir";
|
||||
return make_backup_temp_directory($this->tempdir);
|
||||
}
|
||||
|
||||
/// public static methods //////////////////////////////////////////////////
|
||||
|
@ -139,7 +139,7 @@ class imscc11_backup_convert extends backup_execution_step {
|
||||
|
||||
require_once($CFG->dirroot . '/backup/cc/cc_includes.php');
|
||||
|
||||
$tempdir = $CFG->tempdir . '/backup/' . uniqid('', true);
|
||||
$tempdir = $CFG->backuptempdir . '/' . uniqid('', true);
|
||||
|
||||
if (mkdir($tempdir, $CFG->directorypermissions, true)) {
|
||||
|
||||
|
@ -89,7 +89,8 @@ class moodle1_converter extends base_converter {
|
||||
public static function detect_format($tempdir) {
|
||||
global $CFG;
|
||||
|
||||
$filepath = $CFG->tempdir . '/backup/' . $tempdir . '/moodle.xml';
|
||||
$tempdirpath = make_backup_temp_directory($tempdir, false);
|
||||
$filepath = $tempdirpath . '/moodle.xml';
|
||||
if (file_exists($filepath)) {
|
||||
// looks promising, lets load some information
|
||||
$handle = fopen($filepath, 'r');
|
||||
|
@ -35,6 +35,9 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
/** @var string the name of the directory containing the unpacked Moodle 1.9 backup */
|
||||
protected $tempdir;
|
||||
|
||||
/** @var string the full name of the directory containing the unpacked Moodle 1.9 backup */
|
||||
protected $tempdirpath;
|
||||
|
||||
/** @var string saved hash of an icon file used during testing */
|
||||
protected $iconhash;
|
||||
|
||||
@ -42,39 +45,40 @@ class core_backup_moodle1_converter_testcase extends advanced_testcase {
|
||||
global $CFG;
|
||||
|
||||
$this->tempdir = convert_helper::generate_id('unittest');
|
||||
check_dir_exists("$CFG->tempdir/backup/$this->tempdir/course_files/sub1");
|
||||
check_dir_exists("$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7");
|
||||
$this->tempdirpath = make_backup_temp_directory($this->tempdir);
|
||||
check_dir_exists("$this->tempdirpath/course_files/sub1");
|
||||
check_dir_exists("$this->tempdirpath/moddata/unittest/4/7");
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/moodle.xml",
|
||||
"$CFG->tempdir/backup/$this->tempdir/moodle.xml"
|
||||
"$this->tempdirpath/moodle.xml"
|
||||
);
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
|
||||
"$CFG->tempdir/backup/$this->tempdir/course_files/file1.gif"
|
||||
"$this->tempdirpath/course_files/file1.gif"
|
||||
);
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
|
||||
"$CFG->tempdir/backup/$this->tempdir/course_files/sub1/file2.gif"
|
||||
"$this->tempdirpath/course_files/sub1/file2.gif"
|
||||
);
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
|
||||
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/file1.gif"
|
||||
"$this->tempdirpath/moddata/unittest/4/file1.gif"
|
||||
);
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
|
||||
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/icon.gif"
|
||||
"$this->tempdirpath/moddata/unittest/4/icon.gif"
|
||||
);
|
||||
$this->iconhash = file_storage::hash_from_path($CFG->tempdir.'/backup/'.$this->tempdir.'/moddata/unittest/4/icon.gif');
|
||||
$this->iconhash = file_storage::hash_from_path($this->tempdirpath.'/moddata/unittest/4/icon.gif');
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
|
||||
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
|
||||
"$this->tempdirpath/moddata/unittest/4/7/icon.gif"
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
global $CFG;
|
||||
if (empty($CFG->keeptempdirectoriesonbackup)) {
|
||||
fulldelete("$CFG->tempdir/backup/$this->tempdir");
|
||||
fulldelete($this->tempdirpath);
|
||||
}
|
||||
}
|
||||
|
||||
@ -563,7 +567,7 @@ as it is parsed from the backup file. <br /><br /><img border="0" width="110" vs
|
||||
|
||||
copy(
|
||||
"$CFG->dirroot/backup/converter/moodle1/tests/fixtures/questions.xml",
|
||||
"$CFG->tempdir/backup/$this->tempdir/moodle.xml"
|
||||
"$this->tempdirpath/moodle.xml"
|
||||
);
|
||||
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
|
||||
$converter->convert();
|
||||
|
@ -140,7 +140,7 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
|
||||
// Check whether the backup directory still exists. If missing, something
|
||||
// went really wrong in backup, throw error. Note that backup::MODE_IMPORT
|
||||
// backups don't store resulting files ever
|
||||
$tempdestination = $CFG->tempdir . '/backup/' . $backupid;
|
||||
$tempdestination = make_backup_temp_directory($backupid, false);
|
||||
if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
|
||||
print_error('unknownbackupexporterror'); // shouldn't happen ever
|
||||
}
|
||||
|
@ -127,8 +127,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
|
||||
// Extract backup file.
|
||||
$backupid = 'abc';
|
||||
$backuppath = $CFG->tempdir . '/backup/' . $backupid;
|
||||
check_dir_exists($backuppath);
|
||||
$backuppath = make_backup_temp_directory($backupid);
|
||||
get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(
|
||||
__DIR__ . '/fixtures/availability_26_format.mbz', $backuppath);
|
||||
|
||||
@ -972,8 +971,7 @@ class core_backup_moodle2_testcase extends advanced_testcase {
|
||||
foreach ($backupfiles as $backupfile) {
|
||||
// Extract backup file.
|
||||
$backupid = $backupfile;
|
||||
$backuppath = $CFG->tempdir . '/backup/' . $backupid;
|
||||
check_dir_exists($backuppath);
|
||||
$backuppath = make_backup_temp_directory($backupid);
|
||||
get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(
|
||||
__DIR__ . "/fixtures/$backupfile.mbz", $backuppath);
|
||||
|
||||
|
@ -72,7 +72,7 @@ if (is_null($course)) {
|
||||
$browser = get_file_browser();
|
||||
|
||||
// check if tmp dir exists
|
||||
$tmpdir = $CFG->tempdir . '/backup';
|
||||
$tmpdir = make_backup_temp_directory('', false);
|
||||
if (!check_dir_exists($tmpdir, true, true)) {
|
||||
throw new restore_controller_exception('cannot_create_backup_temp_dir');
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ abstract class backup_factory {
|
||||
|
||||
// Create file_logger, observing $CFG->backup_file_logger_level
|
||||
// defaulting to $dfltloglevel
|
||||
check_dir_exists($CFG->tempdir . '/backup', true, true); // need to ensure that temp/backup already exists
|
||||
$backuptempdir = make_backup_temp_directory(''); // Need to ensure that $CFG->backuptempdir already exists.
|
||||
$fllevel = isset($CFG->backup_file_logger_level) ? $CFG->backup_file_logger_level : $dfltloglevel;
|
||||
$enabledloggers[] = new file_logger($fllevel, true, true, $CFG->tempdir . '/backup/' . $backupid . '.log');
|
||||
$enabledloggers[] = new file_logger($fllevel, true, true, $backuptempdir . '/' . $backupid . '.log');
|
||||
|
||||
// Create database_logger, observing $CFG->backup_database_logger_level and defaulting to LOG_WARNING
|
||||
// and pointing to the backup_logs table
|
||||
|
@ -43,7 +43,8 @@ class backup_file_manager {
|
||||
public static function get_backup_storage_base_dir($backupid) {
|
||||
global $CFG;
|
||||
|
||||
return $CFG->tempdir . '/backup/' . $backupid . '/files';
|
||||
$backupiddir = make_backup_temp_directory($backupid);
|
||||
return $backupiddir . '/files';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,7 +121,8 @@ abstract class backup_general_helper extends backup_helper {
|
||||
|
||||
$info = new stdclass(); // Final information goes here
|
||||
|
||||
$moodlefile = $CFG->tempdir . '/backup/' . $tempdir . '/moodle_backup.xml';
|
||||
$backuptempdir = make_backup_temp_directory('', false);
|
||||
$moodlefile = $backuptempdir . '/' . $tempdir . '/moodle_backup.xml';
|
||||
if (!file_exists($moodlefile)) { // Shouldn't happen ever, but...
|
||||
throw new backup_helper_exception('missing_moodle_backup_xml_file', $moodlefile);
|
||||
}
|
||||
@ -267,7 +268,7 @@ abstract class backup_general_helper extends backup_helper {
|
||||
|
||||
// Extract moodle_backup.xml.
|
||||
$tmpname = 'info_from_mbz_' . time() . '_' . random_string(4);
|
||||
$tmpdir = $CFG->tempdir . '/backup/' . $tmpname;
|
||||
$tmpdir = make_backup_temp_directory($tmpname);
|
||||
$fp = get_file_packer('application/vnd.moodle.backup');
|
||||
|
||||
$extracted = $fp->extract_to_pathname($filepath, $tmpdir, array('moodle_backup.xml'), $progress);
|
||||
|
@ -33,8 +33,8 @@ abstract class backup_helper {
|
||||
* Given one backupid, create all the needed dirs to have one backup temp dir available
|
||||
*/
|
||||
static public function check_and_create_backup_dir($backupid) {
|
||||
global $CFG;
|
||||
if (!check_dir_exists($CFG->tempdir . '/backup/' . $backupid, true, true)) {
|
||||
$backupiddir = make_backup_temp_directory($backupid, false);
|
||||
if (empty($backupiddir)) {
|
||||
throw new backup_helper_exception('cannot_create_backup_temp_dir');
|
||||
}
|
||||
}
|
||||
@ -49,8 +49,8 @@ abstract class backup_helper {
|
||||
* @param \core\progress\base $progress Optional progress reporting object
|
||||
*/
|
||||
static public function clear_backup_dir($backupid, \core\progress\base $progress = null) {
|
||||
global $CFG;
|
||||
if (!self::delete_dir_contents($CFG->tempdir . '/backup/' . $backupid, '', $progress)) {
|
||||
$backupiddir = make_backup_temp_directory($backupid, false);
|
||||
if (!self::delete_dir_contents($backupiddir, '', $progress)) {
|
||||
throw new backup_helper_exception('cannot_empty_backup_temp_dir');
|
||||
}
|
||||
return true;
|
||||
@ -66,9 +66,9 @@ abstract class backup_helper {
|
||||
* @param \core\progress\base $progress Optional progress reporting object
|
||||
*/
|
||||
static public function delete_backup_dir($backupid, \core\progress\base $progress = null) {
|
||||
global $CFG;
|
||||
$backupiddir = make_backup_temp_directory($backupid, false);
|
||||
self::clear_backup_dir($backupid, $progress);
|
||||
return rmdir($CFG->tempdir . '/backup/' . $backupid);
|
||||
return rmdir($backupiddir);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,13 +157,12 @@ abstract class backup_helper {
|
||||
* @param \core\progress\base $progress Optional progress reporting object
|
||||
*/
|
||||
static public function delete_old_backup_dirs($deletefrom, \core\progress\base $progress = null) {
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
// Get files and directories in the temp backup dir witout descend
|
||||
$list = get_directory_list($CFG->tempdir . '/backup', '', false, true, true);
|
||||
// Get files and directories in the backup temp dir without descend.
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
$list = get_directory_list($backuptempdir, '', false, true, true);
|
||||
foreach ($list as $file) {
|
||||
$file_path = $CFG->tempdir . '/backup/' . $file;
|
||||
$file_path = $backuptempdir . '/' . $file;
|
||||
$moddate = filemtime($file_path);
|
||||
if ($status && $moddate < $deletefrom) {
|
||||
//If directory, recurse
|
||||
|
@ -131,15 +131,12 @@ abstract class convert_helper {
|
||||
* @return boolean true if moodle2 format detected, false otherwise
|
||||
*/
|
||||
public static function detect_moodle2_format($tempdir) {
|
||||
global $CFG;
|
||||
|
||||
$dirpath = $CFG->tempdir . '/backup/' . $tempdir;
|
||||
$filepath = $dirpath . '/moodle_backup.xml';
|
||||
|
||||
$dirpath = make_backup_temp_directory($tempdir, false);
|
||||
if (!is_dir($dirpath)) {
|
||||
throw new convert_helper_exception('tmp_backup_directory_not_found', $dirpath);
|
||||
}
|
||||
|
||||
$filepath = $dirpath . '/moodle_backup.xml';
|
||||
if (!file_exists($filepath)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -37,13 +37,12 @@ class backup_plan extends base_plan implements loggable {
|
||||
* Constructor - instantiates one object of this class
|
||||
*/
|
||||
public function __construct($controller) {
|
||||
global $CFG;
|
||||
|
||||
if (! $controller instanceof backup_controller) {
|
||||
throw new backup_plan_exception('wrong_backup_controller_specified');
|
||||
}
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
$this->controller = $controller;
|
||||
$this->basepath = $CFG->tempdir . '/backup/' . $controller->get_backupid();
|
||||
$this->basepath = $backuptempdir . '/' . $controller->get_backupid();
|
||||
$this->excludingdactivities = false;
|
||||
parent::__construct('backup_plan');
|
||||
}
|
||||
|
@ -49,8 +49,9 @@ class restore_plan extends base_plan implements loggable {
|
||||
if (! $controller instanceof restore_controller) {
|
||||
throw new restore_plan_exception('wrong_restore_controller_specified');
|
||||
}
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
$this->controller = $controller;
|
||||
$this->basepath = $CFG->tempdir . '/backup/' . $controller->get_tempdir();
|
||||
$this->basepath = $backuptempdir . '/' . $controller->get_tempdir();
|
||||
$this->preloaded = false;
|
||||
$this->decoder = new restore_decode_processor($this->get_restoreid(), $this->get_info()->original_wwwroot, $CFG->wwwroot);
|
||||
$this->missingmodules = false;
|
||||
|
@ -288,9 +288,9 @@ class restore_ui_stage_confirm extends restore_ui_independent_stage implements f
|
||||
* @throws restore_ui_exception
|
||||
*/
|
||||
public function process() {
|
||||
global $CFG;
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
if ($this->filename) {
|
||||
$archivepath = $CFG->tempdir . '/backup/' . $this->filename;
|
||||
$archivepath = $backuptempdir . '/' . $this->filename;
|
||||
if (!file_exists($archivepath)) {
|
||||
throw new restore_ui_exception('invalidrestorefile');
|
||||
}
|
||||
@ -316,13 +316,14 @@ class restore_ui_stage_confirm extends restore_ui_independent_stage implements f
|
||||
* @return bool
|
||||
*/
|
||||
protected function extract_file_to_dir($source) {
|
||||
global $CFG, $USER;
|
||||
global $USER;
|
||||
|
||||
$this->filepath = restore_controller::get_tempdir_name($this->contextid, $USER->id);
|
||||
$backuptempdir = make_backup_temp_directory('', false);
|
||||
|
||||
$fb = get_file_packer('application/vnd.moodle.backup');
|
||||
$result = $fb->extract_to_pathname($source,
|
||||
$CFG->tempdir . '/backup/' . $this->filepath . '/', null, $this);
|
||||
$backuptempdir . '/' . $this->filepath . '/', null, $this);
|
||||
|
||||
// If any progress happened, end it.
|
||||
if ($this->startedprogress) {
|
||||
@ -473,8 +474,9 @@ class restore_ui_stage_destination extends restore_ui_independent_stage {
|
||||
* @throws restore_ui_exception
|
||||
*/
|
||||
public function process() {
|
||||
global $CFG, $DB;
|
||||
if (!file_exists("$CFG->tempdir/backup/".$this->filepath) || !is_dir("$CFG->tempdir/backup/".$this->filepath)) {
|
||||
global $DB;
|
||||
$filepathdir = make_backup_temp_directory($this->filepath, false);
|
||||
if (!file_exists($filepathdir) || !is_dir($filepathdir)) {
|
||||
throw new restore_ui_exception('invalidrestorepath');
|
||||
}
|
||||
if (optional_param('searchcourses', false, PARAM_BOOL)) {
|
||||
|
@ -75,7 +75,8 @@ $cancelrestore = optional_param('cancelrestore', false, PARAM_INT);
|
||||
if ($usercandownload and $cancelrestore and confirm_sesskey()) {
|
||||
$filename = optional_param('filename', '', PARAM_ALPHANUMEXT);
|
||||
//delete temp file
|
||||
unlink($CFG->tempdir . '/backup/' . $filename . ".mbz");
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
unlink($backuptempdir . '/' . $filename . ".mbz");
|
||||
}
|
||||
|
||||
/// Download
|
||||
|
@ -434,10 +434,16 @@ $CFG->admin = 'admin';
|
||||
// Localcachedir is intended for server clusters, it does not have to be shared by cluster nodes.
|
||||
// The directories must not be accessible via web.
|
||||
//
|
||||
// $CFG->tempdir = '/var/www/moodle/temp'; // Directory MUST BE SHARED by all clsuter nodes.
|
||||
// $CFG->tempdir = '/var/www/moodle/temp'; // Directory MUST BE SHARED by all cluster nodes.
|
||||
// $CFG->cachedir = '/var/www/moodle/cache'; // Directory MUST BE SHARED by all cluster nodes, locking required.
|
||||
// $CFG->localcachedir = '/var/local/cache'; // Intended for local node caching.
|
||||
//
|
||||
// It is possible to specify a different backup temp directory, use local fast filesystem
|
||||
// for normal web servers. Server clusters MUST use shared filesystem for backuptempdir!
|
||||
// The directory must not be accessible via web.
|
||||
//
|
||||
// $CFG->backuptempdir = '/var/www/moodle/backuptemp'; // Directory MUST BE SHARED by all cluster nodes.
|
||||
//
|
||||
// Some filesystems such as NFS may not support file locking operations.
|
||||
// Locking resolves race conditions and is strongly recommended for production servers.
|
||||
// $CFG->preventfilelocking = false;
|
||||
|
@ -45,7 +45,7 @@ class core_course_restore_testcase extends advanced_testcase {
|
||||
* @return string
|
||||
*/
|
||||
protected function backup_course($courseid, $userid = 2) {
|
||||
globaL $CFG;
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
$packer = get_file_packer('application/vnd.moodle.backup');
|
||||
|
||||
$bc = new backup_controller(backup::TYPE_1COURSE, $courseid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO,
|
||||
@ -53,7 +53,7 @@ class core_course_restore_testcase extends advanced_testcase {
|
||||
$bc->execute_plan();
|
||||
|
||||
$results = $bc->get_results();
|
||||
$results['backup_destination']->extract_to_pathname($packer, "$CFG->tempdir/backup/core_course_testcase");
|
||||
$results['backup_destination']->extract_to_pathname($packer, "$backuptempdir/core_course_testcase");
|
||||
|
||||
$bc->destroy();
|
||||
unset($bc);
|
||||
|
@ -163,6 +163,7 @@ $CFG->wwwroot = install_guess_wwwroot(); // can not be changed - pp
|
||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||
$CFG->dataroot = $config->dataroot;
|
||||
$CFG->tempdir = $CFG->dataroot.'/temp';
|
||||
$CFG->backuptempdir = $CFG->tempdir.'/backup';
|
||||
$CFG->cachedir = $CFG->dataroot.'/cache';
|
||||
$CFG->localcachedir = $CFG->dataroot.'/localcache';
|
||||
$CFG->admin = $config->admin;
|
||||
|
@ -375,9 +375,9 @@ class publication {
|
||||
global $CFG, $USER;
|
||||
require_once($CFG->libdir . "/filelib.php");
|
||||
|
||||
make_temp_directory('backup');
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
$filename = md5(time() . '-' . $hubcourseid . '-'. $USER->id . '-'. random_string(20));
|
||||
$path = $CFG->tempdir.'/backup/'.$filename.".mbz";
|
||||
$path = $backuptempdir.'/'.$filename.".mbz";
|
||||
|
||||
api::download_course_backup($hubcourseid, $path);
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
* - $CFG->dataroot - Path to moodle data files directory on server's filesystem.
|
||||
* - $CFG->dirroot - Path to moodle's library folder on server's filesystem.
|
||||
* - $CFG->libdir - Path to moodle's library folder on server's filesystem.
|
||||
* - $CFG->backuptempdir - Path to moodle's backup temp file directory on server's filesystem.
|
||||
* - $CFG->tempdir - Path to moodle's temp file directory on server's filesystem.
|
||||
* - $CFG->cachedir - Path to moodle's cache directory on server's filesystem (shared by cluster nodes).
|
||||
* - $CFG->localcachedir - Path to moodle's local cache directory (not shared by cluster nodes).
|
||||
@ -192,6 +193,11 @@ if (!isset($CFG->tempdir)) {
|
||||
$CFG->tempdir = "$CFG->dataroot/temp";
|
||||
}
|
||||
|
||||
// Allow overriding of backuptempdir but be backwards compatible
|
||||
if (!isset($CFG->backuptempdir)) {
|
||||
$CFG->backuptempdir = "$CFG->tempdir/backup";
|
||||
}
|
||||
|
||||
// Allow overriding of cachedir but be backwards compatible
|
||||
if (!isset($CFG->cachedir)) {
|
||||
$CFG->cachedir = "$CFG->dataroot/cache";
|
||||
|
@ -1661,6 +1661,42 @@ function make_request_directory($exceptiononerror = true) {
|
||||
return make_unique_writable_directory($basedir, $exceptiononerror);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path of a directory under $CFG->backuptempdir.
|
||||
*
|
||||
* @param string $directory the relative path of the directory under $CFG->backuptempdir
|
||||
* @return string|false Returns full path to directory given a valid string; otherwise, false.
|
||||
*/
|
||||
function get_backup_temp_directory($directory) {
|
||||
global $CFG;
|
||||
if (($directory === null) || ($directory === false)) {
|
||||
return false;
|
||||
}
|
||||
return "$CFG->backuptempdir/$directory";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory under $CFG->backuptempdir and make sure it is writable.
|
||||
*
|
||||
* Do not use for storing generic temp files - see make_temp_directory() instead for this purpose.
|
||||
*
|
||||
* Backup temporary files must be on a shared storage.
|
||||
*
|
||||
* @param string $directory the relative path of the directory to be created under $CFG->backuptempdir
|
||||
* @param bool $exceptiononerror throw exception if error encountered
|
||||
* @return string|false Returns full path to directory if successful, false if not; may throw exception
|
||||
*/
|
||||
function make_backup_temp_directory($directory, $exceptiononerror = true) {
|
||||
global $CFG;
|
||||
if ($CFG->backuptempdir !== "$CFG->tempdir/backup") {
|
||||
check_dir_exists($CFG->backuptempdir, true, true);
|
||||
protect_directory($CFG->backuptempdir);
|
||||
} else {
|
||||
protect_directory($CFG->tempdir);
|
||||
}
|
||||
return make_writable_directory("$CFG->backuptempdir/$directory", $exceptiononerror);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory under tempdir and make sure it is writable.
|
||||
*
|
||||
|
@ -813,6 +813,7 @@ abstract class testing_util {
|
||||
}
|
||||
|
||||
make_temp_directory('');
|
||||
make_backup_temp_directory('');
|
||||
make_cache_directory('');
|
||||
make_localcache_directory('');
|
||||
// Purge all data from the caches. This is required for consistency between tests.
|
||||
|
@ -147,7 +147,7 @@ class cronlib_testcase extends basic_testcase {
|
||||
public function test_cron_delete_from_temp($nodes, $expected) {
|
||||
global $CFG;
|
||||
|
||||
$tmpdir = $CFG->tempdir;
|
||||
$tmpdir = realpath($CFG->tempdir);
|
||||
|
||||
foreach ($nodes as $data) {
|
||||
if ($data->isdir) {
|
||||
@ -168,7 +168,12 @@ class cronlib_testcase extends basic_testcase {
|
||||
|
||||
$actual = array();
|
||||
for ($iter->rewind(); $iter->valid(); $iter->next()) {
|
||||
if (!$iter->isDot()) {
|
||||
$isvalid = true;
|
||||
$isvalid = $isvalid && !$iter->isDot();
|
||||
// Remove the default $CFG->tempdir/backup directory and $CFG->tempdir/.htaccess file from this comparison.
|
||||
$isvalid = $isvalid && !($iter->isDir() && ($iter->getRealpath() === "{$tmpdir}/backup"));
|
||||
$isvalid = $isvalid && !($iter->isFile() && ($iter->getRealpath() === "{$tmpdir}/.htaccess"));
|
||||
if ($isvalid) {
|
||||
$actual[] = $iter->getRealPath();
|
||||
}
|
||||
}
|
||||
|
@ -415,9 +415,10 @@ class core_scheduled_task_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function test_file_temp_cleanup_task() {
|
||||
global $CFG;
|
||||
$backuptempdir = make_backup_temp_directory('');
|
||||
|
||||
// Create directories.
|
||||
$dir = $CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR . 'courses';
|
||||
$dir = $backuptempdir . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR . 'courses';
|
||||
mkdir($dir, 0777, true);
|
||||
|
||||
// Create files to be checked and then deleted.
|
||||
@ -440,11 +441,11 @@ class core_scheduled_task_testcase extends advanced_testcase {
|
||||
// Change the time modified on modules.xml.
|
||||
touch($file02, time() - (8 * 24 * 3600));
|
||||
// Change the time modified on the courses directory.
|
||||
touch($CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR .
|
||||
touch($backuptempdir . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR .
|
||||
'courses', time() - (8 * 24 * 3600));
|
||||
// Run the scheduled task to remove the file and directory.
|
||||
$task->execute();
|
||||
$filesarray = scandir($CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01');
|
||||
$filesarray = scandir($backuptempdir . DIRECTORY_SEPARATOR . 'backup01');
|
||||
// There should only be two items in the array, '.' and '..'.
|
||||
$this->assertEquals(2, count($filesarray));
|
||||
|
||||
@ -464,8 +465,8 @@ class core_scheduled_task_testcase extends advanced_testcase {
|
||||
$task->execute();
|
||||
$filesarray = scandir($CFG->tempdir);
|
||||
// All of the files and directories should be deleted.
|
||||
// There should only be two items in the array, '.' and '..'.
|
||||
$this->assertEquals(2, count($filesarray));
|
||||
// There should only be three items in the array, '.', '..' and '.htaccess'.
|
||||
$this->assertEquals([ '.', '..', '.htaccess' ], $filesarray);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1717,6 +1717,9 @@ function install_core($version, $verbose) {
|
||||
remove_dir($CFG->tempdir.'', true);
|
||||
make_temp_directory('', true);
|
||||
|
||||
remove_dir($CFG->backuptempdir.'', true);
|
||||
make_backup_temp_directory('', true);
|
||||
|
||||
remove_dir($CFG->dataroot.'/muc', true);
|
||||
make_writable_directory($CFG->dataroot.'/muc', true);
|
||||
|
||||
|
@ -41,8 +41,7 @@ class mod_quiz_tags_testcase extends advanced_testcase {
|
||||
$this->setAdminUser();
|
||||
|
||||
$backupid = 'abc';
|
||||
$backuppath = $CFG->tempdir . '/backup/' . $backupid;
|
||||
check_dir_exists($backuppath);
|
||||
$backuppath = make_backup_temp_directory($backupid);
|
||||
get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(
|
||||
__DIR__ . "/fixtures/random_by_tag_quiz.mbz", $backuppath);
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
This files describes API changes in /mod/* - activity modules,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.5 ===
|
||||
|
||||
Required changes in code:
|
||||
* use new make_backup_temp_directory()
|
||||
|
||||
=== 3.4 ===
|
||||
|
||||
* Navigation between activities via a previous and next link was added to Boost, Clean and Bootstrapbase. This
|
||||
|
Loading…
x
Reference in New Issue
Block a user