clickandmortar/akeneo-utils-bundle
Symfony bundle for Akeneo that adds handy utility commands: clear old archives, list unused attribute options, remove empty product models, and delete attributes while purging values without touching product modification dates.
Installation:
composer require clickandmortar/akeneo-utils-bundle "^<version-wanted>.*"
Replace <version-wanted> with your Akeneo version (e.g., 7.0 for Akeneo 7.x).
Bundle Registration:
Add the bundle to config/bundles.php:
return [
// ...
ClickAndMortar\AkeneoUtilsBundle\ClickAndMortarAkeneoUtilsBundle::class => ['all' => true],
];
First Use Case:
Run the list-unused-options command to identify unused attribute options for a specific family/attribute:
php bin/console candm:akeneo-utils:list-unused-options --family="electronics" --attribute="color"
Archive Cleanup:
Schedule clear-archives to run periodically (e.g., monthly) to free up disk space:
php bin/console candm:akeneo-utils:clear-archives --days=90
--dry-run to preview what will be deleted:
php bin/console candm:akeneo-utils:clear-archives --days=90 --dry-run
Unused Option Detection:
Integrate list-unused-options into a data cleanup workflow:
php bin/console candm:akeneo-utils:list-unused-options --family="clothing" --attribute="size" > unused_options.csv
Model Pruning:
Use clear-models-without-children to clean up empty models:
php bin/console candm:akeneo-utils:clear-models-without-children --dry-run
--dry-run first to verify the impact.Attribute Deletion: Delete an attribute without updating product modification dates:
php bin/console candm:akeneo-utils:delete-attribute --code="old_attribute_code"
Data Hygiene Pipeline: Combine commands into a script for regular maintenance:
#!/bin/bash
php bin/console candm:akeneo-utils:clear-archives --days=90
php bin/console candm:akeneo-utils:list-unused-options --family="electronics" --attribute="color" > unused_options.log
php bin/console candm:akeneo-utils:clear-models-without-children --dry-run
CI/CD Integration: Add commands to your deployment pipeline to ensure data integrity:
# Example GitHub Actions step
- name: Run Akeneo Utils Commands
run: |
php bin/console candm:akeneo-utils:clear-archives --days=30 --dry-run
php bin/console candm:akeneo-utils:list-unused-options --family="clothing" --attribute="size" > unused_options.csv
php bin/console candm:akeneo-utils:clear-archives --days=90 >> /var/log/akeneo/cleanup.log 2>&1
www-data) has write permissions to the directories being cleaned.Akeneo Version Mismatch:
v7.0.* bundle with Akeneo 6.x) will cause errors.Destructive Commands:
clear-models-without-children and delete-attribute permanently delete data.--dry-run first and back up your database before executing.Disk Space Warnings:
clear-archives may fail if the Akeneo user lacks permissions to delete files.sudo -u www-data php bin/console candm:akeneo-utils:clear-archives --days=90
False Positives in Unused Options:
list-unused-options may flag options as unused even if they’re referenced in other systems (e.g., ERP).Product Modification Dates:
delete-attribute command skips updating product modification dates, which might affect downstream processes.Command Errors:
var/log/dev.log) for detailed error messages.--verbose flag for more output:
php bin/console candm:akeneo-utils:clear-archives --verbose
Database Queries:
// config/packages/dev/doctrine.yaml
doctrine:
dbal:
logging: true
profiling: true
Bundle Enablement:
bundles.php for all environments (['all' => true]).Command Autocompletion:
php bin/console
Custom Commands:
Extend the bundle by creating a new command class and injecting the AkeneoUtilsService:
namespace App\Command;
use ClickAndMortar\AkeneoUtilsBundle\Service\AkeneoUtilsService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CustomAkeneoCommand extends Command
{
protected static $defaultName = 'app:custom-akeneo-task';
private $akeneoUtils;
public function __construct(AkeneoUtilsService $akeneoUtils)
{
$this->akeneoUtils = $akeneoUtils;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// Use $this->akeneoUtils to interact with Akeneo data
$output->writeln('Running custom Akeneo task...');
return Command::SUCCESS;
}
}
Service Overrides:
Override the AkeneoUtilsService to customize behavior:
# config/services.yaml
services:
ClickAndMortar\AkeneoUtilsBundle\Service\AkeneoUtilsService:
class: App\Service\CustomAkeneoUtilsService
arguments:
$akeneoManager: '@pim_catalog.manager.product'
Event Listeners: While the bundle doesn’t provide events, you can listen to Akeneo’s native events to trigger these commands:
// src/EventListener/AkeneoUtilsListener.php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Pim\Tool\Bundle\BatchBundle\Event\BatchEvent;
class AkeneoUtilsListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'pim_enrich.product_variant.save.post' => 'onProductVariantSave',
];
}
public function onProductVariantSave(BatchEvent $event)
{
// Trigger cleanup after product variant save
shell_exec('php bin/console candm:akeneo-utils:clear-models-without-children --dry-run');
}
}
Backup Before Running Destructive Commands:
Always back up your Akeneo database and critical directories before running commands like clear-models-without-children or delete-attribute.
Monitor Disk Usage:
Set up monitoring for Akeneo’s var/export and var/import directories to proactively trigger clear-archives.
Document Command Usage: Maintain a runbook for each command, including:
How can I help you explore Laravel packages today?