function site_settings_update_8003 in Site Settings and Labels 8
Delete orphaned site settings.
There may be orphaned site settings where the site setting entity type was deleted but the site settings of that entity type were left behind. Clean those up.
File
- ./
site_settings.install, line 80 - Contains install and update hooks.
Code
function site_settings_update_8003() {
// If this update hasn't run, ensure update 8004 runs before this.
site_settings_update_8004();
// Get all existing site setting types.
$query = \Drupal::entityQuery('site_setting_entity_type');
if ($entity_type_ids = $query
->execute()) {
// Find any site settings that don't belong to an existing type.
$query = \Drupal::entityQuery('site_setting_entity');
$query
->condition('type', $entity_type_ids, 'NOT IN');
if ($entity_ids = $query
->execute()) {
// Delete the orphaned site settings.
$controller = \Drupal::entityTypeManager()
->getStorage('site_setting_entity');
$entities = $controller
->loadMultiple($entity_ids);
$controller
->delete($entities);
}
}
}