当前位置: 首页>>代码示例>>PHP>>正文


PHP restore_dbops类代码示例

本文整理汇总了PHP中restore_dbops的典型用法代码示例。如果您正苦于以下问题:PHP restore_dbops类的具体用法?PHP restore_dbops怎么用?PHP restore_dbops使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了restore_dbops类的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 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));
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:40,代码来源:restore_glossary_random_block_task.class.php

示例2: 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));
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:32,代码来源:restore_tags_block_task.class.php

示例3: 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

示例4: 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);
     }
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:26,代码来源:restore_lockdownbrowser_block_task.class.php

示例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));
             }
         }
     }
 }
开发者ID:grug,项目名称:moodle,代码行数:39,代码来源:restore_quiz_results_block_task.class.php

示例6: process_log

 protected function process_log($log, $oldctx, $context)
 {
     global $DB;
     $log = (object) $log;
     $oldid = $log->id;
     $mailedusers = explode(',', $log->mailto);
     $validusers = array();
     foreach ($mailedusers as $userid) {
         $validusers[] = $this->get_mappingid('user', $userid);
     }
     $log->courseid = $this->get_courseid();
     $log->userid = $this->get_mappingid('user', $log->userid);
     $log->mailto = implode(',', $validusers);
     $log->time = $this->apply_date_offset($log->time);
     // TODO: correctly convert alternate ids
     $log->alternateid = null;
     $newid = $DB->insert_record('block_quickmail_log', $log);
     $this->set_mapping('log', $oldid, $newid);
     foreach (array('log', 'attachment_log') as $filearea) {
         restore_dbops::send_files_to_pool($this->get_basepath(), $this->get_restoreid(), 'block_quickmail', $filearea, $oldctx, $log->userid);
         $sql = 'UPDATE {files} SET
             itemid = :newid WHERE contextid = :ctxt AND itemid = :oldid';
         $params = array('newid' => $newid, 'oldid' => $oldid, 'ctxt' => $context->id);
         $DB->execute($sql, $params);
     }
 }
开发者ID:amunguia,项目名称:block_quickmail,代码行数:26,代码来源:restore_quickmail_stepslib.php

示例7: 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);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:26,代码来源:restore_questions_parser_processor.class.php

示例8: dispatch_chunk

 protected function dispatch_chunk($data)
 {
     // Received one inforef chunck, we are going to store it into backup_ids
     // table, with name = itemname + "ref" for later use
     $itemname = basename($data['path']) . 'ref';
     $itemid = $data['tags']['id'];
     restore_dbops::set_backup_ids_record($this->restoreid, $itemname, $itemid);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:8,代码来源:restore_inforef_parser_processor.class.php

示例9: 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);
     }
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:12,代码来源:restore_roles_parser_processor.class.php

示例10: 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);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:13,代码来源:restore_users_parser_processor.class.php

示例11: 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);
                 }
             }
         }
     }
 }
开发者ID:edurenye,项目名称:sharing_cart,代码行数:52,代码来源:restore_fix_missing_questions.php

示例12: 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));
         }
     }
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:18,代码来源:restore_checklist_activity_task.class.php

示例13: 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));
             }
         }
     }
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:25,代码来源:restore_quiz_results_block_task.class.php

示例14: test_mod_jclic_backup_restore

 public function test_mod_jclic_backup_restore()
 {
     global $USER, $DB, $CFG;
     require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
     require_once $CFG->dirroot . '/backup/util/includes/restore_includes.php';
     $this->resetAfterTest(true);
     $this->setUser(2);
     // Admin user.
     // Create a course with some availability data set.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course(array('format' => 'topics', 'numsections' => 3, 'enablecompletion' => COMPLETION_ENABLED), array('createsections' => true));
     $jclic = $generator->create_module('jclic', array('course' => $course->id));
     // Turn off file logging, otherwise it can't delete the file (Windows).
     $CFG->backup_file_logger_level = backup::LOG_NONE;
     // Do backup with default settings. MODE_IMPORT means it will just
     // create the directory and not zip it.
     $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id);
     $backupid = $bc->get_backupid();
     $bc->execute_plan();
     $bc->destroy();
     // Do restore to new course with default settings.
     $newcourseid = restore_dbops::create_new_course($course->fullname, $course->shortname . '_2', $course->category);
     $rc = new restore_controller($backupid, $newcourseid, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, backup::TARGET_NEW_COURSE);
     $this->assertTrue($rc->execute_precheck());
     $rc->execute_plan();
     $rc->destroy();
     // Check settings in new course.
     $modinfo = get_fast_modinfo($newcourseid);
     $jclics = array_values($modinfo->get_instances_of('jclic'));
     $newjclic = new jclic(context_module::instance($jclics[0]->id), false, false);
     $newjclicmodule = $newjclic->get_instance();
     $this->assertNotEmpty($newjclic);
     $jclic = new jclic(context_module::instance($jclic->cmid), false, false);
     $jclicmodule = $jclic->get_instance();
     $fields = (array) $jclicmodule;
     unset($fields['id']);
     unset($fields['course']);
     foreach ($fields as $key => $unused) {
         $this->assertEquals($newjclicmodule->{$key}, $jclicmodule->{$key}, "Failed on field {$key}");
     }
     // Avoid errors...
     ini_set('max_execution_time', 0);
 }
开发者ID:danielvdml,项目名称:moodleyarcho,代码行数:43,代码来源:lib_test.php

示例15: 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));
     }
 }
开发者ID:nwp90,项目名称:Moodle-block_progress,代码行数:48,代码来源:restore_progress_block_task.class.php


注:本文中的restore_dbops类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。