Skip to content

Commit

Permalink
Remove temp files only on product importer and improve file search (#175
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lruozzi9 committed Oct 16, 2023
1 parent 4dd7360 commit fba68a7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/MessageHandler/ItemImportHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Webgriffe\SyliusAkeneoPlugin\ImporterInterface;
use Webgriffe\SyliusAkeneoPlugin\ImporterRegistryInterface;
use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport;
use Webgriffe\SyliusAkeneoPlugin\Product\Importer;
use Webgriffe\SyliusAkeneoPlugin\TemporaryFilesManager;
use Webgriffe\SyliusAkeneoPlugin\TemporaryFilesManagerInterface;

Expand All @@ -27,7 +28,9 @@ public function __invoke(ItemImport $message): void
try {
$importer->import($akeneoIdentifier);
} finally {
$this->temporaryFilesManager->deleteAllTemporaryFiles(TemporaryFilesManagerInterface::PRODUCT_VARIANT_PREFIX . $akeneoIdentifier);
if ($message->getAkeneoEntity() === Importer::AKENEO_ENTITY) {
$this->temporaryFilesManager->deleteAllTemporaryFiles(TemporaryFilesManagerInterface::PRODUCT_VARIANT_PREFIX . $akeneoIdentifier);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Product/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

final class Importer implements ImporterInterface, ReconcilerInterface
{
private const AKENEO_ENTITY = 'Product';
public const AKENEO_ENTITY = 'Product';

/**
* @param FactoryInterface<ProductTaxonInterface> $productTaxonFactory
Expand Down
2 changes: 1 addition & 1 deletion src/TemporaryFilesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generateTemporaryFilePath(string $fileIdentifier): string
public function deleteAllTemporaryFiles(string $fileIdentifier): void
{
$tempFiles = $this->finder->in($this->temporaryDirectory)->depth('== 0')->files()->name(
$this->getFilePrefix($fileIdentifier) . '*',
'/^' . str_replace('*', '\*', $this->getFilePrefix($fileIdentifier)) . '*/',
);
foreach ($tempFiles as $tempFile) {
$this->filesystem->remove($tempFile->getPathname());
Expand Down

0 comments on commit fba68a7

Please sign in to comment.