Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-23885 fixed file api encapsulation and lowering number of direcor…

…ies in zip files
  • Loading branch information...
commit 2b199e7c0b270522a4abece7c65ca53f486d3169 1 parent d4514e4
@skodak skodak authored
View
4 backup/util/dbops/restore_dbops.class.php
@@ -298,7 +298,7 @@ public static function send_files_to_pool($basepath, $restoreid, $component, $fi
}
// arrived here, file found
// Find file in backup pool
- $backuppath = $basepath . backup_file_manager::get_content_file_location($file->contenthash);
+ $backuppath = $basepath . backup_file_manager::get_backup_content_file_location($file->contenthash);
if (!file_exists($backuppath)) {
throw new restore_dbops_exception('file_not_found_in_pool', $file);
}
@@ -920,7 +920,7 @@ public static function create_new_course($fullname, $shortname, $categoryid) {
$course->timemodified = $course->timecreated;
$course->visible = $category->visible;
- return $DB->insert_record('course', $course);
+ return $DB->insert_record('course', $course);
}
/**
View
37 backup/util/helper/backup_file_manager.class.php
@@ -33,27 +33,11 @@
* those functions without needeing to know storage internals at all.
* That day, we'll move related functions here to proper file api ones.
*
- * TODO: Unse File API facilities when available instead of har-coded
- * storage access here.
- *
* TODO: Finish phpdocs
*/
class backup_file_manager {
/**
- * Returns the full path to the storage base dir
- */
- public static function get_moodle_storage_base_dir() {
- global $CFG;
-
- if (isset($CFG->filedir)) {
- return $CFG->filedir;
- } else {
- return $CFG->dataroot.'/filedir';
- }
- }
-
- /**
* Returns the full path to backup storage base dir
*/
public static function get_backup_storage_base_dir($backupid) {
@@ -66,10 +50,9 @@ public static function get_backup_storage_base_dir($backupid) {
* Given one file content hash, returns the path (relative to filedir)
* to the file.
*/
- public static function get_content_file_location($contenthash) {
+ public static function get_backup_content_file_location($contenthash) {
$l1 = $contenthash[0].$contenthash[1];
- $l2 = $contenthash[2].$contenthash[3];
- return "$l1/$l2/$contenthash";
+ return "$l1/$contenthash";
}
/**
@@ -88,16 +71,12 @@ public static function copy_file_moodle2backup($backupid, $filerecorid) {
return;
}
+ $fs = get_file_storage();
+ $file = new stored_file($fs, $filerecorid);
+
// Calculate source and target paths (use same subdirs strategy for both)
- $sourcefilepath = self::get_moodle_storage_base_dir() . '/' .
- self::get_content_file_location($filerecorid->contenthash);
$targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' .
- self::get_content_file_location($filerecorid->contenthash);
-
- // Check source exists and is readable
- if (!file_exists($sourcefilepath) || !is_readable($sourcefilepath)) {
- throw new backup_helper_exception('cannot_read_file_from_filepool', $sourcefilepath);
- }
+ self::get_backup_content_file_location($filerecorid->contenthash);
// Create target dir if necessary
if (!file_exists(dirname($targetfilepath))) {
@@ -108,9 +87,7 @@ public static function copy_file_moodle2backup($backupid, $filerecorid) {
// And copy the file (if doesn't exist already)
if (!file_exists($targetfilepath)) {
- if (!copy($sourcefilepath, $targetfilepath)) {
- throw new backup_helper_exception('cannot_copy_file', $sourcefilepath, $targetfilepath);
- }
+ $file->copy_content_to($targetfilepath);
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.