From bc01476ea224f27ae6352fd06ff02f9f1cf9af13 Mon Sep 17 00:00:00 2001
From: Aina Sitraka <35221835+aynsix@users.noreply.github.com>
Date: Tue, 1 Nov 2022 18:20:52 +0300
Subject: [PATCH] PHRAS-3772 bin/setup system:config add option (#4164)
* add option no compile -s for bin/setup system:config
* check db connection on bin/console
* add -s on migration script
---
bin/console | 4 ++
infra/tools/stack_migration/README.md | 3 ++
.../tools/stack_migration/datastores_conf.sh | 44 +++++++--------
infra/tools/stack_migration/email_conf.sh | 18 +++----
infra/tools/stack_migration/network_conf.sh | 14 ++---
infra/tools/stack_migration/storage_conf.sh | 34 ++++++------
.../Command/Setup/ConfigurationEditor.php | 54 ++++++++++++++-----
.../Core/Configuration/Configuration.php | 20 ++++++-
.../Configuration/ConfigurationInterface.php | 7 +++
.../Core/Configuration/HostConfiguration.php | 9 ++++
.../Core/Provider/ORMServiceProvider.php | 16 +++---
.../Core/Version/VersionRepository.php | 2 +-
.../Phrasea/Setup/ConfigurationTester.php | 17 ++++++
lib/classes/base.php | 6 ++-
tests/Alchemy/Tests/Phrasea/MockArrayConf.php | 5 ++
15 files changed, 178 insertions(+), 75 deletions(-)
diff --git a/bin/console b/bin/console
index 68a34a2124..ef81b86196 100755
--- a/bin/console
+++ b/bin/console
@@ -91,6 +91,10 @@ if (!$cli['phraseanet.configuration-tester']->isInstalled()) {
throw new \RuntimeException('Phraseanet is not installed, use setup command instead');
}
+if (!$cli['phraseanet.configuration-tester']->isConnectedToDBHost()) {
+ throw new \RuntimeException('Phraseanet can not connected to the provided DB, use setup command to config!');
+}
+
if (!$cli['phraseanet.configuration-tester']->isUpToDate()) {
throw new \RuntimeException('Phraseanet is not up-to-date, use setup command instead');
}
diff --git a/infra/tools/stack_migration/README.md b/infra/tools/stack_migration/README.md
index 6906f86bbf..7e43e55bec 100644
--- a/infra/tools/stack_migration/README.md
+++ b/infra/tools/stack_migration/README.md
@@ -17,6 +17,9 @@ Scripts can be play in a running FPM container with app users
Before execution of they script keep a copie your existing source and destination "configuration.yml" files
and place the configuration file need to be migrate in place of the current "configuration.yml" file
+After execution of all script you need to `rm config/configuration-compiled.yml`
+and compile-configuration `bin/setup system:config compile`
+
### Datastore_conf
Update configuration.yml in accordance of containers env value for :
diff --git a/infra/tools/stack_migration/datastores_conf.sh b/infra/tools/stack_migration/datastores_conf.sh
index ef4c77caf3..45dc5348a3 100644
--- a/infra/tools/stack_migration/datastores_conf.sh
+++ b/infra/tools/stack_migration/datastores_conf.sh
@@ -6,10 +6,10 @@ cd "/var/alchemy/Phraseanet"
echo `date +"%Y-%m-%d %H:%M:%S"` - "Applying infrastructure stack setup to Phraseanet Database connexion"
- bin/setup system:config set main.database.host $PHRASEANET_DB_HOST
- bin/setup system:config set main.database.port $PHRASEANET_DB_PORT
- bin/setup system:config set main.database.user $PHRASEANET_DB_USER
- bin/setup system:config set main.database.password $PHRASEANET_DB_PASSWORD
+ bin/setup system:config -s set main.database.host $PHRASEANET_DB_HOST
+ bin/setup system:config -s set main.database.port $PHRASEANET_DB_PORT
+ bin/setup system:config -s set main.database.user $PHRASEANET_DB_USER
+ bin/setup system:config -s set main.database.password $PHRASEANET_DB_PASSWORD
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet Database connexion applied"
@@ -19,15 +19,15 @@ cd "/var/alchemy/Phraseanet"
echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phraseanet Elastisearch"
if [ -z "$PHRASEANET_ELASTICSEARCH_HOST" ]; then
- /var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.host elasticsearch
+ /var/alchemy/Phraseanet/bin/setup system:config -s set main.search-engine.options.host elasticsearch
else
- /var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.host $PHRASEANET_ELASTICSEARCH_HOST
+ /var/alchemy/Phraseanet/bin/setup system:config -s set main.search-engine.options.host $PHRASEANET_ELASTICSEARCH_HOST
fi
if [ -z "$PHRASEANET_ELASTICSEARCH_PORT" ]; then
- /var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.port 9200
+ /var/alchemy/Phraseanet/bin/setup system:config -s set main.search-engine.options.port 9200
else
- /var/alchemy/Phraseanet/bin/setup system:config set main.search-engine.options.port $PHRASEANET_ELASTICSEARCH_PORT
+ /var/alchemy/Phraseanet/bin/setup system:config -s set main.search-engine.options.port $PHRASEANET_ELASTICSEARCH_PORT
fi
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet elasticsearch applied"
@@ -39,10 +39,10 @@ echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phra
## Phraseanet application cache setting
echo `date +"%Y-%m-%d %H:%M:%S"` - "Applying infrastructure stack setup to Phraseanet application cache"
- bin/setup system:config set main.cache.options.host $PHRASEANET_CACHE_HOST
- bin/setup system:config set main.cache.options.port $PHRASEANET_CACHE_PORT
- bin/setup system:config set main.cache.options.namespace $PHRASEANET_HOSTNAME
- bin/setup system:config set main.cache.type $PHRASEANET_CACHE_TYPE
+ bin/setup system:config -s set main.cache.options.host $PHRASEANET_CACHE_HOST
+ bin/setup system:config -s set main.cache.options.port $PHRASEANET_CACHE_PORT
+ bin/setup system:config -s set main.cache.options.namespace $PHRASEANET_HOSTNAME
+ bin/setup system:config -s set main.cache.type $PHRASEANET_CACHE_TYPE
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet application cache applied"
@@ -50,8 +50,8 @@ echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phra
## Phraseanet application session setting
echo `date +"%Y-%m-%d %H:%M:%S"` - "Applying infrastructure stack setup to Phraseanet session cache"
- bin/setup system:config set main.session.type "native"
- bin/setup system:config set main.session.ttl "86400"
+ bin/setup system:config -s set main.session.type "native"
+ bin/setup system:config -s set main.session.ttl "86400"
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet session cache applied"
@@ -60,19 +60,21 @@ echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phra
echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phraseanet setting RABBITMQ"
- bin/setup system:config set workers.queue.worker-queue.host $PHRASEANET_RABBITMQ_HOST
- bin/setup system:config set workers.queue.worker-queue.port $PHRASEANET_RABBITMQ_PORT
- bin/setup system:config set workers.queue.worker-queue.vhost $PHRASEANET_RABBITMQ_VHOST
- bin/setup system:config set workers.queue.worker-queue.ssl $PHRASEANET_RABBITMQ_SSL
- bin/setup system:config set workers.queue.worker-queue.heartbeat $PHRASEANET_RABBITMQ_HEARTBEAT
- bin/setup system:config set workers.queue.worker-queue.user $PHRASEANET_RABBITMQ_USER
- bin/setup system:config set workers.queue.worker-queue.password $PHRASEANET_RABBITMQ_PASSWORD
+ bin/setup system:config -s set workers.queue.worker-queue.host $PHRASEANET_RABBITMQ_HOST
+ bin/setup system:config -s set workers.queue.worker-queue.port $PHRASEANET_RABBITMQ_PORT
+ bin/setup system:config -s set workers.queue.worker-queue.vhost $PHRASEANET_RABBITMQ_VHOST
+ bin/setup system:config -s set workers.queue.worker-queue.ssl $PHRASEANET_RABBITMQ_SSL
+ bin/setup system:config -s set workers.queue.worker-queue.heartbeat $PHRASEANET_RABBITMQ_HEARTBEAT
+ bin/setup system:config -s set workers.queue.worker-queue.user $PHRASEANET_RABBITMQ_USER
+ bin/setup system:config -s set workers.queue.worker-queue.password $PHRASEANET_RABBITMQ_PASSWORD
echo `date +"%Y-%m-%d %H:%M:%S"` " - setup of Phraseanet setting RABBITMQ applied"
cd -
echo `date +"%Y-%m-%d %H:%M:%S"` " - End of datastore migration - Check databases in \"sbas\" table in Application Box"
+echo "The configuration file is not compile"
+echo "to compile use : bin/setup system:config compile"
diff --git a/infra/tools/stack_migration/email_conf.sh b/infra/tools/stack_migration/email_conf.sh
index 79ccb28638..cc407df442 100644
--- a/infra/tools/stack_migration/email_conf.sh
+++ b/infra/tools/stack_migration/email_conf.sh
@@ -4,16 +4,16 @@ cd "/var/alchemy/Phraseanet"
echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phraseanet SMTP"
if [[ $PHRASEANET_SMTP_ENABLED && $PHRASEANET_SMTP_ENABLED = true ]]; then
- bin/setup system:config set registry.email.smtp-enabled $PHRASEANET_SMTP_ENABLED
- bin/setup system:config set registry.email.smtp-auth-enabled $PHRASEANET_SMTP_AUTH_ENABLED
- bin/setup system:config set registry.email.smtp-secure-mode $PHRASEANET_SMTP_SECURE_MODE
- bin/setup system:config set registry.email.smtp-host $PHRASEANET_SMTP_HOST
- bin/setup system:config set registry.email.smtp-port $PHRASEANET_SMTP_PORT
- bin/setup system:config set registry.email.smtp-user $PHRASEANET_SMTP_USER
- bin/setup system:config set registry.email.smtp-password $PHRASEANET_SMTP_PASSWORD
- bin/setup system:config set registry.email.emitter-email $PHRASEANET_EMITTER_EMAIL
+ bin/setup system:config -s set registry.email.smtp-enabled $PHRASEANET_SMTP_ENABLED
+ bin/setup system:config -s set registry.email.smtp-auth-enabled $PHRASEANET_SMTP_AUTH_ENABLED
+ bin/setup system:config -s set registry.email.smtp-secure-mode $PHRASEANET_SMTP_SECURE_MODE
+ bin/setup system:config -s set registry.email.smtp-host $PHRASEANET_SMTP_HOST
+ bin/setup system:config -s set registry.email.smtp-port $PHRASEANET_SMTP_PORT
+ bin/setup system:config -s set registry.email.smtp-user $PHRASEANET_SMTP_USER
+ bin/setup system:config -s set registry.email.smtp-password $PHRASEANET_SMTP_PASSWORD
+ bin/setup system:config -s set registry.email.emitter-email $PHRASEANET_EMITTER_EMAIL
fi
cd -
-echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet SMTP setup applied"
\ No newline at end of file
+echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet SMTP setup applied"
diff --git a/infra/tools/stack_migration/network_conf.sh b/infra/tools/stack_migration/network_conf.sh
index 15bc37ca3d..f1b95ecb2d 100644
--- a/infra/tools/stack_migration/network_conf.sh
+++ b/infra/tools/stack_migration/network_conf.sh
@@ -10,10 +10,10 @@ if [[ -n $PHRASEANET_TRUSTED_PROXIES ]]; then
do
counter=$(( counter+1 ))
if [[ $counter -eq 1 ]] ; then
- bin/setup system:config set trusted-proxies $i
- bin/setup system:config add trusted-proxies $i
+ bin/setup system:config -s set trusted-proxies $i
+ bin/setup system:config -s add trusted-proxies $i
else
- bin/setup system:config add trusted-proxies $i
+ bin/setup system:config -s add trusted-proxies $i
fi
done
fi
@@ -29,13 +29,13 @@ if [[ -n $PHRASEANET_DEBUG_ALLOWED_IP ]]; then
do
counter=$(( counter+1 ))
if [[ $counter -eq 1 ]] ; then
- bin/setup system:config set debugger.allowed-ips $i
- bin/setup system:config add debugger.allowed-ips $i
+ bin/setup system:config -s set debugger.allowed-ips $i
+ bin/setup system:config -s add debugger.allowed-ips $i
else
- bin/setup system:config add debugger.allowed-ips $i
+ bin/setup system:config -s add debugger.allowed-ips $i
fi
done
fi
echo `date +"%Y-%m-%d %H:%M:%S"` " - Setup of Phraseanet debugger allowed IP applied"
-cd -
\ No newline at end of file
+cd -
diff --git a/infra/tools/stack_migration/storage_conf.sh b/infra/tools/stack_migration/storage_conf.sh
index 985b1d13f8..783296351c 100644
--- a/infra/tools/stack_migration/storage_conf.sh
+++ b/infra/tools/stack_migration/storage_conf.sh
@@ -4,28 +4,28 @@ cd "/var/alchemy/Phraseanet"
echo `date +"%Y-%m-%d %H:%M:%S"` - "update binaries path in accordance of docker stack"
-bin/setup system:config set main.binaries.php_binary "/usr/local/bin/php"
-bin/setup system:config set main.binaries.ghostscript_binary "/usr/bin/gs"
-bin/setup system:config set main.binaries.swf_extract_binary "/usr/bin/swfextract"
-bin/setup system:config set main.binaries.pdf2swf_binary null
-bin/setup system:config set main.binaries.swf_render_binary "/usr/bin/swfrender"
-bin/setup system:config set main.binaries.unoconv_binary "/usr/bin/unoconv"
-bin/setup system:config set main.binaries.ffmpeg_binary "/usr/local/bin/ffmpeg"
-bin/setup system:config set main.binaries.ffprobe_binary "/usr/local/bin/ffprobe"
-bin/setup system:config set main.binaries.mp4box_binary "/usr/bin/MP4Box"
-bin/setup system:config set main.binaries.pdftotext_binary "/usr/bin/pdftotext"
+bin/setup system:config -s set main.binaries.php_binary "/usr/local/bin/php"
+bin/setup system:config -s set main.binaries.ghostscript_binary "/usr/bin/gs"
+bin/setup system:config -s set main.binaries.swf_extract_binary "/usr/bin/swfextract"
+bin/setup system:config -s set main.binaries.pdf2swf_binary null
+bin/setup system:config -s set main.binaries.swf_render_binary "/usr/bin/swfrender"
+bin/setup system:config -s set main.binaries.unoconv_binary "/usr/bin/unoconv"
+bin/setup system:config -s set main.binaries.ffmpeg_binary "/usr/local/bin/ffmpeg"
+bin/setup system:config -s set main.binaries.ffprobe_binary "/usr/local/bin/ffprobe"
+bin/setup system:config -s set main.binaries.mp4box_binary "/usr/bin/MP4Box"
+bin/setup system:config -s set main.binaries.pdftotext_binary "/usr/bin/pdftotext"
echo `date +"%Y-%m-%d %H:%M:%S"` - "binaries path applied"
echo `date +"%Y-%m-%d %H:%M:%S"` - "update storage path in accordance of docker stack"
-bin/setup system:config set main.storage.subdefs "/var/alchemy/Phraseanet/datas"
-bin/setup system:config set main.storage.cache "/var/alchemy/Phraseanet/cache"
-bin/setup system:config set main.storage.log "/var/alchemy/Phraseanet/logs"
-bin/setup system:config set main.storage.download "/var/alchemy/Phraseanet/datas/download"
-bin/setup system:config set main.storage.lazaret "/var/alchemy/Phraseanet/datas/lazaret"
-bin/setup system:config set main.storage.caption "/var/alchemy/Phraseanet/tmp/caption"
-bin/setup system:config set main.storage.worker_tmp_files "/var/alchemy/Phraseanet/tmp/worker"
+bin/setup system:config -s set main.storage.subdefs "/var/alchemy/Phraseanet/datas"
+bin/setup system:config -s set main.storage.cache "/var/alchemy/Phraseanet/cache"
+bin/setup system:config -s set main.storage.log "/var/alchemy/Phraseanet/logs"
+bin/setup system:config -s set main.storage.download "/var/alchemy/Phraseanet/datas/download"
+bin/setup system:config -s set main.storage.lazaret "/var/alchemy/Phraseanet/datas/lazaret"
+bin/setup system:config -s set main.storage.caption "/var/alchemy/Phraseanet/tmp/caption"
+bin/setup system:config -s set main.storage.worker_tmp_files "/var/alchemy/Phraseanet/tmp/worker"
echo `date +"%Y-%m-%d %H:%M:%S"` - "storage path path applied"
diff --git a/lib/Alchemy/Phrasea/Command/Setup/ConfigurationEditor.php b/lib/Alchemy/Phrasea/Command/Setup/ConfigurationEditor.php
index ed0c201607..60d1ce6b9e 100644
--- a/lib/Alchemy/Phrasea/Command/Setup/ConfigurationEditor.php
+++ b/lib/Alchemy/Phrasea/Command/Setup/ConfigurationEditor.php
@@ -6,11 +6,13 @@ use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Core\Configuration\Configuration;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;
class ConfigurationEditor extends Command
{
+ private $noCompile = false;
public function __construct($name)
{
@@ -22,12 +24,12 @@ class ConfigurationEditor extends Command
$this->addArgument(
'operation',
InputArgument::REQUIRED,
- 'The operation to execute (get, set, or add)'
+ 'The operation to execute (get, set, add, compile)'
);
$this->addArgument(
'parameter',
- InputArgument::REQUIRED,
+ InputArgument::OPTIONAL,
'The name of the configuration parameter to get or set'
);
@@ -36,23 +38,38 @@ class ConfigurationEditor extends Command
InputArgument::OPTIONAL,
'The value to set when operation is "set" or "add", in YAML syntax'
);
+
+ $this->addOption('no-compile', "s", InputOption::VALUE_NONE, 'Do not compile the config after save in yml file');
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$command = $input->getArgument('operation');
$parameter = $input->getArgument('parameter');
+ $this->noCompile = $input->getOption('no-compile');
$parameterNodes = explode('.', $parameter);
- if ($command == 'get') {
- $this->readConfigurationValue($output, $parameter, $parameterNodes);
- }
- elseif ($command == 'set') {
- $this->writeConfigurationValue($output, $parameter, $parameterNodes, $input->getArgument('value'));
- }
- elseif ($command == 'add') {
- $this->appendConfigurationValue($output, $parameter, $parameterNodes, $input->getArgument('value'));
+ if ($command == 'compile') {
+ $this->compileConfiguration($output);
+ } else {
+ if (empty($parameter)) {
+ $output->writeln("Missing 'parameter' argument");
+
+ return 1;
+ }
+
+ if ($command == 'get') {
+ $this->readConfigurationValue($output, $parameter, $parameterNodes);
+ }
+ elseif ($command == 'set') {
+ $this->writeConfigurationValue($output, $parameter, $parameterNodes, $input->getArgument('value'));
+ }
+ elseif ($command == 'add') {
+ $this->appendConfigurationValue($output, $parameter, $parameterNodes, $input->getArgument('value'));
+ } else {
+ $output->writeln("Command not found");
+ }
}
}
@@ -61,6 +78,7 @@ class ConfigurationEditor extends Command
$app = $this->getContainer();
/** @var Configuration $config */
$config = $app['configuration.store'];
+ $config->setNoCompile($this->noCompile);
$values = $config->getConfig();
$current = $values;
@@ -78,6 +96,7 @@ class ConfigurationEditor extends Command
$app = $this->getContainer();
/** @var Configuration $configurationStore */
$configurationStore = $app['configuration.store'];
+ $configurationStore->setNoCompile($this->noCompile);
$lastParameter = end($parameterNodes);
$configurationRoot = $configurationStore->getConfig();
@@ -100,7 +119,9 @@ class ConfigurationEditor extends Command
}
$configurationStore->setConfig($configurationRoot);
- $configurationStore->compileAndWrite();
+ if (!$this->noCompile) {
+ $configurationStore->compileAndWrite();
+ }
$output->writeln('Reading updated configuration value');
@@ -112,6 +133,7 @@ class ConfigurationEditor extends Command
$app = $this->getContainer();
/** @var Configuration $configurationStore */
$configurationStore = $app['configuration.store'];
+ $configurationStore->setNoCompile($this->noCompile);
$lastParameter = end($parameterNodes);
$configurationRoot = $configurationStore->getConfig();
@@ -144,7 +166,9 @@ class ConfigurationEditor extends Command
}
$configurationStore->setConfig($configurationRoot);
- $configurationStore->compileAndWrite();
+ if (!$this->noCompile) {
+ $configurationStore->compileAndWrite();
+ }
$output->writeln('Reading updated configuration value');
@@ -176,4 +200,10 @@ class ConfigurationEditor extends Command
$output->write(PHP_EOL);
}
}
+
+ private function compileConfiguration(OutputInterface $output)
+ {
+ $this->container['configuration.store']->compileAndWrite();
+ $output->writeln('Configuration compiled!');
+ }
}
diff --git a/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php b/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php
index 5adc5a6737..2a9cf416f5 100644
--- a/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php
+++ b/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php
@@ -26,6 +26,8 @@ class Configuration implements ConfigurationInterface
private $compiled;
private $autoReload;
+ private $noCompile = false;
+
/**
* @param Yaml $yaml The Yaml Parser
* @param Compiler $compiler The PHP Compiler
@@ -117,11 +119,25 @@ class Configuration implements ConfigurationInterface
return $newConfig;
}
+ public function setNoCompile(bool $noCompile)
+ {
+ $this->noCompile = !!$noCompile;
+ }
+
+ public function getNoCompile()
+ {
+ return $this->noCompile;
+ }
+
/**
* {@inheritdoc}
*/
public function getConfig()
{
+ if ($this->noCompile) {
+ return $this->parser->parse($this->loadFile($this->config));
+ }
+
if (null !== $this->cache) {
return $this->cache;
}
@@ -145,7 +161,9 @@ class Configuration implements ConfigurationInterface
{
$this->cache = $config;
$this->dumpFile($this->config, $this->parser->dump($config, 7), 0660);
- $this->writeCacheConfig($this->compiler->compile($config));
+ if (!$this->noCompile) {
+ $this->writeCacheConfig($this->compiler->compile($config));
+ }
return $this;
}
diff --git a/lib/Alchemy/Phrasea/Core/Configuration/ConfigurationInterface.php b/lib/Alchemy/Phrasea/Core/Configuration/ConfigurationInterface.php
index 950d8c9348..00c9a7291e 100644
--- a/lib/Alchemy/Phrasea/Core/Configuration/ConfigurationInterface.php
+++ b/lib/Alchemy/Phrasea/Core/Configuration/ConfigurationInterface.php
@@ -13,6 +13,13 @@ namespace Alchemy\Phrasea\Core\Configuration;
interface ConfigurationInterface extends \ArrayAccess
{
+ /**
+ * Do not compile, just save the config
+ *
+ * @param bool $noCompile
+ */
+ public function setNoCompile(bool $noCompile);
+
/**
* Initialize configuration file in setup.
*
diff --git a/lib/Alchemy/Phrasea/Core/Configuration/HostConfiguration.php b/lib/Alchemy/Phrasea/Core/Configuration/HostConfiguration.php
index 249ec213f2..a5badd4a17 100644
--- a/lib/Alchemy/Phrasea/Core/Configuration/HostConfiguration.php
+++ b/lib/Alchemy/Phrasea/Core/Configuration/HostConfiguration.php
@@ -155,6 +155,10 @@ class HostConfiguration implements ConfigurationInterface
throw new RuntimeException('Configuration is not set up.');
}
+ if ($this->configuration->getNoCompile()) {
+ return $this->configuration->getConfig();
+ }
+
return $this->cache;
}
@@ -180,6 +184,11 @@ class HostConfiguration implements ConfigurationInterface
$this->setHost($this->host);
}
+ public function setNoCompile(bool $noCompile)
+ {
+ $this->configuration->setNoCompile($noCompile);
+ }
+
private function match($host, $hostname)
{
return $this->removeHostPrefix($host) === $this->removeHostPrefix($hostname);
diff --git a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php
index 77a2a7a9f0..a40d50e191 100644
--- a/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php
+++ b/lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php
@@ -90,14 +90,18 @@ class ORMServiceProvider implements ServiceProviderInterface
return array();
}
- /** @var Connection $connection */
- $connection = $app['dbal.provider']($app['db.appbox.info']);
+ try {
+ /** @var Connection $connection */
+ $connection = $app['dbal.provider']($app['db.appbox.info']);
- $sql = "SELECT"
- . " host, port, `user`, COALESCE(pwd, '') AS password, dbname, 'utf8' AS charset, 'pdo_mysql' AS driver"
- . " FROM sbas";
+ $sql = "SELECT"
+ . " host, port, `user`, COALESCE(pwd, '') AS password, dbname, 'utf8' AS charset, 'pdo_mysql' AS driver"
+ . " FROM sbas";
- return $connection->fetchAll($sql);
+ return $connection->fetchAll($sql);
+ } catch (\Exception $e) {
+ return [];
+ }
});
// Return unique key for fixture database
diff --git a/lib/Alchemy/Phrasea/Core/Version/VersionRepository.php b/lib/Alchemy/Phrasea/Core/Version/VersionRepository.php
index f6734f4363..0e7411e662 100644
--- a/lib/Alchemy/Phrasea/Core/Version/VersionRepository.php
+++ b/lib/Alchemy/Phrasea/Core/Version/VersionRepository.php
@@ -7,7 +7,7 @@ use Alchemy\Phrasea\Core\Version;
interface VersionRepository
{
- const DEFAULT_VERSION = '0.0.0.0';
+ const DEFAULT_VERSION = '0.0.0';
/**
* @return string
diff --git a/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php b/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php
index ebf725c53e..8627a2c730 100644
--- a/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php
+++ b/lib/Alchemy/Phrasea/Setup/ConfigurationTester.php
@@ -25,6 +25,7 @@ use Alchemy\Phrasea\Setup\Probe\PhpProbe;
use Alchemy\Phrasea\Setup\Probe\SearchEngineProbe;
use Alchemy\Phrasea\Setup\Probe\SubdefsPathsProbe;
use Alchemy\Phrasea\Setup\Probe\SystemProbe;
+use Doctrine\DBAL\Connection;
use vierbergenlars\SemVer\version;
class ConfigurationTester
@@ -130,6 +131,22 @@ class ConfigurationTester
return (Boolean) $this->getMigrations();
}
+ public function isConnectedToDBHost()
+ {
+ $connectionConfig = $this->app['conf']->get(['main', 'database']);
+ /** @var Connection $connection */
+ $connection = $this->app['db.provider']($connectionConfig);
+
+ try {
+ $connection->connect();
+
+ return true;
+ } catch (\Exception $e) {
+
+ return false;
+ }
+ }
+
public function getMigrations()
{
$migrations = [];
diff --git a/lib/classes/base.php b/lib/classes/base.php
index a18190765c..46b68ff228 100644
--- a/lib/classes/base.php
+++ b/lib/classes/base.php
@@ -207,7 +207,11 @@ abstract class base implements cache_cacheableInterface
public function get_version()
{
if (! $this->version) {
- $this->version = $this->versionRepository->getVersion();
+ try {
+ $this->version = $this->versionRepository->getVersion();
+ } catch(\Throwable $e) {
+ return PhraseaVersion\VersionRepository::DEFAULT_VERSION;
+ }
}
return $this->version;
diff --git a/tests/Alchemy/Tests/Phrasea/MockArrayConf.php b/tests/Alchemy/Tests/Phrasea/MockArrayConf.php
index bf5c9e5aae..8e52fc5108 100644
--- a/tests/Alchemy/Tests/Phrasea/MockArrayConf.php
+++ b/tests/Alchemy/Tests/Phrasea/MockArrayConf.php
@@ -67,4 +67,9 @@ class MockArrayConf implements ConfigurationInterface
{
throw new \Exception('not implemented');
}
+
+ public function setNoCompile(bool $noCompile)
+ {
+ throw new \Exception('not implemented');
+ }
}