function drush_cms_content_sync_migrate_acquia_content_hub_content_sync_migrate_acquia_content_hub in CMS Content Sync 2.0.x
Same name and namespace in other branches
- 8 modules/cms_content_sync_migrate_acquia_content_hub/cms_content_sync_migrate_acquia_content_hub.drush.inc \drush_cms_content_sync_migrate_acquia_content_hub_content_sync_migrate_acquia_content_hub()
- 2.1.x modules/cms_content_sync_migrate_acquia_content_hub/cms_content_sync_migrate_acquia_content_hub.drush.inc \drush_cms_content_sync_migrate_acquia_content_hub_content_sync_migrate_acquia_content_hub()
Migrate Acquia Content Hub.
File
- modules/
cms_content_sync_migrate_acquia_content_hub/ cms_content_sync_migrate_acquia_content_hub.drush.inc, line 67 - Contains Drush commands for Content Sync.
Code
function drush_cms_content_sync_migrate_acquia_content_hub_content_sync_migrate_acquia_content_hub() {
$type = drush_get_option('type');
$backend_url = drush_get_option('backend_url');
$authentication_type = drush_get_option('authentication_type');
$site_id = drush_get_option('site_id', '');
$node_push_behavior = drush_get_option('node_push_behavior', '');
$pull_updates_behavior = drush_get_option('pull_updates_behavior', '');
$force_update = drush_get_option('force_update', FALSE);
$override = drush_get_option('sync');
if ($override) {
$override = json_decode($override, TRUE);
}
// Validate type option.
if ($type != 'push' && $type != 'pull') {
drush_set_error('The option "type" has to be either "push" or "pull"');
return;
}
// Validate authentication_type option.
$moduleHandler = Drupal::service('module_handler');
if ($moduleHandler
->moduleExists('basic_auth')) {
if ($authentication_type != IApplicationInterface::AUTHENTICATION_TYPE_BASIC_AUTH && $authentication_type != IApplicationInterface::AUTHENTICATION_TYPE_COOKIE) {
drush_set_error('The option "authentication_type" has to be either "' . IApplicationInterface::AUTHENTICATION_TYPE_BASIC_AUTH . '" or "' . IApplicationInterface::AUTHENTICATION_TYPE_COOKIE . '".');
return;
}
}
else {
drush_set_error('The option "authentication_type" has to be "' . IApplicationInterface::AUTHENTICATION_TYPE_COOKIE . '".');
return;
}
// Validate site_id option.
$acquia_client_name = Drupal::config('acquia_contenthub.admin_settings')
->get('client_name');
if ($site_id == '' && !isset($acquia_client_name) && $acquia_client_name == '') {
drush_set_error('The option "site_id" has to be set since there is also no client_name configuration set for the Acquia Content Hub that could be taken over.');
return;
}
$create_status_entities = new CreateStatusEntities();
$operations = [];
$pool_id = MigrationBase::DEFAULT_POOL_MACHINE_NAME;
$pool = MigrationBase::DEFAULT_POOL;
// Create pools.
MigrationBase::createPools($pool, $backend_url, $authentication_type, $site_id);
// Create export configuration.
if ($type == 'push') {
// Validate node_push_behavior option.
if ($node_push_behavior == '') {
drush_set_error('For the creation of pushing flows the node_push_behavior is required.');
return;
}
if ($node_push_behavior != PushIntent::PUSH_AUTOMATICALLY && $node_push_behavior != PushIntent::PUSH_MANUALLY) {
drush_set_error('The node pushing behavior has to be either "' . PushIntent::PUSH_AUTOMATICALLY . '" or "' . PushIntent::PUSH_MANUALLY . '"');
return;
}
// Create flow.
$flow = MigratePush::createFlow($pool_id, $node_push_behavior, $pull_updates_behavior, $force_update, $override);
// Create status entities.
$operations = $create_status_entities
->prepare($flow['flow_id'], $flow['flow_configuration'], $pool_id, $flow['type']);
// Done.
drush_print('The pushing configuration has been created.');
}
// Create pull configuration.
if ($type == 'pull') {
// Validate pull_updates_behavior option.
if ($pull_updates_behavior == '') {
drush_set_error('For the creation of pull flows the pull_updates_behavior is required.');
return;
}
if ($pull_updates_behavior != PushIntent::PUSH_AUTOMATICALLY && $node_push_behavior != PushIntent::PUSH_MANUALLY && $pull_updates_behavior != PullIntent::PULL_UPDATE_FORCE_AND_FORBID_EDITING) {
drush_set_error('The pull_updates_behavior has to be either "' . PullIntent::PULL_UPDATE_FORCE_AND_FORBID_EDITING . '" or "' . PullIntent::PULL_UPDATE_FORCE_UNLESS_OVERRIDDEN . '" or "' . PullIntent::PULL_UPDATE_FORCE . '" or "' . PullIntent::PULL_UPDATE_IGNORE . '".');
return;
}
$content_hub_filters = Drupal::entityTypeManager()
->getStorage('contenthub_filter')
->loadMultiple();
foreach ($content_hub_filters as $content_hub_filter_id => $content_hub_filter) {
// Create flow.
$flow = MigratePull::createFlow($pool_id, $node_push_behavior, $pull_updates_behavior, $content_hub_filter, $force_update, $override);
// Create status entities.
$operations = array_merge($operations, $create_status_entities
->prepare($flow['flow_id'], $flow['flow_configuration'], $pool_id, $flow['type'], $content_hub_filter->tags));
}
drush_print('The pull configuration has been created.');
}
if (!count($operations)) {
return;
}
$batch = [
'title' => t('Creating status entities'),
'operations' => $operations,
];
batch_set($batch);
// Execute.
drush_backend_batch_process();
}