Skip to content

Commit

Permalink
Rename enqueue command into import command (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Aug 1, 2022
1 parent f85f96e commit 3469d29
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 90 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,49 +379,49 @@ This plugin will also import product associations. It's a zero configuration imp

### Launch data import from CLI

To actually import data you must first create queue items with the **enqueue command** and then you can import them with the **consume command**.
To actually import data you must first create queue items with the **import command** and then you can import them with the **consume command**.

#### Schedule Akeneo PIM import button

This button allows you to queue a product directly from the admin index page. By adding the product to the queue, it will be updated by the Akeneo PIM at the next consume run.

![Schedule Akeneo PIM import button](schedule-akeneo-import-button.png)

#### Enqueue command
#### Import command

To create queue items you can use the `webgriffe:akeneo:enqueue` console command:
To create queue items you can use the `webgriffe:akeneo:import` console command:

```bash
bin/console webgriffe:akeneo:enqueue --since="2020-01-30"
bin/console webgriffe:akeneo:import --since="2020-01-30"
```

This will enqueue all Akeneo entities updated after the provided date.
This will import all Akeneo entities updated after the provided date.

You can also use a "since file" where to read the since date:

```bash
echo "2020-01-30" > var/storage/akeneo-sincefile.txt
bin/console webgriffe:akeneo:enqueue --since-file="var/storage/akeneo-sincefile.txt"
bin/console webgriffe:akeneo:import --since-file="var/storage/akeneo-sincefile.txt"
```

When run with the since file, the enqueue command will write the current date/time to the since file after the enqueueing process is terminated. This is useful when you put the enqueue command in cron:
When run with the since file, the import command will write the current date/time to the since file after the importing process is terminated. This is useful when you put the import command in cron:

```
* * * * * /usr/bin/php /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:enqueue --since-file=/path/to/sylius/var/storage/akeneo-enqueue-sincefile.txt
* * * * * /usr/bin/php /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:import --since-file=/path/to/sylius/var/storage/akeneo-import-sincefile.txt
```

This way the enqueue command is run repeatedly enqueuing only producs modified since the last command execution.
This way the import command is run repeatedly importing only products modified since the last command execution.

You can also enqueue items only for specific importers:
You can also import items only for specific importers:

```bash
bin/console webgriffe:akeneno:enqueue --importer="Product" --importer="MyImporter" --since="2020-01-30"
bin/console webgriffe:akeneno:import --importer="Product" --importer="MyImporter" --since="2020-01-30"
```

You can also enqueue items regardless of their last update date:
You can also import items regardless of their last update date:

```bash
bin/console webgriffe:akeneno:enqueue --all
bin/console webgriffe:akeneno:import --all
```

#### Consume command
Expand Down Expand Up @@ -474,20 +474,20 @@ It could be useful to add also this command to your scheduler to run automatical
To make all importers and other plugin features work automatically the following is the suggested crontab:

```
0 * * * * /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:enqueue --all --importer="AttributeOptions"
* * * * * /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:enqueue --since-file=/path/to/sylius/var/storage/akeneo-enqueue-sincefile.txt --importer="Product" --importer="ProductAssociations"
0 * * * * /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:import --all --importer="AttributeOptions"
* * * * * /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:import --since-file=/path/to/sylius/var/storage/akeneo-import-sincefile.txt --importer="Product" --importer="ProductAssociations"
* * * * * /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:consume
0 0 * * * /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:cleanup-queue
0 */6 * * * /path/to/sylius/bin/console -e prod -q webgriffe:akeneo:reconcile
```

This will:
* Enqueue the update of all attribute options every hour
* Import the update of all attribute options every hour
* Import, every minute, all products that have been modified since the last execution, along with their associations
* Clean the imported items queue older than 10 days, every day at midnight
* Reconcile Akeneo deleted products every 6 hours

Enqueue, Consume and Reconcile commands uses a [lock mechanism](https://symfony.com/doc/current/console/lockable_trait.html) which prevents running them if another instance of the same command is already running.
Import, Consume and Reconcile commands uses a [lock mechanism](https://symfony.com/doc/current/console/lockable_trait.html) which prevents running them if another instance of the same command is already running.

## Architecture & customization

Expand Down
2 changes: 1 addition & 1 deletion UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Removed all deprecations of the v1.x releases.
##### Removed
- [BC] Property Webgriffe\SyliusAkeneoPlugin\DependencyInjection\WebgriffeSyliusAkeneoExtension::$valueHandlersTypesDefinitions was removed
- [BC] Removed the service `webgriffe_sylius_akeneo_plugin.repository.cleanable_queue_item`, use the `webgriffe_sylius_akeneo.repository.cleanable_queue_item` instead.
- [BC] Removed the service `webgriffe_sylius_akeneo_plugin.controller.product_enqueue_controller`, use the `webgriffe_sylius_akeneo.controller.product_enqueue_controller` instead.
- [BC] Removed the service `webgriffe_sylius_akeneo_plugin.controller.product_enqueue_controller`, use the `webgriffe_sylius_akeneo.controller.product_import_controller` instead.
- [BC] Removed the resource `webgriffe_sylius_akeneo_plugin.queue_item` use the `webgriffe_sylius_akeneo.queue_item` instead.

### Test changes
Expand Down
16 changes: 8 additions & 8 deletions features/enqueuing_generic_items.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@
Feature: Enqueuing items
In order to import data from Akeneo
As a Store Owner
I want to add enqueue items to the Akeneo PIM queue
I want to import items from the Akeneo PIM

@cli
Scenario: Enqueueing items when no item is modified since the given date
When I enqueue items for all importers modified since date "2020-01-20 01:00:00"
When I import items for all importers modified since date "2020-01-20 01:00:00"
Then there should be no item in the Akeneo queue

@cli
Scenario: Enqueueing items without a since date
When I enqueue items for all importers with no since date
When I import items for all importers with no since date
Then I should be notified that a since date is required
And there should be no item in the Akeneo queue

@cli
Scenario: Enqueueing items with an invalid since date
When I enqueue items for all importers with invalid since date
When I import items for all importers with invalid since date
Then I should be notified that the since date must be a valid date

@cli
Scenario: Enqueueing items with a since date specified from a not existent file
When I enqueue items with since date specified from a not existent file
When I import items with since date specified from a not existent file
Then I should be notified that the since date file does not exists

@cli
Scenario: Enqueuing all items regardless last modified date
Given there are 3 products on Akeneo
When I enqueue all items for all importers
When I import all items for all importers
Then there should be 3 items for the "Product" importer in the Akeneo queue
And there should be 3 items for the "ProductAssociations" importer in the Akeneo queue

@cli
Scenario: Enqueuing all items for one importer only
Given there are 3 products on Akeneo
When I enqueue all items for the "Product" importer
When I import all items for the "Product" importer
Then there should be 3 items for the "Product" importer in the Akeneo queue
And there should be items for the "Product" importer only in the Akeneo queue

@cli
Scenario: Enqueuing all items for a not existent importer
When I enqueue all items for a not existent importer
When I import all items for a not existent importer
Then I should be notified that the importer does not exists
6 changes: 3 additions & 3 deletions features/enqueuing_products.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Enqueuing products
Given there is a product "product-1" updated at "2020-01-10 22:23:13" on Akeneo
And there is a product "product-2" updated at "2020-01-21 09:54:12" on Akeneo
And there is a product "product-3" updated at "2020-01-22 08:15:08" on Akeneo
When I enqueue items for all importers modified since date "2020-01-20 01:00:00"
When I import items for all importers modified since date "2020-01-20 01:00:00"
Then the queue item with identifier "product-1" for the "Product" importer should not be in the Akeneo queue
And the queue item with identifier "product-2" for the "Product" importer should be in the Akeneo queue
And the queue item with identifier "product-3" for the "Product" importer should be in the Akeneo queue
Expand All @@ -18,7 +18,7 @@ Feature: Enqueuing products
Scenario: There are no products modified since datetime read in file
Given there is a file with name "last-date" and content "2020-01-20 01:00:00"
And current date time is "2020-01-25T12:00:00+01:00"
When I enqueue items for all importers modified since date specified from file "last-date"
When I import items for all importers modified since date specified from file "last-date"
Then there should be no item in the queue for the "Product" importer
And there is a file with name "last-date" that contains "2020-01-25T12:00:00+01:00"

Expand All @@ -28,7 +28,7 @@ Feature: Enqueuing products
And there is a product "product-2" updated at "2020-01-21 09:54:12" on Akeneo
And there is a file with name "last-date" and content "2020-01-20 01:00:00"
And current date time is "2020-01-25T12:00:00+01:00"
When I enqueue items for all importers modified since date specified from file "last-date"
When I import items for all importers modified since date specified from file "last-date"
Then the queue item with identifier "product-1" for the "Product" importer should not be in the Akeneo queue
And the queue item with identifier "product-2" for the "Product" importer should be in the Akeneo queue
And there is a file with name "last-date" that contains "2020-01-25T12:00:00+01:00"
Expand Down
2 changes: 1 addition & 1 deletion features/enqueuing_products_associations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Enqueuing products associations
Given there is a product "product-1" updated at "2020-01-10 22:23:13" on Akeneo
And there is a product "product-2" updated at "2020-01-21 09:54:12" on Akeneo
And there is a product "product-3" updated at "2020-01-22 08:15:08" on Akeneo
When I enqueue items for all importers modified since date "2020-01-20 01:00:00"
When I import items for all importers modified since date "2020-01-20 01:00:00"
Then the queue item with identifier "product-1" for the "ProductAssociations" importer should not be in the Akeneo queue
And the queue item with identifier "product-2" for the "ProductAssociations" importer should be in the Akeneo queue
And the queue item with identifier "product-3" for the "ProductAssociations" importer should be in the Akeneo queue
2 changes: 1 addition & 1 deletion features/importing_product_associations_from_queue.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ Feature: Importing product associations from queue
And the store has a product "upsell-product-2" with code "upsell-product-2"
And there is one product associations to import with identifier "10627329" in the Akeneo queue
And the store has a product association type "Upsell" with a code "UPSELL"
When I consume the messages
When I import all from Akeneo
Then the product "10627329" should be associated to product "upsell-product-1" for association with code "UPSELL"
And the product "10627329" should be associated to product "upsell-product-2" for association with code "UPSELL"
8 changes: 4 additions & 4 deletions features/importing_products_from_queue.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Importing products from queue
And the store is also available in "it_IT"
And there is one item to import with identifier "braided-hat-m" for the "Product" importer in the Akeneo queue
And there is one item to import with identifier "braided-hat-l" for the "Product" importer in the Akeneo queue
When I consume the messages
When I import all from Akeneo
Then the product "model-braided-hat" should exists with the right data
And the product variant "braided-hat-m" of product "model-braided-hat" should exists with the right data
And the product variant "braided-hat-l" of product "model-braided-hat" should exists with the right data
Expand All @@ -20,7 +20,7 @@ Feature: Importing products from queue
Given the store operates on a single channel
And the store is also available in "it_IT"
And there is one item to import with identifier "NOT_EXISTS" for the "Product" importer in the Akeneo queue
When I consume the messages
When I import all from Akeneo
Then the item import message for "NOT_EXISTS" identifier and the "Product" importer should have failed
And the product "NOT_EXISTS" should not exists

Expand All @@ -30,7 +30,7 @@ Feature: Importing products from queue
And the store is also available in "it_IT"
And there is one item to import with identifier "NOT_EXISTS" for the "Product" importer in the Akeneo queue
And there is one item to import with identifier "braided-hat-m" for the "Product" importer in the Akeneo queue
When I consume the messages
When I import all from Akeneo
Then the item import message for "NOT_EXISTS" identifier and the "Product" importer should have failed
And the product "NOT_EXISTS" should not exists
And the product variant "braided-hat-m" of product "model-braided-hat" should exists with the right data
Expand All @@ -41,5 +41,5 @@ Feature: Importing products from queue
And the store is also available in "it_IT"
And there is one item to import with identifier "braided-hat-m" for the "Product" importer in the Akeneo queue
And there is one item to import with identifier "braided-hat-l" for the "Product" importer in the Akeneo queue
When I consume the messages
When I import all from Akeneo
Then there should not be any temporary file in the temporary files directory
12 changes: 6 additions & 6 deletions src/Command/EnqueueCommand.php → src/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport;
use Webmozart\Assert\Assert;

final class EnqueueCommand extends Command
final class ImportCommand extends Command
{
use LockableTrait;

Expand All @@ -31,7 +31,7 @@ final class EnqueueCommand extends Command

private const IMPORTER_OPTION_NAME = 'importer';

protected static $defaultName = 'webgriffe:akeneo:enqueue';
protected static $defaultName = 'webgriffe:akeneo:import';

public function __construct(
private DateTimeBuilderInterface $dateTimeBuilder,
Expand All @@ -44,7 +44,7 @@ public function __construct(
protected function configure(): void
{
$this->setDescription(
'Populate the Queue with Akeneo\'s entities that has been modified since a specified date/datetime',
'Import Akeneo\'s entities that has been modified since a specified date/datetime',
);
$this->addOption(
self::SINCE_OPTION_NAME,
Expand All @@ -62,13 +62,13 @@ protected function configure(): void
self::ALL_OPTION_NAME,
'a',
InputOption::VALUE_NONE,
'Enqueue all identifiers regardless their last modified date.',
'Import all identifiers regardless their last modified date.',
);
$this->addOption(
self::IMPORTER_OPTION_NAME,
'i',
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Enqueue items only for specified importers',
'Import items only for specified importers',
);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->messageBus->dispatch($itemImport);
$output->writeln(
sprintf(
'<info>%s</info> entity with identifier <info>%s</info> enqueued.',
'<info>%s</info> entity with identifier <info>%s</info> imported.',
$importer->getAkeneoEntity(),
$identifier,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Webgriffe\SyliusAkeneoPlugin\Message\ItemImport;
use Webmozart\Assert\Assert;

final class ProductEnqueueController extends AbstractController
final class ProductImportController extends AbstractController
{
public function __construct(
private ProductRepositoryInterface $productRepository,
Expand All @@ -23,7 +23,7 @@ public function __construct(
) {
}

public function enqueueAction(int $productId): Response
public function importAction(int $productId): Response
{
/** @var ProductInterface|null $product */
$product = $this->productRepository->find($productId);
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/admin_routing.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
webgriffe_sylius_akeneo_product_enqueue:
controller: webgriffe_sylius_akeneo.controller.product_enqueue_controller:enqueueAction
path: product/{productId}/enqueue
webgriffe_sylius_akeneo_product_import:
controller: webgriffe_sylius_akeneo.controller.product_import_controller:importAction
path: product/{productId}/import
10 changes: 5 additions & 5 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sylius_grid:
templates:
action:
enqueueProduct: '@WebgriffeSyliusAkeneoPlugin\Product\Grid\Action\enqueue.html.twig'
importProduct: '@WebgriffeSyliusAkeneoPlugin\Product\Grid\Action\import.html.twig'
grids:
webgriffe_sylius_akeneo_admin_queue_item:
driver:
Expand Down Expand Up @@ -59,12 +59,12 @@ sylius_grid:
sylius_admin_product:
actions:
item:
enqueue:
type: enqueueProduct
label: webgriffe_sylius_akeneo.ui.enqueue
import:
type: importProduct
label: webgriffe_sylius_akeneo.ui.import
options:
link:
route: webgriffe_sylius_akeneo_product_enqueue
route: webgriffe_sylius_akeneo_product_import
parameters:
productId: resource.id
icon: cloud download
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<services>
<!-- Commands -->
<service id="webgriffe_sylius_akeneo.command.enqueue" class="Webgriffe\SyliusAkeneoPlugin\Command\EnqueueCommand">
<service id="webgriffe_sylius_akeneo.command.import" class="Webgriffe\SyliusAkeneoPlugin\Command\ImportCommand">
<argument type="service" id="webgriffe_sylius_akeneo.date_time_builder"/>
<argument type="service" id="webgriffe_sylius_akeneo.importer_registry"/>
<argument type="service" id="messenger.default_bus"/>
Expand Down Expand Up @@ -46,7 +46,7 @@
<service id="webgriffe_sylius_akeneo.slugify" class="Cocur\Slugify\Slugify" />
<service id="Cocur\Slugify\SlugifyInterface" alias="webgriffe_sylius_akeneo.slugify" />

<service id="webgriffe_sylius_akeneo.controller.product_enqueue_controller" class="Webgriffe\SyliusAkeneoPlugin\Controller\ProductEnqueueController" >
<service id="webgriffe_sylius_akeneo.controller.product_import_controller" class="Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController" >
<tag name="controller.service_arguments"/>
<argument type="service" id="sylius.repository.product" />
<argument type="service" id="messenger.default_bus" />
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ webgriffe_sylius_akeneo:
imported_yes: Yes, at %date%
imported_no: No
error_message: Error message
enqueue: Schedule Akeneo PIM import
import: Schedule Akeneo PIM import
enqueued_success: Akeneo PIM import for product "{code}" has been successfully scheduled
product_not_exist: Product not found
product_already_enqueued: Akeneo PIM import for product "{code}" has been already scheduled before
Expand Down
Loading

0 comments on commit 3469d29

Please sign in to comment.