Esempio n. 1
0
 /**
  * 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();
         }
     }
 }
Esempio n. 2
0
 /**
  * Handles the upload and delete processes
  *
  * @param \Fadion\Maneuver\Deploy $deploy
  * @return bool
  */
 public function push($deploy)
 {
     // Compare local revision to the remote one, to
     // build files to upload and delete.
     $message = $deploy->compare();
     print $message;
     print "\n+ --------------- + --------------- +";
     $dirty = false;
     $filesToUpload = $deploy->getFilesToUpload();
     $filesToDelete = $deploy->getFilesToDelete();
     if ($filesToUpload) {
         foreach ($filesToUpload as $file) {
             // On list mode, just print the file.
             if ($this->mode == self::MODE_LIST) {
                 print "\n√ {$file} will be uploaded";
                 continue;
             }
             $output = $deploy->upload($file);
             // An upload procedure may have more than one
             // output message (uploaded file, created dir, etc).
             foreach ($output as $message) {
                 print "\n" . $message;
             }
         }
     }
     if ($filesToDelete) {
         foreach ($filesToDelete as $file) {
             // On list mode, just print the file.
             if ($this->mode == self::MODE_LIST) {
                 print "\n× {$file} will be removed";
                 continue;
             }
             print "\n" . $deploy->delete($file);
         }
     }
     // Files were uploaded or deleted, so mark
     // it as dirty.
     if ($filesToUpload or $filesToDelete) {
         $dirty = true;
     }
     return $dirty;
 }