| @@ -18,9 +18,6 @@ | ||
| 18 | 18 | |
| 19 | 19 | /** | 
| 20 | 20 | * @param string $command The command | 
| 21 | - * @param boolean $throwException If true, an Exception will be thrown on a nonzero error code | |
| 22 | - * @param boolean $returnOutput If true, output will be captured | |
| 23 | - * @param boolean $inputContent Content for STDIN. Otherwise the parent script's STDIN is used | |
| 24 | 21 | * @return A map containing 'return', 'output', and 'error' | 
| 25 | 22 | */ | 
| 26 | 23 |  	function execLocal($command, $options = array()) { | 
| @@ -35,7 +35,9 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 |  	function createLocal($command, $options) { | 
| 37 | 37 | $options = array_merge($this->defaultOptions, $options); | 
| 38 | - if(is_array($command)) $command = $this->commandArrayToString($command); | |
| 38 | +		if(is_array($command)) { | |
| 39 | + $command = $this->commandArrayToString($command); | |
| 40 | + } | |
| 39 | 41 | |
| 40 | 42 | return new Process($command, $options); | 
| 41 | 43 | } | 
| @@ -81,8 +83,11 @@ discard block | ||
| 81 | 83 | |
| 82 | 84 | // Modify command for remote execution, if necessary. | 
| 83 | 85 |  		if($this->remoteServer) { | 
| 84 | - if(!empty($options['outputFile']) || !empty($options['outputStream'])) $ssh = "ssh -T "; | |
| 85 | - else $ssh = "ssh -t "; | |
| 86 | +			if(!empty($options['outputFile']) || !empty($options['outputStream'])) { | |
| 87 | + $ssh = "ssh -T "; | |
| 88 | +			} else { | |
| 89 | + $ssh = "ssh -t "; | |
| 90 | + } | |
| 86 | 91 | $command = $ssh . escapeshellarg($this->remoteServer) . ' ' . escapeshellarg($this->command); | 
| 87 | 92 |  		} else { | 
| 88 | 93 | $command = $this->command; | 
| @@ -96,7 +101,9 @@ discard block | ||
| 96 | 101 | ); | 
| 97 | 102 | |
| 98 | 103 | // Alternatives | 
| 99 | -		if($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r'); | |
| 104 | +		if($options['inputContent'] || $options['inputStream']) { | |
| 105 | +			$pipeSpec[0] = array('pipe', 'r'); | |
| 106 | + } | |
| 100 | 107 | |
| 101 | 108 |  		if($options['outputFile']) { | 
| 102 | 109 |  			$pipeSpec[1] = array('file', | 
| @@ -114,7 +121,9 @@ discard block | ||
| 114 | 121 | fwrite($pipes[0], $content); | 
| 115 | 122 | } | 
| 116 | 123 | } | 
| 117 | - if(isset($pipes[0])) fclose($pipes[0]); | |
| 124 | +		if(isset($pipes[0])) { | |
| 125 | + fclose($pipes[0]); | |
| 126 | + } | |
| 118 | 127 | |
| 119 | 128 | $result = array(); | 
| 120 | 129 | |
| @@ -35,7 +35,7 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 |  	function createLocal($command, $options) { | 
| 37 | 37 | $options = array_merge($this->defaultOptions, $options); | 
| 38 | - if(is_array($command)) $command = $this->commandArrayToString($command); | |
| 38 | + if (is_array($command)) $command = $this->commandArrayToString($command); | |
| 39 | 39 | |
| 40 | 40 | return new Process($command, $options); | 
| 41 | 41 | } | 
| @@ -53,8 +53,8 @@ discard block | ||
| 53 | 53 | */ | 
| 54 | 54 |  	function commandArrayToString($command) { | 
| 55 | 55 | $string = escapeshellcmd(array_shift($command)); | 
| 56 | -		foreach($command as $arg) { | |
| 57 | - $string .= ' ' . escapeshellarg($arg); | |
| 56 | +		foreach ($command as $arg) { | |
| 57 | + $string .= ' '.escapeshellarg($arg); | |
| 58 | 58 | } | 
| 59 | 59 | return $string; | 
| 60 | 60 | } | 
| @@ -80,13 +80,13 @@ discard block | ||
| 80 | 80 | $options = array_merge($this->options, $options); | 
| 81 | 81 | |
| 82 | 82 | // Modify command for remote execution, if necessary. | 
| 83 | -		if($this->remoteServer) { | |
| 84 | - if(!empty($options['outputFile']) || !empty($options['outputStream'])) $ssh = "ssh -T "; | |
| 83 | +		if ($this->remoteServer) { | |
| 84 | + if (!empty($options['outputFile']) || !empty($options['outputStream'])) $ssh = "ssh -T "; | |
| 85 | 85 | else $ssh = "ssh -t "; | 
| 86 | 86 |  			if (!empty($options['identity'])) { | 
| 87 | - $ssh .= '-i ' . escapeshellarg($options['identity']) . ' '; | |
| 87 | + $ssh .= '-i '.escapeshellarg($options['identity']).' '; | |
| 88 | 88 | } | 
| 89 | - $command = $ssh . escapeshellarg($this->remoteServer) . ' ' . escapeshellarg($this->command); | |
| 89 | + $command = $ssh.escapeshellarg($this->remoteServer).' '.escapeshellarg($this->command); | |
| 90 | 90 |  		} else { | 
| 91 | 91 | $command = $this->command; | 
| 92 | 92 | } | 
| @@ -99,9 +99,9 @@ discard block | ||
| 99 | 99 | ); | 
| 100 | 100 | |
| 101 | 101 | // Alternatives | 
| 102 | -		if($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r'); | |
| 102 | +		if ($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r'); | |
| 103 | 103 | |
| 104 | -		if($options['outputFile']) { | |
| 104 | +		if ($options['outputFile']) { | |
| 105 | 105 |  			$pipeSpec[1] = array('file', | 
| 106 | 106 | $options['outputFile'], | 
| 107 | 107 | $options['outputFileAppend'] ? 'a' : 'w'); | 
| @@ -109,24 +109,24 @@ discard block | ||
| 109 | 109 | |
| 110 | 110 | $process = proc_open($command, $pipeSpec, $pipes); | 
| 111 | 111 | |
| 112 | -		if($options['inputContent']) { | |
| 112 | +		if ($options['inputContent']) { | |
| 113 | 113 | fwrite($pipes[0], $options['inputContent']); | 
| 114 | 114 | |
| 115 | -		} else if($options['inputStream']) { | |
| 116 | -			while($content = fread($options['inputStream'], 8192)) { | |
| 115 | +		} else if ($options['inputStream']) { | |
| 116 | +			while ($content = fread($options['inputStream'], 8192)) { | |
| 117 | 117 | fwrite($pipes[0], $content); | 
| 118 | 118 | } | 
| 119 | 119 | } | 
| 120 | - if(isset($pipes[0])) fclose($pipes[0]); | |
| 120 | + if (isset($pipes[0])) fclose($pipes[0]); | |
| 121 | 121 | |
| 122 | 122 | $result = array(); | 
| 123 | 123 | |
| 124 | -		if(isset($pipes[1])) { | |
| 124 | +		if (isset($pipes[1])) { | |
| 125 | 125 | // If a stream was provided, then pipe all the content | 
| 126 | 126 | // Doing it this way rather than passing outputStream to $pipeSpec | 
| 127 | 127 | // Means that streams as well as simple FDs can be used | 
| 128 | -			if($options['outputStream']) { | |
| 129 | -				while($content = fread($pipes[1], 8192)) { | |
| 128 | +			if ($options['outputStream']) { | |
| 129 | +				while ($content = fread($pipes[1], 8192)) { | |
| 130 | 130 | fwrite($options['outputStream'], $content); | 
| 131 | 131 | } | 
| 132 | 132 | |
| @@ -136,14 +136,14 @@ discard block | ||
| 136 | 136 | } | 
| 137 | 137 | fclose($pipes[1]); | 
| 138 | 138 | } | 
| 139 | -		if(isset($pipes[2])) { | |
| 139 | +		if (isset($pipes[2])) { | |
| 140 | 140 | $result['error'] = stream_get_contents($pipes[2]); | 
| 141 | 141 | fclose($pipes[2]); | 
| 142 | 142 | } | 
| 143 | 143 | |
| 144 | 144 | $result['return'] = proc_close($process); | 
| 145 | 145 | |
| 146 | -		if($options['throwException'] && $result['return'] != 0)	{ | |
| 146 | +		if ($options['throwException'] && $result['return'] != 0) { | |
| 147 | 147 |  			throw new Exception("Command: $command\nExecution failed: returned {$result['return']}.\n" | 
| 148 | 148 |  				. (empty($result['output']) ? "" : "Output:\n{$result['output']}")); | 
| 149 | 149 | } | 
| @@ -22,6 +22,10 @@ discard block | ||
| 22 | 22 |  	function isLocal() { | 
| 23 | 23 | return $this->server == null; | 
| 24 | 24 | } | 
| 25 | + | |
| 26 | + /** | |
| 27 | + * @return string|null | |
| 28 | + */ | |
| 25 | 29 |  	function getPath() { | 
| 26 | 30 | return $this->path; | 
| 27 | 31 | } | 
| @@ -52,7 +56,6 @@ discard block | ||
| 52 | 56 | |
| 53 | 57 | /** | 
| 54 | 58 | * Upload a file to the given destination on the server | 
| 55 | - * @param string $file The file to upload | |
| 56 | 59 | * @param string $dest The remote filename/dir to upload to | 
| 57 | 60 | */ | 
| 58 | 61 |  	function upload($source, $dest) { | 
| @@ -12,8 +12,8 @@ discard block | ||
| 12 | 12 |  	function __construct($path, $executor) { | 
| 13 | 13 | $this->executor = $executor; | 
| 14 | 14 | |
| 15 | -		if(strpos($path,':') !== false) { | |
| 16 | -			list($this->server,$this->path) = explode(':', $path, 2); | |
| 15 | +		if (strpos($path, ':') !== false) { | |
| 16 | +			list($this->server, $this->path) = explode(':', $path, 2); | |
| 17 | 17 |  		} else { | 
| 18 | 18 | $this->server = null; | 
| 19 | 19 | $this->path = $path; | 
| @@ -47,7 +47,7 @@ discard block | ||
| 47 | 47 | * @return Process | 
| 48 | 48 | */ | 
| 49 | 49 |  	function createProcess($command, $options = array()) { | 
| 50 | -		if($this->server) { | |
| 50 | +		if ($this->server) { | |
| 51 | 51 |  			if ($this->identity && !isset($options['identity'])) { | 
| 52 | 52 | $options['identity'] = $this->identity; | 
| 53 | 53 | } | 
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | * @param string $dest The remote filename/dir to upload to | 
| 64 | 64 | */ | 
| 65 | 65 |  	function upload($source, $dest) { | 
| 66 | -		if($this->server) { | |
| 66 | +		if ($this->server) { | |
| 67 | 67 |  			$this->executor->execLocal(array("scp", $source, "$this->server:$dest")); | 
| 68 | 68 |  		} else { | 
| 69 | 69 |  			$this->executor->execLocal(array("cp", $source, $dest)); | 
| @@ -76,7 +76,7 @@ discard block | ||
| 76 | 76 | * @param string $dest The remote filename/dir to upload to | 
| 77 | 77 | */ | 
| 78 | 78 |  	function uploadContent($content, $dest) { | 
| 79 | -		$this->exec("echo " . escapeshellarg($content) . " > " . escapeshellarg($dest)); | |
| 79 | +		$this->exec("echo ".escapeshellarg($content)." > ".escapeshellarg($dest)); | |
| 80 | 80 | } | 
| 81 | 81 | |
| 82 | 82 | /** | 
| @@ -85,7 +85,7 @@ discard block | ||
| 85 | 85 | * @param string $dest The local filename/dir to download to | 
| 86 | 86 | */ | 
| 87 | 87 |  	function download($source, $dest) { | 
| 88 | -		if($this->server) { | |
| 88 | +		if ($this->server) { | |
| 89 | 89 |  			$this->executor->execLocal(array("scp", "$this->server:$source", $dest)); | 
| 90 | 90 |  		} else { | 
| 91 | 91 |  			$this->executor->execLocal(array("cp", $file, $dest)); | 
| @@ -98,11 +98,11 @@ discard block | ||
| 98 | 98 | * @return boolean | 
| 99 | 99 | */ | 
| 100 | 100 |  	function exists($file = null) { | 
| 101 | - if(!$file) $file = $this->path; | |
| 102 | - if($file == '@self') return true; | |
| 101 | + if (!$file) $file = $this->path; | |
| 102 | + if ($file == '@self') return true; | |
| 103 | 103 | |
| 104 | -		if($this->server) { | |
| 105 | -			$result = $this->exec("if [ -e " . escapeshellarg($file) . " ]; then echo yes; fi"); | |
| 104 | +		if ($this->server) { | |
| 105 | +			$result = $this->exec("if [ -e ".escapeshellarg($file)." ]; then echo yes; fi"); | |
| 106 | 106 | return (trim($result['output']) == 'yes'); | 
| 107 | 107 | |
| 108 | 108 |  		} else { | 
| @@ -114,8 +114,8 @@ discard block | ||
| 114 | 114 | * Create the given file with the given content | 
| 115 | 115 | */ | 
| 116 | 116 |  	function writeFile($file, $content) { | 
| 117 | -		if($this->server) { | |
| 118 | -			$this->exec("echo " . escapeshellarg($content) . " > " . escapeshellarg($file)); | |
| 117 | +		if ($this->server) { | |
| 118 | +			$this->exec("echo ".escapeshellarg($content)." > ".escapeshellarg($file)); | |
| 119 | 119 | |
| 120 | 120 |  		} else { | 
| 121 | 121 | file_put_contents($file, $content); | 
| @@ -128,7 +128,7 @@ discard block | ||
| 128 | 128 | * @param string $file The file to remove | 
| 129 | 129 | */ | 
| 130 | 130 |  	function unlink($file) { | 
| 131 | -		if(!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'"); | |
| 131 | +		if (!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'"); | |
| 132 | 132 |  		$this->exec(array('rm', '-rf', $file)); | 
| 133 | 133 | return true; | 
| 134 | 134 | } | 
| @@ -98,8 +98,12 @@ discard block | ||
| 98 | 98 | * @return boolean | 
| 99 | 99 | */ | 
| 100 | 100 |  	function exists($file = null) { | 
| 101 | - if(!$file) $file = $this->path; | |
| 102 | - if($file == '@self') return true; | |
| 101 | +		if(!$file) { | |
| 102 | + $file = $this->path; | |
| 103 | + } | |
| 104 | +		if($file == '@self') { | |
| 105 | + return true; | |
| 106 | + } | |
| 103 | 107 | |
| 104 | 108 |  		if($this->server) { | 
| 105 | 109 |  			$result = $this->exec("if [ -e " . escapeshellarg($file) . " ]; then echo yes; fi"); | 
| @@ -128,7 +132,9 @@ discard block | ||
| 128 | 132 | * @param string $file The file to remove | 
| 129 | 133 | */ | 
| 130 | 134 |  	function unlink($file) { | 
| 131 | -		if(!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'"); | |
| 135 | +		if(!$file || $file == '/' || $file == '.') { | |
| 136 | +			throw new Exception("Can't unlink file '$file'"); | |
| 137 | + } | |
| 132 | 138 |  		$this->exec(array('rm', '-rf', $file)); | 
| 133 | 139 | return true; | 
| 134 | 140 | } | 
| @@ -234,6 +234,11 @@ discard block | ||
| 234 | 234 | return true; | 
| 235 | 235 | } | 
| 236 | 236 | |
| 237 | + /** | |
| 238 | + * @param Webroot $webroot | |
| 239 | + * @param SSPakFile $sspak | |
| 240 | + * @param string $filename | |
| 241 | + */ | |
| 237 | 242 |  	function getassets($webroot, $assetsPath, $sspak, $filename) { | 
| 238 | 243 | $assetsParentArg = escapeshellarg(dirname($assetsPath)); | 
| 239 | 244 | $assetsBaseArg = escapeshellarg(basename($assetsPath)); | 
| @@ -242,6 +247,11 @@ discard block | ||
| 242 | 247 | $sspak->writeFileFromProcess($filename, $process); | 
| 243 | 248 | } | 
| 244 | 249 | |
| 250 | + /** | |
| 251 | + * @param Webroot $webroot | |
| 252 | + * @param SSPakFile $sspak | |
| 253 | + * @param string $gitRemoteFile | |
| 254 | + */ | |
| 245 | 255 |  	function getgitremote($webroot, $sspak, $gitRemoteFile) { | 
| 246 | 256 | // Only do anything if we're copying from a git checkout | 
| 247 | 257 | $gitRepo = $webroot->getPath() .'/.git'; | 
| @@ -67,13 +67,19 @@ discard block | ||
| 67 | 67 |  		foreach($this->getActions() as $action => $info) { | 
| 68 | 68 | echo "sspak $action"; | 
| 69 | 69 |  			if(!empty($info['unnamedArgs'])) { | 
| 70 | - foreach($info['unnamedArgs'] as $arg) echo " ($arg)"; | |
| 70 | +				foreach($info['unnamedArgs'] as $arg) { | |
| 71 | + echo " ($arg)"; | |
| 72 | + } | |
| 71 | 73 | } | 
| 72 | 74 |  			if(!empty($info['namedFlags'])) { | 
| 73 | - foreach($info['namedFlags'] as $arg) echo " (--$arg)"; | |
| 75 | +				foreach($info['namedFlags'] as $arg) { | |
| 76 | + echo " (--$arg)"; | |
| 77 | + } | |
| 74 | 78 | } | 
| 75 | 79 |  			if(!empty($info['namedArgs'])) { | 
| 76 | - foreach($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\""; | |
| 80 | +				foreach($info['namedArgs'] as $arg) { | |
| 81 | + echo " --$arg=\"$arg value\""; | |
| 82 | + } | |
| 77 | 83 | } | 
| 78 | 84 |  			echo "\n  {$info['description']}\n\n"; | 
| 79 | 85 | } | 
| @@ -126,7 +132,9 @@ discard block | ||
| 126 | 132 | $sspak = new SSPakFile($file, $executor); | 
| 127 | 133 | |
| 128 | 134 | // Validation | 
| 129 | -		if(!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); | |
| 135 | +		if(!$sspak->exists()) { | |
| 136 | +			throw new Exception("File '$file' doesn't exist."); | |
| 137 | + } | |
| 130 | 138 | |
| 131 | 139 | $phar = $sspak->getPhar(); | 
| 132 | 140 | $phar->extractTo($dest); | 
| @@ -145,12 +153,17 @@ discard block | ||
| 145 | 153 | |
| 146 | 154 | $webroot = new Webroot($unnamedArgs[0], $executor); | 
| 147 | 155 | $file = $unnamedArgs[1]; | 
| 148 | - if(file_exists($file)) throw new Exception( "File '$file' already exists."); | |
| 156 | +		if(file_exists($file)) { | |
| 157 | + throw new Exception( "File '$file' already exists."); | |
| 158 | + } | |
| 149 | 159 | |
| 150 | 160 | $sspak = new SSPakFile($file, $executor); | 
| 151 | 161 | |
| 152 | - if(!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']); | |
| 153 | - else if(!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']); | |
| 162 | +		if(!empty($namedArgs['from-sudo'])) { | |
| 163 | + $webroot->setSudo($namedArgs['from-sudo']); | |
| 164 | +		} else if(!empty($namedArgs['sudo'])) { | |
| 165 | + $webroot->setSudo($namedArgs['sudo']); | |
| 166 | + } | |
| 154 | 167 | |
| 155 | 168 | // Look up which parts of the sspak are going to be saved | 
| 156 | 169 | $pakParts = $args->pakParts(); | 
| @@ -253,7 +266,9 @@ discard block | ||
| 253 | 266 | $currentBranch = trim($matches[1]); | 
| 254 | 267 |  				$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"branch.$currentBranch.remote")); | 
| 255 | 268 | $remoteName = trim($output['output']); | 
| 256 | - if(!$remoteName) $remoteName = 'origin'; | |
| 269 | +				if(!$remoteName) { | |
| 270 | + $remoteName = 'origin'; | |
| 271 | + } | |
| 257 | 272 | |
| 258 | 273 | // Default to origin | 
| 259 | 274 |  			} else { | 
| @@ -294,7 +309,9 @@ discard block | ||
| 294 | 309 | $pakParts = $args->pakParts(); | 
| 295 | 310 | |
| 296 | 311 | // Validation | 
| 297 | - if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist."); | |
| 312 | +		if(!$sspak->exists()) { | |
| 313 | + throw new Exception( "File '$file' doesn't exist."); | |
| 314 | + } | |
| 298 | 315 | |
| 299 | 316 | // Push database, if necessary | 
| 300 | 317 | $namedArgs = $args->getNamedArgs(); | 
| @@ -325,8 +342,12 @@ discard block | ||
| 325 | 342 | $pakParts = $args->pakParts(); | 
| 326 | 343 | |
| 327 | 344 | // Validation | 
| 328 | - if($webroot->exists($webroot->getPath())) throw new Exception( "Webroot '$webrootDir' already exists."); | |
| 329 | - if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist."); | |
| 345 | +		if($webroot->exists($webroot->getPath())) { | |
| 346 | + throw new Exception( "Webroot '$webrootDir' already exists."); | |
| 347 | + } | |
| 348 | +		if(!$sspak->exists()) { | |
| 349 | + throw new Exception( "File '$file' doesn't exist."); | |
| 350 | + } | |
| 330 | 351 | |
| 331 | 352 | // Create new dir | 
| 332 | 353 |  		$webroot->exec(array('mkdir', $webroot->getPath())); | 
| @@ -66,16 +66,16 @@ discard block | ||
| 66 | 66 | |
| 67 | 67 |  	function help($args) { | 
| 68 | 68 | echo "SSPak: manage SilverStripe .sspak archives.\n\nUsage:\n"; | 
| 69 | -		foreach($this->getActions() as $action => $info) { | |
| 69 | +		foreach ($this->getActions() as $action => $info) { | |
| 70 | 70 | echo "sspak $action"; | 
| 71 | -			if(!empty($info['unnamedArgs'])) { | |
| 72 | - foreach($info['unnamedArgs'] as $arg) echo " ($arg)"; | |
| 71 | +			if (!empty($info['unnamedArgs'])) { | |
| 72 | + foreach ($info['unnamedArgs'] as $arg) echo " ($arg)"; | |
| 73 | 73 | } | 
| 74 | -			if(!empty($info['namedFlags'])) { | |
| 75 | - foreach($info['namedFlags'] as $arg) echo " (--$arg)"; | |
| 74 | +			if (!empty($info['namedFlags'])) { | |
| 75 | + foreach ($info['namedFlags'] as $arg) echo " (--$arg)"; | |
| 76 | 76 | } | 
| 77 | -			if(!empty($info['namedArgs'])) { | |
| 78 | - foreach($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\""; | |
| 77 | +			if (!empty($info['namedArgs'])) { | |
| 78 | + foreach ($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\""; | |
| 79 | 79 | } | 
| 80 | 80 |  			echo "\n  {$info['description']}\n\n"; | 
| 81 | 81 | } | 
| @@ -99,13 +99,13 @@ discard block | ||
| 99 | 99 | |
| 100 | 100 | $filesystem = new FilesystemEntity(null, $executor); | 
| 101 | 101 | |
| 102 | -		if($pakParts['db']) { | |
| 102 | +		if ($pakParts['db']) { | |
| 103 | 103 | $dbPath = escapeshellarg($namedArgs['db']); | 
| 104 | 104 |  			$process = $filesystem->createProcess("cat $dbPath | gzip -c"); | 
| 105 | 105 |  			$sspak->writeFileFromProcess('database.sql.gz', $process); | 
| 106 | 106 | } | 
| 107 | 107 | |
| 108 | -		if($pakParts['assets']) { | |
| 108 | +		if ($pakParts['assets']) { | |
| 109 | 109 | $assetsParentArg = escapeshellarg(dirname($namedArgs['assets'])); | 
| 110 | 110 | $assetsBaseArg = escapeshellarg(basename($namedArgs['assets'])); | 
| 111 | 111 |  			$process = $filesystem->createProcess("cd $assetsParentArg && tar cfh - $assetsBaseArg | gzip -c"); | 
| @@ -128,7 +128,7 @@ discard block | ||
| 128 | 128 | $sspak = new SSPakFile($file, $executor); | 
| 129 | 129 | |
| 130 | 130 | // Validation | 
| 131 | -		if(!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); | |
| 131 | +		if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); | |
| 132 | 132 | |
| 133 | 133 | $phar = $sspak->getPhar(); | 
| 134 | 134 | $phar->extractTo($dest); | 
| @@ -147,16 +147,16 @@ discard block | ||
| 147 | 147 | |
| 148 | 148 | $webroot = new Webroot($unnamedArgs[0], $executor); | 
| 149 | 149 | $file = $unnamedArgs[1]; | 
| 150 | - if(file_exists($file)) throw new Exception( "File '$file' already exists."); | |
| 150 | +		if (file_exists($file)) throw new Exception("File '$file' already exists."); | |
| 151 | 151 | |
| 152 | 152 | $sspak = new SSPakFile($file, $executor); | 
| 153 | 153 | |
| 154 | -		if(!empty($namedArgs['identity'])) { | |
| 154 | +		if (!empty($namedArgs['identity'])) { | |
| 155 | 155 | // SSH private key | 
| 156 | 156 | $webroot->setSSHItentityFile($namedArgs['identity']); | 
| 157 | 157 | } | 
| 158 | - if(!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']); | |
| 159 | - else if(!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']); | |
| 158 | + if (!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']); | |
| 159 | + else if (!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']); | |
| 160 | 160 | |
| 161 | 161 | // Look up which parts of the sspak are going to be saved | 
| 162 | 162 | $pakParts = $args->pakParts(); | 
| @@ -165,7 +165,7 @@ discard block | ||
| 165 | 165 | $details = $webroot->sniff(); | 
| 166 | 166 | |
| 167 | 167 | // Create a build folder for the sspak file | 
| 168 | - $buildFolder = "/tmp/sspak-" . rand(100000,999999); | |
| 168 | + $buildFolder = "/tmp/sspak-".rand(100000, 999999); | |
| 169 | 169 |  		$webroot->exec(array('mkdir', $buildFolder)); | 
| 170 | 170 | |
| 171 | 171 | $dbFile = "$buildFolder/database.sql.gz"; | 
| @@ -176,22 +176,22 @@ discard block | ||
| 176 | 176 | $fileList = array(); | 
| 177 | 177 | |
| 178 | 178 | // Save DB | 
| 179 | -		if($pakParts['db']) { | |
| 179 | +		if ($pakParts['db']) { | |
| 180 | 180 | // Check the database type | 
| 181 | 181 | $dbFunction = 'getdb_'.$details['db_type']; | 
| 182 | -			if(!method_exists($this,$dbFunction)) { | |
| 183 | -				throw new Exception("Can't process database type '" . $details['db_type'] . "'"); | |
| 182 | +			if (!method_exists($this, $dbFunction)) { | |
| 183 | +				throw new Exception("Can't process database type '".$details['db_type']."'"); | |
| 184 | 184 | } | 
| 185 | 185 | $this->$dbFunction($webroot, $details, $sspak, basename($dbFile)); | 
| 186 | 186 | } | 
| 187 | 187 | |
| 188 | 188 | // Save Assets | 
| 189 | -		if($pakParts['assets']) { | |
| 189 | +		if ($pakParts['assets']) { | |
| 190 | 190 | $this->getassets($webroot, $details['assets_path'], $sspak, basename($assetsFile)); | 
| 191 | 191 | } | 
| 192 | 192 | |
| 193 | 193 | // Save git-remote | 
| 194 | -		if($pakParts['git-remote']) { | |
| 194 | +		if ($pakParts['git-remote']) { | |
| 195 | 195 | $this->getgitremote($webroot, $sspak, basename($gitRemoteFile)); | 
| 196 | 196 | } | 
| 197 | 197 | |
| @@ -211,7 +211,7 @@ discard block | ||
| 211 | 211 | $hostArg = ''; | 
| 212 | 212 | $portArg = ''; | 
| 213 | 213 |  		if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') { | 
| 214 | -			if (strpos($conf['db_server'], ':')!==false) { | |
| 214 | +			if (strpos($conf['db_server'], ':') !== false) { | |
| 215 | 215 | // Handle "server:port" format. | 
| 216 | 216 |  				$server = explode(':', $conf['db_server'], 2); | 
| 217 | 217 |  				$hostArg = escapeshellarg("--host=".$server[0]); | 
| @@ -250,16 +250,16 @@ discard block | ||
| 250 | 250 | |
| 251 | 251 |  	function getgitremote($webroot, $sspak, $gitRemoteFile) { | 
| 252 | 252 | // Only do anything if we're copying from a git checkout | 
| 253 | - $gitRepo = $webroot->getPath() .'/.git'; | |
| 254 | -		if($webroot->exists($gitRepo)) { | |
| 253 | + $gitRepo = $webroot->getPath().'/.git'; | |
| 254 | +		if ($webroot->exists($gitRepo)) { | |
| 255 | 255 | // Identify current branch | 
| 256 | 256 |  			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'branch')); | 
| 257 | -			if(preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1])===false) { | |
| 257 | +			if (preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1]) === false) { | |
| 258 | 258 | // If there is a current branch, use that branch's remove | 
| 259 | 259 | $currentBranch = trim($matches[1]); | 
| 260 | -				$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"branch.$currentBranch.remote")); | |
| 260 | +				$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config', '--get', "branch.$currentBranch.remote")); | |
| 261 | 261 | $remoteName = trim($output['output']); | 
| 262 | - if(!$remoteName) $remoteName = 'origin'; | |
| 262 | + if (!$remoteName) $remoteName = 'origin'; | |
| 263 | 263 | |
| 264 | 264 | // Default to origin | 
| 265 | 265 |  			} else { | 
| @@ -268,11 +268,11 @@ discard block | ||
| 268 | 268 | } | 
| 269 | 269 | |
| 270 | 270 | // Determine the URL of that remote | 
| 271 | -			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"remote.$remoteName.url")); | |
| 271 | +			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config', '--get', "remote.$remoteName.url")); | |
| 272 | 272 | $remoteURL = trim($output['output']); | 
| 273 | 273 | |
| 274 | 274 | // Determine the current SHA | 
| 275 | -			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log','-1','--format=%H')); | |
| 275 | +			$output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log', '-1', '--format=%H')); | |
| 276 | 276 | $sha = trim($output['output']); | 
| 277 | 277 | |
| 278 | 278 | $content = "remote = $remoteURL\nbranch = $currentBranch\nsha = $sha\n"; | 
| @@ -300,22 +300,22 @@ discard block | ||
| 300 | 300 | $pakParts = $args->pakParts(); | 
| 301 | 301 | |
| 302 | 302 | $namedArgs = $args->getNamedArgs(); | 
| 303 | -		if(!empty($namedArgs['identity'])) { | |
| 303 | +		if (!empty($namedArgs['identity'])) { | |
| 304 | 304 | // SSH private key | 
| 305 | 305 | $webroot->setSSHItentityFile($namedArgs['identity']); | 
| 306 | 306 | } | 
| 307 | 307 | |
| 308 | 308 | // Validation | 
| 309 | - if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist."); | |
| 309 | +		if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); | |
| 310 | 310 | |
| 311 | 311 | // Push database, if necessary | 
| 312 | 312 | $namedArgs = $args->getNamedArgs(); | 
| 313 | -		if($pakParts['db'] && $sspak->contains('database.sql.gz')) { | |
| 313 | +		if ($pakParts['db'] && $sspak->contains('database.sql.gz')) { | |
| 314 | 314 | $webroot->putdb($sspak, isset($namedArgs['drop-db'])); | 
| 315 | 315 | } | 
| 316 | 316 | |
| 317 | 317 | // Push assets, if neccessary | 
| 318 | -		if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { | |
| 318 | +		if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { | |
| 319 | 319 | $webroot->putassets($sspak); | 
| 320 | 320 | } | 
| 321 | 321 | } | 
| @@ -337,13 +337,13 @@ discard block | ||
| 337 | 337 | $pakParts = $args->pakParts(); | 
| 338 | 338 | |
| 339 | 339 | // Validation | 
| 340 | - if($webroot->exists($webroot->getPath())) throw new Exception( "Webroot '$webrootDir' already exists."); | |
| 341 | - if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist."); | |
| 340 | +		if ($webroot->exists($webroot->getPath())) throw new Exception("Webroot '$webrootDir' already exists."); | |
| 341 | +		if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); | |
| 342 | 342 | |
| 343 | 343 | // Create new dir | 
| 344 | 344 |  		$webroot->exec(array('mkdir', $webroot->getPath())); | 
| 345 | 345 | |
| 346 | -		if($sspak->contains('git-remote')) { | |
| 346 | +		if ($sspak->contains('git-remote')) { | |
| 347 | 347 | $details = $sspak->gitRemoteDetails(); | 
| 348 | 348 | $webroot->putgit($details); | 
| 349 | 349 | } | 
| @@ -352,12 +352,12 @@ discard block | ||
| 352 | 352 | |
| 353 | 353 | // Push database, if necessary | 
| 354 | 354 | $namedArgs = $args->getNamedArgs(); | 
| 355 | -		if($pakParts['db'] && $sspak->contains('database.sql.gz')) { | |
| 355 | +		if ($pakParts['db'] && $sspak->contains('database.sql.gz')) { | |
| 356 | 356 | $webroot->putdb($sspak, isset($namedArgs['drop-db'])); | 
| 357 | 357 | } | 
| 358 | 358 | |
| 359 | 359 | // Push assets, if neccessary | 
| 360 | -		if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { | |
| 360 | +		if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { | |
| 361 | 361 | $webroot->putassets($sspak); | 
| 362 | 362 | } | 
| 363 | 363 | } | 
| @@ -384,10 +384,10 @@ discard block | ||
| 384 | 384 |  		$sspakScript = str_replace('$isSelfExtracting = false;', '$isSelfExtracting = true;', $sspakScript); | 
| 385 | 385 | |
| 386 | 386 | // Load the sniffer file | 
| 387 | - $snifferFile = dirname(__FILE__) . '/sspak-sniffer.php'; | |
| 387 | + $snifferFile = dirname(__FILE__).'/sspak-sniffer.php'; | |
| 388 | 388 |  		$sspakScript = str_replace("\$snifferFileContent = '';\n", | 
| 389 | 389 | "\$snifferFileContent = '" | 
| 390 | -			. str_replace(array("\\","'"),array("\\\\", "\\'"), file_get_contents($snifferFile)) . "';\n", $sspakScript); | |
| 390 | +			. str_replace(array("\\", "'"), array("\\\\", "\\'"), file_get_contents($snifferFile))."';\n", $sspakScript); | |
| 391 | 391 | |
| 392 | 392 | file_put_contents($destFile, $sspakScript); | 
| 393 | 393 | chmod($destFile, 0775); | 
| @@ -6,6 +6,9 @@ discard block | ||
| 6 | 6 | protected $pharAlias; | 
| 7 | 7 | protected $pharPath; | 
| 8 | 8 | |
| 9 | + /** | |
| 10 | + * @param Executor $executor | |
| 11 | + */ | |
| 9 | 12 |  	function __construct($path, $executor, $pharAlias = 'sspak.phar') { | 
| 10 | 13 | parent::__construct($path, $executor); | 
| 11 | 14 |  		if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); | 
| @@ -73,6 +76,7 @@ discard block | ||
| 73 | 76 | |
| 74 | 77 | /** | 
| 75 | 78 | * Returns the content of a file from this sspak | 
| 79 | + * @param string $file | |
| 76 | 80 | */ | 
| 77 | 81 |  	function content($file) { | 
| 78 | 82 | return file_get_contents($this->phar[$file]); | 
| @@ -105,7 +109,7 @@ discard block | ||
| 105 | 109 | /** | 
| 106 | 110 | * Return a writeable stream corresponding to the given file within the .sspak | 
| 107 | 111 | * @param string $filename The name of the file within the .sspak | 
| 108 | - * @return Stream context | |
| 112 | + * @return resource context | |
| 109 | 113 | */ | 
| 110 | 114 |  	function writeStreamForFile($filename) { | 
| 111 | 115 |  		return fopen('phar://' . $this->pharAlias . '/' . $filename, 'w'); | 
| @@ -114,7 +118,7 @@ discard block | ||
| 114 | 118 | /** | 
| 115 | 119 | * Return a readable stream corresponding to the given file within the .sspak | 
| 116 | 120 | * @param string $filename The name of the file within the .sspak | 
| 117 | - * @return Stream context | |
| 121 | + * @return resource context | |
| 118 | 122 | */ | 
| 119 | 123 |  	function readStreamForFile($filename) { | 
| 120 | 124 | // Note: using pharAlias here doesn't work on Debian Wheezy (nor on Windows for that matter). | 
| @@ -8,7 +8,9 @@ discard block | ||
| 8 | 8 | |
| 9 | 9 |  	function __construct($path, $executor, $pharAlias = 'sspak.phar') { | 
| 10 | 10 | parent::__construct($path, $executor); | 
| 11 | -		if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); | |
| 11 | +		if(!$this->isLocal()) { | |
| 12 | +			throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); | |
| 13 | + } | |
| 12 | 14 | |
| 13 | 15 | $this->pharAlias = $pharAlias; | 
| 14 | 16 | $this->pharPath = $path; | 
| @@ -17,7 +19,9 @@ discard block | ||
| 17 | 19 |  		if(substr($path,-5) === '.phar') { | 
| 18 | 20 | $this->phar = new Phar($path, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, | 
| 19 | 21 | $this->pharAlias); | 
| 20 | - if(!file_exists($this->path)) $this->makeExecutable(); | |
| 22 | +			if(!file_exists($this->path)) { | |
| 23 | + $this->makeExecutable(); | |
| 24 | + } | |
| 21 | 25 | |
| 22 | 26 | // Non-executable Tar version | 
| 23 | 27 |  		} else { | 
| @@ -45,7 +49,9 @@ discard block | ||
| 45 | 49 |  		$this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root . "bin/sspak")); | 
| 46 | 50 | |
| 47 | 51 |  		foreach(scandir($srcRoot) as $file) { | 
| 48 | - if($file[0] == '.') continue; | |
| 52 | +			if($file[0] == '.') { | |
| 53 | + continue; | |
| 54 | + } | |
| 49 | 55 | $this->phar['src/'.$file] = file_get_contents($srcRoot . $file); | 
| 50 | 56 | } | 
| 51 | 57 | |
| @@ -139,7 +145,9 @@ discard block | ||
| 139 | 145 |  		$content = $this->content('git-remote'); | 
| 140 | 146 | $details = array(); | 
| 141 | 147 |  		foreach(explode("\n", trim($content)) as $line) { | 
| 142 | - if(!$line) continue; | |
| 148 | +			if(!$line) { | |
| 149 | + continue; | |
| 150 | + } | |
| 143 | 151 | |
| 144 | 152 |  			if(preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) { | 
| 145 | 153 | $details[$matches[1]] = $matches[2]; | 
| @@ -8,16 +8,16 @@ discard block | ||
| 8 | 8 | |
| 9 | 9 |  	function __construct($path, $executor, $pharAlias = 'sspak.phar') { | 
| 10 | 10 | parent::__construct($path, $executor); | 
| 11 | -		if(!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); | |
| 11 | +		if (!$this->isLocal()) throw new LogicException("Can't manipulate remote .sspak.phar files, only remote webroots."); | |
| 12 | 12 | |
| 13 | 13 | $this->pharAlias = $pharAlias; | 
| 14 | 14 | $this->pharPath = $path; | 
| 15 | 15 | |
| 16 | 16 | // Executable Phar version | 
| 17 | -		if(substr($path,-5) === '.phar') { | |
| 17 | +		if (substr($path, -5) === '.phar') { | |
| 18 | 18 | $this->phar = new Phar($path, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, | 
| 19 | 19 | $this->pharAlias); | 
| 20 | - if(!file_exists($this->path)) $this->makeExecutable(); | |
| 20 | + if (!file_exists($this->path)) $this->makeExecutable(); | |
| 21 | 21 | |
| 22 | 22 | // Non-executable Tar version | 
| 23 | 23 |  		} else { | 
| @@ -34,19 +34,19 @@ discard block | ||
| 34 | 34 | * Add the SSPak executable information into this SSPak file | 
| 35 | 35 | */ | 
| 36 | 36 |  	function makeExecutable() { | 
| 37 | -		if(ini_get('phar.readonly')) { | |
| 37 | +		if (ini_get('phar.readonly')) { | |
| 38 | 38 |  			throw new Exception("Please set phar.readonly to false in your php.ini."); | 
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | 41 | $root = PACKAGE_ROOT; | 
| 42 | - $srcRoot = PACKAGE_ROOT . 'src/'; | |
| 42 | + $srcRoot = PACKAGE_ROOT.'src/'; | |
| 43 | 43 | |
| 44 | 44 | // Add the bin file, but strip of the #! exec header. | 
| 45 | -		$this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root . "bin/sspak")); | |
| 45 | +		$this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root."bin/sspak")); | |
| 46 | 46 | |
| 47 | -		foreach(scandir($srcRoot) as $file) { | |
| 48 | - if($file[0] == '.') continue; | |
| 49 | - $this->phar['src/'.$file] = file_get_contents($srcRoot . $file); | |
| 47 | +		foreach (scandir($srcRoot) as $file) { | |
| 48 | + if ($file[0] == '.') continue; | |
| 49 | + $this->phar['src/'.$file] = file_get_contents($srcRoot.$file); | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 | $stub = <<<STUB | 
| @@ -88,8 +88,8 @@ discard block | ||
| 88 | 88 | // Non-executable Phars can't have content streamed into them | 
| 89 | 89 | // This means that we need to create a temp file, which is a pain, if that file happens to be a 3GB | 
| 90 | 90 | // asset dump. :-/ | 
| 91 | -		if($this->phar instanceof PharData) { | |
| 92 | - $tmpFile = '/tmp/sspak-content-' .rand(100000,999999); | |
| 91 | +		if ($this->phar instanceof PharData) { | |
| 92 | + $tmpFile = '/tmp/sspak-content-'.rand(100000, 999999); | |
| 93 | 93 |  			$process->exec(array('outputFile' => $tmpFile)); | 
| 94 | 94 | $this->phar->addFile($tmpFile, $filename); | 
| 95 | 95 | unlink($tmpFile); | 
| @@ -108,7 +108,7 @@ discard block | ||
| 108 | 108 | * @return Stream context | 
| 109 | 109 | */ | 
| 110 | 110 |  	function writeStreamForFile($filename) { | 
| 111 | -		return fopen('phar://' . $this->pharAlias . '/' . $filename, 'w'); | |
| 111 | +		return fopen('phar://'.$this->pharAlias.'/'.$filename, 'w'); | |
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | /** | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 |  	function readStreamForFile($filename) { | 
| 120 | 120 | // Note: using pharAlias here doesn't work on Debian Wheezy (nor on Windows for that matter). | 
| 121 | 121 |  		//return fopen('phar://' . $this->pharAlias . '/' . $filename, 'r'); | 
| 122 | -		return fopen('phar://' . $this->pharPath . '/' . $filename, 'r'); | |
| 122 | +		return fopen('phar://'.$this->pharPath.'/'.$filename, 'r'); | |
| 123 | 123 | } | 
| 124 | 124 | |
| 125 | 125 | /** | 
| @@ -138,10 +138,10 @@ discard block | ||
| 138 | 138 |  	function gitRemoteDetails() { | 
| 139 | 139 |  		$content = $this->content('git-remote'); | 
| 140 | 140 | $details = array(); | 
| 141 | -		foreach(explode("\n", trim($content)) as $line) { | |
| 142 | - if(!$line) continue; | |
| 141 | +		foreach (explode("\n", trim($content)) as $line) { | |
| 142 | + if (!$line) continue; | |
| 143 | 143 | |
| 144 | -			if(preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) { | |
| 144 | +			if (preg_match('/^([^ ]+) *= *(.*)$/', $line, $matches)) { | |
| 145 | 145 | $details[$matches[1]] = $matches[2]; | 
| 146 | 146 |  			} else { | 
| 147 | 147 |  				throw new Exception("Bad line '$line'"); | 
| @@ -66,9 +66,8 @@ discard block | ||
| 66 | 66 | |
| 67 | 67 | /** | 
| 68 | 68 | * Put the database from the given sspak file into this webroot. | 
| 69 | - * @param array $details The previously sniffed details of this webroot | |
| 70 | 69 | * @param bool $dropdb Drop the DB prior to install | 
| 71 | - * @param string $sspakFile Filename | |
| 70 | + * @param SSPakFile $sspak Filename | |
| 72 | 71 | */ | 
| 73 | 72 |  	function putdb($sspak, $dropdb) { | 
| 74 | 73 | $details = $this->details(); | 
| @@ -131,6 +130,9 @@ discard block | ||
| 131 | 130 | fclose($stream); | 
| 132 | 131 | } | 
| 133 | 132 | |
| 133 | + /** | |
| 134 | + * @param SSPakFile $sspak | |
| 135 | + */ | |
| 134 | 136 |  	function putassets($sspak) { | 
| 135 | 137 | $details = $this->details(); | 
| 136 | 138 | $assetsPath = $details['assets_path']; | 
| @@ -16,7 +16,9 @@ discard block | ||
| 16 | 16 | * Calls sniff once and then caches | 
| 17 | 17 | */ | 
| 18 | 18 |  	function details() { | 
| 19 | - if(!$this->details) $this->details = $this->sniff(); | |
| 19 | +		if(!$this->details) { | |
| 20 | + $this->details = $this->sniff(); | |
| 21 | + } | |
| 20 | 22 | return $this->details; | 
| 21 | 23 | } | 
| 22 | 24 | |
| @@ -26,7 +28,9 @@ discard block | ||
| 26 | 28 |  	function sniff() { | 
| 27 | 29 | global $snifferFileContent; | 
| 28 | 30 | |
| 29 | - if(!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php'); | |
| 31 | +		if(!$snifferFileContent) { | |
| 32 | + $snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php'); | |
| 33 | + } | |
| 30 | 34 | |
| 31 | 35 | $remoteSniffer = '/tmp/sspak-sniffer-' . rand(100000,999999) . '.php'; | 
| 32 | 36 | $this->uploadContent($snifferFileContent, $remoteSniffer); | 
| @@ -35,7 +39,9 @@ discard block | ||
| 35 | 39 | $this->unlink($remoteSniffer); | 
| 36 | 40 | |
| 37 | 41 | $parsed = @unserialize($result['output']); | 
| 38 | -		if(!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n"); | |
| 42 | +		if(!$parsed) { | |
| 43 | +			throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n"); | |
| 44 | + } | |
| 39 | 45 | return $parsed; | 
| 40 | 46 | } | 
| 41 | 47 | |
| @@ -45,7 +51,9 @@ discard block | ||
| 45 | 51 | */ | 
| 46 | 52 |  	function execSudo($command) { | 
| 47 | 53 |  		if($this->sudo) { | 
| 48 | - if(is_array($command)) $command = $this->executor->commandArrayToString($command); | |
| 54 | +			if(is_array($command)) { | |
| 55 | + $command = $this->executor->commandArrayToString($command); | |
| 56 | + } | |
| 49 | 57 | // Try running sudo without asking for a password | 
| 50 | 58 |  			try { | 
| 51 | 59 |  				return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command); | 
| @@ -16,7 +16,7 @@ discard block | ||
| 16 | 16 | * Calls sniff once and then caches | 
| 17 | 17 | */ | 
| 18 | 18 |  	function details() { | 
| 19 | - if(!$this->details) $this->details = $this->sniff(); | |
| 19 | + if (!$this->details) $this->details = $this->sniff(); | |
| 20 | 20 | return $this->details; | 
| 21 | 21 | } | 
| 22 | 22 | |
| @@ -26,16 +26,16 @@ discard block | ||
| 26 | 26 |  	function sniff() { | 
| 27 | 27 | global $snifferFileContent; | 
| 28 | 28 | |
| 29 | - if(!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php'); | |
| 29 | + if (!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT.'src/sspak-sniffer.php'); | |
| 30 | 30 | |
| 31 | - $remoteSniffer = '/tmp/sspak-sniffer-' . rand(100000,999999) . '.php'; | |
| 31 | + $remoteSniffer = '/tmp/sspak-sniffer-'.rand(100000, 999999).'.php'; | |
| 32 | 32 | $this->uploadContent($snifferFileContent, $remoteSniffer); | 
| 33 | 33 | |
| 34 | 34 |  		$result = $this->execSudo(array('/usr/bin/env', 'php', $remoteSniffer, $this->path)); | 
| 35 | 35 | $this->unlink($remoteSniffer); | 
| 36 | 36 | |
| 37 | 37 | $parsed = @unserialize($result['output']); | 
| 38 | -		if(!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n"); | |
| 38 | +		if (!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n"); | |
| 39 | 39 | return $parsed; | 
| 40 | 40 | } | 
| 41 | 41 | |
| @@ -44,19 +44,19 @@ discard block | ||
| 44 | 44 | * @param string $command Shell command, either a fully escaped string or an array | 
| 45 | 45 | */ | 
| 46 | 46 |  	function execSudo($command) { | 
| 47 | -		if($this->sudo) { | |
| 48 | - if(is_array($command)) $command = $this->executor->commandArrayToString($command); | |
| 47 | +		if ($this->sudo) { | |
| 48 | + if (is_array($command)) $command = $this->executor->commandArrayToString($command); | |
| 49 | 49 | // Try running sudo without asking for a password | 
| 50 | 50 |  			try { | 
| 51 | -				return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command); | |
| 51 | +				return $this->exec("sudo -n -u ".escapeshellarg($this->sudo)." ".$command); | |
| 52 | 52 | |
| 53 | 53 | // Otherwise capture SUDO password ourselves and pass it in through STDIN | 
| 54 | -			} catch(Exception $e) { | |
| 54 | +			} catch (Exception $e) { | |
| 55 | 55 | echo "[sspak sudo] Enter your password: "; | 
| 56 | - $stdin = fopen( 'php://stdin', 'r'); | |
| 56 | +				$stdin = fopen('php://stdin', 'r'); | |
| 57 | 57 | $password = fgets($stdin); | 
| 58 | 58 | |
| 59 | -				return $this->exec("sudo -S -p '' -u " . escapeshellarg($this->sudo) . " " . $command, array('inputContent' => $password)); | |
| 59 | +				return $this->exec("sudo -S -p '' -u ".escapeshellarg($this->sudo)." ".$command, array('inputContent' => $password)); | |
| 60 | 60 | } | 
| 61 | 61 | |
| 62 | 62 |  		} else { | 
| @@ -75,8 +75,8 @@ discard block | ||
| 75 | 75 | |
| 76 | 76 | // Check the database type | 
| 77 | 77 | $dbFunction = 'putdb_'.$details['db_type']; | 
| 78 | -		if(!method_exists($this,$dbFunction)) { | |
| 79 | -			throw new Exception("Can't process database type '" . $details['db_type'] . "'"); | |
| 78 | +		if (!method_exists($this, $dbFunction)) { | |
| 79 | +			throw new Exception("Can't process database type '".$details['db_type']."'"); | |
| 80 | 80 | } | 
| 81 | 81 | |
| 82 | 82 | // Extract DB direct from sspak file | 
| @@ -95,7 +95,7 @@ discard block | ||
| 95 | 95 | $hostArg = ''; | 
| 96 | 96 | $portArg = ''; | 
| 97 | 97 |  		if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') { | 
| 98 | -			if (strpos($conf['db_server'], ':')!==false) { | |
| 98 | +			if (strpos($conf['db_server'], ':') !== false) { | |
| 99 | 99 | // Handle "server:port" format. | 
| 100 | 100 |  				$server = explode(':', $conf['db_server'], 2); | 
| 101 | 101 |  				$hostArg = escapeshellarg("--host=".$server[0]); | 
| @@ -104,9 +104,9 @@ discard block | ||
| 104 | 104 |  				$hostArg = escapeshellarg("--host=".$conf['db_server']); | 
| 105 | 105 | } | 
| 106 | 106 | } | 
| 107 | - $dbCommand = "create database if not exists `" . addslashes($conf['db_database']) . "`"; | |
| 108 | -		if($dropdb) { | |
| 109 | - $dbCommand = "drop database if exists `" . addslashes($conf['db_database']) . "`; " . $dbCommand; | |
| 107 | + $dbCommand = "create database if not exists `".addslashes($conf['db_database'])."`"; | |
| 108 | +		if ($dropdb) { | |
| 109 | + $dbCommand = "drop database if exists `".addslashes($conf['db_database'])."`; ".$dbCommand; | |
| 110 | 110 | } | 
| 111 | 111 | |
| 112 | 112 |  		$this->exec("echo '$dbCommand' | mysql $usernameArg $passwordArg $hostArg $portArg"); | 
| @@ -126,7 +126,7 @@ discard block | ||
| 126 | 126 | |
| 127 | 127 | // Create database if needed | 
| 128 | 128 |  		$result = $this->exec("echo \"select count(*) from pg_catalog.pg_database where datname = $databaseArg\" | $passwordArg psql $usernameArg $hostArg $databaseArg -qt"); | 
| 129 | -		if(trim($result['output']) == '0') { | |
| 129 | +		if (trim($result['output']) == '0') { | |
| 130 | 130 |  			$this->exec("$passwordArg createdb $usernameArg $hostArg $databaseArg"); | 
| 131 | 131 | } | 
| 132 | 132 | |
| @@ -163,7 +163,7 @@ discard block | ||
| 163 | 163 | */ | 
| 164 | 164 |  	function putgit($details) { | 
| 165 | 165 |  		$this->exec(array('git', 'clone', $details['remote'], $this->path)); | 
| 166 | -		$this->exec("cd $this->path && git checkout " . escapeshellarg($details['branch'])); | |
| 166 | +		$this->exec("cd $this->path && git checkout ".escapeshellarg($details['branch'])); | |
| 167 | 167 | return true; | 
| 168 | 168 | } | 
| 169 | 169 | } | 
| @@ -13,7 +13,9 @@ | ||
| 13 | 13 | } | 
| 14 | 14 | |
| 15 | 15 | $basePath = $_SERVER['argv'][1]; | 
| 16 | -if($basePath[0] != '/') $basePath = getcwd() . '/' . $basePath; | |
| 16 | +if($basePath[0] != '/') { | |
| 17 | + $basePath = getcwd() . '/' . $basePath; | |
| 18 | +} | |
| 17 | 19 | |
| 18 | 20 | // SilverStripe bootstrap | 
| 19 | 21 |  define('BASE_PATH', $basePath); | 
| @@ -7,13 +7,13 @@ discard block | ||
| 7 | 7 | */ | 
| 8 | 8 | |
| 9 | 9 | // Argument parsing | 
| 10 | -if(empty($_SERVER['argv'][1])) { | |
| 10 | +if (empty($_SERVER['argv'][1])) { | |
| 11 | 11 |  	echo "Usage: {$_SERVER['argv'][0]} (site-docroot)\n"; | 
| 12 | 12 | exit(1); | 
| 13 | 13 | } | 
| 14 | 14 | |
| 15 | 15 | $basePath = $_SERVER['argv'][1]; | 
| 16 | -if($basePath[0] != '/') $basePath = getcwd() . '/' . $basePath; | |
| 16 | +if ($basePath[0] != '/') $basePath = getcwd().'/'.$basePath; | |
| 17 | 17 | |
| 18 | 18 | // SilverStripe bootstrap | 
| 19 | 19 |  define('BASE_PATH', $basePath); | 
| @@ -21,18 +21,18 @@ discard block | ||
| 21 | 21 | $_SERVER['HTTP_HOST'] = 'localhost'; | 
| 22 | 22 | chdir(BASE_PATH); | 
| 23 | 23 | |
| 24 | -if(file_exists(BASE_PATH.'/framework/core/Core.php')) { | |
| 25 | - require_once(BASE_PATH. '/framework/core/Core.php'); | |
| 26 | -} else if(file_exists(BASE_PATH.'/sapphire/core/Core.php')) { | |
| 27 | - require_once(BASE_PATH. '/sapphire/core/Core.php'); | |
| 24 | +if (file_exists(BASE_PATH.'/framework/core/Core.php')) { | |
| 25 | + require_once(BASE_PATH.'/framework/core/Core.php'); | |
| 26 | +} else if (file_exists(BASE_PATH.'/sapphire/core/Core.php')) { | |
| 27 | + require_once(BASE_PATH.'/sapphire/core/Core.php'); | |
| 28 | 28 |  } else { | 
| 29 | - echo "No framework/core/Core.php or sapphire/core/Core.php included in project. Perhaps " . BASE_PATH . " is not a SilverStripe project?\n"; | |
| 29 | + echo "No framework/core/Core.php or sapphire/core/Core.php included in project. Perhaps ".BASE_PATH." is not a SilverStripe project?\n"; | |
| 30 | 30 | exit(2); | 
| 31 | 31 | } | 
| 32 | 32 | |
| 33 | 33 | $output = array(); | 
| 34 | -foreach($databaseConfig as $k => $v) { | |
| 35 | - $output['db_' . $k] = $v; | |
| 34 | +foreach ($databaseConfig as $k => $v) { | |
| 35 | + $output['db_'.$k] = $v; | |
| 36 | 36 | } | 
| 37 | 37 | $output['assets_path'] = ASSETS_PATH; | 
| 38 | 38 | |
| @@ -51,9 +51,13 @@ discard block | ||
| 51 | 51 | * Return the sudo argument, preferring a more specific one with the given optional prefix | 
| 52 | 52 | */ | 
| 53 | 53 |  	function sudo($optionalPrefix) { | 
| 54 | - if(!empty($this->namedArgs[$optionalPrefix . '-sudo'])) return $this->namedArgs[$optionalPrefix . '-sudo']; | |
| 55 | - else if(!empty($this->namedArgs['sudo'])) return $this->namedArgs['sudo']; | |
| 56 | - else return null; | |
| 54 | +		if(!empty($this->namedArgs[$optionalPrefix . '-sudo'])) { | |
| 55 | + return $this->namedArgs[$optionalPrefix . '-sudo']; | |
| 56 | +		} else if(!empty($this->namedArgs['sudo'])) { | |
| 57 | + return $this->namedArgs['sudo']; | |
| 58 | +		} else { | |
| 59 | + return null; | |
| 60 | + } | |
| 57 | 61 | } | 
| 58 | 62 | |
| 59 | 63 | /** | 
| @@ -67,7 +71,9 @@ discard block | ||
| 67 | 71 | } | 
| 68 | 72 | |
| 69 | 73 | // Default to db and assets | 
| 70 | -		if(!array_filter($pakParts)) $pakParts = array('db' => true, 'assets' => true, 'git-remote' => true); | |
| 74 | +		if(!array_filter($pakParts)) { | |
| 75 | +			$pakParts = array('db' => true, 'assets' => true, 'git-remote' => true); | |
| 76 | + } | |
| 71 | 77 | return $pakParts; | 
| 72 | 78 | } | 
| 73 | 79 | |
| @@ -11,10 +11,10 @@ discard block | ||
| 11 | 11 |  	function __construct($args) { | 
| 12 | 12 | array_shift($args); | 
| 13 | 13 | |
| 14 | -		foreach($args as $arg) { | |
| 15 | -			if(preg_match('/^--([^=]+)=(.*)$/', $arg, $matches)) { | |
| 14 | +		foreach ($args as $arg) { | |
| 15 | +			if (preg_match('/^--([^=]+)=(.*)$/', $arg, $matches)) { | |
| 16 | 16 | $this->namedArgs[$matches[1]] = $matches[2]; | 
| 17 | -			} else if(preg_match('/^--([^=]+)$/', $arg, $matches)) { | |
| 17 | +			} else if (preg_match('/^--([^=]+)$/', $arg, $matches)) { | |
| 18 | 18 | $this->namedArgs[$matches[1]] = true; | 
| 19 | 19 |  			} else { | 
| 20 | 20 | $this->unnamedArgs[] = $arg; | 
| @@ -51,8 +51,8 @@ discard block | ||
| 51 | 51 | * Return the sudo argument, preferring a more specific one with the given optional prefix | 
| 52 | 52 | */ | 
| 53 | 53 |  	function sudo($optionalPrefix) { | 
| 54 | - if(!empty($this->namedArgs[$optionalPrefix . '-sudo'])) return $this->namedArgs[$optionalPrefix . '-sudo']; | |
| 55 | - else if(!empty($this->namedArgs['sudo'])) return $this->namedArgs['sudo']; | |
| 54 | + if (!empty($this->namedArgs[$optionalPrefix.'-sudo'])) return $this->namedArgs[$optionalPrefix.'-sudo']; | |
| 55 | + else if (!empty($this->namedArgs['sudo'])) return $this->namedArgs['sudo']; | |
| 56 | 56 | else return null; | 
| 57 | 57 | } | 
| 58 | 58 | |
| @@ -62,18 +62,18 @@ discard block | ||
| 62 | 62 |  	function pakParts() { | 
| 63 | 63 | // Look up which parts of the sspak are going to be saved | 
| 64 | 64 | $pakParks = array(); | 
| 65 | -		foreach(array('assets','db','git-remote') as $part) { | |
| 65 | +		foreach (array('assets', 'db', 'git-remote') as $part) { | |
| 66 | 66 | $pakParts[$part] = !empty($this->namedArgs[$part]); | 
| 67 | 67 | } | 
| 68 | 68 | |
| 69 | 69 | // Default to db and assets | 
| 70 | -		if(!array_filter($pakParts)) $pakParts = array('db' => true, 'assets' => true, 'git-remote' => true); | |
| 70 | +		if (!array_filter($pakParts)) $pakParts = array('db' => true, 'assets' => true, 'git-remote' => true); | |
| 71 | 71 | return $pakParts; | 
| 72 | 72 | } | 
| 73 | 73 | |
| 74 | 74 |  	function requireUnnamed($items) { | 
| 75 | -		if(sizeof($this->unnamedArgs) < sizeof($items)) { | |
| 76 | -			echo "Usage: {$_SERVER['argv'][0]} " . $this->action . " ("; | |
| 75 | +		if (sizeof($this->unnamedArgs) < sizeof($items)) { | |
| 76 | +			echo "Usage: {$_SERVER['argv'][0]} ".$this->action." ("; | |
| 77 | 77 |  			echo implode(") (", $items); | 
| 78 | 78 | echo ")\n"; | 
| 79 | 79 |  			throw new Exception('Arguments missing.'); | 
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | -define('PACKAGE_ROOT' , dirname(__DIR__).'/'); | |
| 4 | -require_once(PACKAGE_ROOT . 'src/SSPak.php'); | |
| 3 | +define('PACKAGE_ROOT', dirname(__DIR__).'/'); | |
| 4 | +require_once(PACKAGE_ROOT.'src/SSPak.php'); | |
| 5 | 5 | |
| 6 | 6 | /** | 
| 7 | 7 | * Confirm that the compile binary executes |