Updating PHPCI to use YAML-based config files.
This commit is contained in:
parent
6e3df00f62
commit
ce6943de86
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ config.php
|
||||||
.project
|
.project
|
||||||
.buildpath
|
.buildpath
|
||||||
.htaccess
|
.htaccess
|
||||||
|
PHPCI/config.yml
|
||||||
|
|
|
@ -38,13 +38,20 @@ class InstallCommand extends Command
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
// Gather initial data from the user:
|
// Gather initial data from the user:
|
||||||
$dbHost = $this->ask('Enter your MySQL host: ');
|
$conf = array();
|
||||||
$dbName = $this->ask('Enter the database name PHPCI should use: ');
|
$conf['b8']['database']['servers']['read'] = $this->ask('Enter your MySQL host: ');
|
||||||
$dbUser = $this->ask('Enter your MySQL username: ');
|
$conf['b8']['database']['servers']['write'] = $conf['b8']['database']['servers']['read'];
|
||||||
$dbPass = $this->ask('Enter your MySQL password: ', true);
|
$conf['b8']['database']['name'] = $this->ask('Enter the database name PHPCI should use: ');
|
||||||
$ciUrl = $this->ask('Your PHPCI URL (without trailing slash): ');
|
$conf['b8']['database']['username'] = $this->ask('Enter your MySQL username: ');
|
||||||
$ghId = $this->ask('(Optional) Github Application ID: ', true);
|
$conf['b8']['database']['password'] = $this->ask('Enter your MySQL password: ', true);
|
||||||
$ghSecret = $this->ask('(Optional) Github Application Secret: ', true);
|
$conf['phpci']['url'] = $this->ask('Your PHPCI URL (without trailing slash): ');
|
||||||
|
$conf['phpci']['github']['id'] = $this->ask('(Optional) Github Application ID: ', true);
|
||||||
|
$conf['phpci']['github']['secret'] = $this->ask('(Optional) Github Application Secret: ', true);
|
||||||
|
|
||||||
|
$dbUser = $conf['b8']['database']['username'];
|
||||||
|
$dbPass = $conf['b8']['database']['password'];
|
||||||
|
$dbHost = $conf['b8']['database']['servers']['write'];
|
||||||
|
$dbName = $conf['b8']['database']['name'];
|
||||||
|
|
||||||
// Create the database if it doesn't exist:
|
// Create the database if it doesn't exist:
|
||||||
$cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost .
|
$cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost .
|
||||||
|
@ -52,29 +59,11 @@ class InstallCommand extends Command
|
||||||
|
|
||||||
shell_exec($cmd);
|
shell_exec($cmd);
|
||||||
|
|
||||||
$str = "<?php
|
$dumper = new \Symfony\Component\Yaml\Dumper();
|
||||||
|
$yaml = $dumper->dump($conf);
|
||||||
|
|
||||||
if(!defined('PHPCI_DB_HOST')) {
|
file_put_contents(PHPCI_DIR . 'PHPCI/config.yml', $yaml);
|
||||||
define('PHPCI_DB_HOST', '{$dbHost}');
|
|
||||||
}
|
|
||||||
|
|
||||||
b8\Database::setDetails('{$dbName}', '{$dbUser}', '{$dbPass}');
|
|
||||||
b8\Database::setWriteServers(array('{$dbHost}'));
|
|
||||||
b8\Database::setReadServers(array('{$dbHost}'));
|
|
||||||
|
|
||||||
\$config = b8\Config::getInstance();
|
|
||||||
\$config->set('install_url', '{$ciUrl}');
|
|
||||||
";
|
|
||||||
|
|
||||||
// Has the user entered Github app details? If so add those to config:
|
|
||||||
if (!empty($ghId) && !empty($ghSecret)) {
|
|
||||||
$str .= PHP_EOL .
|
|
||||||
"\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" .
|
|
||||||
PHP_EOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the config file and then re-bootstrap:
|
|
||||||
file_put_contents(PHPCI_DIR . 'config.php', $str);
|
|
||||||
require(PHPCI_DIR . 'bootstrap.php');
|
require(PHPCI_DIR . 'bootstrap.php');
|
||||||
|
|
||||||
// Update the database:
|
// Update the database:
|
||||||
|
|
|
@ -36,20 +36,43 @@ if (!defined('APPLICATION_PATH')) {
|
||||||
require_once(APPLICATION_PATH . 'vendor/autoload.php');
|
require_once(APPLICATION_PATH . 'vendor/autoload.php');
|
||||||
|
|
||||||
// Load configuration if present:
|
// Load configuration if present:
|
||||||
$config = new b8\Config();
|
$conf = array();
|
||||||
|
$conf['b8']['app']['namespace'] = 'PHPCI';
|
||||||
|
$conf['b8']['app']['default_controller'] = 'Index';
|
||||||
|
$conf['b8']['view']['path'] = dirname(__FILE__) . '/PHPCI/View/';
|
||||||
|
|
||||||
|
$config = new b8\Config($conf);
|
||||||
$request = new b8\Http\Request();
|
$request = new b8\Http\Request();
|
||||||
$registry = new b8\Registry($config, $request);
|
$registry = new b8\Registry($config, $request);
|
||||||
|
|
||||||
if (file_exists(APPLICATION_PATH . 'config.php')) {
|
if (file_exists(APPLICATION_PATH . 'config.php')) {
|
||||||
require(APPLICATION_PATH . 'config.php');
|
require(APPLICATION_PATH . 'config.php');
|
||||||
|
|
||||||
// Define our PHPCI_URL, if not already defined:
|
$conf = $config->get(null);
|
||||||
if (!defined('PHPCI_URL')) {
|
unset($conf['b8']['app']);
|
||||||
define('PHPCI_URL', $config->get('install_url', '') . '/');
|
unset($conf['b8']['view']);
|
||||||
|
|
||||||
|
$conf['phpci']['url'] = $conf['install_url'];
|
||||||
|
|
||||||
|
if (isset($conf['github_app'])) {
|
||||||
|
$conf['phpci']['github'] = $conf['github_app'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($conf['install_url']);
|
||||||
|
unset($conf['github_app']);
|
||||||
|
|
||||||
|
$dumper = new Symfony\Component\Yaml\Dumper();
|
||||||
|
$yaml = $dumper->dump($conf);
|
||||||
|
|
||||||
|
file_put_contents(APPLICATION_PATH . 'PHPCI/config.yml', $yaml);
|
||||||
|
unlink(APPLICATION_PATH . 'config.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the registry:
|
if (file_exists(APPLICATION_PATH . 'PHPCI/config.yml')) {
|
||||||
$config->set('app_namespace', 'PHPCI');
|
$config->loadYaml(APPLICATION_PATH . 'PHPCI/config.yml');
|
||||||
$config->set('default_controller', 'Index');
|
|
||||||
$config->set('view_path', dirname(__FILE__) . '/PHPCI/View/');
|
// Define our PHPCI_URL, if not already defined:
|
||||||
|
if (!defined('PHPCI_URL')) {
|
||||||
|
define('PHPCI_URL', $config->get('phpci.url', '') . '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue