diff --git a/deploy.ini b/deploy.ini index ed5b16c..15c85f7 100644 --- a/deploy.ini +++ b/deploy.ini @@ -23,3 +23,4 @@ passive = true [quickmode] staging = ftp://example:password@staging-example.com:21/path/to/installation production = ftp://example:password@production-example.com:21/path/to/installation + \ No newline at end of file diff --git a/phploy b/phploy index 171df08..775ce8e 100644 --- a/phploy +++ b/phploy @@ -9,7 +9,7 @@ * @author Bruno De Barros * @link http://wplancer.com * @licence MIT Licence - * @version 1.3.5 + * @version 1.4.0 */ /** @@ -55,7 +55,7 @@ class PHPloy /** * @var array $longopts */ - protected $longopts = array('list', 'rollback::', 'server:'); + protected $longopts = array('list', 'rollback::', 'server:', 'sync::'); /** * @var bool|resource $connection @@ -92,6 +92,11 @@ class PHPloy */ protected $listFiles = false; + /** + * @var bool $listFiles + */ + protected $sync = false; + /** * Constructor */ @@ -122,6 +127,10 @@ class PHPloy $this->server = isset($options['s']) ? $options['s'] : $options['server']; } + if (isset($options['sync'])) { + $this->sync = empty($options['sync']) ? 'sync' : $options['sync']; + } + if (isset($options['rollback'])) { $this->revision = ($options['rollback'] == '') ? 'HEAD^' : $options['rollback']; } else { @@ -310,6 +319,12 @@ class PHPloy if ($this->server != '' && $this->server != $name) continue; $this->connect($server); + + if( $this->sync ) { + $this->setRevision(); + continue; + } + $files = $this->compare($revision); if ($this->listFiles === true) { @@ -384,7 +399,7 @@ class PHPloy $pathsThatExist = array(); - $connection = ftp_connect($server['host'], $server['port']); + $connection = @ftp_connect($server['host'], $server['port']); if ($connection) { if (! ftp_login($connection, $server['user'], $server['pass'])) { @@ -393,7 +408,7 @@ class PHPloy ftp_pasv($connection, $server['passive']); - if (ftp_chdir($connection, $server['path'])) { + if (@ftp_chdir($connection, $server['path'])) { $this->connection = $connection; $this->output("\r\n+ ---------- ☻ ---------- +"); } else { @@ -435,7 +450,7 @@ class PHPloy if (! isset($pathsThatExist[$path])) { $origin = ftp_pwd($this->connection); - if (! ftp_chdir($this->connection, $path)) { + if (! @ftp_chdir($this->connection, $path)) { if (! ftp_mkdir($this->connection, $path)) { $ret = false; @@ -451,7 +466,7 @@ class PHPloy $pathsThatExist[$path] = true; } - ftp_chdir($this->connection, $origin); + @ftp_chdir($this->connection, $origin); } } @@ -494,19 +509,9 @@ class PHPloy } } - if (count($filesToUpload) > 0 or count($filesToDelete) > 0) { - $temp = tempnam(sys_get_temp_dir(), 'gitRevision'); - $command = "git --git-dir='$this->repo/.git' --work-tree='$this->repo\' rev-parse HEAD"; - exec(escapeshellcmd($command), $locRev); - - file_put_contents($temp, $locRev); - - if (ftp_put($this->connection, $this->dotRevision, $temp, FTP_BINARY)) { - unlink($temp); - $this->output("+ ---------- ✓ ---------- +\r\n"); - } else { - throw new Exception("Oh Snap: Could not update the revision file on server."); - } + if (count($filesToUpload) > 0 or count($filesToDelete) > 0) { + // Set revision on server + $this->setRevision(); } else { $this->output("No files to upload."); } @@ -520,6 +525,31 @@ class PHPloy } } + /** + * Sets version hash on the server. + * + */ + protected function setRevision() + { + if ( $this->sync == 'sync' or $this->sync == false ) { + $command = "git --git-dir='$this->repo/.git' --work-tree='$this->repo\' rev-parse HEAD"; + exec(escapeshellcmd($command), $locRev); + } else { + $locRev = $this->sync; + } + + $temp = tempnam(sys_get_temp_dir(), 'gitRevision'); + file_put_contents($temp, $locRev); + + if (ftp_put($this->connection, $this->dotRevision, $temp, FTP_BINARY)) { + unlink($temp); + if( $this->sync ) $this->output("⟲ revision synced"); + $this->output("+ ---------- ✓ ---------- +\r\n"); + } else { + throw new Exception("Oh Snap: Could not update the revision file on server."); + } + } + /** * Helper method to display messages on the screen. * diff --git a/readme.md b/readme.md index 35ac99a..446efdd 100644 --- a/readme.md +++ b/readme.md @@ -88,6 +88,16 @@ Or: phploy --list +## Sync Revision + +If you want to sync the `.revision` file on the server with the current revision you are currently on locally, run: + + phploy --sync + +If you want to set it to another previous commit revision, you just repecify the revision like this: + + phploy --sync="your-revision-hash-here" + ## How It Works PHPloy stores a file called `.revision` on your server. This file contains the hash of the commit that you have deployed to that server. When you run phploy, it downloads that file and compares the commit reference in it with the commit you are trying to deploy to find out which files to upload.