You are here

cms_content_sync_health.install in CMS Content Sync 2.1.x

Install file for cms_content_sync_health.

File

modules/cms_content_sync_health/cms_content_sync_health.install
View source
<?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 in
 * the module.
 *
 * @param $configsNames
 */
function _cms_content_sync_health_update_config($configsNames) {
  $config_path = drupal_get_path('module', '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.';
}

Functions

Namesort descending Description
cms_content_sync_health_install Implements hook_install().
cms_content_sync_health_uninstall Implements hook_uninstall().
cms_content_sync_health_update_8001 Add content title filter to health dashboard status entity view.
cms_content_sync_health_update_8002 Add aggregation to avoid translation related duplicates.
cms_content_sync_health_update_8003 Add UUID field and filter to sync health view page.
_cms_content_sync_health_update_config Re-import the given config to reset it to defaults when they're changed in the module.