Record create/delete events OK

This commit is contained in:
Mathieu Darse
2015-01-26 17:39:25 +01:00
parent a01bf29c5b
commit b0959a9a31
10 changed files with 23 additions and 29 deletions

View File

@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\Command;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Border\Manager; use Alchemy\Phrasea\Border\Manager;
use Alchemy\Phrasea\Core\Event\RecordEvent\CreateRecordEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCreatedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\LazaretFile; use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Alchemy\Phrasea\Model\Entities\LazaretSession; use Alchemy\Phrasea\Model\Entities\LazaretSession;
@@ -117,7 +117,7 @@ class RecordAdd extends Command
"Record id <info>%d</info> on collection `%s` (databox `%s`) has been created", $elementCreated->get_record_id(), $elementCreated->get_collection()->get_label($this->container['locale']), $elementCreated->get_databox()->get_label($this->container['locale']) "Record id <info>%d</info> on collection `%s` (databox `%s`) has been created", $elementCreated->get_record_id(), $elementCreated->get_collection()->get_label($this->container['locale']), $elementCreated->get_databox()->get_label($this->container['locale'])
) )
); );
$this->container['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATE, new CreateRecordEvent($elementCreated)); $this->container['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATED, new RecordCreatedEvent($elementCreated));
} elseif ($elementCreated instanceof LazaretFile) { } elseif ($elementCreated instanceof LazaretFile) {
$output->writeln( $output->writeln(
sprintf("Quarantine item id <info>%d</info> has been created", $elementCreated->getId()) sprintf("Quarantine item id <info>%d</info> has been created", $elementCreated->getId())

View File

@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\Controller\Api;
use Alchemy\Phrasea\Core\Event\ChangeStatusEvent; use Alchemy\Phrasea\Core\Event\ChangeStatusEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\CreateRecordEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCreatedEvent;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Alchemy\Phrasea\Cache\Cache as CacheInterface; use Alchemy\Phrasea\Cache\Cache as CacheInterface;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
@@ -562,7 +562,7 @@ class V1 implements ControllerProviderInterface
$ret['entity'] = '0'; $ret['entity'] = '0';
$ret['url'] = '/records/' . $output->get_sbas_id() . '/' . $output->get_record_id() . '/'; $ret['url'] = '/records/' . $output->get_sbas_id() . '/' . $output->get_record_id() . '/';
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATE, new CreateRecordEvent($output)); $app['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATED, new RecordCreatedEvent($output));
} }
if ($output instanceof LazaretFile) { if ($output instanceof LazaretFile) {
$ret['entity'] = '1'; $ret['entity'] = '1';

View File

@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeStatusEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeStatusEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\CreateRecordEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCreatedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\LazaretFile; use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Alchemy\Phrasea\Border; use Alchemy\Phrasea\Border;
@@ -199,7 +199,7 @@ class Lazaret implements ControllerProviderInterface
$lazaretFile->getSession(), $borderFile, $callBack, Border\Manager::FORCE_RECORD $lazaretFile->getSession(), $borderFile, $callBack, Border\Manager::FORCE_RECORD
); );
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATE, new CreateRecordEvent($record)); $app['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATED, new RecordCreatedEvent($record));
if ($keepAttributes) { if ($keepAttributes) {
//add attribute //add attribute

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Controller\RecordsRequest; use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Core\Event\RecordEvent\DeleteStoryEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\DeleteStoryEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordDeletedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Silex\Application; use Silex\Application;
@@ -180,7 +181,7 @@ class Records implements ControllerProviderInterface
if ($record->isStory()) { if ($record->isStory()) {
$app['dispatcher']->dispatch(PhraseaEvents::STORY_DELETE, new DeleteStoryEvent($record)); $app['dispatcher']->dispatch(PhraseaEvents::STORY_DELETE, new DeleteStoryEvent($record));
} else { } else {
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_DELETE, new DeleteRecordEvent($record)); $app['dispatcher']->dispatch(PhraseaEvents::RECORD_DELETED, new RecordDeletedEvent($record));
} }
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -14,7 +14,7 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Border\Attribute\Status; use Alchemy\Phrasea\Border\Attribute\Status;
use Alchemy\Phrasea\Core\Event\LazaretEvent; use Alchemy\Phrasea\Core\Event\LazaretEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\CreateRecordEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCreatedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use DataURI\Parser; use DataURI\Parser;
use DataURI\Exception\Exception as DataUriException; use DataURI\Exception\Exception as DataUriException;
@@ -209,7 +209,7 @@ class Upload implements ControllerProviderInterface
$element = 'record'; $element = 'record';
$message = $app->trans('The record was successfully created'); $message = $app->trans('The record was successfully created');
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATE, new CreateRecordEvent($elementCreated)); $app['dispatcher']->dispatch(PhraseaEvents::RECORD_CREATED, new RecordCreatedEvent($elementCreated));
// try to create thumbnail from data URI // try to create thumbnail from data URI
if ('' !== $b64Image = $request->request->get('b64_image', '')) { if ('' !== $b64Image = $request->request->get('b64_image', '')) {

View File

@@ -11,10 +11,5 @@
namespace Alchemy\Phrasea\Core\Event\RecordEvent; namespace Alchemy\Phrasea\Core\Event\RecordEvent;
use Alchemy\Phrasea\Model\Entities\Basket; class RecordCreatedEvent extends RecordEvent
use Symfony\Component\EventDispatcher\Event as SfEvent; {}
class CreateRecordEvent extends RecordEvent
{
}

View File

@@ -11,9 +11,6 @@
namespace Alchemy\Phrasea\Core\Event\RecordEvent; namespace Alchemy\Phrasea\Core\Event\RecordEvent;
use Alchemy\Phrasea\Model\Entities\Basket; class RecordDeletedEvent extends RecordEvent
use Symfony\Component\EventDispatcher\Event as SfEvent;
class DeleteRecordEvent extends RecordEvent
{ {
} }

View File

@@ -11,17 +11,18 @@
namespace Alchemy\Phrasea\Core\Event\RecordEvent; namespace Alchemy\Phrasea\Core\Event\RecordEvent;
use Symfony\Component\EventDispatcher\Event as SfEvent; use Alchemy\Phrasea\Model\RecordInterface;
use Symfony\Component\EventDispatcher\Event;
class RecordEvent extends SfEvent abstract class RecordEvent extends Event
{ {
public function __construct(\record_adapter $record) public function __construct(RecordInterface $record)
{ {
$this->record = $record; $this->record = $record;
} }
/** /**
* @return \record_adapter * @return RecordInterface
*/ */
public function getRecord() public function getRecord()
{ {

View File

@@ -42,8 +42,8 @@ final class PhraseaEvents
const EXPORT_MAIL_FAILURE = 'export.mail-failure'; const EXPORT_MAIL_FAILURE = 'export.mail-failure';
const EXPORT_CREATE = 'export.create'; const EXPORT_CREATE = 'export.create';
const RECORD_CREATE = 'record.create'; const RECORD_CREATED = 'record.created';
const RECORD_DELETE = 'record.delete'; const RECORD_DELETED = 'record.deleted';
const STORY_CREATE = 'story.create'; const STORY_CREATE = 'story.create';
const STORY_DELETE = 'story.delete'; const STORY_DELETE = 'story.delete';
const RECORD_CHANGE_COLLECTION = 'record.collection'; const RECORD_CHANGE_COLLECTION = 'record.collection';

View File

@@ -14,7 +14,7 @@ namespace Alchemy\Phrasea\TaskManager\Job;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeCollectionEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeCollectionEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeStatusEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeStatusEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\DeleteRecordEvent; use Alchemy\Phrasea\Core\Event\RecordEvent\RecordDeletedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents; use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\TaskManager\Editor\RecordMoverEditor; use Alchemy\Phrasea\TaskManager\Editor\RecordMoverEditor;
use JMS\Serializer\EventDispatcher\EventDispatcher; use JMS\Serializer\EventDispatcher\EventDispatcher;
@@ -114,7 +114,7 @@ class RecordMoverJob extends AbstractJob
foreach ($rec->get_children() as $child) { foreach ($rec->get_children() as $child) {
$child->delete(); $child->delete();
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_DELETE, new DeleteRecordEvent($child)); $app['dispatcher']->dispatch(PhraseaEvents::RECORD_DELETED, new RecordDeletedEvent($child));
if ($logsql) { if ($logsql) {
$this->log('debug', sprintf("on sbas %s delete (grp child) rid %s \n", $row['sbas_id'], $child->get_record_id())); $this->log('debug', sprintf("on sbas %s delete (grp child) rid %s \n", $row['sbas_id'], $child->get_record_id()));
@@ -122,7 +122,7 @@ class RecordMoverJob extends AbstractJob
} }
} }
$rec->delete(); $rec->delete();
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_DELETE, new DeleteRecordEvent($rec)); $app['dispatcher']->dispatch(PhraseaEvents::RECORD_DELETED, new RecordDeletedEvent($rec));
if ($logsql) { if ($logsql) {
$this->log('debug', sprintf("on sbas %s delete rid %s \n", $row['sbas_id'], $rec->get_record_id())); $this->log('debug', sprintf("on sbas %s delete rid %s \n", $row['sbas_id'], $rec->get_record_id()));
} }