function IdAuditor::auditEntityComplete

Same name in other branches
  1. 8.9.x core/modules/migrate/src/Audit/IdAuditor.php \Drupal\migrate\Audit\IdAuditor::auditEntityComplete()
  2. 10 core/modules/migrate/src/Audit/IdAuditor.php \Drupal\migrate\Audit\IdAuditor::auditEntityComplete()
  3. 11.x core/modules/migrate/src/Audit/IdAuditor.php \Drupal\migrate\Audit\IdAuditor::auditEntityComplete()

Audits an EntityComplete migration.

@todo Refactor in https://www.drupal.org/project/drupal/issues/3061676 or https://www.drupal.org/project/drupal/issues/3091004

Parameters

\Drupal\migrate\Plugin\MigrationInterface $migration: The migration to audit.

Return value

bool TRUE if the audit passes and FALSE if not.

1 call to IdAuditor::auditEntityComplete()
IdAuditor::audit in core/modules/migrate/src/Audit/IdAuditor.php
Audits a migration.

File

core/modules/migrate/src/Audit/IdAuditor.php, line 74

Class

IdAuditor
Audits migrations that create content entities in the destination system.

Namespace

Drupal\migrate\Audit

Code

private function auditEntityComplete(MigrationInterface $migration) {
    $map_table = $migration->getIdMap()
        ->mapTableName();
    $database = \Drupal::database();
    if (!$database->schema()
        ->tableExists($map_table)) {
        throw new \InvalidArgumentException();
    }
    $query = $database->select($map_table, 'map')
        ->fields('map', [
        'destid2',
    ])
        ->range(0, 1)
        ->orderBy('destid2', 'DESC');
    $max = (int) $query->execute()
        ->fetchField();
    // Make a migration based on node_complete but with an entity_revision
    // destination.
    $revision_migration = $migration->getPluginDefinition();
    $revision_migration['id'] = $migration->getPluginId() . '-revision';
    $revision_migration['destination']['plugin'] = 'entity_revision:node';
    $revision_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($revision_migration);
    // Get the highest node revision ID.
    $destination = $revision_migration->getDestinationPlugin();
    $highest = $destination->getHighestId();
    return $max <= $highest;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.