diff --git a/.gitignore b/.gitignore index ff9b62a..a764780 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /cache/* /bower_components /config/users.json +/config/env_settings.json /composer.phar /data/confi*.json /logs/*.log @@ -11,3 +12,5 @@ /web/packages.json !.gitkeep !bin/console +.idea +config/deploy_settings.rb \ No newline at end of file diff --git a/README.md b/README.md index 601d788..eb5a60e 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,15 @@ Run test suite $ php -Slocalhost:8000 -tweb $ ./bin/behat ``` + +Troubleshooting +--------------- + +If you cannot build satis repository check your prod.log looking for a message of lost HOME or COMPOSER_HOME environment variable, +this can be fixed with: + +```sh + + $ php bin/console setting:add COMPOSER_HOME /whatever/is/your/composer/home + +``` \ No newline at end of file diff --git a/config/prod.php b/config/prod.php index 182a6d9..7208a5e 100644 --- a/config/prod.php +++ b/config/prod.php @@ -5,6 +5,16 @@ $this['gaufrette.options'] = array($this['app.data_dir']); $this['app.node_path'] = '/usr/bin/node'; +if (!is_file($this['app.env_settings_file'])) { + file_put_contents($this['app.env_settings_file'], json_encode([])); +} +$settings = json_decode(file_get_contents($this['app.env_settings_file']), true); +if ($settings) { + foreach ($settings as $key => $value) { + putenv(sprintf('%s=%s', $key, $value)); + } +} + $this['satis_runner'] = $this->share(function() { return new SatisAdmin\Runner\SatisRunner( $this['model_manager'], diff --git a/src/SatisAdmin/Application.php b/src/SatisAdmin/Application.php index 67416be..6aa3e15 100644 --- a/src/SatisAdmin/Application.php +++ b/src/SatisAdmin/Application.php @@ -58,6 +58,7 @@ protected function registerConfig($env) $this['app.resources_dir'] = $this['app.root_dir'].'/resources'; $this['app.web_dir'] = $this['app.root_dir'].'/web'; $this['app.users_file'] = $this['app.config_dir'].'/users.json'; + $this['app.env_settings_file'] = $this['app.config_dir'].'/env_settings.json'; require sprintf('%s/%s.php', $this['app.config_dir'], $env); } diff --git a/src/SatisAdmin/Console/AddEnvSettingCommand.php b/src/SatisAdmin/Console/AddEnvSettingCommand.php new file mode 100644 index 0000000..9fbb8ce --- /dev/null +++ b/src/SatisAdmin/Console/AddEnvSettingCommand.php @@ -0,0 +1,38 @@ + + */ +class AddEnvSettingCommand extends BaseCommand +{ + protected function configure() + { + $this + ->setName('setting:add') + ->setDescription('Adds a new environment setting') + ->addArgument('key', InputArgument::REQUIRED, 'The setting key') + ->addArgument('value', InputArgument::REQUIRED, 'The setting value'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $app = $this->getApp(); + $key = $input->getArgument('key'); + $value = $input->getArgument('value'); + $settings = is_file($app['app.env_settings_file']) ? json_decode(file_get_contents($app['app.env_settings_file']), true) : []; + + $settings[$key] = $value; + file_put_contents($app['app.env_settings_file'], json_encode($settings, JSON_PRETTY_PRINT)); + + $app->log('Setting added', [$key => $value], Logger::INFO); + } +} diff --git a/src/SatisAdmin/Console/Application.php b/src/SatisAdmin/Console/Application.php index d2f84a5..ad8d9ed 100644 --- a/src/SatisAdmin/Console/Application.php +++ b/src/SatisAdmin/Console/Application.php @@ -54,6 +54,7 @@ protected function getDefaultCommands() [ new BuildCommand, new AddUserCommand, + new AddEnvSettingCommand, new RemoveUserCommand, new AsseticDumpCommand, ]