You are here

function drush_content_synchronizer_launch_import in Content Synchronizer 8.2

Same name and namespace in other branches
  1. 8 content_synchronizer.drush.inc \drush_content_synchronizer_launch_import()

Launche the specified import.

File

./content_synchronizer.drush.inc, line 155
Drush commands for content_synchronizer module.

Code

function drush_content_synchronizer_launch_import($importId) {
  if ($import = ImportEntity::load($importId)) {
    if ($createType = drush_choice(LaunchImportForm::getCreateOptions(), LaunchImportForm::CREATION_ACTION_LABEL)) {
      if ($updateType = drush_choice(LaunchImportForm::getUpdateOptions(), LaunchImportForm::UPDATE_ACTION_LABEL)) {
        if ($doImport = drush_choice([
          'yes' => 'yes',
        ], t('Proceed import ?'))) {
          $importProcessor = new ImportProcessor($import);
          $importProcessor
            ->setCreationType($createType);
          $importProcessor
            ->setUpdateType($updateType);

          // Loop for logs.
          $rootEntities = $import
            ->getRootsEntities();
          $count = count($rootEntities);
          foreach ($rootEntities as $key => $rootEntityData) {
            try {
              $importProcessor
                ->importEntityFromRootData($rootEntityData);
              $status = array_key_exists('edit_url', $rootEntityData) ? t('Updated') : t('Created');
            } catch (\Exception $error) {
              drush_log($error
                ->getMessage(), 'error');
              $status = t('Error');
            }
            drush_log(t('[@key/@count] - "@label" - @status', [
              '@key' => $key + 1,
              '@count' => $count,
              '@status' => $status,
              '@label' => $rootEntityData['label'],
            ]), 'status');
          }

          // Close process.
          $import
            ->removeArchive();
        }
      }
    }
  }
}