Completed
Pull Request — master (#39)
by Daniel
02:23
created
src/Webroot.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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");
Please login to merge, or discard this patch.
src/Executor.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
Please login to merge, or discard this patch.
src/SSPak.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -64,16 +64,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/FilesystemEntity.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.
src/sspak-sniffer.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/SSPakFile.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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'");
Please login to merge, or discard this patch.
src/Args.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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";
Please login to merge, or discard this patch.