/** * Rewind the iterator. * * Implementation of Iterator::rewind() - subclasses of MigrateSource should * implement performRewind() to do any class-specific setup for iterating * source records. */ public function rewind() { $this->idMap = $this->migration->getIdMap(); $this->numProcessed = 0; $this->numIgnored = 0; $this->getIterator()->rewind(); $this->next(); }
protected function mapJoinable() { if (!$this->getIds()) { return FALSE; } $id_map = $this->migration->getIdMap(); if (!$id_map instanceof Sql) { return FALSE; } $id_map_database_options = $id_map->getDatabase()->getConnectionOptions(); $source_database_options = $this->getDatabase()->getConnectionOptions(); foreach (array('username', 'password', 'host', 'port', 'namespace', 'driver') as $key) { if ($id_map_database_options[$key] != $source_database_options[$key]) { return FALSE; } } return TRUE; }
/** * {@inheritdoc} */ public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->migration = $migration; // Set up some defaults based on the source configuration. $this->cacheCounts = !empty($configuration['cache_counts']); $this->skipCount = !empty($configuration['skip_count']); $this->cacheKey = !empty($configuration['cache_key']) ? !empty($configuration['cache_key']) : NULL; $this->trackChanges = !empty($configuration['track_changes']) ? $configuration['track_changes'] : FALSE; $this->idMap = $this->migration->getIdMap(); // Pull out the current highwater mark if we have a highwater property. if ($this->highWaterProperty = $this->migration->get('highWaterProperty')) { $this->originalHighWater = $this->migration->getHighWater(); } // Don't allow the use of both highwater and track changes together. if ($this->highWaterProperty && $this->trackChanges) { throw new MigrateException('You should either use a highwater mark or track changes not both. They are both designed to solve the same problem'); } }
/** * Rewind the iterator. * * Implementation of Iterator::rewind() - subclasses of MigrateSource should * implement performRewind() to do any class-specific setup for iterating * source records. */ public function rewind() { $this->idMap = $this->migration->getIdMap(); $this->getIterator()->rewind(); $this->next(); }
/** * Passes messages through to the map class. * * @param string $message * The message to record. * @param int $level * (optional) Message severity (defaults to MESSAGE_ERROR). */ public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR) { $this->migration->getIdMap()->saveMessage($this->sourceIdValues, $message, $level); }
/** * 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); }