コード例 #1
0
ファイル: Upload.php プロジェクト: briefmedia-digital/drupal8
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $query = $this->select('upload', 'u')->fields('u', array('fid', 'description', 'list'))->condition('u.nid', $row->getSourceProperty('nid'))->orderBy('u.weight');
     $query->innerJoin('node', 'n', static::JOIN);
     $row->setSourceProperty('upload', $query->execute()->fetchAll());
     return parent::prepareRow($row);
 }
コード例 #2
0
 /**
  * Posts are either type recpie or restaurant_review.
  * Recpies contain <div class="recipe">, everything else is considered type
  * restaurant_review.
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $return = array();
     $caption_tags = $this->getTags($value)['caption']['values'];
     if (is_array($caption_tags)) {
         foreach ($caption_tags as $image) {
             // Search for imported File:
             $q = db_select('migrate_map_donkeymedia_file', 'm')->fields('m', array('sourceid1', 'destid1'))->condition('m.sourceid1', $image['attachment'])->execute();
             $map = $q->fetchObject();
             if ($map) {
                 $dest = array('target_id' => $map->destid1, 'alt' => 'Sorry. No describing text available.', 'title' => 'No title');
                 // Alt Tag.
                 if (!empty($image['alt'])) {
                     $dest['alt'] = $image['alt'];
                 }
                 // Title.
                 if (!empty($image['caption'])) {
                     $dest['title'] = $image['caption'];
                 }
                 $return[] = $dest;
             } else {
                 echo 'Source Id: "' . $image['attachment'] . '" not Found in File Map table (migrate_map_donkeymedia_file)' . "\n";
                 throw new MigrateSkipProcessException();
             }
         }
     }
     if (!empty($return)) {
         $row->setDestinationProperty($destination_property, $return);
     }
 }
コード例 #3
0
ファイル: TextField.php プロジェクト: sgtsaughter/d8portfolio
 /**
  * {@inheritdoc}
  */
 public function getFieldType(Row $row)
 {
     $widget_type = $row->getSourceProperty('widget_type');
     if ($widget_type == 'text_textfield') {
         $settings = $row->getSourceProperty('global_settings');
         $field_type = $settings['text_processing'] ? 'text' : 'string';
         if (empty($settings['max_length']) || $settings['max_length'] > 255) {
             $field_type .= '_long';
         }
         return $field_type;
     } else {
         switch ($widget_type) {
             case 'optionwidgets_buttons':
             case 'optionwidgets_select':
                 return 'list_string';
             case 'optionwidgets_onoff':
                 return 'boolean';
             case 'text_textarea':
                 return 'text_long';
             default:
                 return parent::getFieldType($row);
                 break;
         }
     }
 }
コード例 #4
0
ファイル: User.php プロジェクト: atxajon/d8cafe
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $uid = $row->getSourceProperty('uid');
     // field_real_name
     $result = $this->getDatabase()->query('
   SELECT
     fld.field_real_name_value
   FROM
     {dcf_field_data_field_real_name} fld
   WHERE
     fld.entity_id = :uid
 ', array(':uid' => $uid));
     foreach ($result as $record) {
         $row->setSourceProperty('field_real_name', $record->field_real_name_value);
     }
     // field_availability
     $result = $this->getDatabase()->query('
   SELECT
     fld.field_availability_value
   FROM
     {dcf_field_data_field_availability} fld
   WHERE
     fld.entity_id = :uid
 ', array(':uid' => $uid));
     foreach ($result as $record) {
         $row->setSourceProperty('field_availability', $record->field_availability_value);
     }
     return parent::prepareRow($row);
 }
コード例 #5
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $type = $row->getSourceProperty('type');
     $row->setSourceProperty('language_content_type', $this->variableGet('language_content_type_' . $type, NULL));
     $row->setSourceProperty('i18n_lock_node', $this->variableGet('i18n_lock_node_' . $type, 0));
     return parent::prepareRow($row);
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $data = unserialize($row->getSourceProperty('data'));
     $row->setSourceProperty('widget', $data['widget']);
     $row->setSourceProperty('widget_settings', $data['widget']['settings']);
     return parent::prepareRow($row);
 }
コード例 #7
0
ファイル: BeerUser.php プロジェクト: Wylbur/eight
 public function prepareRow(Row $row)
 {
     if ($value = $row->getSourceProperty('beers')) {
         $row->setSourceProperty('beers', explode('|', $value));
     }
     return parent::prepareRow($row);
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $post_type = $row->getSourceProperty('post_type');
     $type = $post_type == 'page' ? 'page' : 'article';
     $row->setSourceProperty('type', $type);
     return parent::prepareRow($row);
 }
コード例 #9
0
ファイル: VariableMultiRow.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     if ($value = $row->getSourceProperty('value')) {
         $row->setSourceProperty('value', unserialize($value));
     }
     return parent::prepareRow($row);
 }
コード例 #10
0
ファイル: FileCopy.php プロジェクト: eigentor/tommiblog
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     // If we're stubbing a file entity, return a URI of NULL so it will get
     // stubbed by the general process.
     if ($row->isStub()) {
         return NULL;
     }
     list($source, $destination) = $value;
     // Ensure the source file exists, if it's a local URI or path.
     if ($this->isLocalUri($source) && !file_exists($source)) {
         throw new MigrateException("File '{$source}' does not exist");
     }
     // If the start and end file is exactly the same, there is nothing to do.
     if ($this->isLocationUnchanged($source, $destination)) {
         return $destination;
     }
     $replace = $this->getOverwriteMode();
     // We attempt the copy/move first to avoid calling file_prepare_directory()
     // any more than absolutely necessary.
     $final_destination = $this->writeFile($source, $destination, $replace);
     if ($final_destination) {
         return $final_destination;
     }
     // If writeFile didn't work, make sure there's a writable directory in
     // place.
     $dir = $this->getDirectory($destination);
     if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
         throw new MigrateException("Could not create or write to directory '{$dir}'");
     }
     $final_destination = $this->writeFile($source, $destination, $replace);
     if ($final_destination) {
         return $final_destination;
     }
     throw new MigrateException("File {$source} could not be copied to {$destination}");
 }
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     // Select all related tickets (rnid) to the current ticket (nid)
     $query = $this->select('support_reference', 'sr')->fields('sr', array('rnid'))->condition('sr.nid', $row->getSourceProperty('nid'));
     $row->setSourceProperty('rnid', $query->execute()->fetchCol());
     return parent::prepareRow($row);
 }
コード例 #12
0
 /**
  * {@inheritdoc}
  */
 protected function getEntityId(Row $row)
 {
     $entity_type = $row->getDestinationProperty('entity_type');
     $bundle = $row->getDestinationProperty('bundle');
     $field_name = $row->getDestinationProperty('field_name');
     return "{$entity_type}.{$bundle}.{$field_name}";
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $source = $this->configuration['source_base_path'] . $row->getSourceProperty($this->configuration['source_path_property']);
     $destination = $row->getDestinationProperty($this->configuration['destination_path_property']);
     $replace = FILE_EXISTS_REPLACE;
     if (!empty($this->configuration['rename'])) {
         $entity_id = $row->getDestinationProperty($this->getKey('id'));
         if (!empty($entity_id) && ($entity = $this->storage->load($entity_id))) {
             $replace = FILE_EXISTS_RENAME;
         }
     }
     $dirname = drupal_dirname($destination);
     if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) {
         throw new MigrateException(t('Could not create directory %dirname', array('%dirname' => $dirname)));
     }
     if ($this->configuration['move']) {
         $copied = file_unmanaged_move($source, $destination, $replace);
     } else {
         // Determine whether we can perform this operation based on overwrite rules.
         $original_destination = $destination;
         $destination = file_destination($destination, $replace);
         if ($destination === FALSE) {
             throw new MigrateException(t('File %file could not be copied because a file by that name already exists in the destination directory (%destination)', array('%file' => $source, '%destination' => $original_destination)));
         }
         $source = $this->urlencode($source);
         $copied = copy($source, $destination);
     }
     if ($copied) {
         return parent::import($row, $old_destination_id_values);
     } else {
         throw new MigrateException(t('File %source could not be copied to %destination.', array('%source' => $source, '%destination' => $destination)));
     }
 }
コード例 #14
0
ファイル: Download.php プロジェクト: Greg-Boggs/electric-dev
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     // If we're stubbing a file entity, return a uri of NULL so it will get
     // stubbed by the general process.
     if ($row->isStub()) {
         return NULL;
     }
     list($source, $destination) = $value;
     // Modify the destination filename if necessary.
     $replace = !empty($this->configuration['rename']) ? FILE_EXISTS_RENAME : FILE_EXISTS_REPLACE;
     $final_destination = file_destination($destination, $replace);
     // Try opening the file first, to avoid calling file_prepare_directory()
     // unnecessarily. We're suppressing fopen() errors because we want to try
     // to prepare the directory before we give up and fail.
     $destination_stream = @fopen($final_destination, 'w');
     if (!$destination_stream) {
         // If fopen didn't work, make sure there's a writable directory in place.
         $dir = $this->fileSystem->dirname($final_destination);
         if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
             throw new MigrateException("Could not create or write to directory '{$dir}'");
         }
         // Let's try that fopen again.
         $destination_stream = @fopen($final_destination, 'w');
         if (!$destination_stream) {
             throw new MigrateException("Could not write to file '{$final_destination}'");
         }
     }
     // Stream the request body directly to the final destination stream.
     $this->configuration['guzzle_options']['sink'] = $destination_stream;
     // Make the request. Guzzle throws an exception for anything other than 200.
     $this->httpClient->get($source, $this->configuration['guzzle_options']);
     return $final_destination;
 }
コード例 #15
0
ファイル: EntityTaxonomyTerm.php プロジェクト: dmyerson/d8ecs
 /**
  * {@inheritdoc}
  */
 protected function getEntity(Row $row, array $old_destination_id_values)
 {
     if ($row->isStub()) {
         $row->setDestinationProperty('name', $this->t('Stub name for source tid:') . $row->getSourceProperty('tid'));
     }
     return parent::getEntity($row, $old_destination_id_values);
 }
コード例 #16
0
ファイル: Field.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row, $keep = TRUE)
 {
     foreach (unserialize($row->getSourceProperty('data')) as $key => $value) {
         $row->setSourceProperty($key, $value);
     }
     return parent::prepareRow($row);
 }
コード例 #17
0
ファイル: File.php プロジェクト: ravindrasingh22/Drupal-8-rc
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $row->setSourceProperty('file_directory_path', $this->filePath);
     $row->setSourceProperty('temp_directory_path', $this->tempFilePath);
     $row->setSourceProperty('is_public', $this->isPublic);
     return parent::prepareRow($row);
 }
コード例 #18
0
ファイル: Term.php プロジェクト: nsp15/Drupal8
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     // Find parents for this row.
     $parents = $this->select('term_hierarchy', 'th')->fields('th', array('parent', 'tid'))->condition('tid', $row->getSourceProperty('tid'))->execute()->fetchCol();
     $row->setSourceProperty('parent', $parents);
     return parent::prepareRow($row);
 }
コード例 #19
0
ファイル: Vocabulary.php プロジェクト: nB-MDSO/mdso-d8blog
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $vocab = $row->getSourceProperty('taxonomy');
     $label = $vocab == 'category' ? 'Category' : 'Post Tags';
     $row->setSourceProperty('label', $label);
     return parent::prepareRow($row);
 }
コード例 #20
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     /**
      * prepareRow() is the most common place to perform custom run-time
      * processing that isn't handled by an existing process plugin. It is called
      * when the raw data has been pulled from the source, and provides the
      * opportunity to modify or add to that data, creating the canonical set of
      * source data that will be fed into the processing pipeline.
      *
      * In our particular case, the list of a user's favorite ssds is a pipe-
      * separated list of ssd IDs. The processing pipeline deals with arrays
      * representing multi-value fields naturally, so we want to explode that
      * string to an array of individual ssd IDs.
      */
     if ($value = $row->getSourceProperty('ssds')) {
         $row->setSourceProperty('ssds', explode('|', $value));
     }
     /**
      * Always call your parent! Essential processing is performed in the base
      * class. Be mindful that prepareRow() returns a boolean status - if FALSE
      * that indicates that the item being processed should be skipped. Unless
      * we're deciding to skip an item ourselves, let the parent class decide.
      */
     return parent::prepareRow($row);
 }
コード例 #21
0
ファイル: EntityBlock.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 protected function getEntityId(Row $row)
 {
     // Try to find the block by its plugin ID and theme.
     $properties = array('plugin' => $row->getDestinationProperty('plugin'), 'theme' => $row->getDestinationProperty('theme'));
     $blocks = array_keys($this->storage->loadByProperties($properties));
     return reset($blocks);
 }
コード例 #22
0
ファイル: Get.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $source = $this->configuration['source'];
     $properties = is_string($source) ? array($source) : $source;
     $return = array();
     foreach ($properties as $property) {
         if ($property || (string) $property === '0') {
             $is_source = TRUE;
             if ($property[0] == '@') {
                 $property = preg_replace_callback('/^(@?)((?:@@)*)([^@]|$)/', function ($matches) use(&$is_source) {
                     // If there are an odd number of @ in the beginning, it's a
                     // destination.
                     $is_source = empty($matches[1]);
                     // Remove the possible escaping and do not lose the terminating
                     // non-@ either.
                     return str_replace('@@', '@', $matches[2]) . $matches[3];
                 }, $property);
             }
             if ($is_source) {
                 $return[] = $row->getSourceProperty($property);
             } else {
                 $return[] = $row->getDestinationProperty($property);
             }
         } else {
             $return[] = $value;
         }
     }
     if (is_string($source)) {
         $this->multiple = is_array($return[0]);
         return $return[0];
     }
     return $return;
 }
コード例 #23
0
ファイル: Vocabulary.php プロジェクト: nsp15/Drupal8
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     // Find node types for this row.
     $node_types = $this->select('vocabulary_node_types', 'nt')->fields('nt', array('type', 'vid'))->condition('vid', $row->getSourceProperty('vid'))->execute()->fetchCol();
     $row->setSourceProperty('node_types', $node_types);
     return parent::prepareRow($row);
 }
コード例 #24
0
ファイル: User.php プロジェクト: Greg-Boggs/electric-dev
  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    // User roles.
    $roles = $this->select('users_roles', 'ur')
      ->fields('ur', array('rid'))
      ->condition('ur.uid', $row->getSourceProperty('uid'))
      ->execute()
      ->fetchCol();
    $row->setSourceProperty('roles', $roles);

    // We are adding here the Event contributed module column.
    // @see https://api.drupal.org/api/drupal/modules%21user%21user.install/function/user_update_7002/7
    if ($row->hasSourceProperty('timezone_id') && $row->getSourceProperty('timezone_id')) {
      if ($this->getDatabase()->schema()->tableExists('event_timezones')) {
        $event_timezone = $this->select('event_timezones', 'e')
          ->fields('e', array('name'))
          ->condition('e.timezone', $row->getSourceProperty('timezone_id'))
          ->execute()
          ->fetchField();
        if ($event_timezone) {
          $row->setSourceProperty('event_timezone', $event_timezone);
        }
      }
    }

    // Unserialize Data.
    $row->setSourceProperty('data', unserialize($row->getSourceProperty('data')));

    return parent::prepareRow($row);
  }
コード例 #25
0
 /**
  * {@inheritdoc}
  *
  * Set field formatter settings when the map didn't map: for date
  * formatters, the fallback format, for everything else, empty array.
  */
 public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property)
 {
     // If the 1 index is set then the map missed.
     if (isset($value[1])) {
         $value = $row->getSourceProperty('module') == 'date' ? array('format_type' => 'fallback') : array();
     }
     return $value;
 }
コード例 #26
0
ファイル: UserData.php プロジェクト: aWEBoLabs/taxi
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     $uid = $row->getDestinationProperty('uid');
     $module = $row->getDestinationProperty('module');
     $key = $row->getDestinationProperty('key');
     $this->userData->set($module, $uid, $key, $row->getDestinationProperty('settings'));
     return [$uid, $module, $key];
 }
コード例 #27
0
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $value = $row->getSourceProperty('settings');
     if ($row->getSourceProperty('type') == 'image' && !is_array($value['default_image'])) {
         $value['default_image'] = array('uuid' => '');
     }
     return $value;
 }
コード例 #28
0
ファイル: FilterSettings.php プロジェクト: dmyerson/d8ecs
 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     // Only the filter_html filter's settings have a changed format.
     if ($row->getDestinationProperty('id') === 'filter_html') {
         $value['allowed_html'] = str_replace(array_keys($this->allowedHtmlDefaultAttributes), array_values($this->allowedHtmlDefaultAttributes), $value['allowed_html']);
     }
     return $value;
 }
コード例 #29
0
 /**
  * {@inheritdoc}
  * @throws \Drupal\migrate\MigrateException
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     // Do not overwrite the root account password.
     if ($row->getDestinationProperty('uid') == 1) {
         $row->removeDestinationProperty('pass');
     }
     return parent::import($row, $old_destination_id_values);
 }
コード例 #30
0
ファイル: ShortcutSetUsers.php プロジェクト: ddrozdik/dmaps
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     /** @var \Drupal\shortcut\ShortcutSetInterface $set */
     $set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
     /** @var \Drupal\user\UserInterface $account */
     $account = User::load($row->getDestinationProperty('uid'));
     $this->shortcutSetStorage->assignUser($set, $account);
     return array($set->id(), $account->id());
 }