Skip to content

Commit a14d8e1

Browse files
Refactor Job plugins to Services and Observers
1 parent b9211b4 commit a14d8e1

File tree

11 files changed

+344
-392
lines changed

11 files changed

+344
-392
lines changed

Observer/CategoryImport.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace JustBetter\AkeneoBundle\Observer;
4+
5+
use Akeneo\Connector\Executor\JobExecutor;
6+
use JustBetter\AkeneoBundle\Service\CategoryExist;
7+
use Magento\Framework\Event\Observer;
8+
use Magento\Framework\Event\ObserverInterface;
9+
10+
class CategoryImport implements ObserverInterface
11+
{
12+
public function __construct(
13+
protected CategoryExist $categoryExist
14+
) {
15+
}
16+
17+
public function execute(Observer $observer): void
18+
{
19+
/** @var JobExecutor $executor */
20+
$executor = $observer->getData('import');
21+
22+
$method = $executor->getMethod();
23+
24+
// Run before setValues step
25+
if ($method === 'setValues') {
26+
$this->categoryExist->execute();
27+
}
28+
}
29+
}

Observer/ImportFinished.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace JustBetter\AkeneoBundle\Observer;
4+
5+
use Akeneo\Connector\Executor\JobExecutor;
6+
use Magento\Framework\Event\ManagerInterface as EventManager;
7+
use Magento\Framework\Event\Observer;
8+
use Magento\Framework\Event\ObserverInterface;
9+
10+
class ImportFinished implements ObserverInterface
11+
{
12+
public function __construct(
13+
protected EventManager $eventManager
14+
) {
15+
}
16+
17+
public function execute(Observer $observer): void
18+
{
19+
/** @var JobExecutor $executor */
20+
$executor = $observer->getData('import');
21+
22+
$method = $executor->getMethod();
23+
24+
// Dispatch custom event before cleanCache step (last step before completion)
25+
if ($method === 'cleanCache') {
26+
$code = $executor->getCurrentJob()->getCode();
27+
$this->eventManager->dispatch('akeneo_connector_import_finish_' . $code);
28+
}
29+
}
30+
}

Observer/ProductImport.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace JustBetter\AkeneoBundle\Observer;
4+
5+
use Akeneo\Connector\Executor\JobExecutor;
6+
use JustBetter\AkeneoBundle\Service\CheckWebsiteAssociation;
7+
use JustBetter\AkeneoBundle\Service\SetTaxClassId;
8+
use Magento\Framework\Event\Observer;
9+
use Magento\Framework\Event\ObserverInterface;
10+
11+
class ProductImport implements ObserverInterface
12+
{
13+
public function __construct(
14+
protected CheckWebsiteAssociation $checkWebsiteAssociation,
15+
protected SetTaxClassId $setTaxClassId
16+
) {
17+
}
18+
19+
public function execute(Observer $observer): void
20+
{
21+
/** @var JobExecutor $executor */
22+
$executor = $observer->getData('import');
23+
24+
$method = $executor->getMethod();
25+
$code = $executor->getCurrentJob()->getCode();
26+
27+
// Run before setWebsites step
28+
if ($method === 'setWebsites') {
29+
$this->checkWebsiteAssociation->execute($code);
30+
}
31+
32+
// Run before updateOption step
33+
if ($method === 'updateOption') {
34+
$this->setTaxClassId->execute($code);
35+
}
36+
}
37+
}

Plugin/CheckWebsiteAssociation.php

Lines changed: 0 additions & 134 deletions
This file was deleted.

Plugin/ImportFinished.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)