Record/story metadata and collection change events OK

This commit is contained in:
Mathieu Darse
2015-01-26 20:06:09 +01:00
parent 47d00db5ab
commit a64b8286e6
14 changed files with 47 additions and 33 deletions

View File

@@ -12,7 +12,7 @@
namespace Alchemy\Phrasea\Controller\Api;
use Alchemy\Phrasea\Core\Event\ChangeStatusEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordMetadataChangedEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCreatedEvent;
use Silex\ControllerProviderInterface;
use Alchemy\Phrasea\Cache\Cache as CacheInterface;
@@ -833,7 +833,7 @@ class V1 implements ControllerProviderInterface
});
$record->set_metadatas($metadatas);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
return Result::create($request, ["record_metadatas" => $this->list_record_caption($record->get_caption())])->createResponse();
}

View File

@@ -11,7 +11,7 @@
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordMetadataChangedEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeStatusEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController;
@@ -351,7 +351,7 @@ class Edit implements ControllerProviderInterface
if (isset($rec['metadatas']) && is_array($rec['metadatas'])) {
$record->set_metadatas($rec['metadatas']);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
}
/**
@@ -378,7 +378,7 @@ class Edit implements ControllerProviderInterface
$record->set_metadatas($metas, true);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
}
$newstat = $record->get_status();

View File

@@ -11,7 +11,7 @@
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordMetadataChangedEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeStatusEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCreatedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
@@ -248,7 +248,7 @@ class Lazaret implements ControllerProviderInterface
$fields = $metaFields->toMetadataArray($record->get_databox()->get_meta_structure());
$record->set_metadatas($fields);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
}
//Delete lazaret file

View File

@@ -12,7 +12,7 @@
namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeCollectionEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCollectionChangedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Silex\Application;
use Silex\ControllerProviderInterface;
@@ -95,7 +95,7 @@ class MoveCollection implements ControllerProviderInterface
foreach ($records as $record) {
$record->move_to_collection($collection, $app['phraseanet.appbox']);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_COLLECTION, new ChangeCollectionEvent($record));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_COLLECTION_CHANGED, new RecordCollectionChangedEvent($record));
if ($request->request->get("chg_coll_son") == "1") {
foreach ($record->get_children() as $child) {
@@ -103,7 +103,7 @@ class MoveCollection implements ControllerProviderInterface
$child->move_to_collection($collection, $app['phraseanet.appbox']);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_COLLECTION, new ChangeCollectionEvent($child));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_COLLECTION_CHANGED, new RecordCollectionChangedEvent($child));
}
}
}

View File

@@ -13,7 +13,7 @@ namespace Alchemy\Phrasea\Controller\Prod;
use Alchemy\Phrasea\Controller\Exception as ControllerException;
use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\StoryMetadataChangedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\StoryWZ;
use Silex\Application;
@@ -76,7 +76,7 @@ class Story implements ControllerProviderInterface
$Story->set_metadatas($metadatas)->rebuild_subdefs();
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($Story));
$app['dispatcher']->dispatch(PhraseaEvents::STORY_METADATA_CHANGED, new StoryMetadataChangedEvent($Story));
$StoryWZ = new StoryWZ();
$StoryWZ->setUser($app['authentication']->getUser());

View File

@@ -11,7 +11,7 @@
namespace Alchemy\Phrasea\Controller\Thesaurus;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordMetadataChangedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\User;
use Silex\Application;
@@ -1497,7 +1497,7 @@ class Xmlhttp implements ControllerProviderInterface
if (!$request->get('debug')) {
$record->set_metadatas($metadatasd, true);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
$ret['nRecsUpdated']++;
}

View File

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

View File

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

View File

@@ -0,0 +1,16 @@
<?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\RecordEvent;
class StoryMetadataChangedEvent extends RecordEvent
{
}

View File

@@ -44,11 +44,14 @@ final class PhraseaEvents
const STORY_CREATED = 'story.created';
const STORY_DELETED = 'story.deleted';
const STORY_METADATA_CHANGED = 'story.metadata_changed';
// Record lifecycle
const RECORD_CREATED = 'record.created';
const RECORD_DELETED = 'record.deleted';
const RECORD_CHANGE_COLLECTION = 'record.collection';
const RECORD_CHANGE_METADATA = 'record.metadata';
// Record change
const RECORD_COLLECTION_CHANGED = 'record.collection_changed';
const RECORD_METADATA_CHANGED = 'record.metadata_changed';
const RECORD_CHANGE_ORIGINAL_NAME = 'record.original_name';
const RECORD_CHANGE_STATUS = 'record.status';
const RECORD_BUILD_SUB_DEFINITION = 'record.sub_definition';

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Metadata;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordMetadataChangedEvent;
use PHPExiftool\Driver\Metadata\Metadata;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -20,7 +21,7 @@ class PhraseanetMetadataSetter
public function __construct(EventDispatcherInterface $dispatcher)
{
$this->disptatcher = $dispatcher;
$this->dispatcher = $dispatcher;
}
public function replaceMetadata($metadataCollection, \record_adapter $record)
@@ -102,7 +103,7 @@ class PhraseanetMetadataSetter
if (count($metas) > 0) {
$record->set_metadatas($metas, true);
$this->disptatcher->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$this->dispatcher->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
}
}
}

View File

@@ -12,7 +12,7 @@
namespace Alchemy\Phrasea\TaskManager\Job;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeCollectionEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordCollectionChangedEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeStatusEvent;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordDeletedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
@@ -84,7 +84,7 @@ class RecordMoverJob extends AbstractJob
$coll = \collection::get_from_coll_id($app, $databox, $row['coll']);
$rec->move_to_collection($coll, $app['phraseanet.appbox']);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_COLLECTION, new ChangeCollectionEvent($rec));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_COLLECTION_CHANGED, new RecordCollectionChangedEvent($rec));
if ($logsql) {
$this->log('debug', sprintf("on sbas %s move rid %s to coll %s \n", $row['sbas_id'], $row['record_id'], $coll->get_coll_id()));

View File

@@ -10,8 +10,8 @@
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordMetadataChangedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class caption_field implements cache_cacheableInterface
@@ -321,7 +321,7 @@ class caption_field implements cache_cacheableInterface
$record = $databox_field->get_databox()->get_record($row['record_id']);
$record->set_metadatas([]);
$dispatcher->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$dispatcher->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
unset($record);
} catch (\Exception $e) {
@@ -375,7 +375,7 @@ class caption_field implements cache_cacheableInterface
$caption_field->delete();
$record->set_metadatas([]);
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
unset($caption_field);
unset($record);

View File

@@ -14,8 +14,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Core\Event\RecordEvent\RecordMetadataChangedEvent;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Core\Event\RecordEvent\ChangeMetadataEvent;
class module_console_fieldsMerge extends Command
{
@@ -198,7 +198,7 @@ class module_console_fieldsMerge extends Command
]], true);
}
$this->getService('dispatcher')->dispatch(PhraseaEvents::RECORD_CHANGE_METADATA, new ChangeMetadataEvent($record));
$this->getService('dispatcher')->dispatch(PhraseaEvents::RECORD_METADATA_CHANGED, new RecordMetadataChangedEvent($record));
unset($record);
}