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

Commit 4d0911f

Browse files
author
Dan Cryer
committed
Bug fixes
Signed-off-by: Dan Cryer <[email protected]>
1 parent 3cdaef8 commit 4d0911f

File tree

7 files changed

+71
-17
lines changed

7 files changed

+71
-17
lines changed

PHPCI/Command/InstallCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Input\InputOption;
2222
use Symfony\Component\Console\Output\OutputInterface;
2323
use PHPCI\Service\UserService;
24+
use Symfony\Component\Console\Question\ConfirmationQuestion;
2425

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

254255
$rtn = [];
255256

257+
$helper = $this->getHelper('question');
258+
$question = new ConfirmationQuestion('Use beanstalkd to manage build queue? ', true);
259+
260+
if (!$helper->ask($input, $output, $question)) {
261+
$output->writeln('<error>Skipping beanstalkd configuration.</error>');
262+
return null;
263+
}
264+
256265
if (!$rtn['host'] = $input->getOption('queue-server')) {
257266
$rtn['host'] = $dialog->ask($output, 'Enter your beanstalkd hostname [localhost]: ', 'localhost');
258267
}

PHPCI/Controller/BuildController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ public function rebuild($buildId)
200200

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

203+
if ($this->buildService->queueError) {
204+
$_SESSION['global_error'] = Lang::get('add_to_queue_failed');
205+
}
206+
203207
$response = new b8\Http\Response\RedirectResponse();
204208
$response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId());
205209
return $response;

PHPCI/Controller/ProjectController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public function build($projectId, $branch = '')
116116
$email = $_SESSION['phpci_user']->getEmail();
117117
$build = $this->buildService->createBuild($project, null, urldecode($branch), $email);
118118

119+
if ($this->buildService->queueError) {
120+
$_SESSION['global_error'] = Lang::get('add_to_queue_failed');
121+
}
122+
119123
$response = new b8\Http\Response\RedirectResponse();
120124
$response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId());
121125
return $response;

PHPCI/Languages/lang.en.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@
372372
'project_id_argument' => 'A project ID',
373373
'commit_id_option' => 'Commit ID to build',
374374
'branch_name_option' => 'Branch to build',
375+
'add_to_queue_failed' => 'Build created successfully, but failed to add to build queue. This usually happens
376+
when PHPCI is set to use a beanstalkd server that does not exist,
377+
or your beanstalkd server has stopped.',
375378

376379
// Run Command
377380
'run_all_pending' => 'Run all pending PHPCI builds.',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use Phinx\Migration\AbstractMigration;
4+
use Phinx\Db\Adapter\MysqlAdapter;
5+
6+
class ProjectTableDefaults extends AbstractMigration
7+
{
8+
public function change()
9+
{
10+
$this->table('project')
11+
->changeColumn('build_config', MysqlAdapter::PHINX_TYPE_TEXT, array('null' => true))
12+
->changeColumn('archived', MysqlAdapter::PHINX_TYPE_INTEGER, array(
13+
'length' => MysqlAdapter::INT_TINY,
14+
'default' => 0,
15+
))
16+
->save();
17+
}
18+
}

PHPCI/Service/BuildService.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class BuildService
3030
*/
3131
protected $buildStore;
3232

33+
/**
34+
* @var bool
35+
*/
36+
public $queueError = false;
37+
3338
/**
3439
* @param BuildStore $buildStore
3540
*/
@@ -155,27 +160,30 @@ public function addBuildToQueue(Build $build)
155160
}
156161

157162
$config = Config::getInstance();
158-
159163
$settings = $config->get('phpci.worker', []);
160164

161165
if (!empty($settings['host']) && !empty($settings['queue'])) {
162-
$jobData = array(
163-
'type' => 'phpci.build',
164-
'build_id' => $build->getId(),
165-
);
166-
167-
if ($config->get('using_custom_file')) {
168-
$jobData['config'] = $config->getArray();
166+
try {
167+
$jobData = array(
168+
'type' => 'phpci.build',
169+
'build_id' => $build->getId(),
170+
);
171+
172+
if ($config->get('using_custom_file')) {
173+
$jobData['config'] = $config->getArray();
174+
}
175+
176+
$pheanstalk = new Pheanstalk($settings['host']);
177+
$pheanstalk->useTube($settings['queue']);
178+
$pheanstalk->put(
179+
json_encode($jobData),
180+
PheanstalkInterface::DEFAULT_PRIORITY,
181+
PheanstalkInterface::DEFAULT_DELAY,
182+
$config->get('phpci.worker.job_timeout', 600)
183+
);
184+
} catch (\Exception $ex) {
185+
$this->queueError = true;
169186
}
170-
171-
$pheanstalk = new Pheanstalk($settings['host']);
172-
$pheanstalk->useTube($settings['queue']);
173-
$pheanstalk->put(
174-
json_encode($jobData),
175-
PheanstalkInterface::DEFAULT_PRIORITY,
176-
PheanstalkInterface::DEFAULT_DELAY,
177-
$config->get('phpci.worker.job_timeout', 600)
178-
);
179187
}
180188
}
181189
}

PHPCI/View/layout.phtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@
292292

293293
<!-- Main content -->
294294
<section class="content">
295+
<?php
296+
if (!empty($_SESSION['global_error'])) {
297+
$message = $_SESSION['global_error'];
298+
unset($_SESSION['global_error']);
299+
print '<div class="alert alert-danger">' . $message . '</div>';
300+
}
301+
?>
302+
295303
<?php print $content; ?>
296304
</section><!-- /.content -->
297305
</aside><!-- /.content-wrapper -->

0 commit comments

Comments
 (0)