From c50f04a2802443fc601d0f65791f2e46892c21f9 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 8 Oct 2017 21:41:32 +0700 Subject: [PATCH] Fixed schedule build command. Issue #125. --- src/PHPCensor/Command/ScheduleBuildCommand.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/PHPCensor/Command/ScheduleBuildCommand.php b/src/PHPCensor/Command/ScheduleBuildCommand.php index 82090ed2..aeeadee7 100644 --- a/src/PHPCensor/Command/ScheduleBuildCommand.php +++ b/src/PHPCensor/Command/ScheduleBuildCommand.php @@ -45,7 +45,7 @@ class ScheduleBuildCommand extends Command $this->projectStore = $projectStore; $this->buildService = $buildService; - $this->buildStore = $buildStore; + $this->buildStore = $buildStore; } /** @@ -64,21 +64,21 @@ class ScheduleBuildCommand extends Command */ public function execute(InputInterface $input, OutputInterface $output) { - $sinceDays = $input->getArgument('days'); - $date = new \DateTime('now'); + $sinceDays = $input->getArgument('days'); + $date = new \DateTime('now'); $difference = new \DateInterval("P{$sinceDays}D"); $date->sub($difference); $projects = $this->projectStore->getAll()['items']; /** @var Project $project */ foreach ($projects as $project) { - $latestBuild = $this->buildStore->getLatestBuilds($project->getId(), 1); - if ($latestBuild['count'] > 0) { + if ($latestBuild) { /** @var Build $build */ - $build = $latestBuild['items'][0]; - if ((int)$build->getStatus() === 1 || (int)$build->getStatus() === 0) { + $build = $latestBuild[0]; + $status = (integer)$build->getStatus(); + if ($status === Build::STATUS_RUNNING || $status === Build::STATUS_PENDING) { // If it's running or just created, we don't want to reschedule already. continue; } @@ -87,6 +87,7 @@ class ScheduleBuildCommand extends Command continue; } } + try { $this->buildService->createBuild($project, null); $output->writeln("Build Created for {$project->getTitle()}");