Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Cryer <[email protected]>
  • Loading branch information
Dan Cryer committed Jun 23, 2016
1 parent 3cdaef8 commit 4d0911f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 17 deletions.
9 changes: 9 additions & 0 deletions PHPCI/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use PHPCI\Service\UserService;
use Symfony\Component\Console\Question\ConfirmationQuestion;

/**
* Install console command - Installs PHPCI.
Expand Down Expand Up @@ -253,6 +254,14 @@ protected function getQueueInformation(InputInterface $input, OutputInterface $o

$rtn = [];

$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Use beanstalkd to manage build queue? ', true);

if (!$helper->ask($input, $output, $question)) {
$output->writeln('<error>Skipping beanstalkd configuration.</error>');
return null;
}

if (!$rtn['host'] = $input->getOption('queue-server')) {
$rtn['host'] = $dialog->ask($output, 'Enter your beanstalkd hostname [localhost]: ', 'localhost');
}
Expand Down
4 changes: 4 additions & 0 deletions PHPCI/Controller/BuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public function rebuild($buildId)

$build = $this->buildService->createDuplicateBuild($copy);

if ($this->buildService->queueError) {
$_SESSION['global_error'] = Lang::get('add_to_queue_failed');
}

$response = new b8\Http\Response\RedirectResponse();
$response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId());
return $response;
Expand Down
4 changes: 4 additions & 0 deletions PHPCI/Controller/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public function build($projectId, $branch = '')
$email = $_SESSION['phpci_user']->getEmail();
$build = $this->buildService->createBuild($project, null, urldecode($branch), $email);

if ($this->buildService->queueError) {
$_SESSION['global_error'] = Lang::get('add_to_queue_failed');
}

$response = new b8\Http\Response\RedirectResponse();
$response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId());
return $response;
Expand Down
3 changes: 3 additions & 0 deletions PHPCI/Languages/lang.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@
'project_id_argument' => 'A project ID',
'commit_id_option' => 'Commit ID to build',
'branch_name_option' => 'Branch to build',
'add_to_queue_failed' => 'Build created successfully, but failed to add to build queue. This usually happens
when PHPCI is set to use a beanstalkd server that does not exist,
or your beanstalkd server has stopped.',

// Run Command
'run_all_pending' => 'Run all pending PHPCI builds.',
Expand Down
18 changes: 18 additions & 0 deletions PHPCI/Migrations/20160623100223_project_table_defaults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

class ProjectTableDefaults extends AbstractMigration
{
public function change()
{
$this->table('project')
->changeColumn('build_config', MysqlAdapter::PHINX_TYPE_TEXT, array('null' => true))
->changeColumn('archived', MysqlAdapter::PHINX_TYPE_INTEGER, array(
'length' => MysqlAdapter::INT_TINY,
'default' => 0,
))
->save();
}
}
42 changes: 25 additions & 17 deletions PHPCI/Service/BuildService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class BuildService
*/
protected $buildStore;

/**
* @var bool
*/
public $queueError = false;

/**
* @param BuildStore $buildStore
*/
Expand Down Expand Up @@ -155,27 +160,30 @@ public function addBuildToQueue(Build $build)
}

$config = Config::getInstance();

$settings = $config->get('phpci.worker', []);

if (!empty($settings['host']) && !empty($settings['queue'])) {
$jobData = array(
'type' => 'phpci.build',
'build_id' => $build->getId(),
);

if ($config->get('using_custom_file')) {
$jobData['config'] = $config->getArray();
try {
$jobData = array(
'type' => 'phpci.build',
'build_id' => $build->getId(),
);

if ($config->get('using_custom_file')) {
$jobData['config'] = $config->getArray();
}

$pheanstalk = new Pheanstalk($settings['host']);
$pheanstalk->useTube($settings['queue']);
$pheanstalk->put(
json_encode($jobData),
PheanstalkInterface::DEFAULT_PRIORITY,
PheanstalkInterface::DEFAULT_DELAY,
$config->get('phpci.worker.job_timeout', 600)
);
} catch (\Exception $ex) {
$this->queueError = true;
}

$pheanstalk = new Pheanstalk($settings['host']);
$pheanstalk->useTube($settings['queue']);
$pheanstalk->put(
json_encode($jobData),
PheanstalkInterface::DEFAULT_PRIORITY,
PheanstalkInterface::DEFAULT_DELAY,
$config->get('phpci.worker.job_timeout', 600)
);
}
}
}
8 changes: 8 additions & 0 deletions PHPCI/View/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@

<!-- Main content -->
<section class="content">
<?php
if (!empty($_SESSION['global_error'])) {
$message = $_SESSION['global_error'];
unset($_SESSION['global_error']);
print '<div class="alert alert-danger">' . $message . '</div>';
}
?>

<?php print $content; ?>
</section><!-- /.content -->
</aside><!-- /.content-wrapper -->
Expand Down

0 comments on commit 4d0911f

Please sign in to comment.