Shell app to clean up the commercetools database.

1.2.0 2018-12-19 11:58 UTC

This package is auto-updated.

Last update: 2024-03-29 03:38:13 UTC


Shell app to delete entries out of your commercetools database matching predicates out of your config.


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:

// 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"
    commercetools_client: # Required
        id:                   ~ # Required
        secret:               ~ # Required
        project:              ~ # Required
        scope:                ~ # Required

    # Please provide the service id for your logging service.
    logger:               ~

        # Define your category predicates (
        category:             []

        # Define your customer predicates (
        customer:             []

        # Define your product predicates (
        product:              []


    # Reuse your default credentials from the commercetools sdk
        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%'
        # The predicates for customers which should be deleted. The array elements are combined to an or query.
            - 'externalId is defined'
            - 'lastName="foobar" and email=""
            # 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