diff --git a/lib/Alchemy/Phrasea/Border/File.php b/lib/Alchemy/Phrasea/Border/File.php index 5aac6344f1..014057da79 100644 --- a/lib/Alchemy/Phrasea/Border/File.php +++ b/lib/Alchemy/Phrasea/Border/File.php @@ -246,7 +246,7 @@ class File /** * Returns an array of AttributeInterface associated to the file * - * @return array + * @return AttributeInterface[] */ public function getAttributes() { diff --git a/lib/Alchemy/Phrasea/Border/Manager.php b/lib/Alchemy/Phrasea/Border/Manager.php index 07a3e1e600..6ef071b4bf 100644 --- a/lib/Alchemy/Phrasea/Border/Manager.php +++ b/lib/Alchemy/Phrasea/Border/Manager.php @@ -20,6 +20,9 @@ use Alchemy\Phrasea\Metadata\Tag\TfBasename; use Alchemy\Phrasea\Metadata\Tag\TfFilename; use Alchemy\Phrasea\Metadata\Tag\TfRecordid; use Alchemy\Phrasea\Border\Attribute\Metadata as MetadataAttr; +use Alchemy\Phrasea\Border\Attribute\MetaField as MetafieldAttr; +use Alchemy\Phrasea\Border\Attribute\Status as StatusAttr; +use Alchemy\Phrasea\Border\Attribute\Story as StoryAttr; use Alchemy\Phrasea\Model\Entities\LazaretAttribute; use Alchemy\Phrasea\Model\Entities\LazaretCheck; use Alchemy\Phrasea\Model\Entities\LazaretFile; @@ -314,6 +317,7 @@ class Manager foreach ($file->getAttributes() as $attribute) { switch ($attribute->getName()) { case AttributeInterface::NAME_METAFIELD: + /** @var MetafieldAttr $attribute */ $values = $attribute->getValue(); $value = $attribute->getField()->is_multi() ? new Multi($values) : new MonoValue(array_pop($values)); @@ -329,14 +333,17 @@ class Manager break; case AttributeInterface::NAME_METADATA: + /** @var MetadataAttr $attribute */ $newMetadata[] = $attribute->getValue(); break; case AttributeInterface::NAME_STATUS: + /** @var StatusAttr $attribute */ $element->set_binary_status(decbin(bindec($element->get_status()) | bindec($attribute->getValue()))); break; case AttributeInterface::NAME_STORY: + /** @var StoryAttr $attribute */ $story = $attribute->getValue(); if ( ! $story->hasChild($element)) { @@ -441,6 +448,8 @@ class Manager * to Phraseanet * * @param File $file The file + * + * @return Manager */ protected function addMediaAttributes(File $file) { diff --git a/lib/Alchemy/Phrasea/Core/Event/AccountDeletedEvent.php b/lib/Alchemy/Phrasea/Core/Event/AccountDeletedEvent.php deleted file mode 100644 index d94500479d..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/AccountDeletedEvent.php +++ /dev/null @@ -1,60 +0,0 @@ -userId = $userId; - $this->login = $login; - $this->emailAddress = $emailAddress; - } - - /** - * @return int - */ - public function getUserId() - { - return $this->userId; - } - - /** - * @return string - */ - public function getLogin() - { - return $this->login; - } - - /** - * @return string - */ - public function getEmailAddress() - { - return $this->emailAddress; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/CollectionDisabled.php b/lib/Alchemy/Phrasea/Core/Event/CollectionDisabled.php deleted file mode 100644 index a36b413611..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/CollectionDisabled.php +++ /dev/null @@ -1,9 +0,0 @@ -collection = $collection; - $this->args = $args; - } - - /** - * @return \collection|null - */ - public function getCollection() - { - return $this->collection; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/CollectionSettingsChanged.php b/lib/Alchemy/Phrasea/Core/Event/CollectionSettingsChanged.php deleted file mode 100644 index 8c9f78b15f..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/CollectionSettingsChanged.php +++ /dev/null @@ -1,13 +0,0 @@ -args['settings_before']; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/CollectionUnmounted.php b/lib/Alchemy/Phrasea/Core/Event/CollectionUnmounted.php deleted file mode 100644 index f96535b242..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/CollectionUnmounted.php +++ /dev/null @@ -1,18 +0,0 @@ -args['coll_id']; - } - - public function getName() - { - return $this->args['name']; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/DataboxCreated.php b/lib/Alchemy/Phrasea/Core/Event/DataboxCreated.php deleted file mode 100644 index ae9f45d1ee..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/DataboxCreated.php +++ /dev/null @@ -1,9 +0,0 @@ -args['dbname']; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/DataboxMounted.php b/lib/Alchemy/Phrasea/Core/Event/DataboxMounted.php deleted file mode 100644 index 9414bed08a..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/DataboxMounted.php +++ /dev/null @@ -1,9 +0,0 @@ -databox = $databox; - $this->args = $args; - } - - public function getDatabox() - { - return $this->databox; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/DataboxStructureChanged.php b/lib/Alchemy/Phrasea/Core/Event/DataboxStructureChanged.php deleted file mode 100644 index 24b1a5bbd1..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/DataboxStructureChanged.php +++ /dev/null @@ -1,13 +0,0 @@ -args['dom_before']; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/DataboxThesaurusChanged.php b/lib/Alchemy/Phrasea/Core/Event/DataboxThesaurusChanged.php deleted file mode 100644 index b683782fa4..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/DataboxThesaurusChanged.php +++ /dev/null @@ -1,13 +0,0 @@ -args['dom_before']; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/DataboxTouChanged.php b/lib/Alchemy/Phrasea/Core/Event/DataboxTouChanged.php deleted file mode 100644 index 2541a7db7f..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/DataboxTouChanged.php +++ /dev/null @@ -1,13 +0,0 @@ -args['tou_before']; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/DataboxUnmounted.php b/lib/Alchemy/Phrasea/Core/Event/DataboxUnmounted.php deleted file mode 100644 index a8afc3fed1..0000000000 --- a/lib/Alchemy/Phrasea/Core/Event/DataboxUnmounted.php +++ /dev/null @@ -1,13 +0,0 @@ -args['dbname']; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordStatusChangedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/CollectionChangedEvent.php similarity index 83% rename from lib/Alchemy/Phrasea/Core/Event/Record/RecordStatusChangedEvent.php rename to lib/Alchemy/Phrasea/Core/Event/Record/CollectionChangedEvent.php index 4db7a42924..7bdb184c0f 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordStatusChangedEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/CollectionChangedEvent.php @@ -11,6 +11,6 @@ namespace Alchemy\Phrasea\Core\Event\Record; -class RecordStatusChangedEvent extends RecordEvent +class CollectionChangedEvent extends RecordEvent { } diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordCreatedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/CreatedEvent.php similarity index 85% rename from lib/Alchemy/Phrasea/Core/Event/Record/RecordCreatedEvent.php rename to lib/Alchemy/Phrasea/Core/Event/Record/CreatedEvent.php index 3cdac78aab..224172b8dd 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordCreatedEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/CreatedEvent.php @@ -11,5 +11,5 @@ namespace Alchemy\Phrasea\Core\Event\Record; -class RecordCreatedEvent extends RecordEvent +class CreatedEvent extends RecordEvent {} diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordDeletedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/DeletedEvent.php similarity index 85% rename from lib/Alchemy/Phrasea/Core/Event/Record/RecordDeletedEvent.php rename to lib/Alchemy/Phrasea/Core/Event/Record/DeletedEvent.php index 0f720c07d3..215ef7f246 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordDeletedEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/DeletedEvent.php @@ -11,6 +11,6 @@ namespace Alchemy\Phrasea\Core\Event\Record; -class RecordDeletedEvent extends RecordEvent +class DeletedEvent extends RecordEvent { } diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordIndexEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/IndexEvent.php similarity index 85% rename from lib/Alchemy/Phrasea/Core/Event/Record/RecordIndexEvent.php rename to lib/Alchemy/Phrasea/Core/Event/Record/IndexEvent.php index 1a0e4a9ba4..9a6c25cf8f 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordIndexEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/IndexEvent.php @@ -11,7 +11,7 @@ namespace Alchemy\Phrasea\Core\Event\Record; -class RecordIndexEvent extends RecordEvent +class IndexEvent extends RecordEvent { } diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/MediaSubstitutedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/MediaSubstitutedEvent.php new file mode 100644 index 0000000000..5ed5779e82 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Record/MediaSubstitutedEvent.php @@ -0,0 +1,16 @@ +subDefinitionName = $subDefinitionName; + $this->media = $media; + } + + /** + * @return string + */ + public function getSubDefinitionName() + { + return $this->subDefinitionName; + } + + /** + * @return MediaInterface + */ + public function getMedia() + { + return $this->media; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/RecordSubDefinitionCreatedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionCreationEvent.php similarity index 86% rename from lib/Alchemy/Phrasea/Core/Event/Record/RecordSubDefinitionCreatedEvent.php rename to lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionCreationEvent.php index 77387ffe02..d5bcaabcc2 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Record/RecordSubDefinitionCreatedEvent.php +++ b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionCreationEvent.php @@ -11,7 +11,7 @@ namespace Alchemy\Phrasea\Core\Event\Record; -class RecordSubDefinitionCreatedEvent extends RecordEvent +class SubDefinitionCreationEvent extends RecordEvent { private $subDefinitionName; @@ -22,6 +22,9 @@ class RecordSubDefinitionCreatedEvent extends RecordEvent $this->subDefinitionName = $subDefinitionName; } + /** + * @return string + */ public function getSubDefinitionName() { return $this->subDefinitionName; diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionCreationFailedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionCreationFailedEvent.php new file mode 100644 index 0000000000..cd87a35d25 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionCreationFailedEvent.php @@ -0,0 +1,31 @@ +subDefinitionName = $subDefinitionName; + } + + /** + * @return string + */ + public function getSubDefinitionName() + { + return $this->subDefinitionName; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionsCreatedEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionsCreatedEvent.php new file mode 100644 index 0000000000..de74e16739 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionsCreatedEvent.php @@ -0,0 +1,39 @@ +media = $media; + } + + /** + * @return MediaInterface[] + */ + public function getMedia() + { + return $this->media; + } +} diff --git a/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionsCreationEvent.php b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionsCreationEvent.php new file mode 100644 index 0000000000..77858e9197 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Record/SubDefinitionsCreationEvent.php @@ -0,0 +1,32 @@ +subDefinitiosnNames = $subDefinitionsNames; + } + + /** + * @return string + */ + public function getSubDefinitionsNames() + { + return $this->subDefinitionsNames; + } +} diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index e2e62c3423..27e1cd5b09 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -12,7 +12,12 @@ namespace Alchemy\Phrasea\Media; use Alchemy\Phrasea\Application; -use Alchemy\Phrasea\Core\Event\Record\RecordSubDefinitionCreatedEvent; +use Alchemy\Phrasea\Core\Event\Record\RecordEvent; +use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreatedEvent; +use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreatedEvent; +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 MediaAlchemyst\Alchemyst; use MediaAlchemyst\Specification\SpecificationInterface; @@ -38,14 +43,28 @@ class SubdefGenerator $this->mediavorus = $mediavorus; } + private function dispatch($eventName, RecordEvent $event) + { + $this->app['dispatcher']->dispatch($eventName, $event); + } + public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null) { - if (null === $subdefs = $record->get_databox()->get_subdef_structure()->getSubdefGroup($record->get_type())) { - $this->logger->info(sprintf('Nothing to do for %s', $record->get_type())); + if (null === $subdefs = $record->getDatabox()->get_subdef_structure()->getSubdefGroup($record->getType())) { + $this->logger->info(sprintf('Nothing to do for %s', $record->getType())); - return; + return $this; } + $this->dispatch( + RecordEvents::SUB_DEFINITIONS_CREATION, + new SubDefinitionsCreationEvent( + $record, + $wanted_subdefs + ) + ); + + $mediaCreated = []; foreach ($subdefs as $subdef) { $subdefname = $subdef->get_name(); @@ -64,6 +83,14 @@ class SubdefGenerator $pathdest = $this->generateSubdefPathname($record, $subdef, $pathdest); + $this->dispatch( + RecordEvents::SUB_DEFINITION_CREATION, + new SubDefinitionCreationEvent( + $record, + $subdefname + ) + ); + $this->logger->addInfo(sprintf('Generating subdef %s to %s', $subdefname, $pathdest)); $this->generateSubdef($record, $subdef, $pathdest); @@ -71,13 +98,37 @@ class SubdefGenerator $media = $this->mediavorus->guess($pathdest); \media_subdef::create($this->app, $record, $subdef->get_name(), $media); + + $this->dispatch( + RecordEvents::SUB_DEFINITION_CREATED, + new SubDefinitionCreatedEvent( + $record, + $subdefname, + $mediaCreated[$subdefname] = $media + ) + ); + } + else { + $this->dispatch( + RecordEvents::SUB_DEFINITION_CREATION_FAILED, + new SubDefinitionCreationFailedEvent( + $record, + $subdefname + ) + ); } $record->clearSubdefCache($subdefname); - - $this->app['dispatcher']->dispatch(RecordEvents::SUB_DEFINITION_CREATED, new RecordSubDefinitionCreatedEvent($record, $subdefname)); } + $this->dispatch( + RecordEvents::SUB_DEFINITIONS_CREATED, + new SubDefinitionsCreatedEvent( + $record, + $mediaCreated + ) + ); + return $this; } @@ -92,7 +143,7 @@ class SubdefGenerator $this->alchemyst->turnInto($record->get_hd_file()->getPathname(), $pathdest, $subdef_class->getSpecs()); } catch (MediaAlchemystException $e) { - $this->logger->error(sprintf('Subdef generation failed for record %d with message %s', $record->get_record_id(), $e->getMessage())); + $this->logger->error(sprintf('Subdef generation failed for record %d with message %s', $record->getRecordId(), $e->getMessage())); } } @@ -104,7 +155,7 @@ class SubdefGenerator $pathdest = \databox::dispatch($this->filesystem, $subdef->get_path()); } - return $pathdest . $record->get_record_id() . '_' . $subdef->get_name() . '.' . $this->getExtensionFromSpec($subdef->getSpecs()); + return $pathdest . $record->getRecordId() . '_' . $subdef->get_name() . '.' . $this->getExtensionFromSpec($subdef->getSpecs()); } /** diff --git a/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php b/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php index c41815b9ee..0eb43f4eb7 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php +++ b/lib/Alchemy/Phrasea/Media/SubdefSubstituer.php @@ -12,7 +12,7 @@ namespace Alchemy\Phrasea\Media; use Alchemy\Phrasea\Application; -use Alchemy\Phrasea\Core\Event\Record\RecordMediaSubstitutedEvent; +use Alchemy\Phrasea\Core\Event\Record\MediaSubstitutedEvent; use Alchemy\Phrasea\Core\Event\Record\RecordEvents; use MediaAlchemyst\Alchemyst; use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException; @@ -97,6 +97,6 @@ class SubdefSubstituer $record->rebuild_subdefs(); } - $this->dispatcher->dispatch(RecordEvents::MEDIA_SUBSTITUTED, new RecordMediaSubstitutedEvent($record)); + $this->dispatcher->dispatch(RecordEvents::MEDIA_SUBSTITUTED, new MediaSubstitutedEvent($record)); } } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php index 9152d455b4..786c3da7ed 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/IndexerSubscriber.php @@ -13,10 +13,10 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic; use Alchemy\Phrasea\Core\Event\Collection\CollectionEvent; use Alchemy\Phrasea\Core\Event\Collection\CollectionEvents; -use Alchemy\Phrasea\Core\Event\Record\RecordDeletedEvent; +use Alchemy\Phrasea\Core\Event\Record\DeletedEvent; use Alchemy\Phrasea\Core\Event\Record\RecordEvent; use Alchemy\Phrasea\Core\Event\Record\RecordEvents; -use Alchemy\Phrasea\Core\Event\Record\RecordSubDefinitionCreatedEvent; +use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreatedEvent; use Alchemy\Phrasea\Core\Event\Record\Structure\RecordStructureEvent; use Alchemy\Phrasea\Core\Event\Record\Structure\RecordStructureEvents; use Alchemy\Phrasea\Core\Event\Thesaurus\ThesaurusEvent; @@ -84,7 +84,7 @@ class IndexerSubscriber implements EventSubscriberInterface RecordEvents::METADATA_CHANGED => 'onRecordChange', RecordEvents::ORIGINAL_NAME_CHANGED => 'onRecordChange', RecordEvents::STATUS_CHANGED => 'onRecordChange', - RecordEvents::SUB_DEFINITION_CREATED => 'onRecordChange', + RecordEvents::SUB_DEFINITIONS_CREATED => 'onRecordChange', RecordEvents::MEDIA_SUBSTITUTED => 'onRecordChange', ThesaurusEvents::IMPORTED => 'onThesaurusChange', ThesaurusEvents::FIELD_LINKED => 'onThesaurusChange', @@ -120,14 +120,13 @@ class IndexerSubscriber implements EventSubscriberInterface public function onRecordChange(RecordEvent $event) { - if ($event instanceof RecordSubDefinitionCreatedEvent && $event->getSubDefinitionName() !== 'thumbnail') { - return; + if ($event instanceof SubDefinitionsCreatedEvent) { + $record = $event->getRecord(); + $this->getIndexer()->indexRecord($record); } - $record = $event->getRecord(); - $this->getIndexer()->indexRecord($record); } - public function onRecordDelete(RecordDeletedEvent $event) + public function onRecordDelete(DeletedEvent $event) { $record = $event->getRecord(); $this->getIndexer()->deleteRecord($record); diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php index d50febcd83..44f8cc7f74 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php @@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\TaskManager\Job; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Border\File; +use Alchemy\Phrasea\Border\Manager as borderManager; use Alchemy\Phrasea\TaskManager\Editor\ArchiveEditor; use Alchemy\Phrasea\Metadata\Tag as PhraseaTag; use Alchemy\Phrasea\Border\Attribute as BorderAttribute; @@ -1080,7 +1081,9 @@ class ArchiveJob extends AbstractJob $record = $element; }; - $app['border-manager']->process($this->getLazaretSession($app), $file, $postProcess, $force); + /** @var borderManager $borderManager */ + $borderManager = $app['border-manager']; + $borderManager->process($this->getLazaretSession($app), $file, $postProcess, $force); return $record; } diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/SubdefsJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/SubdefsJob.php index 0bca61ab5f..01c66d6b14 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/SubdefsJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/SubdefsJob.php @@ -114,25 +114,16 @@ class SubdefsJob extends AbstractJob $this->log('warning', sprintf("Generate subdefs failed for : sbasid=%s / databox=%s / recordid=%s : %s", $databox->get_sbas_id(), $databox->get_dbname() , $row['record_id'], $e->getMessage())); } + // subdef created, ask to rewrite metadata $sql = 'UPDATE record' - . ' SET jeton=(jeton & ~(:flag)), moddate=NOW()' + . ' SET jeton=(jeton & ~(:flag_and)) | :flag_or, moddate=NOW()' . ' WHERE record_id=:record_id'; $stmt = $conn->prepare($sql); $stmt->execute([ ':record_id' => $row['record_id'], - ':flag' => PhraseaTokens::MAKE_SUBDEF - ]); - $stmt->closeCursor(); - - // rewrite metadata - $sql = 'UPDATE record' - . ' SET jeton=(jeton | :flag)' - . ' WHERE record_id=:record_id'; - $stmt = $conn->prepare($sql); - $stmt->execute([ - ':record_id' => $row['record_id'], - ':flag' => (PhraseaTokens::WRITE_META_SUBDEF | PhraseaTokens::TO_INDEX) + ':flag_and' => PhraseaTokens::MAKE_SUBDEF, + ':flag_or' => (PhraseaTokens::WRITE_META_SUBDEF | PhraseaTokens::TO_INDEX) ]); $stmt->closeCursor(); diff --git a/lib/classes/media/subdef.php b/lib/classes/media/subdef.php index f7ca85bbc6..343b5bcfd8 100644 --- a/lib/classes/media/subdef.php +++ b/lib/classes/media/subdef.php @@ -271,7 +271,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface } /** - * Find a substitution file for a sibdef + * Find a substitution file for a subdef * * @return \media_subdef */ @@ -476,7 +476,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface /** * - * @return id + * @return int */ public function get_subdef_id() { @@ -678,6 +678,8 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $newname = $media->getFile()->getFilename(); $params = [ + ':record_id' => $record->getRecordId(), + ':name' => $name, ':path' => $path, ':file' => $newname, ':width' => 0, @@ -694,36 +696,13 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $params[':height'] = $media->getHeight(); } - try { - - $sql = "SELECT subdef_id FROM subdef WHERE record_id = :record_id AND name = :name"; - $stmt = $connbas->prepare($sql); - $stmt->execute([ - ':record_id' => $record->getRecordId(), - ':name' => $name, - ]); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (! $row) { - throw new \Exception_Media_SubdefNotFound('Require the real one'); - } - - $sql = "UPDATE subdef" - . " SET path = :path, file = :file," - . " width = :width , height = :height, mime = :mime," - . " size = :size, dispatched = :dispatched, updated_on = NOW()" - . " WHERE subdef_id = :subdef_id"; - - $params[':subdef_id'] = $row['subdef_id']; - } catch (\Exception_Media_SubdefNotFound $e) { - $sql = "INSERT INTO subdef" - . " (record_id, name, path, file, width, height, mime, size, dispatched, created_on, updated_on)" - . " VALUES (:record_id, :name, :path, :file, :width, :height, :mime, :size, :dispatched, NOW(), NOW())"; - - $params[':record_id'] = $record->getRecordId(); - $params[':name'] = $name; - } + $sql = "INSERT INTO subdef" + . " (record_id, name, path, file, width, height, mime, size, dispatched, created_on, updated_on)" + . " VALUES (:record_id, :name, :path, :file, :width, :height, :mime, :size, :dispatched, NOW(), NOW())" + . " ON DUPLICATE KEY UPDATE" + . " path = VALUES(path), file = VALUES(file)," + . " width = VALUES(width) , height = VALUES(height), mime = VALUES(mime)," + . " size = VALUES(size), dispatched = VALUES(dispatched), updated_on = NOW()"; $stmt = $connbas->prepare($sql); $stmt->execute($params); diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index c24b399128..afc4b1ca4a 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -12,14 +12,14 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Cache\Exception; -use Alchemy\Phrasea\Core\Event\Record\RecordCollectionChangedEvent; -use Alchemy\Phrasea\Core\Event\Record\RecordCreatedEvent; -use Alchemy\Phrasea\Core\Event\Record\RecordDeletedEvent; +use Alchemy\Phrasea\Core\Event\Record\CollectionChangedEvent; +use Alchemy\Phrasea\Core\Event\Record\CreatedEvent; +use Alchemy\Phrasea\Core\Event\Record\DeletedEvent; use Alchemy\Phrasea\Core\Event\Record\RecordEvent; use Alchemy\Phrasea\Core\Event\Record\RecordEvents; -use Alchemy\Phrasea\Core\Event\Record\RecordMetadataChangedEvent; -use Alchemy\Phrasea\Core\Event\Record\RecordOriginalNameChangedEvent; -use Alchemy\Phrasea\Core\Event\Record\RecordStatusChangedEvent; +use Alchemy\Phrasea\Core\Event\Record\MetadataChangedEvent; +use Alchemy\Phrasea\Core\Event\Record\OriginalNameChangedEvent; +use Alchemy\Phrasea\Core\Event\Record\StatusChangedEvent; use Alchemy\Phrasea\Core\PhraseaTokens; use Alchemy\Phrasea\Media\ArrayTechnicalDataSet; use Alchemy\Phrasea\Media\FloatTechnicalData; @@ -38,8 +38,10 @@ use Doctrine\ORM\EntityManager; use MediaVorus\Media\MediaInterface; use MediaVorus\MediaVorus; use Ramsey\Uuid\Uuid; +use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\File as SymfoFile; + class record_adapter implements RecordInterface, cache_cacheableInterface { const CACHE_ORIGINAL_NAME = 'originalname'; @@ -453,7 +455,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->delete_data_from_cache(); - $this->dispatch(RecordEvents::COLLECTION_CHANGED, new RecordCollectionChangedEvent($this)); + $this->dispatch(RecordEvents::COLLECTION_CHANGED, new CollectionChangedEvent($this)); return $this; } @@ -463,7 +465,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface */ public function get_rollover_thumbnail() { - if ($this->get_type() != 'video') { + if ($this->getType() != 'video') { return null; } @@ -793,7 +795,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->delete_data_from_cache(); - $this->dispatch(RecordEvents::ORIGINAL_NAME_CHANGED, new RecordOriginalNameChangedEvent($this)); + $this->dispatch(RecordEvents::ORIGINAL_NAME_CHANGED, new OriginalNameChangedEvent($this)); return $this; } @@ -896,15 +898,18 @@ class record_adapter implements RecordInterface, cache_cacheableInterface { $newfilename = $this->record_id . '_0_' . $name . '.' . $media->getFile()->getExtension(); + /** @var Filesystem $filesystem */ + $filesystem = $app['filesystem']; + if ($name == 'document') { $baseprefs = $this->getDatabox()->get_sxml_structure(); $pathhd = p4string::addEndSlash((string) ($baseprefs->path)); $filehd = $this->getRecordId() . "_document." . strtolower($media->getFile()->getExtension()); - $pathhd = databox::dispatch($app['filesystem'], $pathhd); + $pathhd = databox::dispatch($filesystem, $pathhd); - $app['filesystem']->copy($media->getFile()->getRealPath(), $pathhd . $filehd, true); + $filesystem->copy($media->getFile()->getRealPath(), $pathhd . $filehd, true); $subdefFile = $pathhd . $filehd; @@ -920,8 +925,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->get_subdef($name)->remove_file(); $this->clearSubdefCache($name); } else { - $path = databox::dispatch($app['filesystem'], $subdef_def->get_path()); - $app['filesystem']->mkdir($path, 0750); + $path = databox::dispatch($filesystem, $subdef_def->get_path()); + $filesystem->mkdir($path, 0750); $path_file_dest = $path . $newfilename; } @@ -939,7 +944,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $subdefFile = $path_file_dest; } else{ - $app['filesystem']->copy($media->getFile()->getRealPath(), $path_file_dest); + $filesystem->copy($media->getFile()->getRealPath(), $path_file_dest); $subdefFile = $path_file_dest; } @@ -947,7 +952,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $meta_writable = $subdef_def->meta_writeable(); } - $app['filesystem']->chmod($subdefFile, 0760); + $filesystem->chmod($subdefFile, 0760); $media = $app->getMediaFromUri($subdefFile); $subdef = media_subdef::create($app, $this, $name, $media); $subdef->set_substituted(true); @@ -1076,7 +1081,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->set_xml($xml); unset($xml); - $this->dispatch(RecordEvents::METADATA_CHANGED, new RecordMetadataChangedEvent($this)); + $this->dispatch(RecordEvents::METADATA_CHANGED, new MetadataChangedEvent($this)); return $this; } @@ -1158,23 +1163,28 @@ class record_adapter implements RecordInterface, cache_cacheableInterface ['status' => bindec($status), 'record_id' => $this->record_id] ); - $sql = 'REPLACE INTO status (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; - $stmt = $connection->prepare($sql); - $status = strrev($status); $length = strlen($status); + $sqlValues = []; for ($i = 4; $i < $length; $i++) { - $stmt->execute([ - ':record_id' => $this->getRecordId(), - ':name' => $i, - ':value' => $status[$i] - ]); + $sqlValues[] = join(',', array( + 'null', + $connection->quote($this->getRecordId()), + $connection->quote($i), + $connection->quote($status[$i]) + )); } + $sql = "REPLACE INTO status (id, record_id, name, value)" + . " VALUES (" . join('),(', $sqlValues) . ")"; + $stmt = $connection->prepare($sql); + + $stmt->execute(); + $stmt->closeCursor(); $this->delete_data_from_cache(self::CACHE_STATUS); - $this->dispatch(RecordEvents::STATUS_CHANGED, new RecordStatusChangedEvent($this)); + $this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this)); return $this; } @@ -1231,7 +1241,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface unset($e); } - $story->dispatch(RecordEvents::CREATED, new RecordCreatedEvent($story)); + $story->dispatch(RecordEvents::CREATED, new CreatedEvent($story)); return $story; } @@ -1285,10 +1295,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface unset($e); } - $pathhd = databox::dispatch($app['filesystem'], trim($databox->get_sxml_structure()->path)); + /** @var Filesystem $filesystem */ + $filesystem = $app['filesystem']; + + $pathhd = databox::dispatch($filesystem, trim($databox->get_sxml_structure()->path)); $newname = $record->getRecordId() . "_document." . pathinfo($file->getOriginalName(), PATHINFO_EXTENSION); - $app['filesystem']->copy($file->getFile()->getRealPath(), $pathhd . $newname, true); + $filesystem->copy($file->getFile()->getRealPath(), $pathhd . $newname, true); $media = $app->getMediaFromUri($pathhd . $newname); media_subdef::create($app, $record, 'document', $media); @@ -1297,7 +1310,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $record->insertTechnicalDatas($app['mediavorus']); - $record->dispatch(RecordEvents::CREATED, new RecordCreatedEvent($record)); + $record->dispatch(RecordEvents::CREATED, new CreatedEvent($record)); return $record; } @@ -1316,15 +1329,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return $this; } + $connection = $this->getDatabox()->get_connection(); $sql = 'DELETE FROM technical_datas WHERE record_id = :record_id'; - $stmt = $this->getDatabox()->get_connection()->prepare($sql); + $stmt = $connection->prepare($sql); $stmt->execute([':record_id' => $this->getRecordId()]); $stmt->closeCursor(); - $sql = "INSERT INTO technical_datas (id, record_id, name, value)" - . " VALUES (null, :record_id, :name, :value)"; - $stmt = $this->getDatabox()->get_connection()->prepare($sql); - + $sqlValues = []; foreach ($document->readTechnicalDatas($mediavorus) as $name => $value) { if (is_null($value)) { continue; @@ -1335,13 +1346,19 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $value = 0; } } - - $stmt->execute([ - ':record_id' => $this->getRecordId() - , ':name' => $name - , ':value' => $value - ]); + $sqlValues[] = join(',', array( + 'null', + $connection->quote($this->getRecordId()), + $connection->quote($name), + $connection->quote($value) + )); } + $sql = "INSERT INTO technical_datas (id, record_id, name, value)" + . " VALUES (" . join('),(', $sqlValues) . ")"; + ; + $stmt = $connection->prepare($sql); + + $stmt->execute(); $stmt->closeCursor(); @@ -1510,7 +1527,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->delete_data_from_cache(self::CACHE_SUBDEFS); - $this->dispatch(RecordEvents::DELETED, new RecordDeletedEvent($this)); + $this->dispatch(RecordEvents::DELETED, new DeletedEvent($this)); return array_keys($ftodel); }