mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 20:43:25 +00:00
Add touch capability to record_adapter.
This commit is contained in:
@@ -51,27 +51,49 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
|
|||||||
private $highlight = [];
|
private $highlight = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $_index
|
* @param string $index
|
||||||
* @param string $_type
|
* @param string $type
|
||||||
* @param string $_id
|
* @param string $id
|
||||||
* @param int $_version
|
* @param int $version
|
||||||
* @param float $_score
|
* @param float $score
|
||||||
*/
|
*/
|
||||||
public function setESData($_index, $_type, $_id, $_version, $_score)
|
public function setESData($index, $type, $id, $version, $score)
|
||||||
{
|
{
|
||||||
$this->_index = $_index;
|
$this->_index = $index;
|
||||||
$this->_type = $_type;
|
$this->_type = $type;
|
||||||
$this->_id = $_id;
|
$this->_id = $id;
|
||||||
$this->_version = $_version;
|
$this->_version = $version;
|
||||||
$this->_score = $_score;
|
$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;
|
return $this->_version;
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,9 @@ namespace Alchemy\Phrasea\Model;
|
|||||||
|
|
||||||
interface RecordInterface
|
interface RecordInterface
|
||||||
{
|
{
|
||||||
/** @return string */
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getId();
|
public function getId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
49
lib/Alchemy/Phrasea/Record/RecordUpdateSubscriber.php
Normal file
49
lib/Alchemy/Phrasea/Record/RecordUpdateSubscriber.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2016 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Record;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
|
||||||
|
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
|
class RecordUpdateSubscriber implements EventSubscriberInterface
|
||||||
|
{
|
||||||
|
public static function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
RecordEvents::ROTATE => '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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -219,10 +219,8 @@ class Indexer
|
|||||||
$work($bulk);
|
$work($bulk);
|
||||||
// Flush just in case, it's a noop when already done
|
// Flush just in case, it's a noop when already done
|
||||||
$bulk->flush();
|
$bulk->flush();
|
||||||
|
} finally {
|
||||||
$this->restoreShardRefreshing();
|
$this->restoreShardRefreshing();
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->restoreShardRefreshing();
|
|
||||||
throw $e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -266,7 +266,7 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
$thumbnail = $subdefs[$subdefName];
|
$thumbnail = $subdefs[$subdefName];
|
||||||
if (null !== $path = $thumbnail['path']) {
|
if (null !== $path = $thumbnail['path']) {
|
||||||
if (is_string($path) && '' !== $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);
|
return $staticMode->getUrl($path, $etag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -224,7 +224,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
|
|
||||||
$connbas = $this->databox->get_connection();
|
$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()]);
|
$connbas->executeUpdate($sql, ['type' => $type, 'record_id' => $this->getRecordId()]);
|
||||||
|
|
||||||
if ($old_type !== $type) {
|
if ($old_type !== $type) {
|
||||||
@@ -237,6 +237,16 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
return $this;
|
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
|
* Returns the type of the document
|
||||||
*
|
*
|
||||||
@@ -271,7 +281,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->databox->get_connection()->executeUpdate(
|
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())
|
array(':mime' => $mime, ':record_id' => $this->getRecordId())
|
||||||
)) {
|
)) {
|
||||||
|
|
||||||
@@ -444,7 +454,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
return $this;
|
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 = [
|
$params = [
|
||||||
':coll_id' => $collection->get_coll_id(),
|
':coll_id' => $collection->get_coll_id(),
|
||||||
@@ -796,7 +806,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->getDatabox()->get_connection()->executeUpdate(
|
$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()]
|
['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)
|
protected function set_xml(DOMDocument $dom_doc)
|
||||||
{
|
{
|
||||||
$connbas = $this->getDatabox()->get_connection();
|
$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 = $connbas->prepare($sql);
|
||||||
$stmt->execute(
|
$stmt->execute(
|
||||||
[
|
[
|
||||||
@@ -1090,7 +1100,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
$connection = $this->databox->get_connection();
|
$connection = $this->databox->get_connection();
|
||||||
|
|
||||||
$connection->executeUpdate(
|
$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]
|
['status' => bindec($status), 'record_id' => $this->record_id]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1719,12 +1729,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
|
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id';
|
$this->touch();
|
||||||
$stmt = $connbas->prepare($sql);
|
|
||||||
$stmt->execute([':record_id' => $this->getRecordId()]);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$this->delete_data_from_cache();
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -1748,12 +1753,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id';
|
$this->touch();
|
||||||
$stmt = $connbas->prepare($sql);
|
|
||||||
$stmt->execute([':record_id' => $this->getRecordId()]);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$this->delete_data_from_cache();
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user