Remove legacy record_adapter::get_status

This commit is contained in:
Benoît Burnichon
2016-04-13 19:55:54 +02:00
parent 4171ab9e8d
commit 0fb219cb67
3 changed files with 12 additions and 54 deletions

View File

@@ -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');
}

View File

@@ -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);

View File

@@ -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);
}
/**