class IdAuditor in Drupal 9
Same name and namespace in other branches
- 8 core/modules/migrate/src/Audit/IdAuditor.php \Drupal\migrate\Audit\IdAuditor
- 10 core/modules/migrate/src/Audit/IdAuditor.php \Drupal\migrate\Audit\IdAuditor
Audits migrations that create content entities in the destination system.
Hierarchy
- class \Drupal\migrate\Audit\IdAuditor implements AuditorInterface uses StringTranslationTrait
Expanded class hierarchy of IdAuditor
3 files declare their use of IdAuditor
- IdConflictForm.php in core/
modules/ migrate_drupal_ui/ src/ Form/ IdConflictForm.php - MigrateDrupal6AuditIdsTest.php in core/
modules/ migrate_drupal/ tests/ src/ Kernel/ d6/ MigrateDrupal6AuditIdsTest.php - MigrateDrupal7AuditIdsTest.php in core/
modules/ migrate_drupal/ tests/ src/ Kernel/ d7/ MigrateDrupal7AuditIdsTest.php
File
- core/
modules/ migrate/ src/ Audit/ IdAuditor.php, line 12
Namespace
Drupal\migrate\AuditView source
class IdAuditor implements AuditorInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function auditMultiple(array $migrations) {
$conflicts = [];
foreach ($migrations as $migration) {
$migration_id = $migration
->getPluginId();
$conflicts[$migration_id] = $this
->audit($migration);
}
ksort($conflicts);
return $conflicts;
}
/**
* Audits an EntityComplete migration.
*
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration to audit.
*
* @return bool
* TRUE if the audit passes and FALSE if not.
*
* @todo Refactor in https://www.drupal.org/project/drupal/issues/3061676 or
* https://www.drupal.org/project/drupal/issues/3091004
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IdAuditor:: |
public | function |
Audits a migration. Overrides AuditorInterface:: |
|
IdAuditor:: |
private | function | Audits an EntityComplete migration. | |
IdAuditor:: |
public | function |
Audits a set of migrations. Overrides AuditorInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |