PSR2 for PHPCI/Command - Issue #18

This commit is contained in:
Dan Cryer 2013-05-16 15:14:10 +01:00
parent e4d32b3ea1
commit 65f93555be
3 changed files with 18 additions and 21 deletions

View file

@ -36,4 +36,4 @@ class GenerateCommand extends Command
$gen->generateModels(); $gen->generateModels();
$gen->generateStores(); $gen->generateStores();
} }
} }

View file

@ -42,7 +42,9 @@ class InstallCommand extends Command
$ghId = $this->ask('(Optional) Github Application ID: ', true); $ghId = $this->ask('(Optional) Github Application ID: ', true);
$ghSecret = $this->ask('(Optional) Github Application Secret: ', true); $ghSecret = $this->ask('(Optional) Github Application Secret: ', true);
$cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost . ' -e "CREATE DATABASE IF NOT EXISTS ' . $dbName . '"'; $cmd = 'mysql -u' . $dbUser . (!empty($dbPass) ? ' -p' . $dbPass : '') . ' -h' . $dbHost .
' -e "CREATE DATABASE IF NOT EXISTS ' . $dbName . '"';
shell_exec($cmd); shell_exec($cmd);
$str = "<?php $str = "<?php
@ -59,9 +61,10 @@ b8\Database::setReadServers(array('{$dbHost}'));
\$registry->set('install_url', '{$ciUrl}'); \$registry->set('install_url', '{$ciUrl}');
"; ";
if(!empty($ghId) && !empty($ghSecret)) if (!empty($ghId) && !empty($ghSecret)) {
{ $str .= PHP_EOL .
$str .= PHP_EOL . "\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" . PHP_EOL; "\$registry->set('github_app', array('id' => '{$ghId}', 'secret' => '{$ghSecret}'));" .
PHP_EOL;
} }
@ -76,8 +79,7 @@ b8\Database::setReadServers(array('{$dbHost}'));
$adminPass = $this->ask('Enter your desired admin password: '); $adminPass = $this->ask('Enter your desired admin password: ');
$adminName = $this->ask('Enter your name: '); $adminName = $this->ask('Enter your name: ');
try try {
{
$user = new \PHPCI\Model\User(); $user = new \PHPCI\Model\User();
$user->setEmail($adminEmail); $user->setEmail($adminEmail);
$user->setName($adminName); $user->setName($adminName);
@ -88,15 +90,13 @@ b8\Database::setReadServers(array('{$dbHost}'));
$store->save($user); $store->save($user);
print 'User account created!' . PHP_EOL; print 'User account created!' . PHP_EOL;
} } catch (\Exception $ex) {
catch(\Exception $ex)
{
print 'There was a problem creating your account. :(' . PHP_EOL; print 'There was a problem creating your account. :(' . PHP_EOL;
print $ex->getMessage(); print $ex->getMessage();
} }
} }
function ask($question, $emptyOk = false) protected function ask($question, $emptyOk = false)
{ {
print $question . ' '; print $question . ' ';
@ -107,11 +107,10 @@ b8\Database::setReadServers(array('{$dbHost}'));
$rtn = trim($rtn); $rtn = trim($rtn);
if(!$emptyOk && empty($rtn)) if (!$emptyOk && empty($rtn)) {
{
$rtn = $this->ask($question, $emptyOk); $rtn = $this->ask($question, $emptyOk);
} }
return $rtn; return $rtn;
} }
} }

View file

@ -15,8 +15,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use b8\Store\Factory; use b8\Store\Factory;
use PHPCI\Builder, use PHPCI\Builder;
PHPCI\BuildFactory; use PHPCI\BuildFactory;
/** /**
* Run console command - Runs any pending builds. * Run console command - Runs any pending builds.
@ -40,14 +40,12 @@ class RunCommand extends Command
$store = Factory::getStore('Build'); $store = Factory::getStore('Build');
$result = $store->getByStatus(0); $result = $store->getByStatus(0);
foreach($result['items'] as $build) foreach ($result['items'] as $build) {
{
$build = BuildFactory::getBuild($build); $build = BuildFactory::getBuild($build);
if ($input->getOption('verbose')) { if ($input->getOption('verbose')) {
$builder = new Builder($build, array($this, 'logCallback')); $builder = new Builder($build, array($this, 'logCallback'));
} } else {
else {
$builder = new Builder($build); $builder = new Builder($build);
} }
@ -59,4 +57,4 @@ class RunCommand extends Command
{ {
$this->output->writeln($log); $this->output->writeln($log);
} }
} }