Skip to content

Commit

Permalink
Merge pull request #7 from snowio/new-rsync
Browse files Browse the repository at this point in the history
Rsync csvs from export + assets if they exist
  • Loading branch information
qrz-io authored Oct 11, 2018
2 parents 6bd9f05 + 071652c commit 92aa8c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions Resources/config/steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ services:
- '@akeneo_batch.job_repository'
- '@snowio_connector.media_export.export_location'
- '@snowio_connector.media_export.logger'
- '%asset_storage_dir%'

snowio_connector.step.post:
class: '%snowio_connector.step.post.class%'
Expand Down
24 changes: 20 additions & 4 deletions Step/MediaExportStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ class MediaExportStep extends AbstractStep
/** @var Logger */
private $logger;

/** @var string */
private $assetStorageDir;

/**
* MediaExportStep constructor.
* @param string $name
* @param EventDispatcherInterface $eventDispatcher
* @param JobRepositoryInterface $jobRepository
* @param ExportLocation $exportLocation
* @param Logger $logger
* @param string $assetStorageDir
*/
public function __construct(
$name,
EventDispatcherInterface $eventDispatcher,
JobRepositoryInterface $jobRepository,
ExportLocation $exportLocation,
Logger $logger
Logger $logger,
$assetStorageDir = ''
) {
parent::__construct($name, $eventDispatcher, $jobRepository);
$this->exportLocation = $exportLocation;
$this->logger = $logger;
$this->assetStorageDir = rtrim($assetStorageDir, "/");
}

/**
Expand Down Expand Up @@ -107,15 +113,25 @@ protected function doExecute(StepExecution $stepExecution)
protected function syncMedia($currentExportDir, $newExportDir, $options = '')
{
/**
* append files to the current export dir so that we do not unnecessarily
* copy over the export csv files
* Intentionally copy the export csv files - often we'll need additional data in Magento, and this
* simplifies getting it.
* for instance, we need attributes definitions for definition providers.
*/
exec("rsync -aK $options $currentExportDir/files/ $newExportDir/", $output, $status);
exec("rsync -aK $options $currentExportDir/ $newExportDir/", $output, $status);

if ($status !== 0) {
throw new FileTransferException('Error - rsync failure during media export.' . implode(" : ", $output));
}

if (is_dir($this->assetStorageDir)) {
exec("rsync -aK $options $this->assetStorageDir/ $newExportDir/", $assetRsyncOutput, $status);
if ($status !== 0) {
throw new FileTransferException('Error - rsync failure during asset export.' . implode(" : ", $assetRsyncOutput));
}

$output .= "\n" . $assetRsyncOutput;
}

return $output;
}

Expand Down

0 comments on commit 92aa8c5

Please sign in to comment.