本文整理汇总了PHP中restore_controller::get_logger方法的典型用法代码示例。如果您正苦于以下问题:PHP restore_controller::get_logger方法的具体用法?PHP restore_controller::get_logger怎么用?PHP restore_controller::get_logger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类restore_controller
的用法示例。
在下文中一共展示了restore_controller::get_logger方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: restore
/**
* Takes backupid and original course object as arguments and returns a new courseid.
*
* @param string $backupid The backupid
* @param object $newcourse Target course object
* @throws coding_exception Moodle coding exception
*/
private function restore($backupid, $newcourse)
{
global $CFG, $DB, $USER;
// Call restore.
$rc = new \restore_controller($backupid, $newcourse->id, \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id, \backup::TARGET_EXISTING_ADDING);
// Setup custom logger that prints dots.
$logger = new logger(\backup::LOG_INFO, false, true);
self::$currentlogger = $logger;
$logger->potential_dot();
$rc->get_logger()->set_next($logger);
$rc->set_progress(new progress());
foreach ($rc->get_plan()->get_tasks() as $taskindex => $task) {
$settings = $task->get_settings();
foreach ($settings as $settingindex => $setting) {
// Set userinfo true for activity, since we controlled it
// more accurately (i.e. true only for glossary) in backup.
if (preg_match('/^glossary_([0-9])*_userinfo$$/', $setting->get_name())) {
$setting->set_value(true);
}
if ($taskindex == 0 && isset($this->backupsettings[$setting->get_name()])) {
$setting->set_value($this->backupsettings[$setting->get_name()]);
}
}
}
if (!$rc->execute_precheck()) {
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($this->backupbasepath);
}
$results = print_r($rc->get_precheck_results(), true);
print \html_writer::tag('pre', s($results));
throw new \coding_exception('Restore precheck error.');
}
$logger->potential_dot();
$rc->execute_plan();
$rc->destroy();
// Delete backup file.
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($this->backupbasepath);
}
}
示例2: get_logger
public function get_logger()
{
return $this->controller->get_logger();
}
示例3: execute
/**
* Execute scheduled task
*
* @return boolean
*/
public function execute()
{
global $CFG, $DB;
require_once $CFG->libdir . '/moodlelib.php';
require_once $CFG->libdir . '/filestorage/zip_packer.php';
require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php';
// Get plugin config
$local_sandbox_config = get_config('local_sandbox');
// Counter for restored courses
$count = 0;
// Do only when sandbox directory is configured
if ($local_sandbox_config->coursebackupsdirectory != '') {
// Do only when sandbox directory exists
if (is_dir($local_sandbox_config->coursebackupsdirectory)) {
// Open directory and get all .mbz files
if ($handle = @opendir($local_sandbox_config->coursebackupsdirectory)) {
while (false !== ($file = readdir($handle))) {
if (substr($file, -4) == '.mbz' && $file != '.' && $file != '..') {
// Get course shortname from filename
$shortname = substr($file, 0, -4);
echo "\n\t" . get_string('nowprocessing', 'local_sandbox', $shortname) . "\n";
// Get existing course information
if ($oldcourse = $DB->get_record('course', array('shortname' => $shortname))) {
$oldcourseid = $oldcourse->id;
$categoryid = $oldcourse->category;
$fullname = $oldcourse->fullname;
} else {
// Output error message for cron listing
echo "\n\t" . get_string('skippingnocourse', 'local_sandbox', $shortname) . "\n";
// Inform admin
local_sandbox_inform_admin(get_string('skippingnocourse', 'local_sandbox', $shortname), SANDBOX_LEVEL_WARNING);
continue;
}
// Delete existing course
if (!delete_course($oldcourseid, false)) {
// Output error message for cron listing
echo "\n\t" . get_string('skippingdeletionfailed', 'local_sandbox', $shortname) . "\n";
// Inform admin
local_sandbox_inform_admin(get_string('skippingdeletionfailed', 'local_sandbox', $shortname), SANDBOX_LEVEL_WARNING);
continue;
}
// Unzip course backup file to temp directory
$filepacker = get_file_packer('application/vnd.moodle.backup');
check_dir_exists($CFG->dataroot . '/temp/backup');
if (!$filepacker->extract_to_pathname($local_sandbox_config->coursebackupsdirectory . '/' . $file, $CFG->dataroot . '/temp/backup/' . $shortname)) {
// Output error message for cron listing
echo "\n\t" . get_string('skippingunzipfailed', 'local_sandbox', $file) . "\n";
// Inform admin
local_sandbox_inform_admin(get_string('skippingunzipfailed', 'local_sandbox', $shortname), SANDBOX_LEVEL_WARNING);
continue;
}
// Create new course
if (!($newcourseid = \restore_dbops::create_new_course($shortname, $shortname, $categoryid))) {
// Output error message for cron listing
echo "\n\t" . get_string('skippingcreatefailed', 'local_sandbox', $shortname) . "\n";
// Inform admin
local_sandbox_inform_admin(get_string('skippingcreatefailed', 'local_sandbox', $shortname), SANDBOX_LEVEL_WARNING);
continue;
}
// Get admin user for restore
$admin = get_admin();
$restoreuser = $admin->id;
// Restore course backup file into new course
if ($controller = new \restore_controller($shortname, $newcourseid, \backup::INTERACTIVE_NO, \backup::MODE_SAMESITE, $restoreuser, \backup::TARGET_NEW_COURSE)) {
$controller->get_logger()->set_next(new \output_indented_logger(\backup::LOG_INFO, false, true));
$controller->execute_precheck();
$controller->execute_plan();
} else {
// Output error message for cron listing
echo "\n\t" . get_string('skippingrestorefailed', 'local_sandbox', $shortname) . "\n";
// Inform admin
local_sandbox_inform_admin(get_string('skippingrestorefailed', 'local_sandbox', $shortname), SANDBOX_LEVEL_WARNING);
continue;
}
// Adjust course start date
if ($local_sandbox_config->adjustcoursestartdate == true) {
if (!$DB->update_record('course', (object) array('id' => $newcourseid, 'startdate' => time()))) {
// Output error message for cron listing
echo "\n\t" . get_string('skippingadjuststartdatefailed', 'local_sandbox', $shortname) . "\n";
// Inform admin
local_sandbox_inform_admin(get_string('skippingadjuststartdatefailed', 'local_sandbox', $shortname), SANDBOX_LEVEL_WARNING);
continue;
}
}
// Set shortname and fullname back
if ($DB->update_record('course', (object) array('id' => $newcourseid, 'shortname' => $shortname, 'fullname' => $fullname))) {
// Output info message for cron listing
echo "\n\t" . get_string('successrestored', 'local_sandbox', $shortname) . "\n";
// Inform admin
local_sandbox_inform_admin(get_string('successrestored', 'local_sandbox', $shortname), SANDBOX_LEVEL_NOTICE);
// Log the event
$logevent = \local_sandbox\event\course_restored::create(array('objectid' => $newcourseid, 'context' => \context_course::instance($newcourseid)));
$logevent->trigger();
// Fire course_updated event
$course = $DB->get_record('course', array('id' => $newcourseid));
//.........这里部分代码省略.........