コード例 #1
0
ファイル: PHPloy.php プロジェクト: banago/phploy
 /**
  * Deploy (or list) changed files.
  */
 public function deploy()
 {
     if ($this->listFiles) {
         $this->cli->lightYellow('LIST mode: No remote files will be modified.');
     }
     $this->checkSubmodules($this->repo);
     $this->prepareServers();
     // Exit with an error if the specified server does not exist in phploy.ini
     if ($this->server != '' && !array_key_exists($this->server, $this->servers)) {
         throw new \Exception("The server \"{$this->server}\" is not defined in {$this->iniFilename}.");
     }
     // Loop through all the servers in phploy.ini
     foreach ($this->servers as $name => $server) {
         $this->currentlyDeploying = $name;
         // If a server is specified, it's deployed only to that
         if ($this->server != '' && $this->server != $name) {
             continue;
         } elseif ($this->server == '' && $this->defaultServer == true && $name != 'default' && $this->deployAll == false) {
             continue;
         }
         $connection = new \Banago\PHPloy\Connection($server);
         $this->connection = $connection->server;
         if ($this->sync) {
             $this->dotRevision = $this->dotRevisionFilename;
             $this->setRevision();
             continue;
         }
         $files = $this->compare($this->revision);
         $this->cli->bold()->white()->out("\r\nSERVER: " . $name);
         if ($this->listFiles) {
             $this->listFiles($files[$this->currentlyDeploying]);
         } else {
             // Pre Deploy
             if (isset($this->preDeploy[$name]) && count($this->preDeploy[$name]) > 0) {
                 $this->preDeploy($this->preDeploy[$name]);
             }
             // Pre Deploy Remote
             if (isset($this->preDeployRemote[$name]) && count($this->preDeployRemote[$name]) > 0) {
                 $this->preDeployRemote($this->preDeployRemote[$name]);
             }
             // Push repository
             $this->push($files[$this->currentlyDeploying]);
             // Push Submodules
             if ($this->scanSubmodules && count($this->submodules) > 0) {
                 foreach ($this->submodules as $submodule) {
                     $this->repo = $submodule['path'];
                     $this->currentSubmoduleName = $submodule['name'];
                     $this->cli->gray()->out("\r\nSUBMODULE: " . $this->currentSubmoduleName);
                     $files = $this->compare($submodule['revision']);
                     if ($this->listFiles === true) {
                         $this->listFiles($files[$this->currentlyDeploying]);
                     } else {
                         $this->push($files[$this->currentlyDeploying], $submodule['revision']);
                     }
                 }
                 // We've finished deploying submodules, reset settings for the next server
                 $this->repo = $this->mainRepo;
                 $this->currentSubmoduleName = '';
             }
             // Copy
             if (isset($this->copyDirs[$name]) && count($this->copyDirs[$name]) > 0) {
                 $this->copy($this->copyDirs[$name]);
             }
             // Purge
             if (isset($this->purgeDirs[$name]) && count($this->purgeDirs[$name]) > 0) {
                 $this->purge($this->purgeDirs[$name]);
             }
             // Post Deploy
             if (isset($this->postDeploy[$name]) && count($this->postDeploy[$name]) > 0) {
                 $this->postDeploy($this->postDeploy[$name]);
             }
             // Post Deploy Remote
             if (isset($this->postDeployRemote[$name]) && count($this->postDeployRemote[$name]) > 0) {
                 $this->postDeployRemote($this->postDeployRemote[$name]);
             }
         }
         // Done
         if (!$this->listFiles) {
             $this->cli->bold()->lightGreen("\r\n|---------------[ " . $this->humanFilesize($this->deploymentSize) . ' Deployed ]---------------|');
             $this->deploymentSize = 0;
         }
     }
 }