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


PHP backup_controller_dbops类代码示例

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


在下文中一共展示了backup_controller_dbops类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: copy_file_moodle2backup

 /**
  * Copy one file from moodle storage to backup storage
  */
 public static function copy_file_moodle2backup($backupid, $filerecorid)
 {
     global $DB;
     if (!backup_controller_dbops::backup_includes_files($backupid)) {
         // Only include the files if required by the controller.
         return;
     }
     // Normalise param
     if (!is_object($filerecorid)) {
         $filerecorid = $DB->get_record('files', array('id' => $filerecorid));
     }
     // Directory, nothing to do
     if ($filerecorid->filename === '.') {
         return;
     }
     $fs = get_file_storage();
     $file = $fs->get_file_instance($filerecorid);
     // If the file is external file, skip copying.
     if ($file->is_external_file()) {
         return;
     }
     // Calculate source and target paths (use same subdirs strategy for both)
     $targetfilepath = self::get_backup_storage_base_dir($backupid) . '/' . self::get_backup_content_file_location($filerecorid->contenthash);
     // Create target dir if necessary
     if (!file_exists(dirname($targetfilepath))) {
         if (!check_dir_exists(dirname($targetfilepath), true, true)) {
             throw new backup_helper_exception('cannot_create_directory', dirname($targetfilepath));
         }
     }
     // And copy the file (if doesn't exist already)
     if (!file_exists($targetfilepath)) {
         $file->copy_content_to($targetfilepath);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:37,代码来源:backup_file_manager.class.php

示例2: define_execution

 /**
  * Entry point for executing this step
  */
 protected function define_execution()
 {
     global $CFG;
     backup_controller_dbops::drop_backup_ids_temp_table($this->get_backupid());
     // Drop ids temp table
     //avoid purging old backup dirs to save on performance
     //avoid deleting the current backup dir because it's needed during the restore
     //delete the log file that was created
     $backupid = $this->get_backupid();
     unlink($CFG->dataroot . '/temp/backup/' . $backupid . '.log');
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:14,代码来源:stepslib.php

示例3: define_execution

 protected function define_execution()
 {
     // Get basepath
     $basepath = $this->get_basepath();
     // Calculate the zip fullpath (in OS temp area it's always backup.imscc)
     $zipfile = $basepath . '/backup.imscc';
     // Perform storage and return it (TODO: shouldn't be array but proper result object)
     // Let's send the file to file storage, everything already defined
     // 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($this->get_backupid());
     // Extract useful information to decide
     $file = $sinfo['filename']->value;
     $filename = basename($file, '.' . pathinfo($file, PATHINFO_EXTENSION)) . '.imscc';
     // Backup filename
     $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
     $ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
     $component = 'user';
     $filearea = 'backup';
     $itemid = 0;
     $fs = get_file_storage();
     $fr = array('contextid' => $ctxid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid, 'filepath' => '/', 'filename' => $filename, 'userid' => $userid, 'timecreated' => time(), 'timemodified' => time());
     // If file already exists, delete if before
     // creating it again. This is BC behaviour - copy()
     // overwrites by default
     if ($fs->file_exists($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename'])) {
         $pathnamehash = $fs->get_pathname_hash($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename']);
         $sf = $fs->get_file_by_hash($pathnamehash);
         $sf->delete();
     }
     return array('backup_destination' => $fs->create_file_from_pathname($fr, $zipfile));
 }
开发者ID:nickread,项目名称:moodle,代码行数:36,代码来源:backuplib.php

示例4: define_execution

 /**
  * What to do when this step is executed.
  */
 protected function define_execution()
 {
     global $DB;
     $this->log('processing file aliases queue', backup::LOG_DEBUG);
     $fs = get_file_storage();
     // Load the queue.
     $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $this->get_restoreid(), 'itemname' => 'file_aliases_queue'), '', 'info');
     // Iterate over aliases in the queue.
     foreach ($rs as $record) {
         $info = backup_controller_dbops::decode_backup_temp_info($record->info);
         // Try to pick a repository instance that should serve the alias.
         $repository = $this->choose_repository($info);
         if (is_null($repository)) {
             $this->notify_failure($info, 'unable to find a matching repository instance');
             continue;
         }
         if ($info->oldfile->repositorytype === 'local' or $info->oldfile->repositorytype === 'coursefiles') {
             // Aliases to Server files and Legacy course files may refer to a file
             // contained in the backup file or to some existing file (if we are on the
             // same site).
             try {
                 $reference = file_storage::unpack_reference($info->oldfile->reference);
             } catch (Exception $e) {
                 $this->notify_failure($info, 'invalid reference field format');
                 continue;
             }
             // Let's see if the referred source file was also included in the backup.
             $candidates = $DB->get_recordset('backup_files_temp', array('backupid' => $this->get_restoreid(), 'contextid' => $reference['contextid'], 'component' => $reference['component'], 'filearea' => $reference['filearea'], 'itemid' => $reference['itemid']), '', 'info, newcontextid, newitemid');
             $source = null;
             foreach ($candidates as $candidate) {
                 $candidateinfo = backup_controller_dbops::decode_backup_temp_info($candidate->info);
                 if ($candidateinfo->filename === $reference['filename'] and $candidateinfo->filepath === $reference['filepath'] and !is_null($candidate->newcontextid) and !is_null($candidate->newitemid)) {
                     $source = $candidateinfo;
                     $source->contextid = $candidate->newcontextid;
                     $source->itemid = $candidate->newitemid;
                     break;
                 }
             }
             $candidates->close();
             if ($source) {
                 // We have an alias that refers to another file also included in
                 // the backup. Let us change the reference field so that it refers
                 // to the restored copy of the original file.
                 $reference = file_storage::pack_reference($source);
                 // Send the new alias to the filepool.
                 $fs->create_file_from_reference($info->newfile, $repository->id, $reference);
                 $this->notify_success($info);
                 continue;
             } else {
                 // This is a reference to some moodle file that was not contained in the backup
                 // file. If we are restoring to the same site, keep the reference untouched
                 // and restore the alias as is if the referenced file exists.
                 if ($this->task->is_samesite()) {
                     if ($fs->file_exists($reference['contextid'], $reference['component'], $reference['filearea'], $reference['itemid'], $reference['filepath'], $reference['filename'])) {
                         $reference = file_storage::pack_reference($reference);
                         $fs->create_file_from_reference($info->newfile, $repository->id, $reference);
                         $this->notify_success($info);
                         continue;
                     } else {
                         $this->notify_failure($info, 'referenced file not found');
                         continue;
                     }
                     // If we are at other site, we can't restore this alias.
                 } else {
                     $this->notify_failure($info, 'referenced file not included');
                     continue;
                 }
             }
         } else {
             if ($info->oldfile->repositorytype === 'user') {
                 if ($this->task->is_samesite()) {
                     // For aliases to user Private files at the same site, we have a chance to check
                     // if the referenced file still exists.
                     try {
                         $reference = file_storage::unpack_reference($info->oldfile->reference);
                     } catch (Exception $e) {
                         $this->notify_failure($info, 'invalid reference field format');
                         continue;
                     }
                     if ($fs->file_exists($reference['contextid'], $reference['component'], $reference['filearea'], $reference['itemid'], $reference['filepath'], $reference['filename'])) {
                         $reference = file_storage::pack_reference($reference);
                         $fs->create_file_from_reference($info->newfile, $repository->id, $reference);
                         $this->notify_success($info);
                         continue;
                     } else {
                         $this->notify_failure($info, 'referenced file not found');
                         continue;
                     }
                     // If we are at other site, we can't restore this alias.
                 } else {
                     $this->notify_failure($info, 'restoring at another site');
                     continue;
                 }
             } else {
                 // This is a reference to some external file such as in boxnet or dropbox.
                 // If we are restoring to the same site, keep the reference untouched and
                 // restore the alias as is.
//.........这里部分代码省略.........
开发者ID:Jinelle,项目名称:moodle,代码行数:101,代码来源:restore_stepslib.php

示例5: define_structure

 protected function define_structure()
 {
     global $CFG;
     $info = array();
     $info['name'] = $this->get_setting_value('filename');
     $info['moodle_version'] = $CFG->version;
     $info['moodle_release'] = $CFG->release;
     $info['backup_version'] = $CFG->backup_version;
     $info['backup_release'] = $CFG->backup_release;
     $info['backup_date'] = time();
     $info['backup_uniqueid'] = $this->get_backupid();
     $info['mnet_remoteusers'] = backup_controller_dbops::backup_includes_mnet_remote_users($this->get_backupid());
     $info['original_wwwroot'] = $CFG->wwwroot;
     $info['original_site_identifier_hash'] = md5(get_site_identifier());
     $info['original_course_id'] = $this->get_courseid();
     $originalcourseinfo = backup_controller_dbops::backup_get_original_course_info($this->get_courseid());
     $info['original_course_fullname'] = $originalcourseinfo->fullname;
     $info['original_course_shortname'] = $originalcourseinfo->shortname;
     $info['original_course_startdate'] = $originalcourseinfo->startdate;
     $info['original_course_contextid'] = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
     $info['original_system_contextid'] = get_context_instance(CONTEXT_SYSTEM)->id;
     // Get more information from controller
     list($dinfo, $cinfo, $sinfo) = backup_controller_dbops::get_moodle_backup_information($this->get_backupid());
     // Define elements
     $moodle_backup = new backup_nested_element('moodle_backup');
     $information = new backup_nested_element('information', null, array('name', 'moodle_version', 'moodle_release', 'backup_version', 'backup_release', 'backup_date', 'mnet_remoteusers', 'original_wwwroot', 'original_site_identifier_hash', 'original_course_id', 'original_course_fullname', 'original_course_shortname', 'original_course_startdate', 'original_course_contextid', 'original_system_contextid'));
     $details = new backup_nested_element('details');
     $detail = new backup_nested_element('detail', array('backup_id'), array('type', 'format', 'interactive', 'mode', 'execution', 'executiontime'));
     $contents = new backup_nested_element('contents');
     $activities = new backup_nested_element('activities');
     $activity = new backup_nested_element('activity', null, array('moduleid', 'sectionid', 'modulename', 'title', 'directory'));
     $sections = new backup_nested_element('sections');
     $section = new backup_nested_element('section', null, array('sectionid', 'title', 'directory'));
     $course = new backup_nested_element('course', null, array('courseid', 'title', 'directory'));
     $settings = new backup_nested_element('settings');
     $setting = new backup_nested_element('setting', null, array('level', 'section', 'activity', 'name', 'value'));
     // Build the tree
     $moodle_backup->add_child($information);
     $information->add_child($details);
     $details->add_child($detail);
     $information->add_child($contents);
     if (!empty($cinfo['activities'])) {
         $contents->add_child($activities);
         $activities->add_child($activity);
     }
     if (!empty($cinfo['sections'])) {
         $contents->add_child($sections);
         $sections->add_child($section);
     }
     if (!empty($cinfo['course'])) {
         $contents->add_child($course);
     }
     $information->add_child($settings);
     $settings->add_child($setting);
     // Set the sources
     $information->set_source_array(array((object) $info));
     $detail->set_source_array($dinfo);
     $activity->set_source_array($cinfo['activities']);
     $section->set_source_array($cinfo['sections']);
     $course->set_source_array($cinfo['course']);
     $setting->set_source_array($sinfo);
     // Prepare some information to be sent to main moodle_backup.xml file
     return $moodle_backup;
 }
开发者ID:nutanrajmalanai,项目名称:moodle,代码行数:64,代码来源:backup_stepslib.php

示例6: 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);
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:backup_helper.class.php

示例7: drop_stash_storage

 /**
  * Drops the temporary storage of stashed data
  *
  * This implementation uses backup_ids_temp table.
  */
 public function drop_stash_storage() {
     backup_controller_dbops::drop_backup_ids_temp_table($this->get_id());
 }
开发者ID:ncsu-delta,项目名称:moodle,代码行数:8,代码来源:lib.php

示例8: define_execution

 protected function define_execution()
 {
     // Get basepath
     $basepath = $this->get_basepath();
     // Calculate the zip fullpath (in OS temp area it's always backup.mbz)
     $zipfile = $basepath . '/backup.mbz';
     $has_file_references = backup_controller_dbops::backup_includes_file_references($this->get_backupid());
     // Perform storage and return it (TODO: shouldn't be array but proper result object)
     return array('backup_destination' => backup_helper::store_backup_file($this->get_backupid(), $zipfile, $this->task->get_progress()), 'include_file_references_to_external_content' => $has_file_references);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:10,代码来源:backup_stepslib.php

示例9: test_backup_structure_construct


//.........这里部分代码省略.........
     // 1 object array
     // Skip alternative2 source definition on purpose (will be tested)
     // $alternative2->set_source_array(array((object)array('name' => 'alternative2', 'value' => 2))); // 1 object array
     $alternative3->set_source_array(array((object) array('name' => 'alternative3', 'value' => 3)));
     // 1 object array
     // Alternative 4 source is the forum type and name, so we'll get that in ALL posts (no conditions) that
     // have not another alternative (post4 in our testing data in the only not matching any other alternative)
     $alternative4->set_source_sql('SELECT type AS forumtype, name AS forumname
                                      FROM {forum}
                                     WHERE id = ?', array('/forum/id'));
     // Set children of optigroup_element source
     $dupetest1->set_source_array(array((object) array('field1' => '1', 'field2' => 1)));
     // 1 object array
     $dupetest2->set_source_array(array((object) array('field1' => '2', 'field2' => 2)));
     // 1 object array
     $dupetest3->set_source_array(array((object) array('field1' => '3', 'field2' => 3)));
     // 1 object array
     $dupetest4->set_source_array(array((object) array('field1' => '4', 'field2' => 4)));
     // 1 object array
     // Define some aliases
     $rating->set_source_alias('rating', 'post_rating');
     // Map the 'rating' value from DB to 'post_rating' final element
     // Mark to detect files of type 'forum_intro' in forum (and not item id)
     $forum->annotate_files('mod_forum', 'intro', null);
     // Mark to detect file of type 'forum_post' and 'forum_attachment' in post (with itemid being post->id)
     $post->annotate_files('mod_forum', 'post', 'id');
     $post->annotate_files('mod_forum', 'attachment', 'id');
     // Mark various elements to be annotated
     $discussion->annotate_ids('user1', 'userid');
     $post->annotate_ids('forum_post', 'id');
     $rating->annotate_ids('user2', 'userid');
     $rating->annotate_ids('forum_post', 'itemid');
     // Create the backup_ids_temp table
     backup_controller_dbops::create_backup_ids_temp_table($backupid);
     // Instantiate in memory xml output
     $xo = new memory_xml_output();
     // Instantiate xml_writer and start it
     $xw = new xml_writer($xo);
     $xw->start();
     // Instantiate the backup processor
     $processor = new backup_structure_processor($xw);
     // Set some variables
     $processor->set_var(backup::VAR_ACTIVITYID, $this->forumid);
     $processor->set_var(backup::VAR_BACKUPID, $backupid);
     $processor->set_var(backup::VAR_CONTEXTID, $this->contextid);
     // Process the backup structure with the backup processor
     $forum->process($processor);
     // Stop the xml_writer
     $xw->stop();
     // Check various counters
     $this->assertEquals($forum->get_counter(), $DB->count_records('forum'));
     $this->assertEquals($discussion->get_counter(), $DB->count_records('forum_discussions'));
     $this->assertEquals($rating->get_counter(), $DB->count_records('rating'));
     $this->assertEquals($read->get_counter(), $DB->count_records('forum_read'));
     $this->assertEquals($inventeds->get_counter(), 2);
     // Array
     // Perform some validations with the generated XML
     $dom = new DomDocument();
     $dom->loadXML($xo->get_allcontents());
     $xpath = new DOMXPath($dom);
     // Some more counters
     $query = '/forum/discussions/discussion/posts/post';
     $posts = $xpath->query($query);
     $this->assertEquals($posts->length, $DB->count_records('forum_posts'));
     $query = '/forum/invented_elements/invented';
     $inventeds = $xpath->query($query);
开发者ID:bobpuffer,项目名称:moodleUCLA-LUTH,代码行数:67,代码来源:structure_test.php

示例10: __construct

 /**
  *
  * @param string $tempdir Directory under tempdir/backup awaiting restore
  * @param int $courseid Course id where restore is going to happen
  * @param bool $interactive backup::INTERACTIVE_YES[true] or backup::INTERACTIVE_NO[false]
  * @param int $mode backup::MODE_[ GENERAL | HUB | IMPORT | SAMESITE ]
  * @param int $userid
  * @param int $target backup::TARGET_[ NEW_COURSE | CURRENT_ADDING | CURRENT_DELETING | EXISTING_ADDING | EXISTING_DELETING ]
  */
 public function __construct($tempdir, $courseid, $interactive, $mode, $userid, $target)
 {
     $this->tempdir = $tempdir;
     $this->courseid = $courseid;
     $this->interactive = $interactive;
     $this->mode = $mode;
     $this->userid = $userid;
     $this->target = $target;
     // Apply some defaults
     $this->type = '';
     $this->format = backup::FORMAT_UNKNOWN;
     $this->execution = backup::EXECUTION_INMEDIATE;
     $this->operation = backup::OPERATION_RESTORE;
     $this->executiontime = 0;
     $this->samesite = false;
     $this->checksum = '';
     $this->precheck = null;
     // Apply current backup version and release if necessary
     backup_controller_dbops::apply_version_and_release();
     // Check courseid is correct
     restore_check::check_courseid($this->courseid);
     // Check user is correct
     restore_check::check_user($this->userid);
     // Calculate unique $restoreid
     $this->calculate_restoreid();
     // Default logger chain (based on interactive/execution)
     $this->logger = backup_factory::get_logger_chain($this->interactive, $this->execution, $this->restoreid);
     // Instantiate the output_controller singleton and active it if interactive and inmediate
     $oc = output_controller::get_instance();
     if ($this->interactive == backup::INTERACTIVE_YES && $this->execution == backup::EXECUTION_INMEDIATE) {
         $oc->set_active(true);
     }
     $this->log('instantiating restore controller', backup::LOG_INFO, $this->restoreid);
     // Set initial status
     $this->set_status(backup::STATUS_CREATED);
     // Calculate original restore format
     $this->format = backup_general_helper::detect_backup_format($tempdir);
     // If format is not moodle2, set to conversion needed
     if ($this->format !== backup::FORMAT_MOODLE) {
         $this->set_status(backup::STATUS_REQUIRE_CONV);
         // Else, format is moodle2, load plan, apply security and set status based on interactivity
     } else {
         // Load plan
         $this->load_plan();
         // Perform all initial security checks and apply (2nd param) them to settings automatically
         restore_check::check_security($this, true);
         if ($this->interactive == backup::INTERACTIVE_YES) {
             $this->set_status(backup::STATUS_SETTING_UI);
         } else {
             $this->set_status(backup::STATUS_NEED_PRECHECK);
         }
     }
 }
开发者ID:nickread,项目名称:moodle,代码行数:62,代码来源:restore_controller.class.php

示例11: test_backup_controller_dbops_includes_files

 /**
  * Check backup_includes_files
  */
 function test_backup_controller_dbops_includes_files()
 {
     global $DB;
     $dbman = $DB->get_manager();
     // Going to use some database_manager services for testing
     // A MODE_GENERAL controller - this should include files
     $bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
     $this->assertEquals(backup_controller_dbops::backup_includes_files($bc->get_backupid()), 1);
     // A MODE_IMPORT controller - should not include files
     $bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, $this->userid);
     $this->assertEquals(backup_controller_dbops::backup_includes_files($bc->get_backupid()), 0);
     // A MODE_SAMESITE controller - should not include files
     $bc = new mock_backup_controller4dbops(backup::TYPE_1COURSE, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $this->userid);
     $this->assertEquals(backup_controller_dbops::backup_includes_files($bc->get_backupid()), 0);
 }
开发者ID:bobpuffer,项目名称:moodleUCLA-LUTH,代码行数:18,代码来源:backup_dbops_test.php

示例12: set_course_role_names

 /**
  * For the target course context, put as many custom role names as possible
  */
 public static function set_course_role_names($restoreid, $courseid)
 {
     global $DB;
     // Get the course context
     $coursectx = context_course::instance($courseid);
     // Get all the mapped roles we have
     $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $restoreid, 'itemname' => 'role'), '', 'itemid, info, newitemid');
     foreach ($rs as $recrole) {
         $info = backup_controller_dbops::decode_backup_temp_info($recrole->info);
         // If it's one mapped role and we have one name for it
         if (!empty($recrole->newitemid) && !empty($info['nameincourse'])) {
             // If role name doesn't exist, add it
             $rolename = new stdclass();
             $rolename->roleid = $recrole->newitemid;
             $rolename->contextid = $coursectx->id;
             if (!$DB->record_exists('role_names', (array) $rolename)) {
                 $rolename->name = $info['nameincourse'];
                 $DB->insert_record('role_names', $rolename);
             }
         }
     }
     $rs->close();
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:26,代码来源:restore_dbops.class.php

示例13: create_restore_temp_tables

 public static function create_restore_temp_tables($restoreid)
 {
     global $CFG, $DB;
     $dbman = $DB->get_manager();
     // We are going to use database_manager services
     if ($dbman->table_exists('backup_ids_temp')) {
         // Table exists, from restore prechecks
         // TODO: Improve this by inserting/selecting some record to see there is restoreid match
         // TODO: If not match, exception, table corresponds to another backup/restore operation
         return true;
     }
     backup_controller_dbops::create_temptable_from_real_table($restoreid, 'backup_ids_template', 'backup_ids_temp');
     backup_controller_dbops::create_temptable_from_real_table($restoreid, 'backup_files_template', 'backup_files_temp');
     return false;
 }
开发者ID:renatosousafilho,项目名称:moodle-restore,代码行数:15,代码来源:restore_controller_dbops.class.php

示例14: 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
  */
 public static 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 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
     // 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 false;
     }
     // Calculate file storage options of id being backup
     $ctxid = 0;
     $filearea = '';
     $component = '';
     $itemid = 0;
     switch ($backuptype) {
         case backup::TYPE_1ACTIVITY:
             $ctxid = get_context_instance(CONTEXT_MODULE, $id)->id;
             $component = 'backup';
             $filearea = 'activity';
             $itemid = 0;
             break;
         case backup::TYPE_1SECTION:
             $ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
             $component = 'backup';
             $filearea = 'section';
             $itemid = $id;
             break;
         case backup::TYPE_1COURSE:
             $ctxid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
             $component = 'backup';
             $filearea = 'course';
             $itemid = 0;
             break;
     }
     if ($backupmode == backup::MODE_AUTOMATED) {
         // Automated backups have there own special area!
         $filearea = 'automated';
     }
     // 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;
         $component = 'user';
         $filearea = 'tohub';
         $itemid = 0;
     }
     // Backups without user info or with the anonymise functionality
     // enabled are sent to user's "user_backup"
     // file area. Maintenance of such area is responsibility of
     // the user via corresponding file manager frontend
     if ($backupmode == backup::MODE_GENERAL && (!$hasusers || $isannon)) {
         $ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
         $component = 'user';
         $filearea = 'backup';
         $itemid = 0;
     }
     // Let's send the file to file storage, everything already defined
     $fs = get_file_storage();
     $fr = array('contextid' => $ctxid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid, 'filepath' => '/', 'filename' => $filename, 'userid' => $userid, 'timecreated' => time(), 'timemodified' => time());
     // If file already exists, delete if before
     // creating it again. This is BC behaviour - copy()
     // overwrites by default
     if ($fs->file_exists($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename'])) {
         $pathnamehash = $fs->get_pathname_hash($fr['contextid'], $fr['component'], $fr['filearea'], $fr['itemid'], $fr['filepath'], $fr['filename']);
         $sf = $fs->get_file_by_hash($pathnamehash);
         $sf->delete();
     }
     return $fs->create_file_from_pathname($fr, $filepath);
 }
开发者ID:nmicha,项目名称:moodle,代码行数:95,代码来源:backup_helper.class.php

示例15: test_backup_controller_dbops

 function test_backup_controller_dbops()
 {
     global $DB;
     $dbman = $DB->get_manager();
     // Going to use some database_manager services for testing
     // Instantiate non interactive backup_controller
     $bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
     $this->assertTrue($bc instanceof backup_controller);
     // Calculate checksum
     $checksum = $bc->calculate_checksum();
     $this->assertEqual(strlen($checksum), 32);
     // is one md5
     // save controller
     $recid = backup_controller_dbops::save_controller($bc, $checksum);
     $this->assertTrue($recid);
     $this->todelete[] = array('backup_controllers', $recid);
     // mark this record for deletion
     // save it again (should cause update to happen)
     $recid2 = backup_controller_dbops::save_controller($bc, $checksum);
     $this->assertTrue($recid2);
     $this->todelete[] = array('backup_controllers', $recid2);
     // mark this record for deletion
     $this->assertEqual($recid, $recid2);
     // Same record in both save operations
     // Try incorrect checksum
     $bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
     $checksum = $bc->calculate_checksum();
     try {
         $recid = backup_controller_dbops::save_controller($bc, 'lalala');
         $this->assertTrue(false, 'backup_dbops_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof backup_dbops_exception);
         $this->assertEqual($e->errorcode, 'backup_controller_dbops_saving_checksum_mismatch');
     }
     // Try to save non backup_controller object
     $bc = new stdclass();
     try {
         $recid = backup_controller_dbops::save_controller($bc, 'lalala');
         $this->assertTrue(false, 'backup_controller_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof backup_controller_exception);
         $this->assertEqual($e->errorcode, 'backup_controller_expected');
     }
     // save and load controller (by backupid). Then compare
     $bc = new mock_backup_controller4dbops(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
     $checksum = $bc->calculate_checksum();
     // Calculate checksum
     $backupid = $bc->get_backupid();
     $this->assertEqual(strlen($backupid), 32);
     // is one md5
     $recid = backup_controller_dbops::save_controller($bc, $checksum);
     // save controller
     $this->todelete[] = array('backup_controllers', $recid);
     // mark this record for deletion
     $newbc = backup_controller_dbops::load_controller($backupid);
     // load controller
     $this->assertTrue($newbc instanceof backup_controller);
     $newchecksum = $newbc->calculate_checksum();
     $this->assertEqual($newchecksum, $checksum);
     // try to load non-existing controller
     try {
         $bc = backup_controller_dbops::load_controller('1234567890');
         $this->assertTrue(false, 'backup_dbops_exception expected');
     } catch (exception $e) {
         $this->assertTrue($e instanceof backup_dbops_exception);
         $this->assertEqual($e->errorcode, 'backup_controller_dbops_nonexisting');
     }
     // backup_ids_temp table tests
     // If, for any reason table exists, drop it
     if ($dbman->table_exists('backup_ids_temp')) {
         $dbman->drop_temp_table(new xmldb_table('backup_ids_temp'));
     }
     // Check backup_ids_temp table doesn't exist
     $this->assertFalse($dbman->table_exists('backup_ids_temp'));
     // Create and check it exists
     backup_controller_dbops::create_backup_ids_temp_table('testingid');
     $this->assertTrue($dbman->table_exists('backup_ids_temp'));
     // Drop and check it doesn't exists anymore
     backup_controller_dbops::drop_backup_ids_temp_table('testingid');
     $this->assertFalse($dbman->table_exists('backup_ids_temp'));
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:81,代码来源:testdbops.php


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