cms_content_sync_views.install in CMS Content Sync 8
Same filename and directory in other branches
Install file for cms_content_sync_views.
File
modules/cms_content_sync_views/cms_content_sync_views.installView source
<?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 in
* the module.
*
* @param $configsNames
*/
function _cms_content_sync_views_update_config($configsNames) {
$config_path = drupal_get_path('module', '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();
}
}
/**
* 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.
*
* @return string
*
* @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')
->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::updateStatusEntities',
[
$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);
}
Functions
Name | Description |
---|---|
cms_content_sync_views_install | Implements hook_install(). |
cms_content_sync_views_update_8001 | Update the module weight. |
cms_content_sync_views_update_8002 | Add new action configurations. |
cms_content_sync_views_update_8003 | Add new action configurations. |
cms_content_sync_views_update_8004 | Update status entities. |
_cms_content_sync_views_batch_update_status_entities | Batch update status entities. |
_cms_content_sync_views_update_config | Re-import the given config to reset it to defaults when they're changed in the module. |