/** * Constructor * * @param \Fadion\Maneuver\Git $git * @param \Banago\Bridge\Bridge $bridge * @param array $server */ public function __construct(Git $git, Bridge $bridge, $server) { $this->git = $git; $this->bridge = $bridge; $this->ignoredFiles = $git->getIgnored(); $this->server = $server; }
/** * Writes latest revision to the remote * revision file * * @throws Exception if can't update revision file */ public function writeRevision() { if ($this->syncCommit) { $localRevision = $this->syncCommit; } else { $localRevision = $this->git->localRevision()[0]; } try { $this->bridge->put($localRevision, $this->revisionFile); } catch (Exception $e) { throw new Exception("Could not update the revision file on server: {$e->getMessage()}"); } }
/** * Starts the Maneuver */ public function start() { // Get server list. $connection = new Connection($this->optServer); $servers = $connection->servers(); $rollback = null; // When in rollback mode, get the commit. if ($this->mode == self::MODE_ROLLBACK) { $rollback = array('commit' => $this->optRollback); } // Init the Git object with the repo and // rollback option. $git = new Git($this->optRepo, $rollback); // There may be one or more servers, but in each // case it's build as an array. foreach ($servers as $name => $credentials) { try { $options = isset($credentials['options']) ? $credentials['options'] : array(); // Connect to the server using the selected // scheme and options. $bridge = new Bridge(http_build_url('', $credentials), $options); } catch (Exception $e) { print "Oh snap: {$e->getMessage()}"; continue; } $deploy = new Deploy($git, $bridge, $credentials); print "\r\n+ --------------- § --------------- +"; print "\n» Server: {$name}"; // Sync mode. Write revision and close the // connection, so no other files are uploaded. if ($this->mode == self::MODE_SYNC) { $deploy->setSyncCommit($this->optSyncCommit); $deploy->writeRevision(); print "\n √ Synced local revision file to remote"; print "\n+ --------------- √ --------------- +\r\n"; continue; } // Rollback to the specified commit. if ($this->mode == self::MODE_ROLLBACK) { print "\n« Rolling back "; $git->rollback(); } $dirtyRepo = $this->push($deploy); $dirtySubmodules = false; // Check if there are any submodules. if ($git->getSubModules()) { foreach ($git->getSubModules() as $submodule) { // Change repo. $git->setRepo($submodule['path']); // Set submodule name. $deploy->setIsSubmodule($submodule['name']); print "\n» Submodule: " . $submodule['name']; $dirtySubmodules = $this->push($deploy); } } // Files are uploaded or deleted, for the main // repo or submodules. if ($dirtyRepo or $dirtySubmodules) { if ($this->mode == self::MODE_DEPLOY or $this->mode == self::MODE_ROLLBACK) { // Write latest revision to server. $deploy->writeRevision(); } } else { print "\n» Nothing to do."; } print "\n+ --------------- √ --------------- +\r\n"; // On rollback mode, revert to master. if ($this->mode == self::MODE_ROLLBACK) { $git->revertToMaster(); } } }