本文整理汇总了PHP中restore_dbops::get_backup_ids_record方法的典型用法代码示例。如果您正苦于以下问题:PHP restore_dbops::get_backup_ids_record方法的具体用法?PHP restore_dbops::get_backup_ids_record怎么用?PHP restore_dbops::get_backup_ids_record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类restore_dbops
的用法示例。
在下文中一共展示了restore_dbops::get_backup_ids_record方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: after_restore
/**
* This function, executed after all the tasks in the plan
* have been executed, will perform the recode of the
* target activity for the block. This must be done here
* and not in normal execution so we are sure everything is
* at its finale place.
*/
public function after_restore()
{
global $DB;
// Get the blockid.
$blockid = $this->get_blockid();
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
if (!empty($config->section_id)) {
// Get the mapping and replace it in config.
if ($mapping = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'course_section', $config->section_id)) {
// Update the parent module id (the id from mdl_quiz etc...)
$config->section_id = $mapping->newitemid;
// Encode and save the config.
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
// Arrange the replace link in the course_sections summary.
$newsection = $DB->get_record('course_sections', array('id' => $mapping->newitemid));
// Update the Side Bar section with the required values to make it work.
$reseturl = new moodle_url('/blocks/side_bar/reset.php?cid=' . $newsection->course);
$newsection->name = get_string('sidebar', 'block_side_bar');
$newsection->summary = get_string('sectionsummary', 'block_side_bar', (string) html_writer::link($reseturl, $reseturl));
$newsection->summaryformat = FORMAT_HTML;
$newsection->visible = true;
$DB->update_record('course_sections', $newsection);
}
}
}
}
开发者ID:fernandooliveira,项目名称:moodle-block_sidebar,代码行数:35,代码来源:restore_ned_sidebar_block_task.class.php
示例2: dispatch_chunk
protected function dispatch_chunk($data)
{
// Prepare question_category record
if ($data['path'] == '/question_categories/question_category') {
$info = (object) $data['tags'];
$itemname = 'question_category';
$itemid = $info->id;
$parentitemid = $info->contextid;
$this->lastcatid = $itemid;
// Prepare question record
} else {
if ($data['path'] == '/question_categories/question_category/questions/question') {
$info = (object) $data['tags'];
$itemname = 'question';
$itemid = $info->id;
$parentitemid = $this->lastcatid;
// Not question_category nor question, impossible. Throw exception.
} else {
throw new progressive_parser_exception('restore_questions_parser_processor_unexpected_path', $data['path']);
}
}
// Only load it if needed (exist same question_categoryref itemid in table)
if (restore_dbops::get_backup_ids_record($this->restoreid, 'question_categoryref', $this->lastcatid)) {
restore_dbops::set_backup_ids_record($this->restoreid, $itemname, $itemid, 0, $parentitemid, $info);
}
}
示例3: after_restore
public function after_restore()
{
global $DB;
$course_id = $this->get_courseid();
$records = $DB->get_records("block_lockdownbrowser_sett", array("course" => $course_id));
if ($records === FALSE) {
return;
}
$missing_ids = 0;
foreach ($records as $settings) {
$old_quizid = $settings->quizid;
if (empty($old_quizid)) {
continue;
}
$quizmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), "quiz", $old_quizid);
if (empty($quizmap)) {
$missing_ids++;
continue;
}
$settings->quizid = $quizmap->newitemid;
$DB->update_record('block_lockdownbrowser_sett', $settings);
}
if ($missing_ids > 0) {
$this->get_logger()->process("Failed to restore dependency in block 'lockdownbrowser'. " . "Backup and restore will not work correctly unless you " . "include the dependent 'quiz' modules.", backup::LOG_ERROR);
}
}
示例4: after_restore
/**
* This function, executed after all the tasks in the plan
* have been executed, will perform the recode of the
* target glossary for the block. This must be done here
* and not in normal execution steps because the glossary
* may be restored after the block.
*/
public function after_restore()
{
global $DB;
// Get the blockid
$blockid = $this->get_blockid();
// Extract block configdata and update it to point to the new glossary
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
if (!empty($config->glossary)) {
if ($glossarymap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $config->glossary)) {
// Get glossary mapping and replace it in config
$config->glossary = $glossarymap->newitemid;
} else {
if ($this->is_samesite()) {
// We are restoring on the same site, check if glossary can be used in the block in this course.
$glossaryid = $DB->get_field_sql("SELECT id FROM {glossary} " . "WHERE id = ? AND (course = ? OR globalglossary = 1)", [$config->glossary, $this->get_courseid()]);
if (!$glossaryid) {
unset($config->glossary);
}
} else {
// The block refers to a glossary not present in the backup file.
unset($config->glossary);
}
}
// Unset config variables that are no longer used.
unset($config->globalglossary);
unset($config->courseid);
// Save updated config.
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
}
}
}
示例5: after_restore
/**
* This function, executed after all the tasks in the plan
* have been executed, will perform the recode of the
* target quiz for the block. This must be done here
* and not in normal execution steps because the quiz
* can be restored after the block.
*/
public function after_restore()
{
global $DB;
// Get the blockid.
$blockid = $this->get_blockid();
// Extract block configdata and update it to point to the new quiz.
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
if (!empty($config->quizid)) {
// Get quiz mapping and replace it in config.
if ($quizmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'quiz', $config->quizid)) {
$config->activityparent = 'quiz';
$config->activityparentid = $quizmap->newitemid;
// Set the decimal valuue as appropriate.
if ($config->gradeformat == 1) {
// This block is using percentages, do not display any decimal places.
$config->decimalpoints = 0;
} else {
// Get the decimal value from the corresponding quiz.
$config->decimalpoints = $DB->get_field('quiz', 'decimalpoints', array('id' => $config->activityparentid));
}
// Get the grade_items record to set the activitygradeitemid.
$info = $DB->get_record('grade_items', array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent));
$config->activitygradeitemid = $info->id;
unset($config->quizid);
// Save the new configuration and update the record.
$DB->set_field('block_instances', 'configdata', base64_encode(serialize($config)), array('id' => $blockid));
$DB->set_field('block_instances', 'blockname', 'activity_results', array('id' => $blockid));
}
}
}
}
示例6: after_restore
/**
* This function, executed after all the tasks in the plan
* have been executed, will remove tag collection reference in case block was restored into another site.
* Also get mapping of contextid.
*/
public function after_restore()
{
global $DB;
// Get the blockid.
$blockid = $this->get_blockid();
// Extract block configdata and remove tag collection reference if this is another site. Also map contextid.
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
$changed = false;
if (!empty($config->tagcoll) && $config->tagcoll > 1 && !$this->is_samesite()) {
$config->tagcoll = 0;
$changed = true;
}
if (!empty($config->ctx)) {
if ($ctxmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'context', $config->ctx)) {
$config->ctx = $ctxmap->newitemid;
} else {
$config->ctx = 0;
}
$changed = true;
}
if ($changed) {
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
}
}
}
示例7: dispatch_chunk
protected function dispatch_chunk($data)
{
// Received one role chunck, we are going to store it into backup_ids
// table, with name = role
$itemname = 'role';
$itemid = $data['tags']['id'];
$info = $data['tags'];
// Only load it if needed (exist same roleref itemid in table)
if (restore_dbops::get_backup_ids_record($this->restoreid, 'roleref', $itemid)) {
restore_dbops::set_backup_ids_record($this->restoreid, $itemname, $itemid, 0, null, $info);
}
}
示例8: dispatch_chunk
protected function dispatch_chunk($data)
{
// Received one user chunck, we are going to store it into backup_ids
// table, with name = user and parentid = contextid for later use
$itemname = 'user';
$itemid = $data['tags']['id'];
$parentitemid = $data['tags']['contextid'];
$info = $data['tags'];
// Only load it if needed (exist same userref itemid in table)
if (restore_dbops::get_backup_ids_record($this->restoreid, 'userref', $itemid)) {
restore_dbops::set_backup_ids_record($this->restoreid, $itemname, $itemid, 0, $parentitemid, $info);
}
}
示例9: define_execution
/**
* Checks if mapped questions are exact valid, or marks them to be created
*
* @global $DB
* @throws moodle_exception
*/
protected function define_execution()
{
global $DB;
$restoreid = $this->get_restoreid();
$courseid = $this->get_courseid();
$userid = $this->task->get_userid();
$workaround_qtypes = explode(',', get_config('block_sharing_cart', 'workaround_qtypes'));
// @see /backup/util/dbops/restore_dbops.class.php#prechek_precheck_qbanks_by_level
$contexts = restore_dbops::restore_get_question_banks($restoreid);
foreach ($contexts as $contextid => $contextlevel) {
$categories = restore_dbops::restore_get_question_categories($restoreid, $contextid);
$canadd = false;
if ($targetcontext = restore_dbops::restore_find_best_target_context($categories, $courseid, $contextlevel)) {
$canadd = has_capability('moodle/question:add', $targetcontext, $userid);
}
foreach ($categories as $category) {
$questions = restore_dbops::restore_get_questions($restoreid, $category->id);
foreach ($questions as $question) {
if (!in_array($question->qtype, $workaround_qtypes)) {
continue;
}
$mapping = restore_dbops::get_backup_ids_record($restoreid, 'question', $question->id);
if ($mapping && $mapping->newitemid && !self::is_question_valid($question->qtype, $mapping->newitemid)) {
if (!$canadd) {
throw new moodle_exception('questioncannotberestored', 'backup', '', $question);
}
$catmapping = restore_dbops::get_backup_ids_record($restoreid, 'question_category', $category->id);
$matchquestions = $DB->get_records('question', array('category' => $catmapping->newitemid, 'qtype' => $question->qtype, 'stamp' => $question->stamp, 'version' => $question->version));
$newitemid = 0;
// to be created if no valid duplicate exists
foreach ($matchquestions as $q) {
if ($q->id == $mapping->newitemid) {
continue;
}
if (self::is_question_valid($question->qtype, $q->id)) {
$newitemid = $q->id;
// updates mapping if a valid one found
break;
}
}
$this->update_mapping($mapping, $newitemid);
}
}
}
}
}
示例10: after_restore
/**
* This function, executed after all the tasks in the plan
* have been executed, will perform the recode of the
* target quiz for the block. This must be done here
* and not in normal execution steps because the quiz
* can be restored after the block.
*/
public function after_restore()
{
global $DB;
// Get the blockid
$blockid = $this->get_blockid();
// Extract block configdata and update it to point to the new quiz
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
if (!empty($config->quizid)) {
// Get quiz mapping and replace it in config
if ($quizmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'quiz', $config->quizid)) {
$config->quizid = $quizmap->newitemid;
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
}
}
}
}
示例11: after_restore
public function after_restore()
{
global $DB;
// Find all the items that have a 'moduleid' but are not headings and match them up to the newly-restored activities.
$items = $DB->get_records_select('checklist_item', 'checklist = ? AND moduleid > 0 AND itemoptional <> 2', array($this->get_activityid()));
foreach ($items as $item) {
$moduleid = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'course_module', $item->moduleid);
if ($moduleid) {
// Match up the moduleid to the restored activity module.
$DB->set_field('checklist_item', 'moduleid', $moduleid->newitemid, array('id' => $item->id));
} else {
// Does not match up to a restored activity module => delete the item + associated user data.
$DB->delete_records('checklist_check', array('item' => $item->id));
$DB->delete_records('checklist_comment', array('itemid' => $item->id));
$DB->delete_records('checklist_item', array('id' => $item->id));
}
}
}
示例12: after_restore
/**
* Translates the backed up configuration data for the target course modules.
*
* @global type $DB
*/
public function after_restore()
{
global $DB;
$prefixes = array('monitor_', 'date_time_', 'action_', 'locked_');
// Get the blockid.
$id = $this->get_blockid();
// Get restored course id.
$courseid = $this->get_courseid();
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $id))) {
$config = (array) unserialize(base64_decode($configdata));
$newconfig = $config;
// Filter module related config information.
foreach ($newconfig as $key => $value) {
foreach ($prefixes as $prefix) {
if (substr($key, 0, strlen($prefix)) === $prefix) {
unset($newconfig[$key]);
}
}
}
// Translate the old config information to the target course values.
foreach ($config as $key => $value) {
$matches = array();
preg_match('/monitor_(\\D+)(\\d+)/', $key, $matches);
if (!empty($matches)) {
$module = $matches[1];
$instance = $matches[2];
// Find the mapped instance ID.
if ($newinstance = restore_dbops::get_backup_ids_record($this->get_restoreid(), $module, $instance)) {
$newinstanceid = $newinstance->newitemid;
// Translate new instance values from old IDs.
foreach ($prefixes as $prefix) {
if (isset($config["{$prefix}{$module}{$instance}"])) {
$newconfig["{$prefix}{$module}{$newinstanceid}"] = $config["{$prefix}{$module}{$instance}"];
}
}
}
}
}
// Save everything back to DB.
$configdata = base64_encode(serialize((object) $newconfig));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $id));
}
}
示例13: after_restore
/**
* Translates the backed up configuration data for the target course modules
*
* @global type $DB
*/
public function after_restore()
{
global $DB;
// Get the blockid
$id = $this->get_blockid();
//Restored course id
$courseid = $this->get_courseid();
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $id))) {
$config = (array) unserialize(base64_decode($configdata));
// Translate the old config information to the target course values
foreach ($config as $key => $value) {
$matches = array();
preg_match('/monitor_(\\D+)(\\d+)/', $key, $matches);
if ($value == 1 && !empty($matches)) {
$module = $matches[1];
$instance = $matches[2];
// Find a matching module in the target course
if ($cm = get_coursemodule_from_instance($module, $instance)) {
// Get new cm and instance
$newitem = restore_dbops::get_backup_ids_record($this->get_restoreid(), "course_module", $cm->id);
$newcm = get_coursemodule_from_id($module, $newitem->newitemid);
$newinstance = $newcm->instance;
// Set new config
$config["monitor_{$module}{$newinstance}"] = $config["monitor_{$module}{$instance}"];
$config["locked_{$module}{$newinstance}"] = $config["locked_{$module}{$instance}"];
$config["date_time_{$module}{$newinstance}"] = $config["date_time_{$module}{$instance}"];
$config["action_{$module}{$newinstance}"] = $config["action_{$module}{$instance}"];
// Unset old config
unset($config["monitor_{$module}{$instance}"]);
unset($config["locked_{$module}{$instance}"]);
unset($config["date_time_{$module}{$instance}"]);
unset($config["action_{$module}{$instance}"]);
}
}
}
// Save everything back to DB
$configdata = base64_encode(serialize((object) $config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $id));
}
}
示例14: update_after_restore
public function update_after_restore($restoreid, $courseid, \base_logger $logger, $name)
{
global $DB;
if (!$this->roleid) {
// If using 'same as activity' option, no need to change it.
return false;
}
$rec = \restore_dbops::get_backup_ids_record($restoreid, 'role', $this->roleid);
if (!$rec || !$rec->newitemid) {
// If we are on the same course (e.g. duplicate) then we can just
// use the existing one.
if ($DB->record_exists('roles', array('id' => $this->roleid, 'courseid' => $courseid))) {
return false;
}
// Otherwise it's a warning.
$this->roleid = -1;
$logger->process('Restored item (' . $name . ') has availability condition on grouping that was not restored', \backup::LOG_WARNING);
} else {
$this->roleid = (int) $rec->newitemid;
}
return true;
}
示例15: after_restore
/**
* This function, executed after all the tasks in the plan
* have been executed, will perform the recode of the
* target activity for the block. This must be done here
* and not in normal execution steps because the activity
* can be restored after the block.
*/
public function after_restore()
{
global $DB;
// Get the blockid.
$blockid = $this->get_blockid();
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
if (!empty($config->activityparentid)) {
// Get the mapping and replace it in config.
if ($mapping = restore_dbops::get_backup_ids_record($this->get_restoreid(), $config->activityparent, $config->activityparentid)) {
// Update the parent module id (the id from mdl_quiz etc...)
$config->activityparentid = $mapping->newitemid;
// Get the grade_items record to update the activitygradeitemid.
$info = $DB->get_record('grade_items', array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent));
// Update the activitygradeitemid the id from the grade_items table.
$config->activitygradeitemid = $info->id;
// Encode and save the config.
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
}
}
}
}