|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file has been created by developers from BitBag. |
| 5 | + * Feel free to contact us once you face any issues or want to start |
| 6 | + * You can find more information about us on https://bitbag.io and write us |
| 7 | + |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace BitBag\SyliusWishlistPlugin\Console; |
| 13 | + |
| 14 | +use BitBag\SyliusWishlistPlugin\Remover\AnonymousWishlistsRemoverInterface; |
| 15 | +use SyliusLabs\Polyfill\Symfony\FrameworkBundle\Command\ContainerAwareCommand; |
| 16 | +use Symfony\Component\Console\Input\InputInterface; |
| 17 | +use Symfony\Component\Console\Output\OutputInterface; |
| 18 | + |
| 19 | +/** |
| 20 | + * @final |
| 21 | + */ |
| 22 | +class RemoveAnonymousWishlistsCommand extends ContainerAwareCommand |
| 23 | +{ |
| 24 | + protected static $defaultName = 'bitbag:remove-anonymous-wishlists'; |
| 25 | + |
| 26 | + protected function configure(): void |
| 27 | + { |
| 28 | + $this |
| 29 | + ->setDescription('Removes anonymous wishlists that have been idle for a period set in `bitbag_sylius_wishlist_plugin.parameters.anonymous_wishlist_expiration_period` configuration key.') |
| 30 | + ; |
| 31 | + } |
| 32 | + |
| 33 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 34 | + { |
| 35 | + /** @var string $expirationTime */ |
| 36 | + $expirationTime = $this->getContainer()->getParameter('bitbag_sylius_wishlist_plugin.parameters.anonymous_wishlist_expiration_period'); |
| 37 | + |
| 38 | + if (empty($expirationTime)) { |
| 39 | + $output->writeln('<error>`bitbag_sylius_wishlist_plugin.parameters.anonymous_wishlist_expiration_period` configuration key is not set, so no wishlists will be removed.</error>'); |
| 40 | + |
| 41 | + return 0; |
| 42 | + } |
| 43 | + |
| 44 | + $output->writeln(sprintf( |
| 45 | + 'Command will remove anonymous wishlists that have been idle for <info>%s</info>.', |
| 46 | + (string) $expirationTime, |
| 47 | + )); |
| 48 | + |
| 49 | + /** @var AnonymousWishlistsRemoverInterface $anonymousWishlistsRemover */ |
| 50 | + $anonymousWishlistsRemover = $this->getContainer()->get('bitbag_sylius_wishlist_plugin.services.anonymous_wishlists_remover'); |
| 51 | + $anonymousWishlistsRemover->remove(); |
| 52 | + |
| 53 | + return 0; |
| 54 | + } |
| 55 | +} |
0 commit comments