From 145a0a317b8366bbe835329eaf761708e4ecc681 Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 8 Aug 2008 11:50:45 +0000 Subject: [PATCH] MDL-14589 more local --> stored renaming --- lang/en_utf8/error.php | 8 ++--- lib/file/file_browser.php | 42 +++++++++++++------------- lib/file/file_exceptions.php | 2 +- lib/file/file_info_coursefile.php | 4 +-- lib/file/file_info_stored.php | 8 ++--- lib/file/file_storage.php | 50 +++++++++++++++---------------- lib/file/stored_file.php | 8 ++--- 7 files changed, 61 insertions(+), 61 deletions(-) diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 27dc40ddf3..cc287ada19 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -291,10 +291,6 @@ $string['listcantmoveup'] = 'Failed to move the item up, as it is the first of i $string['listcantmovedown'] = 'Failed to move item down, as it is the last of it\'s peers'; $string['listcantmoveleft'] = 'Failed to move item left, as it has no parent'; $string['listcantmoveright'] = 'Failed to move item right, as there is no peer to make it a child of. Move it below another peer and then you can move it right.'; -$string['localfilecannotcreatefiledirs'] = 'Can not create local file pool directories, please verify permissions in dataroot.'; -$string['localfilecannotread'] = 'Can not read file, either file does not exist or there are permission problems'; -$string['localfilenotcreated'] = 'Can not create file \"$a->contextid/$a->filearea/$a->itemid/$a->filepath/$a->filename\"'; -$string['localfileproblem'] = 'Unknown exception related to local files ($a)'; $string['loginasonecourse'] = 'You cannot enter this course.
You have to terminate the \"Login as\" session before entering any other course.'; $string['loginasnoenrol'] = 'You cannot use enrol or unenrol when in course \"Login as\" session'; $string['logfilenotavailable'] = 'Logs not available'; @@ -387,6 +383,10 @@ $string['sessionipnomatch'] = 'Sorry, but your IP number seems to have changed f $string['socksnotsupported'] = 'SOCKS5 proxy is not supported in PHP4'; $string['spellcheckernotconf'] = 'Spellchecker not configured'; $string['statscatchupmode'] = 'Statistics is currently in catchup mode. So far $a->daysdone day(s) have been processed and $a->dayspending are pending. Check back soon!'; +$string['storedfilecannotcreatefiledirs'] = 'Can not create local file pool directories, please verify permissions in dataroot.'; +$string['storedfilecannotread'] = 'Can not read file, either file does not exist or there are permission problems'; +$string['storedfilenotcreated'] = 'Can not create file \"$a->contextid/$a->filearea/$a->itemid/$a->filepath/$a->filename\"'; +$string['storedfileproblem'] = 'Unknown exception related to local files ($a)'; $string['tagnotfound'] = 'The specified tag was not found in the database'; $string['tagdisabled'] = 'Tags are disabled!'; $string['themenotinstall'] = 'This theme is not installed!'; diff --git a/lib/file/file_browser.php b/lib/file/file_browser.php index 33a22698bf..1e29acc4e9 100644 --- a/lib/file/file_browser.php +++ b/lib/file/file_browser.php @@ -54,9 +54,9 @@ class file_browser { $filepath = is_null($filepath) ? '/' : $filepath; $filename = is_null($filename) ? '.' : $filename; - if (!$localfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { + if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { - $localfile = $fs->create_directory($context->id, $filearea, 0, $filepath, $USER->id); + $storedfile = $fs->create_directory($context->id, $filearea, 0, $filepath, $USER->id); } else { // not found return null; @@ -64,19 +64,19 @@ class file_browser { } $urlbase = $CFG->wwwroot.'/userfile.php'; // TODO: localise - return new file_info_stored($this, $context, $localfile, $urlbase, 'Personal files', false, true, true); + return new file_info_stored($this, $context, $storedfile, $urlbase, 'Personal files', false, true, true); } else if ($filearea == 'user_draft') { if (empty($itemid)) { return new file_info_user($this, $context); } $urlbase = $CFG->wwwroot.'/draftfile.php'; - if (!$localfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) { + if (!$storedfile = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) { return null; } //something must create the top most directory // TODO: localise - return new file_info_stored($this, $context, $localfile, $urlbase, 'Draft file area', true, true, true); + return new file_info_stored($this, $context, $storedfile, $urlbase, 'Draft file area', true, true, true); } } @@ -107,16 +107,16 @@ class file_browser { $filename = is_null($filename) ? '.' : $filename; $urlbase = $CFG->wwwroot.'/pluginfile.php'; - if (!$localfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { + if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { - $localfile = $fs->create_directory($context->id, $filearea, 0, $filepath); + $storedfile = $fs->create_directory($context->id, $filearea, 0, $filepath); } else { // not found return null; } } // TODO: localise - return new file_info_stored($this, $context, $localfile, $urlbase, 'Category introduction files', false, true, true); + return new file_info_stored($this, $context, $storedfile, $urlbase, 'Category introduction files', false, true, true); } } @@ -148,16 +148,16 @@ class file_browser { } $urlbase = $CFG->wwwroot.'/pluginfile.php'; - if (!$localfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { + if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { - $localfile = $fs->create_directory($context->id, $filearea, 0, $filepath); + $storedfile = $fs->create_directory($context->id, $filearea, 0, $filepath); } else { // not found return null; } } // TODO: localise - return new file_info_stored($this, $context, $localfile, $urlbase, 'Course introduction files', false, true, true); + return new file_info_stored($this, $context, $storedfile, $urlbase, 'Course introduction files', false, true, true); } else if ($filearea == 'course_backup') { if (!has_capability('moodle/site:backup', $context) and !has_capability('moodle/site:restore', $context)) { @@ -165,9 +165,9 @@ class file_browser { } $urlbase = $CFG->wwwroot.'/pluginfile.php'; - if (!$localfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { + if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { - $localfile = $fs->create_directory($context->id, $filearea, 0, $filepath); + $storedfile = $fs->create_directory($context->id, $filearea, 0, $filepath); } else { // not found return null; @@ -177,23 +177,23 @@ class file_browser { $downloadable = has_capability('moodle/site:backupdownload', $context); $uploadable = has_capability('moodle/site:backupupload', $context); // TODO: localise - return new file_info_stored($this, $context, $localfile, $urlbase, 'Backup files', false, $downloadable, $uploadable); + return new file_info_stored($this, $context, $storedfile, $urlbase, 'Backup files', false, $downloadable, $uploadable); } else if ($filearea == 'course_content') { if (!has_capability('moodle/course:managefiles', $context)) { return null; } - if (!$localfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { + if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { if ($filepath === '/' and $filename === '.') { - $localfile = $fs->create_directory($context->id, $filearea, 0, $filepath); + $storedfile = $fs->create_directory($context->id, $filearea, 0, $filepath); } else { // not found return null; } } - return new file_info_coursefile($this, $context, $localfile); + return new file_info_coursefile($this, $context, $storedfile); } } @@ -211,8 +211,8 @@ class file_browser { $result = array(); $fs = get_file_storage(); - $localfiles = $fs->get_directory_files($context->id, $filearea, $itemid, $filepath, false, true, "filepath, filename"); - foreach ($localfiles as $file) { + $storedfiles = $fs->get_directory_files($context->id, $filearea, $itemid, $filepath, false, true, "filepath, filename"); + foreach ($storedfiles as $file) { $result[] = new file_info_stored($this, $context, $file, $urlbase, $areavisiblename, $itemidused, $readaccess, $writeaccess); } @@ -226,8 +226,8 @@ class file_browser { $result = array(); $fs = get_file_storage(); - $localfiles = $fs->get_directory_files($context->id, 'course_content', 0, $filepath, false, true, "filepath, filename"); - foreach ($localfiles as $file) { + $storedfiles = $fs->get_directory_files($context->id, 'course_content', 0, $filepath, false, true, "filepath, filename"); + foreach ($storedfiles as $file) { $result[] = new file_info_coursefile($this, $context, $file); } diff --git a/lib/file/file_exceptions.php b/lib/file/file_exceptions.php index ab58bb22f8..8fbf84e62f 100644 --- a/lib/file/file_exceptions.php +++ b/lib/file/file_exceptions.php @@ -20,7 +20,7 @@ class stored_file_creation_exception extends file_exception { $a->itemid = $itemid; $a->filepath = $filepath; $a->filename = $filename; - parent::__construct('localfilenotcreated', $a, $debuginfo); + parent::__construct('storedfilenotcreated', $a, $debuginfo); } } diff --git a/lib/file/file_info_coursefile.php b/lib/file/file_info_coursefile.php index d255362833..9ebc3b4846 100644 --- a/lib/file/file_info_coursefile.php +++ b/lib/file/file_info_coursefile.php @@ -1,10 +1,10 @@ wwwroot.'/file.php'; - parent::__construct($browser, $context, $localfile, $urlbase, 'Course files', false, true, true); // TODO: localise + parent::__construct($browser, $context, $storedfile, $urlbase, 'Course files', false, true, true); // TODO: localise } public function get_url($forcedownload=false, $https=false) { diff --git a/lib/file/file_info_stored.php b/lib/file/file_info_stored.php index a7ff4a77f6..dc92a38d2b 100644 --- a/lib/file/file_info_stored.php +++ b/lib/file/file_info_stored.php @@ -8,10 +8,10 @@ class file_info_stored extends file_info { protected $readaccess; protected $writeaccess; - public function __construct($browser, $context, $localfile, $urlbase, $areavisiblename, $itemidused, $readaccess, $writeaccess) { + public function __construct($browser, $context, $storedfile, $urlbase, $areavisiblename, $itemidused, $readaccess, $writeaccess) { parent::__construct($browser, $context); - $this->lf = $localfile; + $this->lf = $storedfile; $this->urlbase = $urlbase; $this->areavisiblename = $areavisiblename; $this->itemidused = $itemidused; @@ -265,8 +265,8 @@ class file_info_stored extends file_info { if ($this->is_directory()) { $filepath = $this->lf->get_filepath(); $fs = get_file_storage(); - $localfiles = $fs->get_area_files($this->context->id, $this->lf->get_filearea(), $this->lf->get_itemid(), ""); - foreach ($localfiles as $file) { + $storedfiles = $fs->get_area_files($this->context->id, $this->lf->get_filearea(), $this->lf->get_itemid(), ""); + foreach ($storedfiles as $file) { if (strpos($file->get_filepath(), $filepath) === 0) { $file->delete(); } diff --git a/lib/file/file_storage.php b/lib/file/file_storage.php index a4c206751d..38093c9659 100644 --- a/lib/file/file_storage.php +++ b/lib/file/file_storage.php @@ -15,7 +15,7 @@ class file_storage { // make sure the file pool directory exists if (!is_dir($this->filedir)) { if (!check_dir_exists($this->filedir, true, true)) { - throw new file_exception('localfilecannotcreatefiledirs'); // permission trouble + throw new file_exception('storedfilecannotcreatefiledirs'); // permission trouble } // place warning file in file pool root file_put_contents($this->filedir.'/warning.txt', @@ -280,22 +280,22 @@ class file_storage { // validate all parameters, we do not want any rubbish stored in database, right? if (!is_number($contextid) or $contextid < 1) { - throw new file_exception('localfileproblem', 'Invalid contextid'); + throw new file_exception('storedfileproblem', 'Invalid contextid'); } $filearea = clean_param($filearea, PARAM_ALPHAEXT); if ($filearea === '') { - throw new file_exception('localfileproblem', 'Invalid filearea'); + throw new file_exception('storedfileproblem', 'Invalid filearea'); } if (!is_number($itemid) or $itemid < 0) { - throw new file_exception('localfileproblem', 'Invalid itemid'); + throw new file_exception('storedfileproblem', 'Invalid itemid'); } $filepath = clean_param($filepath, PARAM_PATH); if (strpos($filepath, '/') !== 0 or strrpos($filepath, '/') !== strlen($filepath)-1) { // path must start and end with '/' - throw new file_exception('localfileproblem', 'Invalid file path'); + throw new file_exception('storedfileproblem', 'Invalid file path'); } $pathnamehash = $this->get_pathname_hash($contextid, $filearea, $itemid, $filepath, '.'); @@ -361,7 +361,7 @@ class file_storage { $now = time(); if ($newrecord = $DB->get_record('files', array('id'=>$fid))) { - throw new file_exception('localfileproblem', 'File does not exist'); + throw new file_exception('storedfileproblem', 'File does not exist'); } unset($newrecord->id); @@ -369,18 +369,18 @@ class file_storage { foreach ($file_record as $key=>$value) { // validate all parameters, we do not want any rubbish stored in database, right? if ($key == 'contextid' and (!is_number($value) or $value < 1)) { - throw new file_exception('localfileproblem', 'Invalid contextid'); + throw new file_exception('storedfileproblem', 'Invalid contextid'); } if ($key == 'filearea') { $value = clean_param($value, PARAM_ALPHAEXT); if ($value === '') { - throw new file_exception('localfileproblem', 'Invalid filearea'); + throw new file_exception('storedfileproblem', 'Invalid filearea'); } } if ($key == 'itemid' and (!is_number($value) or $value < 0)) { - throw new file_exception('localfileproblem', 'Invalid itemid'); + throw new file_exception('storedfileproblem', 'Invalid itemid'); } @@ -388,7 +388,7 @@ class file_storage { $value = clean_param($value, PARAM_PATH); if (strpos($value, '/') !== 0 or strpos($value, '/') !== strlen($value)-1) { // path must start and end with '/' - throw new file_exception('localfileproblem', 'Invalid file path'); + throw new file_exception('storedfileproblem', 'Invalid file path'); } } @@ -396,7 +396,7 @@ class file_storage { $value = clean_param($value, PARAM_FILE); if ($value === '') { // path must start and end with '/' - throw new file_exception('localfileproblem', 'Invalid file name'); + throw new file_exception('storedfileproblem', 'Invalid file name'); } } @@ -434,28 +434,28 @@ class file_storage { // validate all parameters, we do not want any rubbish stored in database, right? if (!is_number($file_record->contextid) or $file_record->contextid < 1) { - throw new file_exception('localfileproblem', 'Invalid contextid'); + throw new file_exception('storedfileproblem', 'Invalid contextid'); } $file_record->filearea = clean_param($file_record->filearea, PARAM_ALPHAEXT); if ($file_record->filearea === '') { - throw new file_exception('localfileproblem', 'Invalid filearea'); + throw new file_exception('storedfileproblem', 'Invalid filearea'); } if (!is_number($file_record->itemid) or $file_record->itemid < 0) { - throw new file_exception('localfileproblem', 'Invalid itemid'); + throw new file_exception('storedfileproblem', 'Invalid itemid'); } $file_record->filepath = clean_param($file_record->filepath, PARAM_PATH); if (strpos($file_record->filepath, '/') !== 0 or strrpos($file_record->filepath, '/') !== strlen($file_record->filepath)-1) { // path must start and end with '/' - throw new file_exception('localfileproblem', 'Invalid file path'); + throw new file_exception('storedfileproblem', 'Invalid file path'); } $file_record->filename = clean_param($file_record->filename, PARAM_FILE); if ($file_record->filename === '') { // path must start and end with '/' - throw new file_exception('localfileproblem', 'Invalid file name'); + throw new file_exception('storedfileproblem', 'Invalid file name'); } $now = time(); @@ -509,28 +509,28 @@ class file_storage { // validate all parameters, we do not want any rubbish stored in database, right? if (!is_number($file_record->contextid) or $file_record->contextid < 1) { - throw new file_exception('localfileproblem', 'Invalid contextid'); + throw new file_exception('storedfileproblem', 'Invalid contextid'); } $file_record->filearea = clean_param($file_record->filearea, PARAM_ALPHAEXT); if ($file_record->filearea === '') { - throw new file_exception('localfileproblem', 'Invalid filearea'); + throw new file_exception('storedfileproblem', 'Invalid filearea'); } if (!is_number($file_record->itemid) or $file_record->itemid < 0) { - throw new file_exception('localfileproblem', 'Invalid itemid'); + throw new file_exception('storedfileproblem', 'Invalid itemid'); } $file_record->filepath = clean_param($file_record->filepath, PARAM_PATH); if (strpos($file_record->filepath, '/') !== 0 or strrpos($file_record->filepath, '/') !== strlen($file_record->filepath)-1) { // path must start and end with '/' - throw new file_exception('localfileproblem', 'Invalid file path'); + throw new file_exception('storedfileproblem', 'Invalid file path'); } $file_record->filename = clean_param($file_record->filename, PARAM_FILE); if ($file_record->filename === '') { // path must start and end with '/' - throw new file_exception('localfileproblem', 'Invalid file name'); + throw new file_exception('storedfileproblem', 'Invalid file name'); } $now = time(); @@ -579,7 +579,7 @@ class file_storage { */ public function add_file_to_pool($pathname, $contenthash=null) { if (!is_readable($pathname)) { - throw new file_exception('localfilecannotread'); + throw new file_exception('storedfilecannotread'); } if (is_null($contenthash)) { @@ -599,12 +599,12 @@ class file_storage { } else { if (!check_dir_exists($hashpath, true, true)) { - throw new file_exception('localfilecannotcreatefiledirs'); // permission trouble + throw new file_exception('storedfilecannotcreatefiledirs'); // permission trouble } $newfile = true; if (!copy($pathname, $hashfile)) { - throw new file_exception('localfilecannotread'); + throw new file_exception('storedfilecannotread'); } if (filesize($hashfile) !== $filesize) { @@ -638,7 +638,7 @@ class file_storage { } else { if (!check_dir_exists($hashpath, true, true)) { - throw new file_exception('localfilecannotcreatefiledirs'); // permission trouble + throw new file_exception('storedfilecannotcreatefiledirs'); // permission trouble } $newfile = true; diff --git a/lib/file/stored_file.php b/lib/file/stored_file.php index dae35b3a88..8da8965641 100644 --- a/lib/file/stored_file.php +++ b/lib/file/stored_file.php @@ -56,7 +56,7 @@ class stored_file { public function get_content_file_handle() { $path = $this->get_content_file_location(); if (!is_readable($path)) { - throw new file_exception('localfilecannotread'); + throw new file_exception('storedfilecannotread'); } return fopen($path, 'rb'); //binary reading only!! } @@ -68,7 +68,7 @@ class stored_file { public function readfile() { $path = $this->get_content_file_location(); if (!is_readable($path)) { - throw new file_exception('localfilecannotread'); + throw new file_exception('storedfilecannotread'); } readfile($path); } @@ -80,7 +80,7 @@ class stored_file { public function get_content() { $path = $this->get_content_file_location(); if (!is_readable($path)) { - throw new file_exception('localfilecannotread'); + throw new file_exception('storedfilecannotread'); } return file_get_contents($this->get_content_file_location()); } @@ -93,7 +93,7 @@ class stored_file { public function copy_content_to($pathname) { $path = $this->get_content_file_location(); if (!is_readable($path)) { - throw new file_exception('localfilecannotread'); + throw new file_exception('storedfilecannotread'); } return copy($path, $pathname); } -- 2.39.5