bestit/commercetools-cleanup

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-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