Skip to content

Commit

Permalink
MDL-28701 Change all uses of $CFG->dataroot/temp to $CFG->tempdir
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlanyon authored and skodak committed Sep 10, 2011
1 parent 3e93987 commit 7aa06e6
Show file tree
Hide file tree
Showing 50 changed files with 111 additions and 111 deletions.
14 changes: 7 additions & 7 deletions admin/timezoneimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

if (!$ok or !confirm_sesskey()) {
$message = '<br /><br />';
$message .= $CFG->dataroot.'/temp/olson.txt<br />';
$message .= $CFG->dataroot.'/temp/timezone.txt<br />';
$message .= $CFG->tempdir.'/olson.txt<br />';
$message .= $CFG->tempdir.'/timezone.txt<br />';
$message .= '<a href="http://download.moodle.org/timezone/">http://download.moodle.org/timezone/</a><br />';
$message .= '<a href="'.$CFG->wwwroot.'/lib/timezone.txt">'.$CFG->dirroot.'/lib/timezone.txt</a><br />';
$message .= '<br />';
Expand All @@ -43,7 +43,7 @@

/// First, look for an Olson file locally

$source = $CFG->dataroot.'/temp/olson.txt';
$source = $CFG->tempdir.'/olson.txt';
if (!$importdone and is_readable($source)) {
if ($timezones = olson_to_timezones($source)) {
update_timezone_records($timezones);
Expand All @@ -53,7 +53,7 @@

/// Next, look for a CSV file locally

$source = $CFG->dataroot.'/temp/timezone.txt';
$source = $CFG->tempdir.'/timezone.txt';
if (!$importdone and is_readable($source)) {
if ($timezones = get_records_csv($source, 'timezone')) {
update_timezone_records($timezones);
Expand All @@ -64,14 +64,14 @@
/// Otherwise, let's try moodle.org's copy
$source = 'http://download.moodle.org/timezone/';
if (!$importdone && ($content=download_file_content($source))) {
if ($file = fopen($CFG->dataroot.'/temp/timezone.txt', 'w')) { // Make local copy
if ($file = fopen($CFG->tempdir.'/timezone.txt', 'w')) { // Make local copy
fwrite($file, $content);
fclose($file);
if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezone.txt', 'timezone')) { // Parse it
if ($timezones = get_records_csv($CFG->tempdir.'/timezone.txt', 'timezone')) { // Parse it
update_timezone_records($timezones);
$importdone = $source;
}
unlink($CFG->dataroot.'/temp/timezone.txt');
unlink($CFG->tempdir.'/timezone.txt');
}
}

Expand Down
2 changes: 1 addition & 1 deletion admin/uploadpicture.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

// Create a unique temporary directory, to process the zip file
// contents.
$zipdir = my_mktempdir($CFG->dataroot.'/temp/', 'usrpic');
$zipdir = my_mktempdir($CFG->tempdir.'/', 'usrpic');
$dstfile = $zipdir.'/images.zip';

if (!$mform->save_file('userpicturesfile', $dstfile, true)) {
Expand Down
2 changes: 1 addition & 1 deletion auth/mnet/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ function confirm_mnet_session($token, $remotepeer) {
$fetchrequest->add_param($localuser->username);
if ($fetchrequest->send($remotepeer) === true) {
if (strlen($fetchrequest->response['f1']) > 0) {
$imagefilename = $CFG->dataroot . '/temp/mnet-usericon-' . $localuser->id;
$imagefilename = $CFG->tempdir . '/mnet-usericon-' . $localuser->id;
$imagecontents = base64_decode($fetchrequest->response['f1']);
file_put_contents($imagefilename, $imagecontents);
if (process_new_icon($usercontext, 'user', 'icon', 0, $imagefilename)) {
Expand Down
4 changes: 2 additions & 2 deletions backup/controller/restore_controller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class restore_controller extends backup implements loggable {

protected $tempdir; // Directory under dataroot/temp/backup awaiting restore
protected $tempdir; // Directory under tempdir/backup awaiting restore
protected $restoreid; // Unique identificator for this restore

protected $courseid; // courseid where restore is going to happen
Expand Down Expand Up @@ -61,7 +61,7 @@ class restore_controller extends backup implements loggable {

/**
*
* @param string $tempdir Directory under dataroot/temp/backup awaiting restore
* @param string $tempdir Directory under tempdir/backup 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 ]
Expand Down
4 changes: 2 additions & 2 deletions backup/converter/convertlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function convert() {
public function get_workdir_path() {
global $CFG;

return "$CFG->dataroot/temp/backup/$this->workdir";
return "$CFG->tempdir/backup/$this->workdir";
}

/**
Expand All @@ -156,7 +156,7 @@ public function get_workdir_path() {
public function get_tempdir_path() {
global $CFG;

return "$CFG->dataroot/temp/backup/$this->tempdir";
return "$CFG->tempdir/backup/$this->tempdir";
}

/// public static methods //////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion backup/converter/moodle1/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function log($message, $level, $a = null, $depth = null, $display = false
public static function detect_format($tempdir) {
global $CFG;

$filepath = $CFG->dataroot . '/temp/backup/' . $tempdir . '/moodle.xml';
$filepath = $CFG->tempdir . '/backup/' . $tempdir . '/moodle.xml';
if (file_exists($filepath)) {
// looks promising, lets load some information
$handle = fopen($filepath, 'r');
Expand Down
20 changes: 10 additions & 10 deletions backup/converter/moodle1/simpletest/testlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,38 @@ public function setUp() {
global $CFG;

$this->tempdir = convert_helper::generate_id('simpletest');
check_dir_exists("$CFG->dataroot/temp/backup/$this->tempdir/course_files/sub1");
check_dir_exists("$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/7");
check_dir_exists("$CFG->tempdir/backup/$this->tempdir/course_files/sub1");
check_dir_exists("$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7");
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/moodle.xml",
"$CFG->dataroot/temp/backup/$this->tempdir/moodle.xml"
"$CFG->tempdir/backup/$this->tempdir/moodle.xml"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
"$CFG->dataroot/temp/backup/$this->tempdir/course_files/file1.gif"
"$CFG->tempdir/backup/$this->tempdir/course_files/file1.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
"$CFG->dataroot/temp/backup/$this->tempdir/course_files/sub1/file2.gif"
"$CFG->tempdir/backup/$this->tempdir/course_files/sub1/file2.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
"$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/file1.gif"
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/file1.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
"$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/icon.gif"
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/icon.gif"
);
copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
"$CFG->dataroot/temp/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
);
}

public function tearDown() {
global $CFG;
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete("$CFG->dataroot/temp/backup/$this->tempdir");
fulldelete("$CFG->tempdir/backup/$this->tempdir");
}
}

Expand Down Expand Up @@ -440,7 +440,7 @@ public function test_question_bank_conversion() {

copy(
"$CFG->dirroot/backup/converter/moodle1/simpletest/files/questions.xml",
"$CFG->dataroot/temp/backup/$this->tempdir/moodle.xml"
"$CFG->tempdir/backup/$this->tempdir/moodle.xml"
);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->convert();
Expand Down
2 changes: 1 addition & 1 deletion backup/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
// 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->dataroot . '/temp/backup/' . $backupid;
$tempdestination = $CFG->tempdir . '/backup/' . $backupid;
if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
print_error('unknownbackupexporterror'); // shouldn't happen ever
}
Expand Down
18 changes: 9 additions & 9 deletions backup/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function backup_delete_old_dirs($delete_from) {

$status = true;
//Get files and directories in the temp backup dir witout descend
$list = get_directory_list($CFG->dataroot."/temp/backup", "", false, true, true);
$list = get_directory_list($CFG->tempdir."/backup", "", false, true, true);
foreach ($list as $file) {
$file_path = $CFG->dataroot."/temp/backup/".$file;
$file_path = $CFG->tempdir."/backup/".$file;
$moddate = filemtime($file_path);
if ($status && $moddate < $delete_from) {
//If directory, recurse
Expand All @@ -81,12 +81,12 @@ function backup_delete_old_dirs($delete_from) {
function check_and_create_backup_dir($backup_unique_code) {
global $CFG;

$status = check_dir_exists($CFG->dataroot."/temp",true);
$status = check_dir_exists($CFG->tempdir."",true);
if ($status) {
$status = check_dir_exists($CFG->dataroot."/temp/backup",true);
$status = check_dir_exists($CFG->tempdir."/backup",true);
}
if ($status) {
$status = check_dir_exists($CFG->dataroot."/temp/backup/".$backup_unique_code,true);
$status = check_dir_exists($CFG->tempdir."/backup/".$backup_unique_code,true);
}

return $status;
Expand Down Expand Up @@ -162,7 +162,7 @@ function delete_dir_contents ($dir,$excludeddir="") {
function clear_backup_dir($backup_unique_code) {
global $CFG;

$rootdir = $CFG->dataroot."/temp/backup/".$backup_unique_code;
$rootdir = $CFG->tempdir."/backup/".$backup_unique_code;

//Delete recursively
$status = delete_dir_contents($rootdir);
Expand Down Expand Up @@ -237,7 +237,7 @@ function clean_temp_data ($preferences) {
&& $DB->delete_records('backup_files', array('backup_code'=>$preferences->backup_unique_code));

//Now, delete temp directory (if exists)
$file_path = $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code;
$file_path = $CFG->tempdir."/backup/".$preferences->backup_unique_code;
if (is_dir($file_path)) {
$status = delete_dir_contents($file_path);
//There is nothing, delete the directory itself
Expand Down Expand Up @@ -348,7 +348,7 @@ function backup_putid($backup_unique_code, $table, $old_id, $new_id, $info="") {

if (strlen($info_ser) > $max_db_storage) {
//Calculate filename (in current_backup_dir, $backup_unique_code_$table_$old_id.info)
$filename = $CFG->dataroot."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
$filename = $CFG->tempdir."/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
//Save data to file
$status = backup_data2file($filename,$info_ser);
//Set info_to save
Expand Down Expand Up @@ -394,7 +394,7 @@ function backup_getid ($backup_unique_code, $table, $old_id) {

//If info field = "infile", get file contents
if (!empty($status->info) && $status->info == "infile") {
$filename = $CFG->dataroot."/temp/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
$filename = $CFG->tempdir."/backup/".$backup_unique_code."/".$backup_unique_code."_".$table."_".$old_id.".info";
//Read data from file
$status2 = backup_file2data($filename,$info);
if ($status2) {
Expand Down
2 changes: 1 addition & 1 deletion backup/restorefile.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
$browser = get_file_browser();

// check if tmp dir exists
$tmpdir = $CFG->dataroot . '/temp/backup';
$tmpdir = $CFG->tempdir . '/backup';
if (!check_dir_exists($tmpdir, true, true)) {
throw new restore_controller_exception('cannot_create_backup_temp_dir');
}
Expand Down
4 changes: 2 additions & 2 deletions backup/util/factories/backup_factory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public static function get_logger_chain($interactive, $execution, $backupid) {

// Create file_logger, observing $CFG->backup_file_logger_level
// defaulting to $dfltloglevel
check_dir_exists($CFG->dataroot . '/temp/backup', true, true); // need to ensure that temp/backup already exists
check_dir_exists($CFG->tempdir . '/backup', true, true); // need to ensure that temp/backup already exists
$fllevel = isset($CFG->backup_file_logger_level) ? $CFG->backup_file_logger_level : $dfltloglevel;
$enabledloggers[] = new file_logger($fllevel, true, true, $CFG->dataroot . '/temp/backup/' . $backupid . '.log');
$enabledloggers[] = new file_logger($fllevel, true, true, $CFG->tempdir . '/backup/' . $backupid . '.log');

// Create database_logger, observing $CFG->backup_database_logger_level and defaulting to LOG_WARNING
// and pointing to the backup_logs table
Expand Down
2 changes: 1 addition & 1 deletion backup/util/helper/backup_file_manager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class backup_file_manager {
public static function get_backup_storage_base_dir($backupid) {
global $CFG;

return $CFG->dataroot . '/temp/backup/' . $backupid . '/files';
return $CFG->tempdir . '/backup/' . $backupid . '/files';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion backup/util/helper/backup_general_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function get_backup_information($tempdir) {

$info = new stdclass(); // Final information goes here

$moodlefile = $CFG->dataroot . '/temp/backup/' . $tempdir . '/moodle_backup.xml';
$moodlefile = $CFG->tempdir . '/backup/' . $tempdir . '/moodle_backup.xml';
if (!file_exists($moodlefile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_moodle_backup_xml_file', $moodlefile);
}
Expand Down
10 changes: 5 additions & 5 deletions backup/util/helper/backup_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class backup_helper {
*/
static public function check_and_create_backup_dir($backupid) {
global $CFG;
if (!check_dir_exists($CFG->dataroot . '/temp/backup/' . $backupid, true, true)) {
if (!check_dir_exists($CFG->tempdir . '/backup/' . $backupid, true, true)) {
throw new backup_helper_exception('cannot_create_backup_temp_dir');
}
}
Expand All @@ -44,7 +44,7 @@ static public function check_and_create_backup_dir($backupid) {
*/
static public function clear_backup_dir($backupid) {
global $CFG;
if (!self::delete_dir_contents($CFG->dataroot . '/temp/backup/' . $backupid)) {
if (!self::delete_dir_contents($CFG->tempdir . '/backup/' . $backupid)) {
throw new backup_helper_exception('cannot_empty_backup_temp_dir');
}
return true;
Expand All @@ -56,7 +56,7 @@ static public function clear_backup_dir($backupid) {
static public function delete_backup_dir($backupid) {
global $CFG;
self::clear_backup_dir($backupid);
return rmdir($CFG->dataroot . '/temp/backup/' . $backupid);
return rmdir($CFG->tempdir . '/backup/' . $backupid);
}

/**
Expand Down Expand Up @@ -132,9 +132,9 @@ static public function delete_old_backup_dirs($deletefrom) {

$status = true;
// Get files and directories in the temp backup dir witout descend
$list = get_directory_list($CFG->dataroot . '/temp/backup', '', false, true, true);
$list = get_directory_list($CFG->tempdir . '/backup', '', false, true, true);
foreach ($list as $file) {
$file_path = $CFG->dataroot . '/temp/backup/' . $file;
$file_path = $CFG->tempdir . '/backup/' . $file;
$moddate = filemtime($file_path);
if ($status && $moddate < $deletefrom) {
//If directory, recurse
Expand Down
2 changes: 1 addition & 1 deletion backup/util/helper/convert_helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function available_converters() {
public static function detect_moodle2_format($tempdir) {
global $CFG;

$dirpath = $CFG->dataroot . '/temp/backup/' . $tempdir;
$dirpath = $CFG->tempdir . '/backup/' . $tempdir;
$filepath = $dirpath . '/moodle_backup.xml';

if (!is_dir($dirpath)) {
Expand Down
10 changes: 5 additions & 5 deletions backup/util/loggers/simpletest/testlogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function test_database_logger() {
function test_file_logger() {
global $CFG;

$file = $CFG->dataroot . '/temp/test/test_file_logger.txt';
$file = $CFG->tempdir . '/test/test_file_logger.txt';
// Remove the test dir and any content
@remove_dir(dirname($file));
// Recreate test dir
Expand Down Expand Up @@ -272,7 +272,7 @@ function test_file_logger() {
unlink($file); // delete file

// Try one html file
$file = $CFG->dataroot . '/temp/test/test_file_logger.html';
$file = $CFG->tempdir . '/test/test_file_logger.html';
$options = array('depth' => 1);
$lo = new file_logger(backup::LOG_ERROR, true, true, $file);
$this->assertTrue($lo instanceof file_logger);
Expand All @@ -289,7 +289,7 @@ function test_file_logger() {
unlink($file); // delete file

// Instantiate, write something, force deletion, try to write again
$file = $CFG->dataroot . '/temp/test/test_file_logger.html';
$file = $CFG->tempdir . '/test/test_file_logger.html';
$lo = new mock_file_logger(backup::LOG_ERROR, true, true, $file);
$this->assertTrue(file_exists($file));
$message = 'testing file_logger';
Expand All @@ -313,7 +313,7 @@ function test_file_logger() {
}

// Instantiate in (near) impossible path
$file = $CFG->dataroot . '/temp/test_azby/test_file_logger.txt';
$file = $CFG->tempdir . '/test_azby/test_file_logger.txt';
try {
$lo = new file_logger(backup::LOG_WARNING, true, true, $file);
$this->assertTrue(false, 'base_logger_exception expected');
Expand All @@ -324,7 +324,7 @@ function test_file_logger() {
}

// Instatiate one file logger with level = backup::LOG_NONE
$file = $CFG->dataroot . '/temp/test/test_file_logger.txt';
$file = $CFG->tempdir . '/test/test_file_logger.txt';
$lo = new file_logger(backup::LOG_NONE, true, true, $file);
$this->assertTrue($lo instanceof file_logger);
$this->assertFalse(file_exists($file));
Expand Down
2 changes: 1 addition & 1 deletion backup/util/plan/backup_plan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($controller) {
throw new backup_plan_exception('wrong_backup_controller_specified');
}
$this->controller = $controller;
$this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_backupid();
$this->basepath = $CFG->tempdir . '/backup/' . $controller->get_backupid();
parent::__construct('backup_plan');
}

Expand Down
2 changes: 1 addition & 1 deletion backup/util/plan/restore_plan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct($controller) {
throw new restore_plan_exception('wrong_restore_controller_specified');
}
$this->controller = $controller;
$this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_tempdir();
$this->basepath = $CFG->tempdir . '/backup/' . $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;
Expand Down
Loading

0 comments on commit 7aa06e6

Please sign in to comment.