You are here

public function IdAuditor::audit in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Audit/IdAuditor.php \Drupal\migrate\Audit\IdAuditor::audit()

Audits a migration.

Parameters

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

Return value

\Drupal\migrate\Audit\AuditResult The result of the audit.

Throws

\Drupal\migrate\Audit\AuditException If the audit fails.

Overrides AuditorInterface::audit

1 call to IdAuditor::audit()
IdAuditor::auditMultiple in core/modules/migrate/src/Audit/IdAuditor.php
Audits a set of migrations.

File

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

Class

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

Namespace

Drupal\migrate\Audit

Code

public function audit(MigrationInterface $migration) {

  // If the migration does not opt into auditing, it passes.
  if (!$migration
    ->isAuditable()) {
    return AuditResult::pass($migration);
  }
  $interface = HighestIdInterface::class;
  $destination = $migration
    ->getDestinationPlugin();
  if (!$destination instanceof HighestIdInterface) {
    throw new AuditException($migration, "Destination does not implement {$interface}");
  }
  $id_map = $migration
    ->getIdMap();
  if (!$id_map instanceof HighestIdInterface) {
    throw new AuditException($migration, "ID map does not implement {$interface}");
  }
  if ($destination
    ->getHighestId() > $id_map
    ->getHighestId() || $destination instanceof EntityContentComplete && !$this
    ->auditEntityComplete($migration)) {
    return AuditResult::fail($migration, [
      $this
        ->t('The destination system contains data which was not created by a migration.'),
    ]);
  }
  return AuditResult::pass($migration);
}