@@ -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,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,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | function commandArrayToString($command) { |
| 55 | 55 | $string = escapeshellcmd(array_shift($command)); |
| 56 | - foreach($command as $arg) { |
|
| 56 | + foreach ($command as $arg) { |
|
| 57 | 57 | $string .= ' ' . escapeshellarg($arg); |
| 58 | 58 | } |
| 59 | 59 | return $string; |
@@ -80,8 +80,8 @@ 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 | $command = $ssh . escapeshellarg($this->remoteServer) . ' ' . escapeshellarg($this->command); |
| 87 | 87 | } else { |
@@ -96,9 +96,9 @@ discard block |
||
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | 98 | // Alternatives |
| 99 | - if($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r'); |
|
| 99 | + if ($options['inputContent'] || $options['inputStream']) $pipeSpec[0] = array('pipe', 'r'); |
|
| 100 | 100 | |
| 101 | - if($options['outputFile']) { |
|
| 101 | + if ($options['outputFile']) { |
|
| 102 | 102 | $pipeSpec[1] = array('file', |
| 103 | 103 | $options['outputFile'], |
| 104 | 104 | $options['outputFileAppend'] ? 'a' : 'w'); |
@@ -106,24 +106,24 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | $process = proc_open($command, $pipeSpec, $pipes); |
| 108 | 108 | |
| 109 | - if($options['inputContent']) { |
|
| 109 | + if ($options['inputContent']) { |
|
| 110 | 110 | fwrite($pipes[0], $options['inputContent']); |
| 111 | 111 | |
| 112 | - } else if($options['inputStream']) { |
|
| 113 | - while($content = fread($options['inputStream'], 8192)) { |
|
| 112 | + } else if ($options['inputStream']) { |
|
| 113 | + while ($content = fread($options['inputStream'], 8192)) { |
|
| 114 | 114 | fwrite($pipes[0], $content); |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | - if(isset($pipes[0])) fclose($pipes[0]); |
|
| 117 | + if (isset($pipes[0])) fclose($pipes[0]); |
|
| 118 | 118 | |
| 119 | 119 | $result = array(); |
| 120 | 120 | |
| 121 | - if(isset($pipes[1])) { |
|
| 121 | + if (isset($pipes[1])) { |
|
| 122 | 122 | // If a stream was provided, then pipe all the content |
| 123 | 123 | // Doing it this way rather than passing outputStream to $pipeSpec |
| 124 | 124 | // Means that streams as well as simple FDs can be used |
| 125 | - if($options['outputStream']) { |
|
| 126 | - while($content = fread($pipes[1], 8192)) { |
|
| 125 | + if ($options['outputStream']) { |
|
| 126 | + while ($content = fread($pipes[1], 8192)) { |
|
| 127 | 127 | fwrite($options['outputStream'], $content); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | fclose($pipes[1]); |
| 135 | 135 | } |
| 136 | - if(isset($pipes[2])) { |
|
| 136 | + if (isset($pipes[2])) { |
|
| 137 | 137 | $result['error'] = stream_get_contents($pipes[2]); |
| 138 | 138 | fclose($pipes[2]); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $result['return'] = proc_close($process); |
| 142 | 142 | |
| 143 | - if($options['throwException'] && $result['return'] != 0) { |
|
| 143 | + if ($options['throwException'] && $result['return'] != 0) { |
|
| 144 | 144 | throw new Exception("Command: $command\nExecution failed: returned {$result['return']}.\n" |
| 145 | 145 | . (empty($result['output']) ? "" : "Output:\n{$result['output']}")); |
| 146 | 146 | } |
@@ -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 | |
@@ -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) { |
@@ -11,8 +11,8 @@ discard block |
||
| 11 | 11 | function __construct($path, $executor) { |
| 12 | 12 | $this->executor = $executor; |
| 13 | 13 | |
| 14 | - if(strpos($path,':') !== false) { |
|
| 15 | - list($this->server,$this->path) = explode(':', $path, 2); |
|
| 14 | + if (strpos($path, ':') !== false) { |
|
| 15 | + list($this->server, $this->path) = explode(':', $path, 2); |
|
| 16 | 16 | } else { |
| 17 | 17 | $this->server = null; |
| 18 | 18 | $this->path = $path; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param string $command Shell command, either a fully escaped string or an array |
| 35 | 35 | */ |
| 36 | 36 | function exec($command, $options = array()) { |
| 37 | - if($this->server) $process = $this->executor->createRemote($this->server, $command, $options); |
|
| 37 | + if ($this->server) $process = $this->executor->createRemote($this->server, $command, $options); |
|
| 38 | 38 | else $process = $this->executor->createLocal($command, $options); |
| 39 | 39 | |
| 40 | 40 | return $process->exec(); |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @return Process |
| 47 | 47 | */ |
| 48 | 48 | function createProcess($command, $options = array()) { |
| 49 | - if($this->server) return $this->executor->createRemote($this->server, $command, $options); |
|
| 49 | + if ($this->server) return $this->executor->createRemote($this->server, $command, $options); |
|
| 50 | 50 | else return $this->executor->createLocal($command, $options); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param string $dest The remote filename/dir to upload to |
| 57 | 57 | */ |
| 58 | 58 | function upload($source, $dest) { |
| 59 | - if($this->server) { |
|
| 59 | + if ($this->server) { |
|
| 60 | 60 | $this->executor->execLocal(array("scp", $source, "$this->server:$dest")); |
| 61 | 61 | } else { |
| 62 | 62 | $this->executor->execLocal(array("cp", $source, $dest)); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @param string $dest The local filename/dir to download to |
| 79 | 79 | */ |
| 80 | 80 | function download($source, $dest) { |
| 81 | - if($this->server) { |
|
| 81 | + if ($this->server) { |
|
| 82 | 82 | $this->executor->execLocal(array("scp", "$this->server:$source", $dest)); |
| 83 | 83 | } else { |
| 84 | 84 | $this->executor->execLocal(array("cp", $file, $dest)); |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | * @return boolean |
| 92 | 92 | */ |
| 93 | 93 | function exists($file = null) { |
| 94 | - if(!$file) $file = $this->path; |
|
| 95 | - if($file == '@self') return true; |
|
| 94 | + if (!$file) $file = $this->path; |
|
| 95 | + if ($file == '@self') return true; |
|
| 96 | 96 | |
| 97 | - if($this->server) { |
|
| 97 | + if ($this->server) { |
|
| 98 | 98 | $result = $this->exec("if [ -e " . escapeshellarg($file) . " ]; then echo yes; fi"); |
| 99 | 99 | return (trim($result['output']) == 'yes'); |
| 100 | 100 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * Create the given file with the given content |
| 108 | 108 | */ |
| 109 | 109 | function writeFile($file, $content) { |
| 110 | - if($this->server) { |
|
| 110 | + if ($this->server) { |
|
| 111 | 111 | $this->exec("echo " . escapeshellarg($content) . " > " . escapeshellarg($file)); |
| 112 | 112 | |
| 113 | 113 | } else { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param string $file The file to remove |
| 122 | 122 | */ |
| 123 | 123 | function unlink($file) { |
| 124 | - if(!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'"); |
|
| 124 | + if (!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'"); |
|
| 125 | 125 | $this->exec(array('rm', '-rf', $file)); |
| 126 | 126 | return true; |
| 127 | 127 | } |
@@ -34,8 +34,11 @@ discard block |
||
| 34 | 34 | * @param string $command Shell command, either a fully escaped string or an array |
| 35 | 35 | */ |
| 36 | 36 | function exec($command, $options = array()) { |
| 37 | - if($this->server) $process = $this->executor->createRemote($this->server, $command, $options); |
|
| 38 | - else $process = $this->executor->createLocal($command, $options); |
|
| 37 | + if($this->server) { |
|
| 38 | + $process = $this->executor->createRemote($this->server, $command, $options); |
|
| 39 | + } else { |
|
| 40 | + $process = $this->executor->createLocal($command, $options); |
|
| 41 | + } |
|
| 39 | 42 | |
| 40 | 43 | return $process->exec(); |
| 41 | 44 | } |
@@ -46,8 +49,11 @@ discard block |
||
| 46 | 49 | * @return Process |
| 47 | 50 | */ |
| 48 | 51 | function createProcess($command, $options = array()) { |
| 49 | - if($this->server) return $this->executor->createRemote($this->server, $command, $options); |
|
| 50 | - else return $this->executor->createLocal($command, $options); |
|
| 52 | + if($this->server) { |
|
| 53 | + return $this->executor->createRemote($this->server, $command, $options); |
|
| 54 | + } else { |
|
| 55 | + return $this->executor->createLocal($command, $options); |
|
| 56 | + } |
|
| 51 | 57 | } |
| 52 | 58 | |
| 53 | 59 | /** |
@@ -91,8 +97,12 @@ discard block |
||
| 91 | 97 | * @return boolean |
| 92 | 98 | */ |
| 93 | 99 | function exists($file = null) { |
| 94 | - if(!$file) $file = $this->path; |
|
| 95 | - if($file == '@self') return true; |
|
| 100 | + if(!$file) { |
|
| 101 | + $file = $this->path; |
|
| 102 | + } |
|
| 103 | + if($file == '@self') { |
|
| 104 | + return true; |
|
| 105 | + } |
|
| 96 | 106 | |
| 97 | 107 | if($this->server) { |
| 98 | 108 | $result = $this->exec("if [ -e " . escapeshellarg($file) . " ]; then echo yes; fi"); |
@@ -121,7 +131,9 @@ discard block |
||
| 121 | 131 | * @param string $file The file to remove |
| 122 | 132 | */ |
| 123 | 133 | function unlink($file) { |
| 124 | - if(!$file || $file == '/' || $file == '.') throw new Exception("Can't unlink file '$file'"); |
|
| 134 | + if(!$file || $file == '/' || $file == '.') { |
|
| 135 | + throw new Exception("Can't unlink file '$file'"); |
|
| 136 | + } |
|
| 125 | 137 | $this->exec(array('rm', '-rf', $file)); |
| 126 | 138 | return true; |
| 127 | 139 | } |
@@ -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'; |
@@ -64,16 +64,16 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function help($args) { |
| 66 | 66 | echo "SSPak: manage SilverStripe .sspak archives.\n\nUsage:\n"; |
| 67 | - foreach($this->getActions() as $action => $info) { |
|
| 67 | + foreach ($this->getActions() as $action => $info) { |
|
| 68 | 68 | echo "sspak $action"; |
| 69 | - if(!empty($info['unnamedArgs'])) { |
|
| 70 | - foreach($info['unnamedArgs'] as $arg) echo " ($arg)"; |
|
| 69 | + if (!empty($info['unnamedArgs'])) { |
|
| 70 | + foreach ($info['unnamedArgs'] as $arg) echo " ($arg)"; |
|
| 71 | 71 | } |
| 72 | - if(!empty($info['namedFlags'])) { |
|
| 73 | - foreach($info['namedFlags'] as $arg) echo " (--$arg)"; |
|
| 72 | + if (!empty($info['namedFlags'])) { |
|
| 73 | + foreach ($info['namedFlags'] as $arg) echo " (--$arg)"; |
|
| 74 | 74 | } |
| 75 | - if(!empty($info['namedArgs'])) { |
|
| 76 | - foreach($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\""; |
|
| 75 | + if (!empty($info['namedArgs'])) { |
|
| 76 | + foreach ($info['namedArgs'] as $arg) echo " --$arg=\"$arg value\""; |
|
| 77 | 77 | } |
| 78 | 78 | echo "\n {$info['description']}\n\n"; |
| 79 | 79 | } |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $filesystem = new FilesystemEntity(null, $executor); |
| 99 | 99 | |
| 100 | - if($pakParts['db']) { |
|
| 100 | + if ($pakParts['db']) { |
|
| 101 | 101 | $dbPath = escapeshellarg($namedArgs['db']); |
| 102 | 102 | $process = $filesystem->createProcess("cat $dbPath | gzip -c"); |
| 103 | 103 | $sspak->writeFileFromProcess('database.sql.gz', $process); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if($pakParts['assets']) { |
|
| 106 | + if ($pakParts['assets']) { |
|
| 107 | 107 | $assetsParentArg = escapeshellarg(dirname($namedArgs['assets'])); |
| 108 | 108 | $assetsBaseArg = escapeshellarg(basename($namedArgs['assets'])); |
| 109 | 109 | $process = $filesystem->createProcess("cd $assetsParentArg && tar cfh - $assetsBaseArg | gzip -c"); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $sspak = new SSPakFile($file, $executor); |
| 127 | 127 | |
| 128 | 128 | // Validation |
| 129 | - if(!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); |
|
| 129 | + if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); |
|
| 130 | 130 | |
| 131 | 131 | $phar = $sspak->getPhar(); |
| 132 | 132 | $phar->extractTo($dest); |
@@ -145,12 +145,12 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $webroot = new Webroot($unnamedArgs[0], $executor); |
| 147 | 147 | $file = $unnamedArgs[1]; |
| 148 | - if(file_exists($file)) throw new Exception( "File '$file' already exists."); |
|
| 148 | + if (file_exists($file)) throw new Exception("File '$file' already exists."); |
|
| 149 | 149 | |
| 150 | 150 | $sspak = new SSPakFile($file, $executor); |
| 151 | 151 | |
| 152 | - if(!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']); |
|
| 153 | - else if(!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']); |
|
| 152 | + if (!empty($namedArgs['from-sudo'])) $webroot->setSudo($namedArgs['from-sudo']); |
|
| 153 | + else if (!empty($namedArgs['sudo'])) $webroot->setSudo($namedArgs['sudo']); |
|
| 154 | 154 | |
| 155 | 155 | // Look up which parts of the sspak are going to be saved |
| 156 | 156 | $pakParts = $args->pakParts(); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $details = $webroot->sniff(); |
| 160 | 160 | |
| 161 | 161 | // Create a build folder for the sspak file |
| 162 | - $buildFolder = "/tmp/sspak-" . rand(100000,999999); |
|
| 162 | + $buildFolder = "/tmp/sspak-" . rand(100000, 999999); |
|
| 163 | 163 | $webroot->exec(array('mkdir', $buildFolder)); |
| 164 | 164 | |
| 165 | 165 | $dbFile = "$buildFolder/database.sql.gz"; |
@@ -170,22 +170,22 @@ discard block |
||
| 170 | 170 | $fileList = array(); |
| 171 | 171 | |
| 172 | 172 | // Save DB |
| 173 | - if($pakParts['db']) { |
|
| 173 | + if ($pakParts['db']) { |
|
| 174 | 174 | // Check the database type |
| 175 | - $dbFunction = 'getdb_'.$details['db_type']; |
|
| 176 | - if(!method_exists($this,$dbFunction)) { |
|
| 175 | + $dbFunction = 'getdb_' . $details['db_type']; |
|
| 176 | + if (!method_exists($this, $dbFunction)) { |
|
| 177 | 177 | throw new Exception("Can't process database type '" . $details['db_type'] . "'"); |
| 178 | 178 | } |
| 179 | 179 | $this->$dbFunction($webroot, $details, $sspak, basename($dbFile)); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Save Assets |
| 183 | - if($pakParts['assets']) { |
|
| 183 | + if ($pakParts['assets']) { |
|
| 184 | 184 | $this->getassets($webroot, $details['assets_path'], $sspak, basename($assetsFile)); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Save git-remote |
| 188 | - if($pakParts['git-remote']) { |
|
| 188 | + if ($pakParts['git-remote']) { |
|
| 189 | 189 | $this->getgitremote($webroot, $sspak, basename($gitRemoteFile)); |
| 190 | 190 | } |
| 191 | 191 | |
@@ -198,20 +198,20 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | function getdb_MySQLDatabase($webroot, $conf, $sspak, $filename) { |
| 201 | - $usernameArg = escapeshellarg("--user=".$conf['db_username']); |
|
| 202 | - $passwordArg = escapeshellarg("--password=".$conf['db_password']); |
|
| 201 | + $usernameArg = escapeshellarg("--user=" . $conf['db_username']); |
|
| 202 | + $passwordArg = escapeshellarg("--password=" . $conf['db_password']); |
|
| 203 | 203 | $databaseArg = escapeshellarg($conf['db_database']); |
| 204 | 204 | |
| 205 | 205 | $hostArg = ''; |
| 206 | 206 | $portArg = ''; |
| 207 | 207 | if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') { |
| 208 | - if (strpos($conf['db_server'], ':')!==false) { |
|
| 208 | + if (strpos($conf['db_server'], ':') !== false) { |
|
| 209 | 209 | // Handle "server:port" format. |
| 210 | 210 | $server = explode(':', $conf['db_server'], 2); |
| 211 | - $hostArg = escapeshellarg("--host=".$server[0]); |
|
| 212 | - $portArg = escapeshellarg("--port=".$server[1]); |
|
| 211 | + $hostArg = escapeshellarg("--host=" . $server[0]); |
|
| 212 | + $portArg = escapeshellarg("--port=" . $server[1]); |
|
| 213 | 213 | } else { |
| 214 | - $hostArg = escapeshellarg("--host=".$conf['db_server']); |
|
| 214 | + $hostArg = escapeshellarg("--host=" . $conf['db_server']); |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | function getdb_PostgreSQLDatabase($webroot, $conf, $sspak, $filename) { |
| 226 | - $usernameArg = escapeshellarg("--username=".$conf['db_username']); |
|
| 227 | - $passwordArg = "PGPASSWORD=".escapeshellarg($conf['db_password']); |
|
| 226 | + $usernameArg = escapeshellarg("--username=" . $conf['db_username']); |
|
| 227 | + $passwordArg = "PGPASSWORD=" . escapeshellarg($conf['db_password']); |
|
| 228 | 228 | $databaseArg = escapeshellarg($conf['db_database']); |
| 229 | - $hostArg = escapeshellarg("--host=".$conf['db_server']); |
|
| 229 | + $hostArg = escapeshellarg("--host=" . $conf['db_server']); |
|
| 230 | 230 | $filenameArg = escapeshellarg($filename); |
| 231 | 231 | |
| 232 | 232 | $process = $webroot->createProcess("$passwordArg pg_dump --clean --no-owner --no-tablespaces $usernameArg $hostArg $databaseArg | gzip -c"); |
@@ -244,16 +244,16 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | function getgitremote($webroot, $sspak, $gitRemoteFile) { |
| 246 | 246 | // Only do anything if we're copying from a git checkout |
| 247 | - $gitRepo = $webroot->getPath() .'/.git'; |
|
| 248 | - if($webroot->exists($gitRepo)) { |
|
| 247 | + $gitRepo = $webroot->getPath() . '/.git'; |
|
| 248 | + if ($webroot->exists($gitRepo)) { |
|
| 249 | 249 | // Identify current branch |
| 250 | - $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'branch')); |
|
| 251 | - if(preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1])===false) { |
|
| 250 | + $output = $webroot->exec(array('git', '--git-dir=' . $gitRepo, 'branch')); |
|
| 251 | + if (preg_match("/\* ([^ \n]*)/", $output['output'], $matches) && strpos("(no branch)", $matches[1]) === false) { |
|
| 252 | 252 | // If there is a current branch, use that branch's remove |
| 253 | 253 | $currentBranch = trim($matches[1]); |
| 254 | - $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"branch.$currentBranch.remote")); |
|
| 254 | + $output = $webroot->exec(array('git', '--git-dir=' . $gitRepo, 'config', '--get', "branch.$currentBranch.remote")); |
|
| 255 | 255 | $remoteName = trim($output['output']); |
| 256 | - if(!$remoteName) $remoteName = 'origin'; |
|
| 256 | + if (!$remoteName) $remoteName = 'origin'; |
|
| 257 | 257 | |
| 258 | 258 | // Default to origin |
| 259 | 259 | } else { |
@@ -262,11 +262,11 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // Determine the URL of that remote |
| 265 | - $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'config','--get',"remote.$remoteName.url")); |
|
| 265 | + $output = $webroot->exec(array('git', '--git-dir=' . $gitRepo, 'config', '--get', "remote.$remoteName.url")); |
|
| 266 | 266 | $remoteURL = trim($output['output']); |
| 267 | 267 | |
| 268 | 268 | // Determine the current SHA |
| 269 | - $output = $webroot->exec(array('git', '--git-dir='.$gitRepo, 'log','-1','--format=%H')); |
|
| 269 | + $output = $webroot->exec(array('git', '--git-dir=' . $gitRepo, 'log', '-1', '--format=%H')); |
|
| 270 | 270 | $sha = trim($output['output']); |
| 271 | 271 | |
| 272 | 272 | $content = "remote = $remoteURL\nbranch = $currentBranch\nsha = $sha\n"; |
@@ -294,16 +294,16 @@ discard block |
||
| 294 | 294 | $pakParts = $args->pakParts(); |
| 295 | 295 | |
| 296 | 296 | // Validation |
| 297 | - if(!$sspak->exists()) throw new Exception( "File '$file' doesn't exist."); |
|
| 297 | + if (!$sspak->exists()) throw new Exception("File '$file' doesn't exist."); |
|
| 298 | 298 | |
| 299 | 299 | // Push database, if necessary |
| 300 | 300 | $namedArgs = $args->getNamedArgs(); |
| 301 | - if($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 301 | + if ($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 302 | 302 | $webroot->putdb($sspak, isset($namedArgs['drop-db'])); |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | // Push assets, if neccessary |
| 306 | - if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 306 | + if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 307 | 307 | $webroot->putassets($sspak); |
| 308 | 308 | } |
| 309 | 309 | } |
@@ -325,13 +325,13 @@ discard block |
||
| 325 | 325 | $pakParts = $args->pakParts(); |
| 326 | 326 | |
| 327 | 327 | // 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."); |
|
| 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."); |
|
| 330 | 330 | |
| 331 | 331 | // Create new dir |
| 332 | 332 | $webroot->exec(array('mkdir', $webroot->getPath())); |
| 333 | 333 | |
| 334 | - if($sspak->contains('git-remote')) { |
|
| 334 | + if ($sspak->contains('git-remote')) { |
|
| 335 | 335 | $details = $sspak->gitRemoteDetails(); |
| 336 | 336 | $webroot->putgit($details); |
| 337 | 337 | } |
@@ -340,12 +340,12 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | // Push database, if necessary |
| 342 | 342 | $namedArgs = $args->getNamedArgs(); |
| 343 | - if($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 343 | + if ($pakParts['db'] && $sspak->contains('database.sql.gz')) { |
|
| 344 | 344 | $webroot->putdb($sspak, isset($namedArgs['drop-db'])); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | // Push assets, if neccessary |
| 348 | - if($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 348 | + if ($pakParts['assets'] && $sspak->contains('assets.tar.gz')) { |
|
| 349 | 349 | $webroot->putassets($sspak); |
| 350 | 350 | } |
| 351 | 351 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | $sspakScript = file_get_contents($_SERVER['argv'][0]); |
| 368 | 368 | // Broken up to not get detected by our sed command |
| 369 | - $sspakScript .= "\n__halt_compiler();\n"."//"." TAR START?>\n"; |
|
| 369 | + $sspakScript .= "\n__halt_compiler();\n" . "//" . " TAR START?>\n"; |
|
| 370 | 370 | |
| 371 | 371 | // Mark as self-extracting |
| 372 | 372 | $sspakScript = str_replace('$isSelfExtracting = false;', '$isSelfExtracting = true;', $sspakScript); |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | $snifferFile = dirname(__FILE__) . '/sspak-sniffer.php'; |
| 376 | 376 | $sspakScript = str_replace("\$snifferFileContent = '';\n", |
| 377 | 377 | "\$snifferFileContent = '" |
| 378 | - . str_replace(array("\\","'"),array("\\\\", "\\'"), file_get_contents($snifferFile)) . "';\n", $sspakScript); |
|
| 378 | + . str_replace(array("\\", "'"), array("\\\\", "\\'"), file_get_contents($snifferFile)) . "';\n", $sspakScript); |
|
| 379 | 379 | |
| 380 | 380 | file_put_contents($destFile, $sspakScript); |
| 381 | 381 | chmod($destFile, 0775); |
@@ -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())); |
@@ -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,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,7 +34,7 @@ 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 | |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | // Add the bin file, but strip of the #! exec header. |
| 45 | 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); |
@@ -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'"); |
@@ -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]; |
@@ -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,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,16 +44,16 @@ 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 | 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 | 59 | return $this->exec("sudo -S -p '' -u " . escapeshellarg($this->sudo) . " " . $command, array('inputContent' => $password)); |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | $details = $this->details(); |
| 75 | 75 | |
| 76 | 76 | // Check the database type |
| 77 | - $dbFunction = 'putdb_'.$details['db_type']; |
|
| 78 | - if(!method_exists($this,$dbFunction)) { |
|
| 77 | + $dbFunction = 'putdb_' . $details['db_type']; |
|
| 78 | + if (!method_exists($this, $dbFunction)) { |
|
| 79 | 79 | throw new Exception("Can't process database type '" . $details['db_type'] . "'"); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -84,24 +84,24 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | function putdb_MySQLDatabase($conf, $sspak, $dropdb) { |
| 87 | - $usernameArg = escapeshellarg("--user=".$conf['db_username']); |
|
| 88 | - $passwordArg = escapeshellarg("--password=".$conf['db_password']); |
|
| 87 | + $usernameArg = escapeshellarg("--user=" . $conf['db_username']); |
|
| 88 | + $passwordArg = escapeshellarg("--password=" . $conf['db_password']); |
|
| 89 | 89 | $databaseArg = escapeshellarg($conf['db_database']); |
| 90 | 90 | |
| 91 | 91 | $hostArg = ''; |
| 92 | 92 | $portArg = ''; |
| 93 | 93 | if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') { |
| 94 | - if (strpos($conf['db_server'], ':')!==false) { |
|
| 94 | + if (strpos($conf['db_server'], ':') !== false) { |
|
| 95 | 95 | // Handle "server:port" format. |
| 96 | 96 | $server = explode(':', $conf['db_server'], 2); |
| 97 | - $hostArg = escapeshellarg("--host=".$server[0]); |
|
| 98 | - $portArg = escapeshellarg("--port=".$server[1]); |
|
| 97 | + $hostArg = escapeshellarg("--host=" . $server[0]); |
|
| 98 | + $portArg = escapeshellarg("--port=" . $server[1]); |
|
| 99 | 99 | } else { |
| 100 | - $hostArg = escapeshellarg("--host=".$conf['db_server']); |
|
| 100 | + $hostArg = escapeshellarg("--host=" . $conf['db_server']); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | $dbCommand = "create database if not exists `" . addslashes($conf['db_database']) . "`"; |
| 104 | - if($dropdb) { |
|
| 104 | + if ($dropdb) { |
|
| 105 | 105 | $dbCommand = "drop database if exists `" . addslashes($conf['db_database']) . "`; " . $dbCommand; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | function putdb_PostgreSQLDatabase($conf, $sspak, $dropdb) { |
| 117 | 117 | // TODO: Support dropdb for postgresql |
| 118 | - $usernameArg = escapeshellarg("--username=".$conf['db_username']); |
|
| 119 | - $passwordArg = "PGPASSWORD=".escapeshellarg($conf['db_password']); |
|
| 118 | + $usernameArg = escapeshellarg("--username=" . $conf['db_username']); |
|
| 119 | + $passwordArg = "PGPASSWORD=" . escapeshellarg($conf['db_password']); |
|
| 120 | 120 | $databaseArg = escapeshellarg($conf['db_database']); |
| 121 | - $hostArg = escapeshellarg("--host=".$conf['db_server']); |
|
| 121 | + $hostArg = escapeshellarg("--host=" . $conf['db_server']); |
|
| 122 | 122 | |
| 123 | 123 | // Create database if needed |
| 124 | 124 | $result = $this->exec("echo \"select count(*) from pg_catalog.pg_database where datname = $databaseArg\" | $passwordArg psql $usernameArg $hostArg $databaseArg -qt"); |
| 125 | - if(trim($result['output']) == '0') { |
|
| 125 | + if (trim($result['output']) == '0') { |
|
| 126 | 126 | $this->exec("$passwordArg createdb $usernameArg $hostArg $databaseArg"); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $assetsParentArg = escapeshellarg(dirname($assetsPath)); |
| 139 | 139 | $assetsBaseArg = escapeshellarg(basename($assetsPath)); |
| 140 | - $assetsBaseOldArg = escapeshellarg(basename($assetsPath).'.old'); |
|
| 140 | + $assetsBaseOldArg = escapeshellarg(basename($assetsPath) . '.old'); |
|
| 141 | 141 | |
| 142 | 142 | // Move existing assets to assets.old |
| 143 | 143 | $this->exec("if [ -d $assetsBaseArg ]; then mv $assetsBaseArg $assetsBaseOldArg; fi"); |
@@ -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); |
@@ -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,17 +21,17 @@ 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 | 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) { |
|
| 34 | +foreach ($databaseConfig as $k => $v) { |
|
| 35 | 35 | $output['db_' . $k] = $v; |
| 36 | 36 | } |
| 37 | 37 | $output['assets_path'] = ASSETS_PATH; |
@@ -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); |
@@ -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,17 +62,17 @@ 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)) { |
|
| 75 | + if (sizeof($this->unnamedArgs) < sizeof($items)) { |
|
| 76 | 76 | echo "Usage: {$_SERVER['argv'][0]} " . $this->action . " ("; |
| 77 | 77 | echo implode(") (", $items); |
| 78 | 78 | echo ")\n"; |
@@ -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 | |