示例#1
0
 /**
  * A helper for adding tags and metadata to the query.
  *
  * @return \Drupal\Core\Database\Query\SelectInterface
  *   The query with additional tags and metadata.
  */
 protected function prepareQuery()
 {
     $this->query = clone $this->query();
     $this->query->addTag('migrate');
     $this->query->addTag('migrate_' . $this->migration->id());
     $this->query->addMetaData('migration', $this->migration);
     return $this->query;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', array($row, $this, $this->migration));
     $result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', array($row, $this, $this->migration));
     // If any of the hooks returned false, we want to skip the row.
     if ($result_hook && in_array(FALSE, $result_hook) || $result_named_hook && in_array(FALSE, $result_named_hook)) {
         return FALSE;
     }
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $result = TRUE;
     try {
         $result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', array($row, $this, $this->migration));
         $result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', array($row, $this, $this->migration));
         // We will skip if any hook returned FALSE.
         $skip = $result_hook && in_array(FALSE, $result_hook) || $result_named_hook && in_array(FALSE, $result_named_hook);
         $save_to_map = TRUE;
     } catch (MigrateSkipRowException $e) {
         $skip = TRUE;
         $save_to_map = $e->getSaveToMap();
     }
     // We're explicitly skipping this row - keep track in the map table.
     if ($skip) {
         // Make sure we replace any previous messages for this item with any
         // new ones.
         if ($save_to_map) {
             $this->idMap->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED);
             $this->currentRow = NULL;
             $this->currentSourceIds = NULL;
         }
         $result = FALSE;
     } elseif ($this->trackChanges) {
         // When tracking changed data, We want to quietly skip (rather than
         // "ignore") rows with changes. The caller needs to make that decision,
         // so we need to provide them with the necessary information (before and
         // after hashes).
         $row->rehash();
     }
     return $result;
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function prepareRow(Row $row)
 {
     $result = TRUE;
     $result_hook = $this->getModuleHandler()->invokeAll('migrate_prepare_row', array($row, $this, $this->migration));
     $result_named_hook = $this->getModuleHandler()->invokeAll('migrate_' . $this->migration->id() . '_prepare_row', array($row, $this, $this->migration));
     // We're explicitly skipping this row - keep track in the map table.
     if ($result_hook && in_array(FALSE, $result_hook) || $result_named_hook && in_array(FALSE, $result_named_hook)) {
         // Make sure we replace any previous messages for this item with any
         // new ones.
         $id_map = $this->migration->getIdMap();
         $id_map->delete($this->currentSourceIds, TRUE);
         $this->migrateExecutable->saveQueuedMessages();
         $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->migrateExecutable->rollbackAction);
         $this->numIgnored++;
         $this->currentRow = NULL;
         $this->currentSourceIds = NULL;
         $result = FALSE;
     } elseif ($this->trackChanges) {
         // When tracking changed data, We want to quietly skip (rather than
         // "ignore") rows with changes. The caller needs to make that decision,
         // so we need to provide them with the necessary information (before and
         // after hashes).
         $row->rehash();
     }
     $this->numProcessed++;
     return $result;
 }
示例#5
0
/**
 * Allows adding data to a row before processing it.
 *
 * For example, filter module used to store filter format settings in the
 * variables table which now needs to be inside the filter format config
 * file. So, it needs to be added here.
 *
 * hook_migrate_MIGRATION_ID_prepare_row is also available.
 */
function hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration)
{
    if ($migration->id() == 'd6_filter_formats') {
        $value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')))->fetchField();
        if ($value) {
            $row->setSourceProperty('settings:mymodule:foo', unserialize($value));
        }
    }
}
示例#6
0
 /**
  * Initialize the plugin.
  */
 protected function init()
 {
     if (!$this->initialized) {
         $this->initialized = TRUE;
         // Default generated table names, limited to 63 characters.
         $machine_name = str_replace(':', '__', $this->migration->id());
         $prefix_length = strlen($this->getDatabase()->tablePrefix());
         $this->mapTableName = 'migrate_map_' . Unicode::strtolower($machine_name);
         $this->mapTableName = Unicode::substr($this->mapTableName, 0, 63 - $prefix_length);
         $this->messageTableName = 'migrate_message_' . Unicode::strtolower($machine_name);
         $this->messageTableName = Unicode::substr($this->messageTableName, 0, 63 - $prefix_length);
         $this->ensureTables();
     }
 }
 /**
  * Performs an import operation - migrate items from source to destination.
  */
 public function import()
 {
     // Knock off migration if the requirements haven't been met.
     if (!$this->migration->checkRequirements()) {
         $this->message->display($this->t('Migration @id did not meet the requirements', array('@id' => $this->migration->id())), 'error');
         return MigrationInterface::RESULT_FAILED;
     }
     $return = MigrationInterface::RESULT_COMPLETED;
     $source = $this->getSource();
     $id_map = $this->migration->getIdMap();
     try {
         $source->rewind();
     } catch (\Exception $e) {
         $this->message->display($this->t('Migration failed with source plugin exception: !e', array('!e' => $e->getMessage())), 'error');
         return MigrationInterface::RESULT_FAILED;
     }
     $destination = $this->migration->getDestinationPlugin();
     while ($source->valid()) {
         $row = $source->current();
         if ($this->sourceIdValues = $row->getSourceIdValues()) {
             // Wipe old messages, and save any new messages.
             $id_map->delete($this->sourceIdValues, TRUE);
             $this->saveQueuedMessages();
         }
         try {
             $this->processRow($row);
             $save = TRUE;
         } catch (MigrateSkipRowException $e) {
             $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->rollbackAction);
             $save = FALSE;
         }
         if ($save) {
             try {
                 $destination_id_values = $destination->import($row, $id_map->lookupDestinationId($this->sourceIdValues));
                 if ($destination_id_values) {
                     // We do not save an idMap entry for config.
                     if ($destination_id_values !== TRUE) {
                         $id_map->saveIdMapping($row, $destination_id_values, $this->sourceRowStatus, $this->rollbackAction);
                     }
                     $this->successesSinceFeedback++;
                     $this->totalSuccesses++;
                 } else {
                     $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction);
                     if (!$id_map->messageCount()) {
                         $message = $this->t('New object was not saved, no error provided');
                         $this->saveMessage($message);
                         $this->message->display($message);
                     }
                 }
             } catch (MigrateException $e) {
                 $this->migration->getIdMap()->saveIdMapping($row, array(), $e->getStatus(), $this->rollbackAction);
                 $this->saveMessage($e->getMessage(), $e->getLevel());
                 $this->message->display($e->getMessage(), 'error');
             } catch (\Exception $e) {
                 $this->migration->getIdMap()->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction);
                 $this->handleException($e);
             }
         }
         $this->totalProcessed++;
         $this->processedSinceFeedback++;
         if ($highwater_property = $this->migration->get('highwaterProperty')) {
             $this->migration->saveHighwater($row->getSourceProperty($highwater_property['name']));
         }
         // Reset row properties.
         unset($sourceValues, $destinationValues);
         $this->sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED;
         if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) {
             break;
         }
         if ($this->timeOptionExceeded()) {
             break;
         }
         try {
             $source->next();
         } catch (\Exception $e) {
             $this->message->display($this->t('Migration failed with source plugin exception: !e', array('!e' => $e->getMessage())), 'error');
             return MigrationInterface::RESULT_FAILED;
         }
     }
     /**
      * @TODO uncomment this
      */
     #$this->progressMessage($return);
     return $return;
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL)
 {
     $migration_configuration['migration'][] = $migration->id();
     return new static($configuration, $plugin_id, $plugin_definition, $container->get('plugin.manager.migrate.process')->createInstance('migration', $migration_configuration, $migration), $container->get('plugin.manager.menu.link'), $container->get('entity.manager')->getStorage('menu_link_content'));
 }
 /**
  * Builds a row for an entity in the entity listing.
  *
  * @param EntityInterface $migration
  *   The entity for which to build the row.
  *
  * @return array
  *   A render array of the table row for displaying the entity.
  *
  * @see Drupal\Core\Entity\EntityListController::render()
  */
 public function buildRow(MigrationInterface $migration)
 {
     $row['label'] = $migration->label();
     $row['machine_name'] = $migration->id();
     $row['status'] = $migration->getStatusLabel();
     // Derive the stats
     $source_plugin = $migration->getSourcePlugin();
     $row['total'] = $source_plugin->count();
     $map = $migration->getIdMap();
     $row['imported'] = $map->importedCount();
     // -1 indicates uncountable sources.
     if ($row['total'] == -1) {
         $row['total'] = $this->t('N/A');
         $row['unprocessed'] = $this->t('N/A');
     } else {
         $row['unprocessed'] = $row['total'] - $map->processedCount();
     }
     $group = $migration->get('migration_group');
     if (!$group) {
         $group = 'default';
     }
     // @todo: This is most likely not a Best Practice (tm).
     $row['messages']['data']['#markup'] = '<a href="/admin/structure/migrate/manage/' . $group . '/migrations/' . $migration->id() . '/messages">' . $map->messageCount() . '</a>';
     $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported');
     $last_imported = $migrate_last_imported_store->get($migration->id(), FALSE);
     if ($last_imported) {
         /** @var DateFormatter $date_formatter */
         $date_formatter = \Drupal::service('date.formatter');
         $row['last_imported'] = $date_formatter->format($last_imported / 1000, 'custom', 'Y-m-d H:i:s');
     } else {
         $row['last_imported'] = '';
     }
     return $row;
     // + parent::buildRow($migration);
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL)
 {
     list($entity_type_id) = explode('__', $migration->id());
     return new static($configuration, $plugin_id, $plugin_definition, $migration, $container->get('entity.manager')->getStorage($entity_type_id), array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)), $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), $container->get('password'));
 }