diff --git a/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php b/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php index bc098412af..53d68bfc0c 100644 --- a/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php +++ b/lib/Alchemy/Phrasea/Databox/Record/LegacyRecordRepository.php @@ -125,7 +125,8 @@ class LegacyRecordRepository implements RecordRepository $connection->quoteIdentifier('type'), 'originalname AS originalName', 'sha256', - 'mime' + 'mime', + 'LPAD(BIN(status), 32, \'0\') as status' ) ->from('record', 'r'); } diff --git a/lib/classes/cache/databox.php b/lib/classes/cache/databox.php index 229eb7676c..4e9ed4dd82 100644 --- a/lib/classes/cache/databox.php +++ b/lib/classes/cache/databox.php @@ -75,8 +75,6 @@ class cache_databox $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_SHA256; $databox->delete_data_from_cache($key); - $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_STATUS; - $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_TECHNICAL_DATA; $databox->delete_data_from_cache($key); diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 8b59ad0693..eeb048b1cb 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -48,7 +48,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface const CACHE_SHA256 = 'sha256'; const CACHE_SUBDEFS = 'subdefs'; const CACHE_GROUPING = 'grouping'; - const CACHE_STATUS = 'status'; /** * @param Application $app @@ -78,6 +77,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface private $collection_id; private $mime; private $number; + + /** + * @var string + */ private $status; private $subdefs; private $type; @@ -524,51 +527,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return $this->sha256; } - /** - * @return string - */ - public function get_status() - { - if (!$this->status) { - $this->status = $this->retrieve_status(); - } - - return $this->status; - } - - /** - * @return string - * @throws Exception - * @throws \Doctrine\DBAL\DBALException - */ - protected function retrieve_status() - { - try { - $data = $this->get_data_from_cache(self::CACHE_STATUS); - } catch (Exception $e) { - $data = false; - } - - if (false !== $data) { - return $data; - } - - $status = $this->getDataboxConnection()->fetchColumn( - 'SELECT BIN(status) as status FROM record WHERE record_id = :record_id', - [':record_id' => $this->getRecordId()] - ); - - if (false === $status) { - throw new Exception('status not found'); - } - - $status = str_pad($status, 32, '0', STR_PAD_LEFT); - - $this->set_data_to_cache($status, self::CACHE_STATUS); - - return $status; - } - public function has_subdef($name) { return in_array($name, $this->get_available_subdefs(), false); @@ -1490,9 +1448,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface { switch ($option) { - case self::CACHE_STATUS: - $this->status = null; - break; case self::CACHE_SUBDEFS: $this->subdefs = null; break; @@ -1785,7 +1740,9 @@ class record_adapter implements RecordInterface, cache_cacheableInterface ['status' => bindec($status), 'record_id' => $this->getRecordId()] ); - $this->delete_data_from_cache(self::CACHE_STATUS); + $this->status = str_pad($status, 32, '0', STR_PAD_LEFT); + // modification date is now unknown, delete from cache to reload on another record + $this->delete_data_from_cache(); $this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this)); } @@ -1795,7 +1752,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface */ public function getStatus() { - return $this->get_status(); + return $this->status; } /** {@inheritdoc} */ @@ -1828,6 +1785,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface 'created' => $this->created->format(DATE_ISO8601), 'base_id' => $this->base_id, 'collection_id' => $this->collection_id, + 'status' => $this->status, ]; $this->set_data_to_cache($data); @@ -1853,6 +1811,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface $this->original_name = $row['originalName']; $this->sha256 = $row['sha256']; $this->mime = $row['mime']; + $this->status = str_pad($row['status'], 32, '0', STR_PAD_LEFT); } /**