You are here

function nopremium_migrate_prepare_row in Node Option Premium 8

Implements hook_migrate_prepare_row().

Adds premium data to node source.

File

./nopremium.module, line 224
Hook implementations.

Code

function nopremium_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
  if ($source instanceof MigrateD6Node || $source instanceof MigrateD7Node) {
    if (!$source
      ->getDatabase()
      ->schema()
      ->fieldExists('node', 'premium')) {

      // The node table from the database in question does not have a column
      // named 'premium', so there's no premium data to migrate from the D6 or
      // D7 site.
      return;
    }

    // Get the premium data from the node table for the given node.
    // @todo find out how to alter the original migrate query as that would give
    // a better performance.
    $value = (bool) $source
      ->getDatabase()
      ->query('SELECT premium FROM {node} WHERE nid = :nid', [
      ':nid' => $row
        ->getSourceProperty('nid'),
    ])
      ->fetchField();
    $row
      ->setSourceProperty('premium', $value);
  }
}