PHRAS-1158_STAMP-CHANGE-COLL

fix : the stamp was not updated when a record changed of collection
#time 2h
This commit is contained in:
Jean-Yves Gaulier
2016-06-15 19:50:03 +02:00
parent 41334c5421
commit 51ff2e040a
4 changed files with 20 additions and 12 deletions

View File

@@ -116,15 +116,14 @@ class CollectionService
*/ */
public function resetStamp(Collection $collection, $record_id = null) public function resetStamp(Collection $collection, $record_id = null)
{ {
$sql = 'SELECT path, file FROM record r INNER JOIN subdef s USING(record_id) $sql = "SELECT path, file FROM record r INNER JOIN subdef s USING(record_id)\n"
WHERE r.coll_id = :coll_id . "WHERE r.coll_id = :coll_id\n"
AND r.type="image" AND s.name IN ("preview", "document")'; . "AND r.type='image' AND s.name IN ('preview', 'document')";
$params = [':coll_id' => $collection->getCollectionId()]; $params = [':coll_id' => $collection->getCollectionId()];
if ($record_id) { if ($record_id) {
$sql .= ' AND record_id = :record_id'; $sql .= " AND record_id = :record_id";
$params[':record_id'] = $record_id; $params[':record_id'] = $record_id;
} }

View File

@@ -364,10 +364,7 @@ class EditController extends Controller
$record->setStatus($newstat); $record->setStatus($newstat);
} }
$record $record->write_metas();
->write_metas()
->getCollection()
->reset_stamp($record->getRecordId());
if ($statbits != '') { if ($statbits != '') {
$this->getDataboxLogger($databox) $this->getDataboxLogger($databox)

View File

@@ -42,9 +42,9 @@ class RecordEditSubscriber implements EventSubscriberInterface
public function onEdit(RecordEdit $event) 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(); $metaStructure = $databox->get_meta_structure();
$editDateField = false; $editDateField = false;
@@ -55,7 +55,7 @@ class RecordEditSubscriber implements EventSubscriberInterface
} }
if ($editDateField instanceof \databox_field) { if ($editDateField instanceof \databox_field) {
$this->updateRecord($this->convertToRecordAdapter($record), $editDateField); $this->updateRecord($recordAdapter, $editDateField);
} }
} }

View File

@@ -475,6 +475,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
return $this; 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"; $sql = "UPDATE record SET moddate = NOW(), coll_id = :coll_id WHERE record_id =:record_id";
$params = [ $params = [
@@ -993,6 +997,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
$this->set_metadata($param, $this->getDatabox()); $this->set_metadata($param, $this->getDatabox());
} }
$this->clearStampCache();
$xml = new DOMDocument(); $xml = new DOMDocument();
$xml->loadXML($this->app['serializer.caption']->serialize($this->get_caption(), CaptionSerializer::SERIALIZE_XML, true)); $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; return null;
} }
public function clearStampCache()
{
$this->getCollection()->reset_stamp($this->getRecordId());
}
/** /**
* @return array[] list of deleted files real paths * @return array[] list of deleted files real paths
*/ */