public function annotate($backupid)
 {
     if (empty($this->annotationitem)) {
         // We aren't annotating this item
         return;
     }
     if (!$this->is_set()) {
         throw new base_element_struct_exception('attribute_has_not_value', $this->get_name());
     }
     backup_structure_dbops::insert_backup_ids_record($backupid, $this->annotationitem, $this->get_value());
 }
 /**
  * For sql or table datasources, this will iterate over the "external" DB connection
  * stored in this class instead of the default $DB. All other cases use the parent default.
  * @param object $processor the processor
  */
 protected function get_iterator($processor)
 {
     if ($this->get_source_table() !== null) {
         // It's one table, return recordset iterator.
         return $this->get_source_db()->get_recordset($this->get_source_table(), backup_structure_dbops::convert_params_to_values($this->procparams, $processor), $this->get_source_table_sortby());
     } else {
         if ($this->get_source_sql() !== null) {
             // It's one sql, return recordset iterator.
             return $this->get_source_db()->get_recordset_sql($this->get_source_sql(), backup_structure_dbops::convert_params_to_values($this->procparams, $processor));
         }
     }
     return parent::get_iterator($processor);
 }
 public function process_nested_element(base_nested_element $nested)
 {
     // Proceed with all the file annotations for this element
     $fileannotations = $nested->get_file_annotations();
     if ($fileannotations) {
         // If there are areas to search
         $backupid = $this->get_var(backup::VAR_BACKUPID);
         foreach ($fileannotations as $component => $area) {
             foreach ($area as $filearea => $info) {
                 $contextid = !is_null($info->contextid) ? $info->contextid : $this->get_var(backup::VAR_CONTEXTID);
                 $itemid = !is_null($info->element) ? $info->element->get_value() : null;
                 backup_structure_dbops::annotate_files($backupid, $contextid, $component, $filearea, $itemid);
             }
         }
     }
 }
 protected function define_execution()
 {
     global $DB;
     // List of fileareas we are going to annotate
     $fileareas = array('profile', 'icon');
     if ($this->get_setting_value('user_files')) {
         // private files only if enabled in settings
         $fileareas[] = 'private';
     }
     // Fetch all annotated (final) users
     $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $this->get_backupid(), 'itemname' => 'userfinal'));
     foreach ($rs as $record) {
         $userid = $record->itemid;
         $userctx = get_context_instance(CONTEXT_USER, $userid);
         if (!$userctx) {
             continue;
             // User has not context, sure it's a deleted user, so cannot have files
         }
         // Proceed with every user filearea
         foreach ($fileareas as $filearea) {
             // We don't need to specify itemid ($userid - 5th param) as far as by
             // context we can get all the associated files. See MDL-22092
             backup_structure_dbops::annotate_files($this->get_backupid(), $userctx->id, 'user', $filearea, null);
         }
     }
     $rs->close();
 }
 protected function define_execution()
 {
     global $DB;
     // List of fileareas we are going to annotate
     $fileareas = array('profile', 'icon');
     // Fetch all annotated (final) users
     $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $this->get_backupid(), 'itemname' => 'userfinal'));
     $progress = $this->task->get_progress();
     $progress->start_progress($this->get_name());
     foreach ($rs as $record) {
         $userid = $record->itemid;
         $userctx = context_user::instance($userid, IGNORE_MISSING);
         if (!$userctx) {
             continue;
             // User has not context, sure it's a deleted user, so cannot have files
         }
         // Proceed with every user filearea
         foreach ($fileareas as $filearea) {
             // We don't need to specify itemid ($userid - 5th param) as far as by
             // context we can get all the associated files. See MDL-22092
             backup_structure_dbops::annotate_files($this->get_backupid(), $userctx->id, 'user', $filearea, null);
             $progress->progress();
         }
     }
     $progress->end_progress();
     $rs->close();
 }
 protected function define_execution()
 {
     global $DB;
     // List of fileareas we are going to annotate
     $fileareas = array('profile', 'icon');
     // Fetch all annotated (final) users
     $rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $this->get_backupid(), 'itemname' => 'userfinal'));
     foreach ($rs as $record) {
         $userid = $record->itemid;
         $userctxid = get_context_instance(CONTEXT_USER, $userid)->id;
         // Proceed with every user filearea
         foreach ($fileareas as $filearea) {
             // We don't need to specify itemid ($userid - 5th param) as far as by
             // context we can get all the associated files. See MDL-22092
             backup_structure_dbops::annotate_files($this->get_backupid(), $userctxid, 'user', $filearea, null);
         }
     }
     $rs->close();
 }
 /**
  * Returns one PHP iterator over each "ocurrence" of this nested
  * element (array or DB recordset). Delegated to backup_structure_dbops class
  */
 protected function get_iterator($processor)
 {
     return backup_structure_dbops::get_iterator($this, $this->procparams, $processor);
 }