cms_content_sync-3.0.x-dev/modules/cms_content_sync_views/cms_content_sync_views.install

modules/cms_content_sync_views/cms_content_sync_views.install
<?php

/**
 * @file
 * Install file for cms_content_sync_views.
 */

use Drupal\Core\Config\FileStorage;

/**
 * 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_views_update_config(array $configsNames) {
  $config_path = \Drupal::service('extension.list.module')->getPath('cms_content_sync_views') . '/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) {
    $config_storage->write($name, $source->read($name));
    $config_factory->getEditable($name)->set('uuid', $uuid_service->generate())->save();
  }
}

/**
 * Add action to push to Sync Core v2.
 */
function cms_content_sync_views_update_8005() {
  // Migration code has been removed in 3.x.
  // $configsNames = [
  //  'system.action.push_status_entity_to_v2',
  // ];.

  // _cms_content_sync_views_update_config($configsNames);

  return 'Added new configuration to manually push to Sync Core v2.';
}

/**
 * Update status entities.
 */
function cms_content_sync_views_update_8004() {
  _cms_content_sync_views_batch_update_status_entities();

  return 'Status entities have been updated.';
}

/**
 * Add new action configurations.
 */
function cms_content_sync_views_update_8003() {
  $configsNames = [
    'system.action.import_status_entity',
    'system.action.export_status_entity',
  ];

  _cms_content_sync_views_update_config($configsNames);

  return 'Added new configurations for views bulk operations.';
}

/**
 * Add new action configurations.
 */
function cms_content_sync_views_update_8002() {
  $configsNames = [
    'system.action.reset_status_entity',
  ];

  _cms_content_sync_views_update_config($configsNames);

  return 'Added new configurations for views bulk operations.';
}

/**
 * Update the module weight.
 *
 * @internal param $sandbox
 */
function cms_content_sync_views_update_8001() {
  // Set module weight higher then the cms_content_sync module to ensure
  // update hooks are triggered after it.
  module_set_weight('cms_content_sync_views', 100);

  return 'Updated module weight to execute hooks after main module.';
}

/**
 * Implements hook_install().
 */
function cms_content_sync_views_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_views', 100);

  // Cache rebuild is require, otherwise the module weight does not take effect.
  drupal_flush_all_caches();

  // Batch update status entities.
  _cms_content_sync_views_batch_update_status_entities();
}

/**
 * Batch update status entities.
 */
function _cms_content_sync_views_batch_update_status_entities() {
  $ids = Drupal::entityQuery('cms_content_sync_entity_status')->accessCheck(FALSE)->execute();

  if (empty($ids)) {
    return;
  }

  // Update 50 entities during each batch run.
  $operations = [];
  foreach (array_chunk($ids, 50) as $batch_data) {
    $operations[] = [
      '\Drupal\cms_content_sync_views\Controller\UpdateStatusEntities::updateEntityReference',
          [
            $batch_data,
          ],
    ];
  }

  // Setup and define batch.
  $batch = [
    'title' => t('Updating status entities'),
    'operations' => $operations,
    'finished' => '\Drupal\cms_content_sync_views\Controller\UpdateStatusEntities::updateStatusEntitiesFinished',
  ];

  batch_set($batch);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc