public function ContentSynchronizerCommands::synchronizerCreateImport in Content Synchronizer 8.2
Same name and namespace in other branches
- 8 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
string $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
int The import id.
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 72
Class
- ContentSynchronizerCommands
- A Drush commandfile.
Namespace
Drupal\content_synchronizer\CommandsCode
public function synchronizerCreateImport($path, array $options = [
'as_function' => FALSE,
]) {
if (file_exists($path)) {
$extensionData = explode('.', $path);
if (end($extensionData) == 'gz') {
if ($file = file_save_data(file_get_contents($path))) {
$name = strip_tags($this
->t('Drush import - %date', [
'%date' => $this->dateFormatter
->format(time()),
]));
$ie = ImportEntity::create([
'name' => $name,
ImportEntity::FIELD_ARCHIVE => $file,
]);
$ie
->save();
$this->logger
->notice($this
->t('The import has been created')
->__toString());
}
}
else {
$this->logger
->error($this
->t('The file is not a .zip archive')
->__toString());
}
}
else {
$this->logger
->error($this
->t('No file found')
->__toString());
}
if ($options['as_function'] == TRUE) {
return $ie
->id();
}
}