mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
Extract repository classes to read/update box versions
This commit is contained in:
@@ -13,7 +13,6 @@ use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Core\Connection\ConnectionSettings;
|
||||
use Alchemy\Phrasea\Core\Database\DatabaseMaintenanceService;
|
||||
use Alchemy\Phrasea\Core\Version as PhraseaVersion;
|
||||
use vierbergenlars\SemVer\version;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
abstract class base implements cache_cacheableInterface
|
||||
@@ -53,16 +52,26 @@ abstract class base implements cache_cacheableInterface
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @var PhraseaVersion\VersionRepository
|
||||
*/
|
||||
protected $versionRepository;
|
||||
|
||||
/**
|
||||
* @param Application $application
|
||||
* @param Connection $connection
|
||||
* @param ConnectionSettings $connectionSettings
|
||||
* @param PhraseaVersion\VersionRepository $versionRepository
|
||||
*/
|
||||
public function __construct(Application $application, Connection $connection, ConnectionSettings $connectionSettings)
|
||||
public function __construct(Application $application,
|
||||
Connection $connection,
|
||||
ConnectionSettings $connectionSettings,
|
||||
PhraseaVersion\VersionRepository $versionRepository)
|
||||
{
|
||||
$this->app = $application;
|
||||
$this->connection = $connection;
|
||||
$this->connectionSettings = $connectionSettings;
|
||||
$this->versionRepository = $versionRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,31 +208,21 @@ abstract class base implements cache_cacheableInterface
|
||||
public function get_version()
|
||||
{
|
||||
if (! $this->version) {
|
||||
$version = '0.0.0';
|
||||
$sql = '';
|
||||
|
||||
if ($this->get_base_type() == self::APPLICATION_BOX) {
|
||||
$sql = 'SELECT version FROM sitepreff';
|
||||
}
|
||||
|
||||
if ($this->get_base_type() == self::DATA_BOX) {
|
||||
$sql = 'SELECT value AS version FROM pref WHERE prop="version" LIMIT 1;';
|
||||
}
|
||||
|
||||
if ($sql !== '') {
|
||||
$row = $this->connection->fetchAssoc($sql);
|
||||
|
||||
if ($row) {
|
||||
$version = $row['version'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->version = $version;
|
||||
$this->version = $this->versionRepository->getVersion($this);
|
||||
}
|
||||
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
protected function setVersion(PhraseaVersion $version)
|
||||
{
|
||||
try {
|
||||
return $this->versionRepository->saveVersion($this, $version);
|
||||
} catch (\Exception $e) {
|
||||
throw new Exception('Unable to set the database version : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function upgradeDb($applyPatches)
|
||||
{
|
||||
$service = new DatabaseMaintenanceService($this->app, $this->connection);
|
||||
@@ -231,32 +230,6 @@ abstract class base implements cache_cacheableInterface
|
||||
return $service->upgradeDatabase($this, $applyPatches);
|
||||
}
|
||||
|
||||
protected function setVersion(PhraseaVersion $version)
|
||||
{
|
||||
try {
|
||||
$sql = '';
|
||||
if ($this->get_base_type() === self::APPLICATION_BOX) {
|
||||
$sql = 'UPDATE sitepreff SET version = :version WHERE id = 1';
|
||||
}
|
||||
if ($this->get_base_type() === self::DATA_BOX) {
|
||||
$sql = 'DELETE FROM pref WHERE prop="version"';
|
||||
$this->get_connection()->query($sql);
|
||||
$sql = 'INSERT INTO pref (prop, value, locale, updated_on) VALUES ("version", :version, "", NOW())';
|
||||
}
|
||||
if ($sql !== '') {
|
||||
$stmt = $this->get_connection()->prepare($sql);
|
||||
$stmt->execute([':version' => $version->getNumber()]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->version = $version->getNumber();
|
||||
|
||||
return true;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new Exception('Unable to set the database version : ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return base
|
||||
* @throws Exception
|
||||
|
Reference in New Issue
Block a user