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
This commit is contained in:
Aina Sitraka
2022-11-01 18:20:52 +03:00
committed by GitHub
parent d4a5b8b738
commit bc01476ea2
15 changed files with 178 additions and 75 deletions

View File

@@ -91,6 +91,10 @@ if (!$cli['phraseanet.configuration-tester']->isInstalled()) {
throw new \RuntimeException('Phraseanet is not installed, use setup command instead'); 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()) { if (!$cli['phraseanet.configuration-tester']->isUpToDate()) {
throw new \RuntimeException('Phraseanet is not up-to-date, use setup command instead'); throw new \RuntimeException('Phraseanet is not up-to-date, use setup command instead');
} }

View File

@@ -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 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 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 ### Datastore_conf
Update configuration.yml in accordance of containers env value for : Update configuration.yml in accordance of containers env value for :

View File

@@ -6,10 +6,10 @@ cd "/var/alchemy/Phraseanet"
echo `date +"%Y-%m-%d %H:%M:%S"` - "Applying infrastructure stack setup to Phraseanet Database connexion" 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 -s set main.database.host $PHRASEANET_DB_HOST
bin/setup system:config set main.database.port $PHRASEANET_DB_PORT bin/setup system:config -s set main.database.port $PHRASEANET_DB_PORT
bin/setup system:config set main.database.user $PHRASEANET_DB_USER bin/setup system:config -s 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.password $PHRASEANET_DB_PASSWORD
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet Database connexion applied" 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" echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phraseanet Elastisearch"
if [ -z "$PHRASEANET_ELASTICSEARCH_HOST" ]; then 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 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 fi
if [ -z "$PHRASEANET_ELASTICSEARCH_PORT" ]; then 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 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 fi
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet elasticsearch applied" 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 ## Phraseanet application cache setting
echo `date +"%Y-%m-%d %H:%M:%S"` - "Applying infrastructure stack setup to Phraseanet application cache" 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 -s set main.cache.options.host $PHRASEANET_CACHE_HOST
bin/setup system:config set main.cache.options.port $PHRASEANET_CACHE_PORT bin/setup system:config -s set main.cache.options.port $PHRASEANET_CACHE_PORT
bin/setup system:config set main.cache.options.namespace $PHRASEANET_HOSTNAME bin/setup system:config -s 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.type $PHRASEANET_CACHE_TYPE
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet application cache applied" 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 ## Phraseanet application session setting
echo `date +"%Y-%m-%d %H:%M:%S"` - "Applying infrastructure stack setup to Phraseanet session cache" 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 -s set main.session.type "native"
bin/setup system:config set main.session.ttl "86400" bin/setup system:config -s set main.session.ttl "86400"
echo `date +"%Y-%m-%d %H:%M:%S"` - "setup of Phraseanet session cache applied" 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" 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 -s 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 -s 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 -s 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 -s 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 -s 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 -s 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.password $PHRASEANET_RABBITMQ_PASSWORD
echo `date +"%Y-%m-%d %H:%M:%S"` " - setup of Phraseanet setting RABBITMQ applied" echo `date +"%Y-%m-%d %H:%M:%S"` " - setup of Phraseanet setting RABBITMQ applied"
cd - cd -
echo `date +"%Y-%m-%d %H:%M:%S"` " - End of datastore migration - Check databases in \"sbas\" table in Application Box" 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"

View File

@@ -4,16 +4,16 @@ cd "/var/alchemy/Phraseanet"
echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phraseanet SMTP" echo `date +"%Y-%m-%d %H:%M:%S"` " - Applying infrastructure stack setup to Phraseanet SMTP"
if [[ $PHRASEANET_SMTP_ENABLED && $PHRASEANET_SMTP_ENABLED = true ]]; then 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 -s 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 -s 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 -s 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 -s set registry.email.smtp-host $PHRASEANET_SMTP_HOST
bin/setup system:config set registry.email.smtp-port $PHRASEANET_SMTP_PORT bin/setup system:config -s set registry.email.smtp-port $PHRASEANET_SMTP_PORT
bin/setup system:config set registry.email.smtp-user $PHRASEANET_SMTP_USER bin/setup system:config -s set registry.email.smtp-user $PHRASEANET_SMTP_USER
bin/setup system:config set registry.email.smtp-password $PHRASEANET_SMTP_PASSWORD bin/setup system:config -s 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.emitter-email $PHRASEANET_EMITTER_EMAIL
fi fi
cd - cd -
echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet SMTP setup applied" echo `date +"%Y-%m-%d %H:%M:%S"` " - Phraseanet SMTP setup applied"

View File

@@ -10,10 +10,10 @@ if [[ -n $PHRASEANET_TRUSTED_PROXIES ]]; then
do do
counter=$(( counter+1 )) counter=$(( counter+1 ))
if [[ $counter -eq 1 ]] ; then if [[ $counter -eq 1 ]] ; then
bin/setup system:config set trusted-proxies $i bin/setup system:config -s set trusted-proxies $i
bin/setup system:config add trusted-proxies $i bin/setup system:config -s add trusted-proxies $i
else else
bin/setup system:config add trusted-proxies $i bin/setup system:config -s add trusted-proxies $i
fi fi
done done
fi fi
@@ -29,13 +29,13 @@ if [[ -n $PHRASEANET_DEBUG_ALLOWED_IP ]]; then
do do
counter=$(( counter+1 )) counter=$(( counter+1 ))
if [[ $counter -eq 1 ]] ; then if [[ $counter -eq 1 ]] ; then
bin/setup system:config set debugger.allowed-ips $i bin/setup system:config -s set debugger.allowed-ips $i
bin/setup system:config add debugger.allowed-ips $i bin/setup system:config -s add debugger.allowed-ips $i
else else
bin/setup system:config add debugger.allowed-ips $i bin/setup system:config -s add debugger.allowed-ips $i
fi fi
done done
fi fi
echo `date +"%Y-%m-%d %H:%M:%S"` " - Setup of Phraseanet debugger allowed IP applied" echo `date +"%Y-%m-%d %H:%M:%S"` " - Setup of Phraseanet debugger allowed IP applied"
cd - cd -

View File

@@ -4,28 +4,28 @@ cd "/var/alchemy/Phraseanet"
echo `date +"%Y-%m-%d %H:%M:%S"` - "update binaries path in accordance of docker stack" 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 -s 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 -s 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 -s set main.binaries.swf_extract_binary "/usr/bin/swfextract"
bin/setup system:config set main.binaries.pdf2swf_binary null bin/setup system:config -s set main.binaries.pdf2swf_binary null
bin/setup system:config set main.binaries.swf_render_binary "/usr/bin/swfrender" bin/setup system:config -s 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 -s 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 -s 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 -s 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 -s 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.pdftotext_binary "/usr/bin/pdftotext"
echo `date +"%Y-%m-%d %H:%M:%S"` - "binaries path applied" 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" 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 -s set main.storage.subdefs "/var/alchemy/Phraseanet/datas"
bin/setup system:config set main.storage.cache "/var/alchemy/Phraseanet/cache" bin/setup system:config -s set main.storage.cache "/var/alchemy/Phraseanet/cache"
bin/setup system:config set main.storage.log "/var/alchemy/Phraseanet/logs" bin/setup system:config -s 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 -s 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 -s 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 -s 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.worker_tmp_files "/var/alchemy/Phraseanet/tmp/worker"
echo `date +"%Y-%m-%d %H:%M:%S"` - "storage path path applied" echo `date +"%Y-%m-%d %H:%M:%S"` - "storage path path applied"

View File

@@ -6,11 +6,13 @@ use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Core\Configuration\Configuration; use Alchemy\Phrasea\Core\Configuration\Configuration;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
class ConfigurationEditor extends Command class ConfigurationEditor extends Command
{ {
private $noCompile = false;
public function __construct($name) public function __construct($name)
{ {
@@ -22,12 +24,12 @@ class ConfigurationEditor extends Command
$this->addArgument( $this->addArgument(
'operation', 'operation',
InputArgument::REQUIRED, InputArgument::REQUIRED,
'The operation to execute (get, set, or add)' 'The operation to execute (get, set, add, compile)'
); );
$this->addArgument( $this->addArgument(
'parameter', 'parameter',
InputArgument::REQUIRED, InputArgument::OPTIONAL,
'The name of the configuration parameter to get or set' 'The name of the configuration parameter to get or set'
); );
@@ -36,23 +38,38 @@ class ConfigurationEditor extends Command
InputArgument::OPTIONAL, InputArgument::OPTIONAL,
'The value to set when operation is "set" or "add", in YAML syntax' '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) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$command = $input->getArgument('operation'); $command = $input->getArgument('operation');
$parameter = $input->getArgument('parameter'); $parameter = $input->getArgument('parameter');
$this->noCompile = $input->getOption('no-compile');
$parameterNodes = explode('.', $parameter); $parameterNodes = explode('.', $parameter);
if ($command == 'get') { if ($command == 'compile') {
$this->readConfigurationValue($output, $parameter, $parameterNodes); $this->compileConfiguration($output);
} } else {
elseif ($command == 'set') { if (empty($parameter)) {
$this->writeConfigurationValue($output, $parameter, $parameterNodes, $input->getArgument('value')); $output->writeln("<error>Missing 'parameter' argument</error>");
}
elseif ($command == 'add') { return 1;
$this->appendConfigurationValue($output, $parameter, $parameterNodes, $input->getArgument('value')); }
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("<error>Command not found</error>");
}
} }
} }
@@ -61,6 +78,7 @@ class ConfigurationEditor extends Command
$app = $this->getContainer(); $app = $this->getContainer();
/** @var Configuration $config */ /** @var Configuration $config */
$config = $app['configuration.store']; $config = $app['configuration.store'];
$config->setNoCompile($this->noCompile);
$values = $config->getConfig(); $values = $config->getConfig();
$current = $values; $current = $values;
@@ -78,6 +96,7 @@ class ConfigurationEditor extends Command
$app = $this->getContainer(); $app = $this->getContainer();
/** @var Configuration $configurationStore */ /** @var Configuration $configurationStore */
$configurationStore = $app['configuration.store']; $configurationStore = $app['configuration.store'];
$configurationStore->setNoCompile($this->noCompile);
$lastParameter = end($parameterNodes); $lastParameter = end($parameterNodes);
$configurationRoot = $configurationStore->getConfig(); $configurationRoot = $configurationStore->getConfig();
@@ -100,7 +119,9 @@ class ConfigurationEditor extends Command
} }
$configurationStore->setConfig($configurationRoot); $configurationStore->setConfig($configurationRoot);
$configurationStore->compileAndWrite(); if (!$this->noCompile) {
$configurationStore->compileAndWrite();
}
$output->writeln('<comment>Reading updated configuration value</comment>'); $output->writeln('<comment>Reading updated configuration value</comment>');
@@ -112,6 +133,7 @@ class ConfigurationEditor extends Command
$app = $this->getContainer(); $app = $this->getContainer();
/** @var Configuration $configurationStore */ /** @var Configuration $configurationStore */
$configurationStore = $app['configuration.store']; $configurationStore = $app['configuration.store'];
$configurationStore->setNoCompile($this->noCompile);
$lastParameter = end($parameterNodes); $lastParameter = end($parameterNodes);
$configurationRoot = $configurationStore->getConfig(); $configurationRoot = $configurationStore->getConfig();
@@ -144,7 +166,9 @@ class ConfigurationEditor extends Command
} }
$configurationStore->setConfig($configurationRoot); $configurationStore->setConfig($configurationRoot);
$configurationStore->compileAndWrite(); if (!$this->noCompile) {
$configurationStore->compileAndWrite();
}
$output->writeln('<comment>Reading updated configuration value</comment>'); $output->writeln('<comment>Reading updated configuration value</comment>');
@@ -176,4 +200,10 @@ class ConfigurationEditor extends Command
$output->write(PHP_EOL); $output->write(PHP_EOL);
} }
} }
private function compileConfiguration(OutputInterface $output)
{
$this->container['configuration.store']->compileAndWrite();
$output->writeln('<comment>Configuration compiled!</comment>');
}
} }

View File

@@ -26,6 +26,8 @@ class Configuration implements ConfigurationInterface
private $compiled; private $compiled;
private $autoReload; private $autoReload;
private $noCompile = false;
/** /**
* @param Yaml $yaml The Yaml Parser * @param Yaml $yaml The Yaml Parser
* @param Compiler $compiler The PHP Compiler * @param Compiler $compiler The PHP Compiler
@@ -117,11 +119,25 @@ class Configuration implements ConfigurationInterface
return $newConfig; return $newConfig;
} }
public function setNoCompile(bool $noCompile)
{
$this->noCompile = !!$noCompile;
}
public function getNoCompile()
{
return $this->noCompile;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getConfig() public function getConfig()
{ {
if ($this->noCompile) {
return $this->parser->parse($this->loadFile($this->config));
}
if (null !== $this->cache) { if (null !== $this->cache) {
return $this->cache; return $this->cache;
} }
@@ -145,7 +161,9 @@ class Configuration implements ConfigurationInterface
{ {
$this->cache = $config; $this->cache = $config;
$this->dumpFile($this->config, $this->parser->dump($config, 7), 0660); $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; return $this;
} }

View File

@@ -13,6 +13,13 @@ namespace Alchemy\Phrasea\Core\Configuration;
interface ConfigurationInterface extends \ArrayAccess interface ConfigurationInterface extends \ArrayAccess
{ {
/**
* Do not compile, just save the config
*
* @param bool $noCompile
*/
public function setNoCompile(bool $noCompile);
/** /**
* Initialize configuration file in setup. * Initialize configuration file in setup.
* *

View File

@@ -155,6 +155,10 @@ class HostConfiguration implements ConfigurationInterface
throw new RuntimeException('Configuration is not set up.'); throw new RuntimeException('Configuration is not set up.');
} }
if ($this->configuration->getNoCompile()) {
return $this->configuration->getConfig();
}
return $this->cache; return $this->cache;
} }
@@ -180,6 +184,11 @@ class HostConfiguration implements ConfigurationInterface
$this->setHost($this->host); $this->setHost($this->host);
} }
public function setNoCompile(bool $noCompile)
{
$this->configuration->setNoCompile($noCompile);
}
private function match($host, $hostname) private function match($host, $hostname)
{ {
return $this->removeHostPrefix($host) === $this->removeHostPrefix($hostname); return $this->removeHostPrefix($host) === $this->removeHostPrefix($hostname);

View File

@@ -90,14 +90,18 @@ class ORMServiceProvider implements ServiceProviderInterface
return array(); return array();
} }
/** @var Connection $connection */ try {
$connection = $app['dbal.provider']($app['db.appbox.info']); /** @var Connection $connection */
$connection = $app['dbal.provider']($app['db.appbox.info']);
$sql = "SELECT" $sql = "SELECT"
. " host, port, `user`, COALESCE(pwd, '') AS password, dbname, 'utf8' AS charset, 'pdo_mysql' AS driver" . " host, port, `user`, COALESCE(pwd, '') AS password, dbname, 'utf8' AS charset, 'pdo_mysql' AS driver"
. " FROM sbas"; . " FROM sbas";
return $connection->fetchAll($sql); return $connection->fetchAll($sql);
} catch (\Exception $e) {
return [];
}
}); });
// Return unique key for fixture database // Return unique key for fixture database

View File

@@ -7,7 +7,7 @@ use Alchemy\Phrasea\Core\Version;
interface VersionRepository interface VersionRepository
{ {
const DEFAULT_VERSION = '0.0.0.0'; const DEFAULT_VERSION = '0.0.0';
/** /**
* @return string * @return string

View File

@@ -25,6 +25,7 @@ use Alchemy\Phrasea\Setup\Probe\PhpProbe;
use Alchemy\Phrasea\Setup\Probe\SearchEngineProbe; use Alchemy\Phrasea\Setup\Probe\SearchEngineProbe;
use Alchemy\Phrasea\Setup\Probe\SubdefsPathsProbe; use Alchemy\Phrasea\Setup\Probe\SubdefsPathsProbe;
use Alchemy\Phrasea\Setup\Probe\SystemProbe; use Alchemy\Phrasea\Setup\Probe\SystemProbe;
use Doctrine\DBAL\Connection;
use vierbergenlars\SemVer\version; use vierbergenlars\SemVer\version;
class ConfigurationTester class ConfigurationTester
@@ -130,6 +131,22 @@ class ConfigurationTester
return (Boolean) $this->getMigrations(); 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() public function getMigrations()
{ {
$migrations = []; $migrations = [];

View File

@@ -207,7 +207,11 @@ abstract class base implements cache_cacheableInterface
public function get_version() public function get_version()
{ {
if (! $this->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; return $this->version;

View File

@@ -67,4 +67,9 @@ class MockArrayConf implements ConfigurationInterface
{ {
throw new \Exception('not implemented'); throw new \Exception('not implemented');
} }
public function setNoCompile(bool $noCompile)
{
throw new \Exception('not implemented');
}
} }