diff --git a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php index df17d3e5c4..101e63401b 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php +++ b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php @@ -51,27 +51,49 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface private $highlight = []; /** - * @param string $_index - * @param string $_type - * @param string $_id - * @param int $_version - * @param float $_score + * @param string $index + * @param string $type + * @param string $id + * @param int $version + * @param float $score */ - public function setESData($_index, $_type, $_id, $_version, $_score) + public function setESData($index, $type, $id, $version, $score) { - $this->_index = $_index; - $this->_type = $_type; - $this->_id = $_id; - $this->_version = $_version; - $this->_score = $_score; + $this->_index = $index; + $this->_type = $type; + $this->_id = $id; + $this->_version = $version; + $this->_score = $score; } - // todo: add getters for other ES data _index, _type, _id, _score + /** + * @return string + */ + public function getIndex() + { + return $this->_index; + } /** - * @return int the _version value from ES for the document + * @return string */ - public function getESVersion() + public function getScore() + { + return $this->_score; + } + + /** + * @return string + */ + public function getElasticsearchType() + { + return $this->_type; + } + + /** + * @return int + */ + public function getVersion() { return $this->_version; } diff --git a/lib/Alchemy/Phrasea/Model/RecordInterface.php b/lib/Alchemy/Phrasea/Model/RecordInterface.php index 74320df6d2..e1ff83c847 100644 --- a/lib/Alchemy/Phrasea/Model/RecordInterface.php +++ b/lib/Alchemy/Phrasea/Model/RecordInterface.php @@ -4,7 +4,9 @@ namespace Alchemy\Phrasea\Model; interface RecordInterface { - /** @return string */ + /** + * @return string + */ public function getId(); /** diff --git a/lib/Alchemy/Phrasea/Record/RecordUpdateSubscriber.php b/lib/Alchemy/Phrasea/Record/RecordUpdateSubscriber.php new file mode 100644 index 0000000000..53c2e7f1c7 --- /dev/null +++ b/lib/Alchemy/Phrasea/Record/RecordUpdateSubscriber.php @@ -0,0 +1,49 @@ + 'onRecordChange', + ]; + } + + /** + * @var \appbox + */ + private $appbox; + + public function __construct(\appbox $appbox) + { + $this->appbox = $appbox; + } + + public function onRecordChange(RecordEvent $recordEvent) + { + $record = $recordEvent->getRecord(); + + $databoxId = $record->getDataboxId(); + $recordId = $record->getRecordId(); + + $recordAdapter = $this->appbox->get_databox($databoxId)->getRecordRepository()->find($recordId); + + if ($recordAdapter) { + $recordAdapter->touch(); + } + } +} diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php index 4473a52166..42cea72872 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer.php @@ -219,10 +219,8 @@ class Indexer $work($bulk); // Flush just in case, it's a noop when already done $bulk->flush(); + } finally { $this->restoreShardRefreshing(); - } catch (\Exception $e) { - $this->restoreShardRefreshing(); - throw $e; } } diff --git a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php index 0424b09a72..43fdd1253b 100644 --- a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php +++ b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php @@ -266,7 +266,7 @@ class PhraseanetExtension extends \Twig_Extension $thumbnail = $subdefs[$subdefName]; if (null !== $path = $thumbnail['path']) { if (is_string($path) && '' !== $path) { - $etag = dechex(crc32(dechex($record->getESVersion() ^ 0x5A5A5A5A))); + $etag = dechex(crc32(dechex($record->getVersion() ^ 0x5A5A5A5A))); return $staticMode->getUrl($path, $etag); } } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 840bb1711e..d7113ac631 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -224,7 +224,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $connbas = $this->databox->get_connection(); - $sql = 'UPDATE record SET type = :type WHERE record_id = :record_id'; + $sql = 'UPDATE record SET moddate = NOW(), type = :type WHERE record_id = :record_id'; $connbas->executeUpdate($sql, ['type' => $type, 'record_id' => $this->getRecordId()]); if ($old_type !== $type) { @@ -237,6 +237,16 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return $this; } + public function touch() + { + $this->databox->get_connection()->executeUpdate( + 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id', + ['record_id' => $this->getRecordId()] + ); + + $this->delete_data_from_cache(); + } + /** * Returns the type of the document * @@ -271,7 +281,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } if ($this->databox->get_connection()->executeUpdate( - 'UPDATE record SET mime = :mime WHERE record_id = :record_id', + 'UPDATE record SET moddate = NOW(), mime = :mime WHERE record_id = :record_id', array(':mime' => $mime, ':record_id' => $this->getRecordId()) )) { @@ -444,7 +454,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return $this; } - $sql = "UPDATE record SET 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 = [ ':coll_id' => $collection->get_coll_id(), @@ -796,7 +806,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface } $this->getDatabox()->get_connection()->executeUpdate( - 'UPDATE record SET originalname = :originalname WHERE record_id = :record_id', + 'UPDATE record SET moddate = NOW(), originalname = :originalname WHERE record_id = :record_id', ['originalname' => $original_name, 'record_id' => $this->getRecordId()] ); @@ -908,7 +918,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface protected function set_xml(DOMDocument $dom_doc) { $connbas = $this->getDatabox()->get_connection(); - $sql = 'UPDATE record SET xml = :xml WHERE record_id= :record_id'; + $sql = 'UPDATE record SET moddate = NOW(), xml = :xml WHERE record_id= :record_id'; $stmt = $connbas->prepare($sql); $stmt->execute( [ @@ -1090,7 +1100,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $connection = $this->databox->get_connection(); $connection->executeUpdate( - 'UPDATE record SET status = :status WHERE record_id= :record_id', + 'UPDATE record SET moddate = NOW(), status = :status WHERE record_id= :record_id', ['status' => bindec($status), 'record_id' => $this->record_id] ); @@ -1719,12 +1729,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $stmt->closeCursor(); - $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); - $stmt->execute([':record_id' => $this->getRecordId()]); - $stmt->closeCursor(); - - $this->delete_data_from_cache(); + $this->touch(); return $this; } @@ -1748,12 +1753,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $stmt->execute($params); $stmt->closeCursor(); - $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); - $stmt->execute([':record_id' => $this->getRecordId()]); - $stmt->closeCursor(); - - $this->delete_data_from_cache(); + $this->touch(); return $this; }