Automate imports/exports

A common need when it comes to imports/exports is to be able to automate them. As Akeneo PIM provides Symfony commands to manage imports and exports you can easily schedule them.

The batch job command

Akeneo PIM provides a simple command to launch jobs:

app/console akeneo:batch:job [-c|--config CONFIG] [--email EMAIL] [--no-log] [--] <code>

So to run the job csv_product_import you can run:

app/console akeneo:batch:job csv_product_import --env=prod


Don’t forget to add –env=prod to avoid memory leaks in dev environment (the default environment for commands)

You can also provide a custom configuration (in JSON format) for the job:

app/console akeneo:batch:job csv_product_import -c "{\"filePath\": \"/custom/path/to/product.csv\"}" --env=prod

Scheduling the jobs

To run a command periodically, you can use a cron:

First, you need to install it (example in debian/ubuntu based distributions):

apt-get install cron

Then, you can edit your crontab:

crontab -e

You can now add a new line at the end of the opened file:

0 * * * * /home/akeneo/pim/app/console akeneo:batch:job csv_product_import -c "{\"filePath\": \"/custom/path/to/product.csv\"}" --env=prod > /tmp/import.log

With this cron configuration a product import will be launched every hour with the file /custom/path/to/product.csv