mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
MDL-22145 backup storage - provide 'user_tohub' storage for HUB files
This commit is contained in:
parent
96449a1698
commit
ce937f9957
11 changed files with 131 additions and 12 deletions
|
@ -163,6 +163,44 @@ abstract class backup_helper {
|
|||
output_controller::get_instance()->output($message, 'backup', $a, $depth);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one backupid and the (FS) final generated file, perform its final storage
|
||||
* into Moodle file storage
|
||||
*/
|
||||
static public function store_backup_file($backupid, $filepath) {
|
||||
|
||||
// First of all, get some information from the backup_controller to help us decide
|
||||
list($dinfo, $cinfo, $sinfo) = backup_controller_dbops::get_moodle_backup_information($backupid);
|
||||
|
||||
// Extract useful information to decide
|
||||
$hasusers = (bool)$sinfo['users']->value; // Backup has users
|
||||
$isannon = (bool)$sinfo['anonymize']->value; // Backup is annonymzed
|
||||
$backupmode= $dinfo[0]->mode; // Backup mode backup::MODE_GENERAL/IMPORT/HUB
|
||||
$userid = $dinfo[0]->userid; // User->id executing the backup
|
||||
|
||||
// Backups of type IMPORT aren't stored ever
|
||||
if ($backupmode == backup::MODE_IMPORT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Backups of type HUB (by definition never have user info)
|
||||
// are sent to user's "user_tohub" file area. The upload process
|
||||
// will be responsible for cleaning that filearea once finished
|
||||
if ($backupmode == backup::MODE_HUB) {
|
||||
$ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
|
||||
$fs = get_file_storage();
|
||||
$fr = array(
|
||||
'contextid' => $ctxid,
|
||||
'filearea' => 'user_tohub',
|
||||
'itemid' => 0,
|
||||
'filepath' => '/',
|
||||
'filename' => basename($filepath),
|
||||
'timecreated' => time(),
|
||||
'timemodified'=> time());
|
||||
return $fs->create_file_from_pathname($fr, $filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue