-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add symfony command to remove expired anonymous wishlists
To reduce database table size generated by guest customers
- Loading branch information
Showing
11 changed files
with
221 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusWishlistPlugin\Console; | ||
|
||
use BitBag\SyliusWishlistPlugin\Remover\AnonymousWishlistsRemoverInterface; | ||
use SyliusLabs\Polyfill\Symfony\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @final | ||
*/ | ||
class RemoveAnonymousWishlistsCommand extends ContainerAwareCommand | ||
{ | ||
protected static $defaultName = 'bitbag:remove-anonymous-wishlists'; | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Removes anonymous wishlists that have been idle for a period set in `bitbag_sylius_wishlist_plugin.parameters.anonymous_wishlist_expiration_period` configuration key.') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
/** @var string $expirationTime */ | ||
$expirationTime = $this->getContainer()->getParameter('bitbag_sylius_wishlist_plugin.parameters.anonymous_wishlist_expiration_period'); | ||
|
||
if (empty($expirationTime)) { | ||
$output->writeln('<error>`bitbag_sylius_wishlist_plugin.parameters.anonymous_wishlist_expiration_period` configuration key is not set, so no wishlists will be removed.</error>'); | ||
|
||
return 0; | ||
} | ||
|
||
$output->writeln(sprintf( | ||
'Command will remove anonymous wishlists that have been idle for <info>%s</info>.', | ||
(string) $expirationTime, | ||
)); | ||
|
||
/** @var AnonymousWishlistsRemoverInterface $anonymousWishlistsRemover */ | ||
$anonymousWishlistsRemover = $this->getContainer()->get('bitbag_sylius_wishlist_plugin.services.anonymous_wishlists_remover'); | ||
$anonymousWishlistsRemover->remove(); | ||
|
||
return 0; | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusWishlistPlugin\Remover; | ||
|
||
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
|
||
final class AnonymousWishlistsRemover implements AnonymousWishlistsRemoverInterface | ||
{ | ||
public function __construct( | ||
private WishlistRepositoryInterface $wishlistRepository, | ||
private ObjectManager $wishlistManager, | ||
private ?string $expirationPeriod, | ||
) { | ||
} | ||
|
||
public function remove(): void | ||
{ | ||
$this->wishlistRepository->deleteAllAnonymousUntil( | ||
new \DateTime('-' . $this->expirationPeriod), | ||
); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusWishlistPlugin\Remover; | ||
|
||
interface AnonymousWishlistsRemoverInterface | ||
{ | ||
public function remove(): 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
46 changes: 46 additions & 0 deletions
46
tests/Integration/DataFixtures/ORM/test_it_delete_all_anonymous_until_wishlists.yaml
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,46 @@ | ||
Sylius\Component\Locale\Model\Locale: | ||
locale: | ||
createdAt: '<dateTimeBetween("-200 days", "now")>' | ||
code: 'en_US' | ||
Sylius\Component\Currency\Model\Currency: | ||
dollar: | ||
code: 'USD' | ||
Sylius\Component\Core\Model\Channel: | ||
channel_us: | ||
code: 'US' | ||
name: 'name' | ||
defaultLocale: '@locale' | ||
locales: [ '@locale' ] | ||
taxCalculationStrategy: 'order_items_based' | ||
baseCurrency: '@dollar' | ||
enabled: true | ||
Sylius\Component\Core\Model\Customer: | ||
customer_oliver: | ||
firstName: 'John' | ||
lastName: 'Nowak' | ||
email: '[email protected]' | ||
emailCanonical: '[email protected]' | ||
Sylius\Component\Core\Model\ShopUser: | ||
user_oliver: | ||
plainPassword: '123password' | ||
roles: [ 'ROLE_USER' ] | ||
enabled: 'true' | ||
customer: '@customer_oliver' | ||
username: '[email protected]' | ||
usernameCanonical: '[email protected]' | ||
BitBag\SyliusWishlistPlugin\Entity\Wishlist: | ||
wishlist_one: | ||
name: 'Wishlist One' | ||
channel: '@channel_us' | ||
token: 'token' | ||
updatedAt: '<date_create_from_format("Y-m-d H:i:s", "2023-01-01 00:00:00")>' | ||
wishlist_two: | ||
name: 'Wishlist Two' | ||
channel: '@channel_us' | ||
token: 'token' | ||
updatedAt: '<date_create_from_format("Y-m-d H:i:s", "2024-01-02 00:00:00")>' | ||
olivier_wishlist: | ||
name: 'Olivier Wishlist' | ||
shopUser: '@user_oliver' | ||
channel: '@channel_us' | ||
updatedAt: '<date_create_from_format("Y-m-d H:i:s", "2023-01-01 00:00:00")>' |
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