mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 18:44:30 +00:00

* select by id or name ; add / enhance clauses (date, number, ...) ; change example to match default db ; add doc * fix "in code" example * big refacto ; bc break on syntax ; add "compute" ; allow b/c work:run-serv without payload * exception if not settings/version=2 --------- Co-authored-by: Nicolas Maillat <maillat@alchemy.fr>
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Phrasea\WorkerManager\Command;
|
|
|
|
use Alchemy\Phrasea\Command\Command;
|
|
use Alchemy\Phrasea\WorkerManager\Worker\Resolver\WorkerResolverInterface;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class WorkerRunServiceCommand extends Command
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct('worker:run-service');
|
|
|
|
$this->setDescription('Execute a service')
|
|
->addArgument('type', InputArgument::REQUIRED)
|
|
->addArgument('body', InputArgument::OPTIONAL)
|
|
->addOption('preserve-payload', 'p', InputOption::VALUE_NONE, 'Preserve temporary payload file');
|
|
|
|
return $this;
|
|
}
|
|
|
|
protected function doExecute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
/** @var WorkerResolverInterface $workerResolver */
|
|
$workerResolver = $this->container['alchemy_worker.type_based_worker_resolver'];
|
|
|
|
$type = $input->getArgument('type');
|
|
$body = $input->getArgument('body');
|
|
|
|
|
|
$body = [];
|
|
if($input->getArgument('body')) {
|
|
$body = @file_get_contents($input->getArgument('body'));
|
|
|
|
if ($body === false) {
|
|
$output->writeln(sprintf('<error>Unable to read payload file %s</error>', $input->getArgument('body')));
|
|
|
|
return;
|
|
}
|
|
|
|
$body = json_decode($body, true);
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
$output->writeln('<error>Invalid message body</error>');
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
$worker = $workerResolver->getWorker($type, $body);
|
|
|
|
$worker->process($body);
|
|
|
|
if (! $input->getOption('preserve-payload')) {
|
|
@unlink($input->getArgument('body'));
|
|
}
|
|
|
|
}
|
|
}
|