fix subscriber

This commit is contained in:
aynsix
2020-05-13 15:25:16 +03:00
parent 7228b43cf5
commit 8ace8aeab7
4 changed files with 42 additions and 32 deletions

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\WorkerManager\Provider;
use Alchemy\Phrasea\Core\LazyLocator;
use Alchemy\Phrasea\Model\Manipulator\WebhookEventManipulator;
use Alchemy\Phrasea\Plugin\PluginProviderInterface;
use Alchemy\Phrasea\Application as PhraseaApplication;
@@ -61,9 +62,7 @@ class QueueWorkerServiceProvider implements PluginProviderInterface
$app->extend('dispatcher', function (EventDispatcherInterface $dispatcher, Application $app) {
$dispatcher->addSubscriber(
(new RecordSubscriber($app)
)->setApplicationBox($app['phraseanet.appbox'])
new RecordSubscriber($app, new LazyLocator($app, 'phraseanet.appbox'))
);
$dispatcher->addSubscriber(new ExportSubscriber($app['alchemy_worker.message.publisher']));
$dispatcher->addSubscriber(new AssetsIngestSubscriber($app['alchemy_worker.message.publisher']));

View File

@@ -3,7 +3,6 @@
namespace Alchemy\Phrasea\WorkerManager\Subscriber;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\ApplicationBoxAware;
use Alchemy\Phrasea\Core\Event\Record\DeletedEvent;
use Alchemy\Phrasea\Core\Event\Record\DeleteEvent;
use Alchemy\Phrasea\Core\Event\Record\MetadataChangedEvent;
@@ -23,8 +22,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class RecordSubscriber implements EventSubscriberInterface
{
use ApplicationBoxAware;
/** @var MessagePublisher $messagePublisher */
private $messagePublisher;
@@ -34,17 +31,24 @@ class RecordSubscriber implements EventSubscriberInterface
/** @var Application */
private $app;
public function __construct(Application $app)
/**
* @var callable
*/
private $appboxLocator;
public function __construct(Application $app, callable $appboxLocator)
{
$this->messagePublisher = $app['alchemy_worker.message.publisher'];
$this->workerResolver = $app['alchemy_worker.type_based_worker_resolver'];
$this->app = $app;
$this->appboxLocator = $appboxLocator;
}
public function onSubdefinitionCreate(SubdefinitionCreateEvent $event)
{
$record = $this->findDataboxById($event->getRecord()->getDataboxId())->get_record($event->getRecord()->getRecordId());
$record = $this->getApplicationBox()->get_databox($event->getRecord()->getDataboxId())->get_record($event->getRecord()->getRecordId());
if (!$record->isStory()) {
$subdefs = $record->getDatabox()->get_subdef_structure()->getSubdefGroup($record->getType());
foreach ($subdefs as $subdef) {
@@ -60,7 +64,7 @@ class RecordSubscriber implements EventSubscriberInterface
$this->messagePublisher->publishMessage($payload, MessagePublisher::SUBDEF_QUEUE);
}
}
}
public function onDelete(DeleteEvent $event)
@@ -116,7 +120,7 @@ class RecordSubscriber implements EventSubscriberInterface
$mediaSubdefRepository = $this->getMediaSubdefRepository($databoxId);
$mediaSubdefs = $mediaSubdefRepository->findByRecordIdsAndNames([$recordId]);
$databox = $this->findDataboxById($databoxId);
$databox = $this->getApplicationBox()->get_databox($databoxId);
$record = $databox->get_record($recordId);
$type = $record->getType();
@@ -205,7 +209,7 @@ class RecordSubscriber implements EventSubscriberInterface
$databoxId = $event->getRecord()->getDataboxId();
$recordId = $event->getRecord()->getRecordId();
$databox = $this->findDataboxById($databoxId);
$databox = $this->getApplicationBox()->get_databox($databoxId);
$record = $databox->get_record($recordId);
$type = $record->getType();
@@ -265,4 +269,14 @@ class RecordSubscriber implements EventSubscriberInterface
return false;
}
/**
* @return \appbox
*/
private function getApplicationBox()
{
$callable = $this->appboxLocator;
return $callable();
}
}

View File

@@ -19,9 +19,6 @@ class SubscriberTest extends \PhraseanetTestCase
$sexportSubscriber = new ExportSubscriber($app['alchemy_worker.message.publisher']->reveal());
$this->assertInstanceOf('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface', $sexportSubscriber);
$recordSubscriber = new RecordSubscriber($app);
$this->assertInstanceOf('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface', $recordSubscriber);
}
public function testIfPublisheMessageOnSubscribeEvent()

View File

@@ -44,8 +44,8 @@ class WorkerServiceTest extends \PHPUnit_Framework_TestCase
$writemetadatasWorker = new WriteMetadatasWorker(
$writer,
$app['alchemy_service.logger'],
$app['alchemy_service.message.publisher'],
$app['alchemy_worker.logger'],
$app['alchemy_worker.message.publisher'],
$app['repo.worker-running-job']
);
$this->assertInstanceOf('Alchemy\\Phrasea\\WorkerManager\\Worker\\WorkerInterface', $writemetadatasWorker);