Revert "start subdef creation after first write meta"

This reverts commit cfa854f307.
This commit is contained in:
aynsix
2020-02-20 11:11:18 +03:00
parent ed7a5fe288
commit db0489c05e
5 changed files with 14 additions and 64 deletions

View File

@@ -14,6 +14,8 @@ namespace Alchemy\Phrasea\Border;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\Checker\CheckerInterface; use Alchemy\Phrasea\Border\Checker\CheckerInterface;
use Alchemy\Phrasea\Border\Attribute\AttributeInterface; 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\Exception\RuntimeException;
use Alchemy\Phrasea\Metadata\Tag\TfArchivedate; use Alchemy\Phrasea\Metadata\Tag\TfArchivedate;
use Alchemy\Phrasea\Metadata\Tag\TfQuarantine; use Alchemy\Phrasea\Metadata\Tag\TfQuarantine;
@@ -110,9 +112,6 @@ class Manager
if (($visa->isValid() || $forceBehavior === self::FORCE_RECORD) && $forceBehavior !== self::FORCE_LAZARET) { if (($visa->isValid() || $forceBehavior === self::FORCE_RECORD) && $forceBehavior !== self::FORCE_LAZARET) {
// Write UUID
$file->getUUID(false, true);
$this->addMediaAttributes($file); $this->addMediaAttributes($file);
$element = $this->createRecord($file, $nosubdef); $element = $this->createRecord($file, $nosubdef);
@@ -120,14 +119,14 @@ class Manager
$code = self::RECORD_CREATED; $code = self::RECORD_CREATED;
} else { } else {
// Write UUID
$file->getUUID(false, true);
$element = $this->createLazaret($file, $visa, $session, $forceBehavior === self::FORCE_LAZARET); $element = $this->createLazaret($file, $visa, $session, $forceBehavior === self::FORCE_LAZARET);
$code = self::LAZARET_CREATED; $code = self::LAZARET_CREATED;
} }
// Write UUID
$file->getUUID(false, true);
if (is_callable($callable)) { if (is_callable($callable)) {
$callable($element, $visa, $code); $callable($element, $visa, $code);
} }
@@ -333,11 +332,11 @@ class Manager
} }
} }
if ($nosubdef) { $this->app['phraseanet.metadata-setter']->replaceMetadata($newMetadata, $element);
$element->setNoSubdef();
}
$this->app['phraseanet.metadata-setter']->replaceMetadata($newMetadata, $element, true, $nosubdef);// true for $isNewRecord if(!$nosubdef) {
$this->app['dispatcher']->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($element, true));
}
return $element; return $element;
} }

View File

@@ -11,31 +11,6 @@
namespace Alchemy\Phrasea\Core\Event\Record; namespace Alchemy\Phrasea\Core\Event\Record;
use Alchemy\Phrasea\Model\RecordInterface;
class MetadataChangedEvent extends RecordEvent class MetadataChangedEvent extends RecordEvent
{ {
private $isNewRecord;
private $nosubdef;
public function __construct(RecordInterface $record, $isNewRecord = false, $nosubdef = false)
{
parent::__construct($record);
$this->isNewRecord = $isNewRecord;
$this->nosubdef = $nosubdef;
}
/**
* @return bool
*/
public function isNewRecord()
{
return $this->isNewRecord;
}
public function isNosubdef()
{
return $this->nosubdef;
}
} }

View File

@@ -34,7 +34,7 @@ class PhraseanetMetadataSetter
* @param \record_adapter $record * @param \record_adapter $record
* @throws \Exception_InvalidArgument * @throws \Exception_InvalidArgument
*/ */
public function replaceMetadata($metadataCollection, \record_adapter $record, $isNewRecord = false, $nosubdef = false) public function replaceMetadata($metadataCollection, \record_adapter $record)
{ {
$metaStructure = $this->repository->find($record->getDataboxId())->get_meta_structure()->get_elements(); $metaStructure = $this->repository->find($record->getDataboxId())->get_meta_structure()->get_elements();
@@ -82,7 +82,7 @@ class PhraseanetMetadataSetter
} }
if (! empty($metadataInRecordFormat)) { if (! empty($metadataInRecordFormat)) {
$record->set_metadatas($metadataInRecordFormat, true, $isNewRecord, $nosubdef); $record->set_metadatas($metadataInRecordFormat, true);
} }
} }

View File

@@ -12,8 +12,6 @@
namespace Alchemy\Phrasea\TaskManager\Job; namespace Alchemy\Phrasea\TaskManager\Job;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionCreateEvent;
use Alchemy\Phrasea\Core\PhraseaTokens; use Alchemy\Phrasea\Core\PhraseaTokens;
use Alchemy\Phrasea\Metadata\TagFactory; use Alchemy\Phrasea\Metadata\TagFactory;
use Alchemy\Phrasea\TaskManager\Editor\WriteMetadataEditor; use Alchemy\Phrasea\TaskManager\Editor\WriteMetadataEditor;
@@ -71,7 +69,7 @@ class WriteMetadataJob extends AbstractJob
foreach ($jobData->getApplication()->getDataboxes() as $databox) { foreach ($jobData->getApplication()->getDataboxes() as $databox) {
$connection = $databox->get_connection(); $connection = $databox->get_connection();
$statement = $connection->prepare('SELECT record_id, coll_id, work, jeton FROM record WHERE (jeton & :token > 0)'); $statement = $connection->prepare('SELECT record_id, coll_id, jeton FROM record WHERE (jeton & :token > 0)');
$statement->execute(['token' => PhraseaTokens::WRITE_META]); $statement->execute(['token' => PhraseaTokens::WRITE_META]);
$rs = $statement->fetchAll(\PDO::FETCH_ASSOC); $rs = $statement->fetchAll(\PDO::FETCH_ASSOC);
$statement->closeCursor(); $statement->closeCursor();
@@ -205,13 +203,6 @@ class WriteMetadataJob extends AbstractJob
'record_id' => $record_id, 'record_id' => $record_id,
'token' => PhraseaTokens::WRITE_META, 'token' => PhraseaTokens::WRITE_META,
]); ]);
// write meta for the document is finished
// if it's a new record, order to create subdef
if (count($record->get_subdefs()) == 3 && count($subdefs) == 1 && isset($subdefs['document']) && $row['work'] != 1) {
$this->getDispatcher($jobData->getApplication())->dispatch(RecordEvents::SUBDEFINITION_CREATE, new SubdefinitionCreateEvent($record, true));
}
$statement->closeCursor(); $statement->closeCursor();
} }
} }
@@ -226,11 +217,6 @@ class WriteMetadataJob extends AbstractJob
return $app['exiftool.writer']; return $app['exiftool.writer'];
} }
private function getDispatcher(Application $app)
{
return $app['dispatcher'];
}
/** /**
* @param \databox $databox * @param \databox $databox
* @param string $subdefType * @param string $subdefType

View File

@@ -1083,7 +1083,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
* *
* @return record_adapter * @return record_adapter
*/ */
public function set_metadatas(array $metadatas, $force_readonly = false, $isNewRecord = false, $nosubdef = false) public function set_metadatas(array $metadatas, $force_readonly = false)
{ {
$databox_descriptionStructure = $this->getDatabox()->get_meta_structure(); $databox_descriptionStructure = $this->getDatabox()->get_meta_structure();
@@ -1108,7 +1108,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
unset($xml); unset($xml);
$this->write_metas(); $this->write_metas();
$this->dispatch(RecordEvents::METADATA_CHANGED, new MetadataChangedEvent($this, $isNewRecord, $nosubdef)); $this->dispatch(RecordEvents::METADATA_CHANGED, new MetadataChangedEvent($this));
return $this; return $this;
} }
@@ -1175,16 +1175,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $this; return $this;
} }
public function setNoSubdef()
{
$this->getDataboxConnection()->executeUpdate(
'UPDATE record SET work = 1 WHERE record_id= :record_id',
['record_id' => $this->getRecordId()]
);
return $this;
}
private function dispatch($eventName, RecordEvent $event) private function dispatch($eventName, RecordEvent $event)
{ {
$this->app['dispatcher']->dispatch($eventName, $event); $this->app['dispatcher']->dispatch($eventName, $event);