public function ContentSynchronizerCommands::synchronizerLaunchImport in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Commands/ContentSynchronizerCommands.php \Drupal\content_synchronizer\Commands\ContentSynchronizerCommands::synchronizerLaunchImport()
Launch the import of the passed ID.
@option publish Autopublish imported content : publish|unpublish @option update Update stategy : systematic|if_recent|no_update
@command content:synchronizer-launch-import @aliases cslim,content-synchronizer-launch-import
Parameters
$importId: The import id.
array $options: An associative array of options whose values come from cli, aliases, config, etc.
Throws
\Exception
1 call to ContentSynchronizerCommands::synchronizerLaunchImport()
- ContentSynchronizerCommands::synchronizerImportZip in src/
Commands/ ContentSynchronizerCommands.php - Import from zip : bind together csci & cslim
File
- src/
Commands/ ContentSynchronizerCommands.php, line 162
Class
- ContentSynchronizerCommands
- A Drush commandfile.
Namespace
Drupal\content_synchronizer\CommandsCode
public function synchronizerLaunchImport($importId, $options = [
'publish' => '',
'update' => '',
]) {
if ($import = ImportEntity::load($importId)) {
if (!in_array('publication_' . $options['publish'], array_keys(LaunchImportForm::getCreateOptions()))) {
$message = "Publish option must be in : publish|unpublish";
throw new \Exception($message);
}
if (!in_array('update_' . $options['update'], array_keys(LaunchImportForm::getUpdateOptions()))) {
$message = "Update option must be in : systematic|if_recent|no_update";
throw new \Exception($message);
}
$createType = 'publication_' . $options['publish'];
$updateType = 'update_' . $options['update'];
$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) {
$this->logger
->error($error
->getMessage());
$status = t('Error');
}
$this->logger
->notice(t('[@key/@count] - "@label" - @status', [
'@key' => $key + 1,
'@count' => $count,
'@status' => $status,
'@label' => $rootEntityData['label'],
])
->__toString());
}
// Close process.
$import
->removeArchive();
}
}