-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
311 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Data Definitions. | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wvision\Bundle\DataDefinitionsBundle\Command; | ||
|
||
use Exception; | ||
use InvalidArgumentException; | ||
use Pimcore\Console\AbstractCommand; | ||
use Symfony\Component\Console\Helper\Helper; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Wvision\Bundle\DataDefinitionsBundle\Event\ImportDefinitionEvent; | ||
use Wvision\Bundle\DataDefinitionsBundle\Importer\AsyncImporterInterface; | ||
use Wvision\Bundle\DataDefinitionsBundle\Importer\ImporterInterface; | ||
use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; | ||
use Wvision\Bundle\DataDefinitionsBundle\Repository\DefinitionRepository; | ||
|
||
final class ImportAsyncCommand extends AbstractCommand | ||
{ | ||
public function __construct( | ||
protected EventDispatcherInterface $eventDispatcher, | ||
protected DefinitionRepository $repository, | ||
protected AsyncImporterInterface $importer | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setName('data-definitions:async-import') | ||
->setDescription('Run a Data Definition Import Async.') | ||
->addOption( | ||
'definition', | ||
'd', | ||
InputOption::VALUE_REQUIRED, | ||
'Import Definition ID or Name' | ||
) | ||
->addOption( | ||
'params', | ||
'p', | ||
InputOption::VALUE_REQUIRED, | ||
'JSON Encoded Params' | ||
); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$eventDispatcher = $this->eventDispatcher; | ||
|
||
$params = json_decode($input->getOption('params'), true); | ||
|
||
if (!isset($params['userId'])) { | ||
$params['userId'] = 0; | ||
} | ||
|
||
try { | ||
$definition = $this->repository->find($input->getOption('definition')); | ||
} catch (InvalidArgumentException $e) { | ||
$definition = $this->repository->findByName($input->getOption('definition')); | ||
} | ||
|
||
if (!$definition instanceof ImportDefinitionInterface) { | ||
throw new Exception('Import Definition not found'); | ||
} | ||
|
||
$this->importer->doImportAsync($definition, $params); | ||
|
||
return 0; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/DataDefinitionsBundle/Importer/AsyncImporterInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Data Definitions. | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wvision\Bundle\DataDefinitionsBundle\Importer; | ||
|
||
use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinitionInterface; | ||
|
||
interface AsyncImporterInterface | ||
{ | ||
public function doImportRowAsync(ImportDefinitionInterface $definition, array $row, array $params): void; | ||
|
||
public function doImportAsync(ImportDefinitionInterface $definition, array $params): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Data Definitions. | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wvision\Bundle\DataDefinitionsBundle\Messenger; | ||
|
||
class ImportRowMessage | ||
{ | ||
private int $definitionId; | ||
private array $data; | ||
private array $params; | ||
|
||
public function __construct(int $definitionId, array $data, array $params) | ||
{ | ||
$this->definitionId = $definitionId; | ||
$this->data = $data; | ||
$this->params = $params; | ||
} | ||
|
||
public function getDefinitionId(): int | ||
{ | ||
return $this->definitionId; | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function getParams(): array | ||
{ | ||
return $this->params; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/DataDefinitionsBundle/Messenger/ImportRowMessageHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Data Definitions. | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the GNU General Public License version 3 (GPLv3) | ||
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt | ||
* files that are distributed with this source code. | ||
* | ||
* @copyright Copyright (c) 2016-2019 w-vision AG (https://www.w-vision.ch) | ||
* @license https://github.com/w-vision/DataDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Wvision\Bundle\DataDefinitionsBundle\Messenger; | ||
|
||
use Wvision\Bundle\DataDefinitionsBundle\Importer\AsyncImporterInterface; | ||
use Wvision\Bundle\DataDefinitionsBundle\Model\ImportDefinition; | ||
|
||
class ImportRowMessageHandler | ||
{ | ||
public function __construct( | ||
private AsyncImporterInterface $importer, | ||
) | ||
{ | ||
} | ||
|
||
public function __invoke(ImportRowMessage $message): void | ||
{ | ||
$definition = ImportDefinition::getById($message->getDefinitionId()); | ||
|
||
if (!$definition) { | ||
throw new \InvalidArgumentException('Invalid definition id'); | ||
} | ||
|
||
$this->importer->doImportRowAsync( | ||
$definition, | ||
$message->getData(), | ||
$message->getParams(), | ||
); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/DataDefinitionsBundle/Resources/config/pimcore/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
imports: | ||
- { resource: messenger.yml } | ||
|
||
jms_serializer: | ||
metadata: | ||
directories: | ||
|
18 changes: 18 additions & 0 deletions
18
src/DataDefinitionsBundle/Resources/config/pimcore/messenger.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
framework: | ||
messenger: | ||
transports: | ||
data_definitions_import: | ||
dsn: "doctrine://default?queue_name=data_definitions_import" | ||
failure_transport: data_definitions_import_failed | ||
retry_strategy: | ||
max_retries: 5 | ||
delay: 300000 | ||
multiplier: 2 | ||
# we store failed messages here for admins to manually review them later | ||
data_definitions_import_failed: | ||
dsn: "doctrine://default?queue_name=data_definitions_import_failed" | ||
retry_strategy: | ||
max_retries: 0 | ||
|
||
routing: | ||
'Wvision\Bundle\DataDefinitionsBundle\Messenger\ImportRowMessage': data_definitions_import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.