cms_content_sync-3.0.x-dev/modules/cms_content_sync_health/cms_content_sync_health.install
modules/cms_content_sync_health/cms_content_sync_health.install
<?php
/**
* @file
* Install file for cms_content_sync_health.
*/
use Drupal\Core\Config\FileStorage;
/**
* Implements hook_install().
*/
function cms_content_sync_health_install() {
// Set module weight higher then the cms_content_sync module to ensure
// update hooks are triggered after it.
module_set_weight('cms_content_sync_health', 99);
// Cache rebuild is require, otherwise the module weight does not take effect.
drupal_flush_all_caches();
}
/**
* Implements hook_uninstall().
*/
function cms_content_sync_health_uninstall() {
/**
* @var \Drupal\Core\Config\CachedStorage $config_storage
*/
$config_storage = Drupal::service('config.storage');
// For some reason the dependency on the views configuration for the
// cms_content_sync_health module is not added to the actual configuration
// during the installation of the module. Because of this the view
// is not being removed during the uninstall process of the module.
$config_storage->delete('views.view.content_sync_entity_status');
}
/**
* Re-import the given config to reset it to defaults when they're changed.
*
* @param array $configsNames
* The configs to be imported.
*/
function _cms_content_sync_health_update_config(array $configsNames) {
$config_path = \Drupal::service('extension.list.module')->getPath('cms_content_sync_health') . '/config/install';
$source = new FileStorage($config_path);
$config_storage = Drupal::service('config.storage');
$config_factory = Drupal::configFactory();
$uuid_service = Drupal::service('uuid');
foreach ($configsNames as $name) {
// Ensure to delete the configuration if it already exists.
$config_factory->getEditable($name)->delete();
// Create config.
$config_storage->write($name, $source->read($name));
$config_factory->getEditable($name)->set('uuid', $uuid_service->generate())->save();
}
}
/**
* Add content title filter to health dashboard status entity view.
*/
function cms_content_sync_health_update_8001() {
$configsNames = [
'views.view.content_sync_entity_status',
];
_cms_content_sync_health_update_config($configsNames);
return 'Added new configurations for views bulk operations.';
}
/**
* Add aggregation to avoid translation related duplicates.
*/
function cms_content_sync_health_update_8002() {
$configsNames = [
'views.view.content_sync_entity_status',
];
_cms_content_sync_health_update_config($configsNames);
return 'Add aggregation to avoid translation related duplicates.';
}
/**
* Add UUID field and filter to sync health view page.
*/
function cms_content_sync_health_update_8003() {
$configsNames = [
'views.view.content_sync_entity_status',
];
_cms_content_sync_health_update_config($configsNames);
return 'Added UUID field and filter to sync health view page.';
}
/**
* Add content title filter to health dashboard status entity view.
*/
function cms_content_sync_health_update_8004() {
$configsNames = [
'views.view.content_sync_entity_status',
];
_cms_content_sync_health_update_config($configsNames);
return 'Adjust view configuration to show all entities instead of just nodes.';
}
