本文整理汇总了PHP中backup_controller::load_controller方法的典型用法代码示例。如果您正苦于以下问题:PHP backup_controller::load_controller方法的具体用法?PHP backup_controller::load_controller怎么用?PHP backup_controller::load_controller使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backup_controller
的用法示例。
在下文中一共展示了backup_controller::load_controller方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store_backup_file
/**
* Given one backupid and the (FS) final generated file, perform its final storage
* into Moodle file storage. For stored files it returns the complete file_info object
*
* Note: the $filepath is deleted if the backup file is created successfully
*
* If you specify the progress monitor, this will start a new progress section
* to track progress in processing (in case this task takes a long time).
*
* @param int $backupid
* @param string $filepath zip file containing the backup
* @param \core\progress\base $progress Optional progress monitor
* @return stored_file if created, null otherwise
*
* @throws moodle_exception in case of any problems
*/
public static function store_backup_file($backupid, $filepath, \core\progress\base $progress = null)
{
global $CFG;
// 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, $progress);
// Extract useful information to decide
$hasusers = (bool) $sinfo['users']->value;
// Backup has users
$isannon = (bool) $sinfo['anonymize']->value;
// Backup is anonymised
$filename = $sinfo['filename']->value;
// Backup filename
$backupmode = $dinfo[0]->mode;
// Backup mode backup::MODE_GENERAL/IMPORT/HUB
$backuptype = $dinfo[0]->type;
// Backup type backup::TYPE_1ACTIVITY/SECTION/COURSE
$userid = $dinfo[0]->userid;
// User->id executing the backup
$id = $dinfo[0]->id;
// Id of activity/section/course (depends of type)
$courseid = $dinfo[0]->courseid;
// Id of the course
$format = $dinfo[0]->format;
// Type of backup file
// Quick hack. If for any reason, filename is blank, fix it here.
// TODO: This hack will be out once MDL-22142 - P26 gets fixed
if (empty($filename)) {
$filename = backup_plan_dbops::get_default_backup_filename('moodle2', $backuptype, $id, $hasusers, $isannon);
}
// Backups of type IMPORT aren't stored ever
if ($backupmode == backup::MODE_IMPORT) {
return null;
}
if (!is_readable($filepath)) {
// we have a problem if zip file does not exist
throw new coding_exception('backup_helper::store_backup_file() expects valid $filepath parameter');
}
// Calculate file storage options of id being backup
$ctxid = 0;
$filearea = '';
$component = '';
$itemid = 0;
switch ($backuptype) {
case backup::TYPE_1ACTIVITY:
$ctxid = context_module::instance($id)->id;
$component = 'backup';
$filearea = 'activity';
$itemid = 0;
break;
case backup::TYPE_1SECTION:
$ctxid = context_course::instance($courseid)->id;
$component = 'backup';
$filearea = 'section';
$itemid = $id;
break;
case backup::TYPE_1COURSE:
$ctxid = context_course::instance($courseid)->id;
$component = 'backup';
$filearea = 'course';
$itemid = 0;
break;
}
if ($backupmode == backup::MODE_AUTOMATED) {
// Automated backups have there own special area!
$filearea = 'automated';
// If we're keeping the backup only in a chosen path, just move it there now
// this saves copying from filepool to here later and filling trashdir.
$config = get_config('backup');
$dir = $config->backup_auto_destination;
if ($config->backup_auto_storage == 1 and $dir and is_dir($dir) and is_writable($dir)) {
$filedest = $dir . '/' . backup_plan_dbops::get_default_backup_filename($format, $backuptype, $courseid, $hasusers, $isannon, !$config->backup_shortname);
// first try to move the file, if it is not possible copy and delete instead
if (@rename($filepath, $filedest)) {
return null;
}
umask($CFG->umaskpermissions);
if (copy($filepath, $filedest)) {
@chmod($filedest, $CFG->filepermissions);
// may fail because the permissions may not make sense outside of dataroot
unlink($filepath);
return null;
} else {
$bc = backup_controller::load_controller($backupid);
$bc->log('Attempt to copy backup file to the specified directory using filesystem failed - ', backup::LOG_WARNING, $dir);
//.........这里部分代码省略.........
示例2: load_controller
/**
* Loads the backup controller if we are tracking one
* @return backup_controller|false
*/
public static final function load_controller($backupid = false)
{
// Get the backup id optional param
if ($backupid) {
try {
// Try to load the controller with it.
// If it fails at this point it is likely because this is the first load
$controller = backup_controller::load_controller($backupid);
return $controller;
} catch (Exception $e) {
return false;
}
}
return $backupid;
}