public function ContentSynchronizerCommands::synchronizerCreateImport in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Commands/ContentSynchronizerCommands.php \Drupal\content_synchronizer\Commands\ContentSynchronizerCommands::synchronizerCreateImport()
Create an import from passed .zip file.
@option as_function if this command will call as a function, in this case, return ImportEntity Id.
@command content:synchronizer-create-import @aliases csci,content-synchronizer-create-import
Parameters
$path: Optional. The cache bin to fetch from.
array $options: An associative array of options whose values come from cli, aliases, config, etc.
Return value
integer
1 call to ContentSynchronizerCommands::synchronizerCreateImport()
- ContentSynchronizerCommands::synchronizerImportZip in src/
Commands/ ContentSynchronizerCommands.php - Import from zip : bind together csci & cslim
File
- src/
Commands/ ContentSynchronizerCommands.php, line 43
Class
- ContentSynchronizerCommands
- A Drush commandfile.
Namespace
Drupal\content_synchronizer\CommandsCode
public function synchronizerCreateImport($path, $options = [
'as_function' => FALSE,
]) {
if (file_exists($path)) {
$extensionData = explode('.', $path);
if (end($extensionData) == 'zip') {
if ($file = file_save_data(file_get_contents($path))) {
$name = strip_tags(t('Drush import - %date', [
'%date' => \Drupal::service('date.formatter')
->format(time()),
]));
$ie = ImportEntity::create([
'name' => $name,
ImportEntity::FIELD_ARCHIVE => $file,
]);
$ie
->save();
$this->logger
->notice(t('The import has been created')
->__toString());
}
}
else {
$this->logger
->error(t('The file is not a .zip archive')
->__toString());
}
}
else {
$this->logger
->error(t('No file found')
->__toString());
}
if ($options['as_function'] == TRUE) {
return $ie
->id();
}
}