diff -u b/src/Commands/ContentSyncCommands.php b/src/Commands/ContentSyncCommands.php --- b/src/Commands/ContentSyncCommands.php +++ b/src/Commands/ContentSyncCommands.php @@ -257,7 +257,7 @@ // Set Batch to process the files from the content directory. // Get the files to be processed. $content_to_sync = $content_to_delete = []; - foreach ((array) $change_list as $actions) { + foreach ($change_list as $actions) { if (!empty($actions['create'])) { $content_to_sync = array_merge($content_to_sync, $actions['create']); } @@ -431,7 +431,7 @@ ->translate('An error occurred while processing %error_operation with arguments: @arguments', [ '%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE), - ]); + ])->__toString(); \Drupal::getContainer()->get('content_sync.commands')->io()->writeln($message); } } @@ -454,15 +454,15 @@ * @aliases cse,content-sync-export */ public function export($label = NULL, array $options = ['destination' => '', 'diff' => FALSE]) { - drush_op([$this, 'doUpdate']); + // Get destination directory. + $destination_dir = self::getDirectory($label, $options['destination']); + + drush_op([$this, 'doUpdate'], $destination_dir); $temp_source_dir = drush_tempdir(); $this->getArchiver()->extract($temp_source_dir); $temp_source_storage = new FileStorage($temp_source_dir); - // Get destination directory. - $destination_dir = self::getDirectory($label, $options['destination']); - // Do the actual content export operation. drush_op([$this, 'doExport'], $options, $destination_dir, $temp_source_storage); } @@ -470,7 +470,7 @@ /** * Copied from submitForm() at src/Form/ContentExportForm.php. */ - public function doUpdate() { + public function doUpdate($destination_dir) { // Delete the content tar file in case an older version exist. file_unmanaged_delete($this->getTempFile()); // Set batch operations by entity type/bundle. @@ -491,7 +491,7 @@ } } if (!empty($entities_list)) { - $batch = $this->generateBatch($entities_list); + $batch = $this->generateBatch($entities_list, ['content_sync_directory_file' => $destination_dir]); batch_set($batch); drush_backend_batch_process(); } diff -u b/src/Form/ContentExportTrait.php b/src/Form/ContentExportTrait.php --- b/src/Form/ContentExportTrait.php +++ b/src/Form/ContentExportTrait.php @@ -22,17 +22,17 @@ * * @return array */ - public function generateBatch($entities) { + public function generateBatch($entities, $serializer_context = []) { //Set batch operations by entity type/bundle $operations = []; $operations[] = [[$this, 'generateSiteUUIDFile'], [0 => 0]]; + $entity_to_export = []; foreach ($entities as $entity) { - $entity_to_export = []; - $entity_to_export['values'][] = $entity; - $operations[] = [[$this, 'processContentExportFiles'], $entity_to_export]; + $entity_to_export[] = $entity; + $operations[] = [[$this, 'processContentExportFiles'], [$entity_to_export, $serializer_context]]; } if (empty($operations)) { - $operations[] = [[$this, 'processContentExportFiles'], [0 => 0]]; + $operations[] = [[$this, 'processContentExportFiles'], [[], $serializer_context]]; } //Set Batch $batch = [ @@ -55,7 +55,7 @@ * @param array $context * The batch context. */ - public function processContentExportFiles($files, &$context) { + public function processContentExportFiles($files, $serializer_context, &$context) { //Initialize Batch if (empty($context['sandbox'])) { $context['sandbox']['progress'] = 0; @@ -75,7 +75,6 @@ $entity = $this->getEntityTypeManager()->getStorage($entity_type) ->load($entity_id); // Generate the YAML file. - $serializer_context = []; $exported_entity = $this->getContentExporter() ->exportEntity($entity, $serializer_context); // Create the name only in patch2: unchanged: --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -112,11 +112,11 @@ class FileEntityNormalizer extends ContentEntityNormalizer { $data = parent::normalize($object, $format, $context); // The image will be saved in the export directory. - if (!empty($context['content_sync_directory'])) { + if (!empty($context['content_sync_directory_file'])) { $uri = $object->getFileUri(); $scheme = $this->fileSystem->uriScheme($uri); - $destination = "{$context['content_sync_directory']}/files/{$scheme}/"; + $destination = "{$context['content_sync_directory_file']}/files/{$scheme}/"; $destination = str_replace($scheme . '://', $destination, $uri); file_prepare_directory($this->fileSystem->dirname($destination), FILE_CREATE_DIRECTORY); file_unmanaged_copy($uri, $destination, FILE_EXISTS_REPLACE);