bestit / commercetools-cleanup
Shell app to clean up the commercetools database.
Requires
- php: ^7.0
- commercetools/php-sdk: ^1.7
- incenteev/composer-parameter-handler: ^2.0
- sensio/distribution-bundle: ^5.0
- sensio/framework-extra-bundle: ^3.0.2
- symfony/monolog-bundle: ^3.0.2
- symfony/polyfill-apcu: ^1.0
- symfony/symfony: ^3.2
Requires (Dev)
- phpunit/phpunit: ^5.5
- sensio/generator-bundle: ^3.0
- squizlabs/php_codesniffer: ^2.8
This package is auto-updated.
Last update: 2024-11-29 05:09:39 UTC
README
Shell app to delete entries out of your commercetools database matching predicates out of your config.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require bestit/commercetools-cleanup
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = []; // ... if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { $bundles[] = new BestIt\CtCleanUpBundle\BestItCtCleanUpBundle(); } // ... } // ... }
Step 3: Configure the bundle
# Default configuration for "BestItCtCleanUpBundle" best_it_ct_clean_up: commercetools_client: # Required id: ~ # Required secret: ~ # Required project: ~ # Required scope: ~ # Required # Please provide the service id for your logging service. logger: ~ predicates: # Define your category predicates (https://dev.commercetools.com/http-api.html). category: [] # Define your customer predicates (https://dev.commercetools.com/http-api.html). customer: [] # Define your product predicates (https://dev.commercetools.com/http-api.html). product: []
Example:
best_it_ct_clean_up: # Reuse your default credentials from the commercetools sdk commercetools_client: id: '%commercetools.client_id%' project: '%commercetools.project%' secret: '%commercetools.client_secret%' scope: '%commercetools.scope%' # Use your logger specially used for the cleanup logger: 'monolog.logger.%cleanup.log_channel%' predicates: # The predicates for customers which should be deleted. The array elements are combined to an or query. customer: - 'externalId is defined' - 'lastName="foobar" and email="test@example.com" product: # Delete every product which is not published and older than 5 minutes. - 'masterData(published=false) and lastModifiedAt <= "{{- 5 minutes}}"'
You can provide a strtotime-compatible string enclosed with {{ and }} to get dynamic date checks.
Step 4: Use the command
$ php bin/console bestit:cleanup -s
If you provide the option -s/--simulate no row will be deleted, the total count will just be outputted.
Further Todos
- More Unittesting
- Refactor the command
- Add more Types
- Add Exceptions in the delete process