-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from webgriffe/issue-17
Remove temporary files after consume with a TemporaryFilesManager
- Loading branch information
Showing
15 changed files
with
293 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusAkeneoPlugin\EventSubscriber; | ||
|
||
use Symfony\Component\Console\ConsoleEvents; | ||
use Symfony\Component\Console\Event\ConsoleTerminateEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Webgriffe\SyliusAkeneoPlugin\TemporaryFilesManagerInterface; | ||
|
||
final class CommandEventSubscriber implements EventSubscriberInterface | ||
{ | ||
/** @var TemporaryFilesManagerInterface */ | ||
private $temporaryFilesManager; | ||
|
||
public function __construct(TemporaryFilesManagerInterface $temporaryFilesManager) | ||
{ | ||
$this->temporaryFilesManager = $temporaryFilesManager; | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ConsoleEvents::TERMINATE => ['onTerminateCommand']]; | ||
} | ||
|
||
public function onTerminateCommand(ConsoleTerminateEvent $event): void | ||
{ | ||
$command = $event->getCommand(); | ||
|
||
if ($command !== null && $command->getName() === 'webgriffe:akeneo:consume') { | ||
$this->temporaryFilesManager->deleteAllTemporaryFiles(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusAkeneoPlugin; | ||
|
||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
final class TemporaryFilesManager implements TemporaryFilesManagerInterface | ||
{ | ||
/** @var Filesystem */ | ||
private $filesystem; | ||
|
||
/** @var Finder */ | ||
private $finder; | ||
|
||
/** @var string */ | ||
private $temporaryDirectory; | ||
|
||
/** @var string */ | ||
private $temporaryFilesPrefix; | ||
|
||
public function __construct( | ||
Filesystem $filesystem, | ||
Finder $finder, | ||
string $temporaryDirectory, | ||
string $temporaryFilesPrefix | ||
) { | ||
$this->filesystem = $filesystem; | ||
$this->finder = $finder; | ||
$this->temporaryDirectory = $temporaryDirectory; | ||
$this->temporaryFilesPrefix = $temporaryFilesPrefix; | ||
} | ||
|
||
public function generateTemporaryFilePath(): string | ||
{ | ||
return $this->filesystem->tempnam($this->temporaryDirectory, $this->temporaryFilesPrefix); | ||
} | ||
|
||
public function deleteAllTemporaryFiles(): void | ||
{ | ||
$tempFiles = $this->finder->in($this->temporaryDirectory)->depth('== 0')->files()->name( | ||
$this->temporaryFilesPrefix . '*' | ||
); | ||
foreach ($tempFiles as $tempFile) { | ||
$this->filesystem->remove($tempFile->getPathname()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusAkeneoPlugin; | ||
|
||
interface TemporaryFilesManagerInterface | ||
{ | ||
public function generateTemporaryFilePath(): string; | ||
|
||
public function deleteAllTemporaryFiles(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.