mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Merge pull request #3173 from aynsix/PHRAS-2741-worker-service-part1
PHRAS-2741 #comment merge worker service part 1, require for Phraseanet-plugin-worker
This commit is contained in:
@@ -160,9 +160,9 @@ $cli->command(new QueryParseCommand());
|
||||
$cli->command(new QuerySampleCommand());
|
||||
$cli->command(new FindConceptsCommand());
|
||||
|
||||
$cli->command($cli['alchemy_worker.commands.run_dispatcher_command']);
|
||||
$cli->command($cli['alchemy_worker.commands.run_worker_command']);
|
||||
$cli->command($cli['alchemy_worker.commands.show_configuration']);
|
||||
//$cli->command($cli['alchemy_worker.commands.run_dispatcher_command']);
|
||||
//$cli->command($cli['alchemy_worker.commands.run_worker_command']);
|
||||
//$cli->command($cli['alchemy_worker.commands.show_configuration']);
|
||||
|
||||
$cli->loadPlugins();
|
||||
|
||||
|
@@ -14,6 +14,8 @@ namespace Alchemy\Phrasea\Border;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Border\Checker\CheckerInterface;
|
||||
use Alchemy\Phrasea\Border\Attribute\AttributeInterface;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Alchemy\Phrasea\Metadata\Tag\TfArchivedate;
|
||||
use Alchemy\Phrasea\Metadata\Tag\TfQuarantine;
|
||||
@@ -333,7 +335,7 @@ class Manager
|
||||
$this->app['phraseanet.metadata-setter']->replaceMetadata($newMetadata, $element);
|
||||
|
||||
if(!$nosubdef) {
|
||||
$element->rebuild_subdefs();
|
||||
$this->app['dispatcher']->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($element, true));
|
||||
}
|
||||
|
||||
return $element;
|
||||
|
@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Application\Helper\FilesystemAware;
|
||||
use Alchemy\Phrasea\Application\Helper\NotifierAware;
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Core\Event\ExportFailureEvent;
|
||||
use Alchemy\Phrasea\Core\Event\ExportMailEvent;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||
use Alchemy\Phrasea\Model\Manipulator\TokenManipulator;
|
||||
@@ -193,42 +194,26 @@ class ExportController extends Controller
|
||||
$token = $this->getTokenManipulator()->createEmailExportToken(serialize($list));
|
||||
|
||||
if (count($destMails) > 0) {
|
||||
//zip documents
|
||||
\set_export::build_zip(
|
||||
$this->app,
|
||||
$token,
|
||||
$list,
|
||||
$this->app['tmp.download.path'].'/'. $token->getValue() . '.zip'
|
||||
);
|
||||
$emitterId = $this->getAuthenticatedUser()->getId();
|
||||
|
||||
$remaingEmails = $destMails;
|
||||
$tokenValue = $token->getValue();
|
||||
|
||||
$url = $this->app->url('prepare_download', ['token' => $token->getValue(), 'anonymous' => false, 'type' => \Session_Logger::EVENT_EXPORTMAIL]);
|
||||
|
||||
$user = $this->getAuthenticatedUser();
|
||||
$emitter = new Emitter($user->getDisplayName(), $user->getEmail());
|
||||
$params = [
|
||||
'url' => $url,
|
||||
'textmail' => $request->request->get('textmail'),
|
||||
'reading_confirm' => !!$request->request->get('reading_confirm', false),
|
||||
'ssttid' => $ssttid = $request->request->get('ssttid', ''),
|
||||
'lst' => $lst = $request->request->get('lst', ''),
|
||||
];
|
||||
|
||||
foreach ($destMails as $key => $mail) {
|
||||
try {
|
||||
$receiver = new Receiver(null, trim($mail));
|
||||
} catch (InvalidArgumentException $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$mail = MailRecordsExport::create($this->app, $receiver, $emitter, $request->request->get('textmail'));
|
||||
$mail->setButtonUrl($url);
|
||||
$mail->setExpiration($token->getExpiration());
|
||||
|
||||
$this->deliver($mail, !!$request->request->get('reading_confirm', false));
|
||||
unset($remaingEmails[$key]);
|
||||
}
|
||||
|
||||
//some mails failed
|
||||
if (count($remaingEmails) > 0) {
|
||||
foreach ($remaingEmails as $mail) {
|
||||
$this->dispatch(PhraseaEvents::EXPORT_MAIL_FAILURE, new ExportFailureEvent($this->getAuthenticatedUser(), $ssttid, $lst, \eventsmanager_notify_downloadmailfail::MAIL_FAIL, $mail));
|
||||
}
|
||||
}
|
||||
$this->dispatch(PhraseaEvents::EXPORT_MAIL_CREATE, new ExportMailEvent(
|
||||
$emitterId,
|
||||
$tokenValue,
|
||||
$destMails,
|
||||
$params
|
||||
));
|
||||
}
|
||||
|
||||
return $this->app->json([
|
||||
|
@@ -14,6 +14,8 @@ use Alchemy\Phrasea\Application\Helper\EntityManagerAware;
|
||||
use Alchemy\Phrasea\Application\Helper\SearchEngineAware;
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Controller\RecordsRequest;
|
||||
use Alchemy\Phrasea\Core\Event\Record\DeleteEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\RecordEdit;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Model\Entities\BasketElement;
|
||||
@@ -234,7 +236,7 @@ class RecordController extends Controller
|
||||
if($trashCollectionsBySbasId[$sbasId] !== null) {
|
||||
if($record->getCollection()->get_coll_id() == $trashCollectionsBySbasId[$sbasId]->get_coll_id()) {
|
||||
// record is already in trash so delete it
|
||||
$record->delete();
|
||||
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
|
||||
} else {
|
||||
// move to trash collection
|
||||
$record->move_to_collection($trashCollectionsBySbasId[$sbasId], $this->getApplicationBox());
|
||||
@@ -247,7 +249,7 @@ class RecordController extends Controller
|
||||
}
|
||||
} else {
|
||||
// no trash collection, delete
|
||||
$record->delete();
|
||||
$this->getEventDispatcher()->dispatch(RecordEvents::DELETE, new DeleteEvent($record));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@ use Alchemy\Phrasea\Application\Helper\EntityManagerAware;
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Controller\RecordsRequest;
|
||||
use Alchemy\Phrasea\Controller\Exception as ControllerException;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
|
||||
use Alchemy\Phrasea\Core\Event\RecordEdit;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Model\Entities\StoryWZ;
|
||||
@@ -68,7 +70,9 @@ class StoryController extends Controller
|
||||
break;
|
||||
}
|
||||
|
||||
$story->set_metadatas($metadatas)->rebuild_subdefs();
|
||||
$recordAdapter = $story->set_metadatas($metadatas);
|
||||
// tell phraseanet to rebuild subdef
|
||||
$this->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($recordAdapter));
|
||||
|
||||
$storyWZ = new StoryWZ();
|
||||
$storyWZ->setUser($this->getAuthenticatedUser());
|
||||
|
@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Application\Helper\SubDefinitionSubstituerAware;
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Controller\RecordsRequest;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Alchemy\Phrasea\Metadata\PhraseanetMetadataReader;
|
||||
use Alchemy\Phrasea\Metadata\PhraseanetMetadataSetter;
|
||||
@@ -156,7 +157,7 @@ class ToolsController extends Controller
|
||||
}
|
||||
|
||||
if (!$substituted || $force) {
|
||||
$record->rebuild_subdefs();
|
||||
$this->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($record));
|
||||
}
|
||||
}
|
||||
|
||||
|
53
lib/Alchemy/Phrasea/Core/Event/ExportMailEvent.php
Normal file
53
lib/Alchemy/Phrasea/Core/Event/ExportMailEvent.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2019 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event as SfEvent;
|
||||
|
||||
class ExportMailEvent extends SfEvent
|
||||
{
|
||||
private $emitterUserId;
|
||||
private $tokenValue;
|
||||
/** @var array */
|
||||
private $destinationMails;
|
||||
/** @var array */
|
||||
private $params;
|
||||
|
||||
|
||||
public function __construct($emitterUserId, $tokenValue, array $destMails, array $params)
|
||||
{
|
||||
$this->emitterUserId = $emitterUserId;
|
||||
$this->tokenValue = $tokenValue;
|
||||
$this->destinationMails = $destMails;
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function getTokenValue()
|
||||
{
|
||||
return $this->tokenValue;
|
||||
}
|
||||
|
||||
public function getDestinationMails()
|
||||
{
|
||||
return $this->destinationMails;
|
||||
}
|
||||
|
||||
public function getEmitterUserId()
|
||||
{
|
||||
return $this->emitterUserId;
|
||||
}
|
||||
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
}
|
7
lib/Alchemy/Phrasea/Core/Event/Record/DeleteEvent.php
Normal file
7
lib/Alchemy/Phrasea/Core/Event/Record/DeleteEvent.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event\Record;
|
||||
|
||||
class DeleteEvent extends RecordEvent
|
||||
{
|
||||
}
|
@@ -13,8 +13,10 @@ namespace Alchemy\Phrasea\Core\Event\Record;
|
||||
|
||||
final class RecordEvents
|
||||
{
|
||||
const CREATED = 'record.created';
|
||||
const DELETED = 'record.deleted';
|
||||
const CREATED = 'record.created';
|
||||
const DELETED = 'record.deleted';
|
||||
const DELETE = 'record.delete';
|
||||
|
||||
// Change
|
||||
const COLLECTION_CHANGED = 'record.collection_changed';
|
||||
const METADATA_CHANGED = 'record.metadata_changed';
|
||||
@@ -29,6 +31,8 @@ final class RecordEvents
|
||||
const SUB_DEFINITIONS_CREATED = 'record.sub_definitions_created';
|
||||
const SUB_DEFINITION_CREATION_FAILED = 'record.sub_definition_creation_failed';
|
||||
|
||||
const SUBDEFINITION_CREATE = 'record.subdefinition_create';
|
||||
|
||||
const MEDIA_SUBSTITUTED = 'record.media_substituted';
|
||||
|
||||
const STORY_COVER_CHANGED = 'record.story_cover_changed';
|
||||
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event\Record;
|
||||
|
||||
use Alchemy\Phrasea\Model\RecordInterface;
|
||||
|
||||
class SubdefinitionCreateEvent extends RecordEvent
|
||||
{
|
||||
private $isNewRecord;
|
||||
|
||||
public function __construct(RecordInterface $record, $isNewRecord = false)
|
||||
{
|
||||
parent::__construct($record);
|
||||
|
||||
$this->isNewRecord = $isNewRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isNewRecord()
|
||||
{
|
||||
return $this->isNewRecord;
|
||||
}
|
||||
}
|
@@ -12,7 +12,15 @@
|
||||
namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Core\Event\ExportFailureEvent;
|
||||
use Alchemy\Phrasea\Core\Event\ExportMailEvent;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||
use Alchemy\Phrasea\Model\Entities\Token;
|
||||
use Alchemy\Phrasea\Model\Repositories\TokenRepository;
|
||||
use Alchemy\Phrasea\Model\Repositories\UserRepository;
|
||||
use Alchemy\Phrasea\Notification\Emitter;
|
||||
use Alchemy\Phrasea\Notification\Mail\MailRecordsExport;
|
||||
use Alchemy\Phrasea\Notification\Receiver;
|
||||
|
||||
class ExportSubscriber extends AbstractNotificationSubscriber
|
||||
{
|
||||
@@ -39,10 +47,65 @@ class ExportSubscriber extends AbstractNotificationSubscriber
|
||||
$this->app['event-manager']->notify($params['usr_id'], 'eventsmanager_notify_downloadmailfail', $datas, $mailed);
|
||||
}
|
||||
|
||||
public function onCreateExportMail(ExportMailEvent $event)
|
||||
{
|
||||
$destMails = $event->getDestinationMails();
|
||||
|
||||
$params = $event->getParams();
|
||||
|
||||
/** @var UserRepository $userRepository */
|
||||
$userRepository = $this->app['repo.users'];
|
||||
|
||||
$user = $userRepository->find($event->getEmitterUserId());
|
||||
|
||||
/** @var TokenRepository $tokenRepository */
|
||||
$tokenRepository = $this->app['repo.tokens'];
|
||||
|
||||
/** @var Token $token */
|
||||
$token = $tokenRepository->findValidToken($event->getTokenValue());
|
||||
|
||||
$list = unserialize($token->getData());
|
||||
|
||||
//zip documents
|
||||
\set_export::build_zip(
|
||||
$this->app,
|
||||
$token,
|
||||
$list,
|
||||
$this->app['tmp.download.path'].'/'. $token->getValue() . '.zip'
|
||||
);
|
||||
|
||||
$remaingEmails = $destMails;
|
||||
|
||||
$emitter = new Emitter($user->getDisplayName(), $user->getEmail());
|
||||
|
||||
foreach ($destMails as $key => $mail) {
|
||||
try {
|
||||
$receiver = new Receiver(null, trim($mail));
|
||||
} catch (InvalidArgumentException $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$mail = MailRecordsExport::create($this->app, $receiver, $emitter, $params['textmail']);
|
||||
$mail->setButtonUrl($params['url']);
|
||||
$mail->setExpiration($token->getExpiration());
|
||||
|
||||
$this->deliver($mail, $params['reading_confirm']);
|
||||
unset($remaingEmails[$key]);
|
||||
}
|
||||
|
||||
//some mails failed
|
||||
if (count($remaingEmails) > 0) {
|
||||
foreach ($remaingEmails as $mail) {
|
||||
$this->app['dispatcher']->dispatch(PhraseaEvents::EXPORT_MAIL_FAILURE, new ExportFailureEvent($user, $params['ssttid'], $params['lst'], \eventsmanager_notify_downloadmailfail::MAIL_FAIL, $mail));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
PhraseaEvents::EXPORT_MAIL_FAILURE => 'onMailExportFailure'
|
||||
PhraseaEvents::EXPORT_MAIL_FAILURE => 'onMailExportFailure',
|
||||
PhraseaEvents::EXPORT_MAIL_CREATE => 'onCreateExportMail',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -11,8 +11,10 @@
|
||||
namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Core\Event\Record\CollectionChangedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\DeleteEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
|
||||
use Alchemy\Phrasea\Core\Event\RecordEdit;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Metadata\Tag\TfEditdate;
|
||||
@@ -26,10 +28,12 @@ class RecordEditSubscriber implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
PhraseaEvents::RECORD_EDIT => 'onEdit',
|
||||
PhraseaEvents::RECORD_UPLOAD => 'onEdit',
|
||||
RecordEvents::ROTATE => 'onRecordChange',
|
||||
RecordEvents::COLLECTION_CHANGED => 'onCollectionChanged',
|
||||
PhraseaEvents::RECORD_EDIT => 'onEdit',
|
||||
PhraseaEvents::RECORD_UPLOAD => 'onEdit',
|
||||
RecordEvents::ROTATE => 'onRecordChange',
|
||||
RecordEvents::COLLECTION_CHANGED => 'onCollectionChanged',
|
||||
RecordEvents::SUBDEFINITION_CREATE => 'onSubdefinitionCreate',
|
||||
RecordEvents::DELETE => 'onDelete',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,6 +53,18 @@ class RecordEditSubscriber implements EventSubscriberInterface
|
||||
$recordAdapter->clearStampCache();
|
||||
}
|
||||
|
||||
public function onSubdefinitionCreate(SubdefinitionCreateEvent $event)
|
||||
{
|
||||
$recordAdapter = $this->convertToRecordAdapter($event->getRecord());
|
||||
$recordAdapter->rebuild_subdefs();
|
||||
}
|
||||
|
||||
public function onDelete(DeleteEvent $event)
|
||||
{
|
||||
$recordAdapter = $this->convertToRecordAdapter($event->getRecord());
|
||||
$recordAdapter->delete();
|
||||
}
|
||||
|
||||
public function onEdit(RecordEdit $event)
|
||||
{
|
||||
static $into = false;
|
||||
|
@@ -48,7 +48,8 @@ final class PhraseaEvents
|
||||
const BRIDGE_UPLOAD_FAILURE = 'bridge.upload-failure';
|
||||
|
||||
const EXPORT_MAIL_FAILURE = 'export.mail-failure';
|
||||
const EXPORT_CREATE = 'export.create';
|
||||
const EXPORT_CREATE = 'export.create';
|
||||
const EXPORT_MAIL_CREATE = 'export.mail-create';
|
||||
|
||||
const RECORD_EDIT = 'record.edit';
|
||||
const RECORD_UPLOAD = 'record.upload';
|
||||
|
@@ -32,11 +32,12 @@ class WorkerConfigurationServiceProvider implements ServiceProviderInterface
|
||||
$app['alchemy_queues.queues'] = $app->share(function (Application $app) {
|
||||
$defaultConfiguration = [
|
||||
'worker-queue' => [
|
||||
'registry' => 'alchemy_worker.queue_registry',
|
||||
'host' => 'localhost',
|
||||
'port' => 5672,
|
||||
'user' => 'guest',
|
||||
'vhost' => '/'
|
||||
'registry' => 'alchemy_worker.queue_registry',
|
||||
'host' => 'localhost',
|
||||
'port' => 5672,
|
||||
'user' => 'guest',
|
||||
'password' => 'guest',
|
||||
'vhost' => '/'
|
||||
]
|
||||
];
|
||||
|
||||
@@ -46,19 +47,22 @@ class WorkerConfigurationServiceProvider implements ServiceProviderInterface
|
||||
|
||||
$queueConfigurations = $configuration->get(['workers', 'queue'], $defaultConfiguration);
|
||||
|
||||
$queueConfiguration = reset($queueConfigurations);
|
||||
$queueKey = key($queueConfigurations);
|
||||
$config = [];
|
||||
|
||||
if (! isset($queueConfiguration['name'])) {
|
||||
if (! is_string($queueKey)) {
|
||||
throw new \RuntimeException('Invalid queue configuration: configuration has no key or name.');
|
||||
foreach($queueConfigurations as $name => $queueConfiguration) {
|
||||
$queueKey = $name;
|
||||
|
||||
if (! isset($queueConfiguration['name'])) {
|
||||
if (! is_string($queueKey)) {
|
||||
throw new \RuntimeException('Invalid queue configuration: configuration has no key or name.');
|
||||
}
|
||||
|
||||
$queueConfiguration['name'] = $queueKey;
|
||||
}
|
||||
|
||||
$queueConfiguration['name'] = $queueKey;
|
||||
$config[$queueConfiguration['name']] = $queueConfiguration ;
|
||||
}
|
||||
|
||||
$config = [ $queueConfiguration['name'] => $queueConfiguration ];
|
||||
|
||||
return $config;
|
||||
}
|
||||
catch (RuntimeException $exception) {
|
||||
|
@@ -18,6 +18,7 @@ use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreationEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreationEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreationFailedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
|
||||
use Alchemy\Phrasea\Filesystem\FilesystemService;
|
||||
use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification;
|
||||
use MediaAlchemyst\Alchemyst;
|
||||
@@ -170,13 +171,53 @@ class SubdefGenerator
|
||||
unset($this->tmpFilePath);
|
||||
}
|
||||
|
||||
$this->dispatch(
|
||||
RecordEvents::SUB_DEFINITIONS_CREATED,
|
||||
new SubDefinitionsCreatedEvent(
|
||||
$record,
|
||||
$mediaCreated
|
||||
)
|
||||
);
|
||||
// if we created subdef one by one
|
||||
if (count($wanted_subdefs) == 1) {
|
||||
$mediaSubdefRepository = $this->getMediaSubdefRepository($record->getDataboxId());
|
||||
$mediaSubdefs = $mediaSubdefRepository->findByRecordIdsAndNames([$record->getRecordId()]);
|
||||
$medias = [];
|
||||
foreach ($mediaSubdefs as $subdef) {
|
||||
try {
|
||||
$medias[$subdef->get_name()] = $this->mediavorus->guess($subdef->getRealPath());
|
||||
} catch (MediaVorusFileNotFoundException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->dispatch(
|
||||
RecordEvents::SUB_DEFINITIONS_CREATED,
|
||||
new SubDefinitionsCreatedEvent(
|
||||
$record,
|
||||
$medias
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->dispatch(
|
||||
RecordEvents::SUB_DEFINITIONS_CREATED,
|
||||
new SubDefinitionsCreatedEvent(
|
||||
$record,
|
||||
$mediaCreated
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set a logger to use
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* to get the logger
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
private function generateSubdef(\record_adapter $record, \databox_subdef $subdef_class, $pathdest)
|
||||
@@ -276,4 +317,14 @@ class SubdefGenerator
|
||||
$i = floor(log($bytes, 1024));
|
||||
return round($bytes / pow(1024, $i), [0,0,2,2,3][$i]).['B','kB','MB','GB'][$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $databoxId
|
||||
*
|
||||
* @return MediaSubdefRepository|Object
|
||||
*/
|
||||
private function getMediaSubdefRepository($databoxId)
|
||||
{
|
||||
return $this->app['provider.repo.media_subdef']->getRepositoryForDatabox($databoxId);
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Media;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Event\Record\MediaSubstitutedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
|
||||
use Alchemy\Phrasea\Filesystem\FilesystemService;
|
||||
use MediaAlchemyst\Alchemyst;
|
||||
use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException;
|
||||
@@ -79,7 +80,7 @@ class SubdefSubstituer
|
||||
$record->write_metas();
|
||||
|
||||
if ($shouldSubdefsBeRebuilt) {
|
||||
$record->rebuild_subdefs();
|
||||
$this->dispatcher->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($record));
|
||||
}
|
||||
|
||||
$this->dispatcher->dispatch(RecordEvents::MEDIA_SUBSTITUTED, new MediaSubstitutedEvent($record));
|
||||
|
@@ -12,7 +12,7 @@
|
||||
namespace Alchemy\Phrasea\Model\Manipulator;
|
||||
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
use Alchemy\Phrasea\Webhook\WebhookPublisher;
|
||||
use Alchemy\Phrasea\Webhook\WebhookPublisherInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
@@ -29,11 +29,11 @@ class WebhookEventManipulator implements ManipulatorInterface
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var WebhookPublisher
|
||||
* @var WebhookPublisherInterface
|
||||
*/
|
||||
private $publisher;
|
||||
|
||||
public function __construct(ObjectManager $om, EntityRepository $repo, WebhookPublisher $publisher)
|
||||
public function __construct(ObjectManager $om, EntityRepository $repo, WebhookPublisherInterface $publisher)
|
||||
{
|
||||
$this->om = $om;
|
||||
$this->repository = $repo;
|
||||
|
@@ -12,6 +12,8 @@
|
||||
namespace Alchemy\Phrasea\TaskManager\Job;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
use Alchemy\Phrasea\Border\File;
|
||||
use Alchemy\Phrasea\Border\Manager as borderManager;
|
||||
@@ -1001,7 +1003,7 @@ class ArchiveJob extends AbstractJob
|
||||
{
|
||||
// quick fix to reconnect if mysql is lost
|
||||
$app->getApplicationBox()->get_connection();
|
||||
$databox->get_connection();
|
||||
$collection->get_connection();
|
||||
|
||||
$status = \databox_status::operation_or($stat0, $stat1);
|
||||
|
||||
@@ -1032,7 +1034,8 @@ class ArchiveJob extends AbstractJob
|
||||
}
|
||||
|
||||
$story->setStatus(\databox_status::operation_or($stat0, $stat1));
|
||||
$story->rebuild_subdefs();
|
||||
|
||||
$app['dispatcher']->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($story));
|
||||
|
||||
unset($media);
|
||||
|
||||
|
@@ -19,7 +19,7 @@ use Alchemy\Queue\MessageQueueRegistry;
|
||||
* Class WebhookPublisher publishes webhook event notifications in message queues
|
||||
* @package Alchemy\Phrasea\Webhook
|
||||
*/
|
||||
class WebhookPublisher
|
||||
class WebhookPublisher implements WebhookPublisherInterface
|
||||
{
|
||||
/**
|
||||
* @var MessageQueueRegistry
|
||||
|
10
lib/Alchemy/Phrasea/Webhook/WebhookPublisherInterface.php
Normal file
10
lib/Alchemy/Phrasea/Webhook/WebhookPublisherInterface.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook;
|
||||
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
|
||||
interface WebhookPublisherInterface
|
||||
{
|
||||
public function publishWebhookEvent(WebhookEvent $event);
|
||||
}
|
@@ -19,6 +19,7 @@ use Alchemy\Phrasea\Core\Event\Record\OriginalNameChangedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\StatusChangedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
|
||||
use Alchemy\Phrasea\Core\PhraseaTokens;
|
||||
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
|
||||
use Alchemy\Phrasea\Filesystem\FilesystemService;
|
||||
@@ -284,7 +285,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$this->getDataboxConnection()->executeUpdate($sql, ['type' => $type, 'record_id' => $this->getRecordId()]);
|
||||
|
||||
if ($old_type !== $type) {
|
||||
$this->rebuild_subdefs();
|
||||
$this->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($this));
|
||||
}
|
||||
|
||||
$this->type = $type;
|
||||
@@ -341,7 +342,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
array(':mime' => $mime, ':record_id' => $this->getRecordId())
|
||||
)) {
|
||||
|
||||
$this->rebuild_subdefs();
|
||||
$this->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($this));
|
||||
|
||||
$this->delete_data_from_cache();
|
||||
}
|
||||
|
||||
|
@@ -169,7 +169,8 @@ class ExportTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testExportMail()
|
||||
{
|
||||
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRecordsExport');
|
||||
// deliver method removed in the listener
|
||||
// $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRecordsExport');
|
||||
|
||||
$this->getClient()->request('POST', '/prod/export/mail/', [
|
||||
'lst' => $this->getRecord1()->getId(),
|
||||
|
Reference in New Issue
Block a user