From 51ff2e040a05daadb2c2d3e587efcf2475d94f64 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Wed, 15 Jun 2016 19:50:03 +0200 Subject: [PATCH] PHRAS-1158_STAMP-CHANGE-COLL fix : the stamp was not updated when a record changed of collection #time 2h --- lib/Alchemy/Phrasea/Collection/CollectionService.php | 9 ++++----- .../Phrasea/Controller/Prod/EditController.php | 5 +---- .../Core/Event/Subscriber/RecordEditSubscriber.php | 6 +++--- lib/classes/record/adapter.php | 12 ++++++++++++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/Alchemy/Phrasea/Collection/CollectionService.php b/lib/Alchemy/Phrasea/Collection/CollectionService.php index b02b332e3c..de9d04c8e9 100644 --- a/lib/Alchemy/Phrasea/Collection/CollectionService.php +++ b/lib/Alchemy/Phrasea/Collection/CollectionService.php @@ -116,15 +116,14 @@ class CollectionService */ public function resetStamp(Collection $collection, $record_id = null) { - $sql = 'SELECT path, file FROM record r INNER JOIN subdef s USING(record_id) - WHERE r.coll_id = :coll_id - AND r.type="image" AND s.name IN ("preview", "document")'; - + $sql = "SELECT path, file FROM record r INNER JOIN subdef s USING(record_id)\n" + . "WHERE r.coll_id = :coll_id\n" + . "AND r.type='image' AND s.name IN ('preview', 'document')"; $params = [':coll_id' => $collection->getCollectionId()]; if ($record_id) { - $sql .= ' AND record_id = :record_id'; + $sql .= " AND record_id = :record_id"; $params[':record_id'] = $record_id; } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php index c719bda833..ba7e35b145 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/EditController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/EditController.php @@ -364,10 +364,7 @@ class EditController extends Controller $record->setStatus($newstat); } - $record - ->write_metas() - ->getCollection() - ->reset_stamp($record->getRecordId()); + $record->write_metas(); if ($statbits != '') { $this->getDataboxLogger($databox) diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/RecordEditSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/RecordEditSubscriber.php index 307350fc72..b89b60118a 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/RecordEditSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/RecordEditSubscriber.php @@ -42,9 +42,9 @@ class RecordEditSubscriber implements EventSubscriberInterface public function onEdit(RecordEdit $event) { - $record = $event->getRecord(); + $recordAdapter = $this->convertToRecordAdapter($event->getRecord()); - $databox = $this->getRecordDatabox($record); + $databox = $recordAdapter->getDatabox(); $metaStructure = $databox->get_meta_structure(); $editDateField = false; @@ -55,7 +55,7 @@ class RecordEditSubscriber implements EventSubscriberInterface } if ($editDateField instanceof \databox_field) { - $this->updateRecord($this->convertToRecordAdapter($record), $editDateField); + $this->updateRecord($recordAdapter, $editDateField); } } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 628a1fab05..82b6ff99a3 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -475,6 +475,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return $this; } + // remove stamp BEFORE changing collection since it uses the collection id :( + // todo : change clearStampCache() to be agnostic of collection + $this->clearStampCache(); + $sql = "UPDATE record SET moddate = NOW(), coll_id = :coll_id WHERE record_id =:record_id"; $params = [ @@ -993,6 +997,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->set_metadata($param, $this->getDatabox()); } + $this->clearStampCache(); + $xml = new DOMDocument(); $xml->loadXML($this->app['serializer.caption']->serialize($this->get_caption(), CaptionSerializer::SERIALIZE_XML, true)); @@ -1292,6 +1298,12 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return null; } + + public function clearStampCache() + { + $this->getCollection()->reset_stamp($this->getRecordId()); + } + /** * @return array[] list of deleted files real paths */