Index: src/applications/harbormaster/engine/HarbormasterBuildEngine.php =================================================================== --- src/applications/harbormaster/engine/HarbormasterBuildEngine.php +++ src/applications/harbormaster/engine/HarbormasterBuildEngine.php @@ -72,49 +72,24 @@ } private function updateBuild(HarbormasterBuild $build) { - - $should_stop = false; - $should_resume = false; - $should_restart = false; - foreach ($build->getUnprocessedCommands() as $command) { - switch ($command->getCommand()) { - case HarbormasterBuildCommand::COMMAND_STOP: - $should_stop = true; - $should_resume = false; - break; - case HarbormasterBuildCommand::COMMAND_RESUME: - $should_resume = true; - $should_stop = false; - break; - case HarbormasterBuildCommand::COMMAND_RESTART: - $should_restart = true; - $should_resume = true; - $should_stop = false; - break; - } - } - if (($build->getBuildStatus() == HarbormasterBuild::STATUS_PENDING) || - ($should_restart)) { + ($build->isRestarting())) { $this->destroyBuildTargets($build); $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); $build->save(); } - if ($should_resume) { + if ($build->isResuming()) { $build->setBuildStatus(HarbormasterBuild::STATUS_BUILDING); $build->save(); } - if ($should_stop && !$build->isComplete()) { + if ($build->isStopping() && !$build->isComplete()) { $build->setBuildStatus(HarbormasterBuild::STATUS_STOPPED); $build->save(); } - foreach ($build->getUnprocessedCommands() as $command) { - $command->delete(); - } - $build->attachUnprocessedCommands(array()); + $build->deleteUnprocessedCommands(); if ($build->getBuildStatus() == HarbormasterBuild::STATUS_BUILDING) { $this->updateBuildSteps($build); Index: src/applications/harbormaster/storage/build/HarbormasterBuild.php =================================================================== --- src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -56,6 +56,15 @@ ->setBuildStatus(self::STATUS_INACTIVE); } + public function delete() { + $this->openTransaction(); + $this->deleteUnprocessedCommands(); + $result = parent::delete(); + $this->saveTransaction(); + + return $result; + } + public function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, @@ -212,7 +221,7 @@ /* -( Build Commands )----------------------------------------------------- */ - public function getUnprocessedCommands() { + private function getUnprocessedCommands() { return $this->assertAttached($this->unprocessedCommands); } @@ -221,15 +230,6 @@ return $this; } - public function hasWaitingCommand($command_name) { - foreach ($this->getUnprocessedCommands() as $command_object) { - if ($command_object->getCommand() == $command_name) { - return true; - } - } - return false; - } - public function canRestartBuild() { return !$this->isRestarting(); } @@ -246,15 +246,62 @@ } public function isStopping() { - return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_STOP); + $is_stopping = false; + foreach ($this->getUnprocessedCommands() as $command_object) { + $command = $command_object->getCommand(); + switch ($command) { + case HarbormasterBuildCommand::COMMAND_STOP: + $is_stopping = true; + break; + case HarbormasterBuildCommand::COMMAND_RESUME: + case HarbormasterBuildCommand::COMMAND_RESTART: + $is_stopping = false; + break; + } + } + + return $is_stopping; } public function isResuming() { - return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_RESUME); + $is_resuming = false; + foreach ($this->getUnprocessedCommands() as $command_object) { + $command = $command_object->getCommand(); + switch ($command) { + case HarbormasterBuildCommand::COMMAND_RESTART: + case HarbormasterBuildCommand::COMMAND_RESUME: + $is_resuming = true; + break; + case HarbormasterBuildCommand::COMMAND_STOP: + $is_resuming = false; + break; + } + } + + return $is_resuming; } public function isRestarting() { - return $this->hasWaitingCommand(HarbormasterBuildCommand::COMMAND_RESTART); + $is_restarting = false; + foreach ($this->getUnprocessedCommands() as $command_object) { + $command = $command_object->getCommand(); + switch ($command) { + case HarbormasterBuildCommand::COMMAND_RESTART: + $is_restarting = true; + break; + } + } + + return $is_restarting; + } + + public function deleteUnprocessedCommands() { + foreach ($this->getUnprocessedCommands() as $key => $command_object) { + $command_object->delete(); + unset($this->unprocessedCommands[$key]); + } + + return $this; }