public function AcquiaContentHubConfigNullUuidsFix::fixConfigEntitiesWithNullUuids in Acquia Content Hub 8.2
Assigns randomly generated UUIDs to configuration entities with NULL UUIDs.
@command acquia:contenthub-fix-config-entities-with-null-uuids @aliases ach-fix-null-uuids
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- modules/
acquia_contenthub_site_health/ src/ Commands/ AcquiaContentHubConfigNullUuidsFix.php, line 75
Class
- AcquiaContentHubConfigNullUuidsFix
- Drush command to fix config entities with null uuids.
Namespace
Drupal\acquia_contenthub_site_health\CommandsCode
public function fixConfigEntitiesWithNullUuids() {
$this
->output()
->writeln(sprintf("Checking Drupal configuration entities for compatibility with Content Hub...\n\n"));
// If this site isn't a publisher, don't generate UUIDs for config entities.
if (!$this->moduleHandler
->moduleExists('acquia_contenthub_publisher')) {
throw new \Exception("This command should only be run on a publisher site.");
}
$missing_uuid_count = 0;
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type) {
if (!$entity_type instanceof ConfigEntityType) {
continue;
}
$entity_type_id = $entity_type
->id();
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
$entities = $storage
->loadMultiple();
$missing_uuid_count = 0;
foreach ($entities as $entity) {
if (!$entity
->uuid()) {
$missing_uuid_count++;
$config_id = $entity
->getConfigDependencyName();
$config = $this->configFactory
->getEditable($config_id);
$config
->set('uuid', $this->uuidGenerator
->generate());
$config
->save();
$entity = $storage
->load($entity
->id());
$this
->output()
->writeln(sprintf("Entity type: %s, Entity id: %s, Entity uuid: %s\n", $entity_type
->id(), $entity
->id(), $entity
->uuid()));
}
}
}
if ($missing_uuid_count === 0) {
$this
->output()
->writeln(sprintf("\n\nAll Drupal configuration entities have proper UUIDs."));
}
}