Completed
Pull Request — master (#643)
by Stig
04:09
created
code/api/nouns/APINoun.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	protected function getAPIResponse($output) {
61 61
 		$response = $this->getResponse();
62
-		if($this->respondWithText()) {
62
+		if ($this->respondWithText()) {
63 63
 			$body = print_r($output, true);
64 64
 			$response->addHeader('Content-Type', 'text/plain');
65 65
 		} else {
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 	 * @return boolean
75 75
 	 */
76 76
 	protected function respondWithJSON() {
77
-		if($this->getRequest()->getExtension() == 'json') {
77
+		if ($this->getRequest()->getExtension() == 'json') {
78 78
 			return true;
79 79
 		}
80
-		if(strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false) {
80
+		if (strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false) {
81 81
 			return true;
82 82
 		}
83 83
 		return false;
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
 	 * @return boolean
88 88
 	 */
89 89
 	protected function respondWithText() {
90
-		if($this->getRequest()->getExtension() == 'txt') {
90
+		if ($this->getRequest()->getExtension() == 'txt') {
91 91
 			return true;
92 92
 		}
93
-		if(strpos($this->getRequest()->getHeader('Accept'), 'text/plain') !== false) {
93
+		if (strpos($this->getRequest()->getHeader('Accept'), 'text/plain') !== false) {
94 94
 			return true;
95 95
 		}
96 96
 		return false;
Please login to merge, or discard this patch.
code/api/nouns/APIProject.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 	 * @return SS_HTTPResponse
16 16
 	 */
17 17
 	public function index(SS_HTTPRequest $request) {
18
-		if(!$this->record->canView($this->getMember())) {
18
+		if (!$this->record->canView($this->getMember())) {
19 19
 			return $this->message('You are not authorized to this environment', 403);
20 20
 		}
21 21
 
22
-		switch($request->httpMethod()) {
22
+		switch ($request->httpMethod()) {
23 23
 			case 'GET':
24 24
 				$response = array(
25 25
 					"name" => $this->record->Name,
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 					"disk-quota-mb" => $this->record->DiskQuotaMB,
30 30
 					"environments" => array(),
31 31
 				);
32
-				foreach($this->record->DNEnvironmentList() as $environment) {
32
+				foreach ($this->record->DNEnvironmentList() as $environment) {
33 33
 					$response['environments'][] = array(
34 34
 						'name' => $environment->Name,
35 35
 						'href' => Director::absoluteURL($this->record->APILink($environment->Name)),
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 * @return SS_HTTPResponse
48 48
 	 */
49 49
 	public function fetch(SS_HTTPRequest $request) {
50
-		if(!$this->record->canView($this->getMember())) {
50
+		if (!$this->record->canView($this->getMember())) {
51 51
 			return $this->message('You are not authorized to do that on this environment', 403);
52 52
 		}
53
-		switch($request->httpMethod()) {
53
+		switch ($request->httpMethod()) {
54 54
 			case 'GET':
55 55
 				return $this->getFetch($this->getRequest()->param('ID'));
56 56
 			case 'POST':
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	protected function getFetch($ID) {
68 68
 		$ping = DNGitFetch::get()->byID($ID);
69
-		if(!$ping) {
69
+		if (!$ping) {
70 70
 			return $this->message('Fetch not found', 404);
71 71
 		}
72 72
 		$output = array(
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 		$fetch->write();
88 88
 		$fetch->start();
89 89
 
90
-		$location = Director::absoluteBaseURL() . $this->Link() . '/fetch/' . $fetch->ID;
90
+		$location = Director::absoluteBaseURL().$this->Link().'/fetch/'.$fetch->ID;
91 91
 		$output = array(
92
-			'message' => 'Fetch queued as job ' . $fetch->ResqueToken,
92
+			'message' => 'Fetch queued as job '.$fetch->ResqueToken,
93 93
 			'href' => $location,
94 94
 		);
95 95
 
Please login to merge, or discard this patch.
code/api/nouns/APIEnvironment.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 	 * @return SS_HTTPResponse
16 16
 	 */
17 17
 	public function index(SS_HTTPRequest $request) {
18
-		if(!$this->record->canView($this->getMember())) {
18
+		if (!$this->record->canView($this->getMember())) {
19 19
 			return $this->message('You are not authorized to view this environment', 403);
20 20
 		}
21
-		switch($request->httpMethod()) {
21
+		switch ($request->httpMethod()) {
22 22
 			case 'GET':
23 23
 				$href = Director::absoluteURL($this->record->Project()->APILink($this->record->Name));
24 24
 				return $this->getAPIResponse(array(
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 * @return SS_HTTPResponse
52 52
 	 */
53 53
 	public function ping(SS_HTTPRequest $request) {
54
-		if(!$this->record->canView($this->getMember())) {
54
+		if (!$this->record->canView($this->getMember())) {
55 55
 			return $this->message('You are not authorized to do that on this environment', 403);
56 56
 		}
57
-		switch($request->httpMethod()) {
57
+		switch ($request->httpMethod()) {
58 58
 			case 'GET':
59 59
 				return $this->getPing($this->getRequest()->param('ID'));
60 60
 			case 'POST':
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 	 * @return SS_HTTPResponse
72 72
 	 */
73 73
 	public function deploy(SS_HTTPRequest $request) {
74
-		if(!$this->record->canView($this->getMember())) {
74
+		if (!$this->record->canView($this->getMember())) {
75 75
 			return $this->message('You are not authorized to do that on this environment', 403);
76 76
 		}
77
-		switch($request->httpMethod()) {
77
+		switch ($request->httpMethod()) {
78 78
 			case 'GET':
79 79
 				return $this->getDeploy($this->getRequest()->param('ID'));
80 80
 			case 'POST':
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return SS_HTTPResponse
107 107
 	 */
108 108
 	protected function createPing() {
109
-		if(!$this->record->canDeploy($this->getMember())) {
109
+		if (!$this->record->canDeploy($this->getMember())) {
110 110
 			return $this->message('You are not authorized to do that on this environment', 403);
111 111
 		}
112 112
 		$ping = DNPing::create();
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		$ping->write();
115 115
 		$ping->start();
116 116
 
117
-		$location = Director::absoluteBaseURL() . $this->Link() . '/ping/' . $ping->ID;
117
+		$location = Director::absoluteBaseURL().$this->Link().'/ping/'.$ping->ID;
118 118
 		$output = array(
119
-			'message' => 'Ping queued as job ' . $ping->ResqueToken,
119
+			'message' => 'Ping queued as job '.$ping->ResqueToken,
120 120
 			'href' => $location,
121 121
 		);
122 122
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	protected function getPing($ID) {
134 134
 		$ping = DNPing::get()->byID($ID);
135
-		if(!$ping) {
135
+		if (!$ping) {
136 136
 			return $this->message('Ping not found', 404);
137 137
 		}
138 138
 		$output = array(
@@ -149,17 +149,17 @@  discard block
 block discarded – undo
149 149
 	 * @return SS_HTTPResponse
150 150
 	 */
151 151
 	protected function createDeploy() {
152
-		if(!$this->record->canDeploy($this->getMember())) {
152
+		if (!$this->record->canDeploy($this->getMember())) {
153 153
 			return $this->message('You are not authorized to do that on this environment', 403);
154 154
 		}
155 155
 
156 156
 		$reqBody = $this->getRequestBody();
157 157
 
158
-		if($reqBody === null) {
158
+		if ($reqBody === null) {
159 159
 			return $this->message('the request body did not contain a valid JSON object.', 400);
160 160
 		}
161 161
 
162
-		if(empty($reqBody['release'])) {
162
+		if (empty($reqBody['release'])) {
163 163
 			return $this->message('deploy requires a {"release": "sha1"} in the body of the request.', 400);
164 164
 		}
165 165
 
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
 		));
169 169
 		$deploy = $strategy->createDeployment();
170 170
 		$deploy->start();
171
-		$location = Director::absoluteBaseURL() . $this->Link() . '/deploy/' . $deploy->ID;
171
+		$location = Director::absoluteBaseURL().$this->Link().'/deploy/'.$deploy->ID;
172 172
 		$output = array(
173
-			'message' => 'Deploy queued as job ' . $deploy->ResqueToken,
173
+			'message' => 'Deploy queued as job '.$deploy->ResqueToken,
174 174
 			'href' => $location,
175 175
 		);
176 176
 		$response = $this->getAPIResponse($output);
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 */
188 188
 	protected function getDeploy($id) {
189 189
 		$deploy = DNDeployment::get()->byID($id);
190
-		if(!$deploy) {
190
+		if (!$deploy) {
191 191
 			return $this->message('Deploy not found', 404);
192 192
 		}
193 193
 		$output = array(
Please login to merge, or discard this patch.
code/api/DeploynautAPI.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
 			'projects' => array(),
52 52
 		);
53 53
 
54
-		if($request->httpMethod() != 'GET') {
54
+		if ($request->httpMethod() != 'GET') {
55 55
 			return $this->message('API not found', 404);
56 56
 		}
57 57
 
58
-		foreach(DNProject::get() as $item) {
59
-			if($item->canView($this->getMember())) {
58
+		foreach (DNProject::get() as $item) {
59
+			if ($item->canView($this->getMember())) {
60 60
 				$response['projects'][] = array(
61 61
 					"name" => $item->Name,
62 62
 					"href" => Director::absoluteURL($item->APILink("")),
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	public function project(SS_HTTPRequest $request) {
77 77
 		$project = $this->getProject();
78
-		if(!$project) {
78
+		if (!$project) {
79 79
 			return $this->project404Response();
80 80
 		}
81 81
 		return new APIProject($this, $project);
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	public function environment(SS_HTTPRequest $request) {
91 91
 		$project = $this->getProject();
92
-		if(!$project) {
92
+		if (!$project) {
93 93
 			return $this->project404Response();
94 94
 		}
95 95
 
96 96
 		$environment = $this->getEnvironment();
97
-		if(!$environment) {
97
+		if (!$environment) {
98 98
 			return $this->environment404Response();
99 99
 		}
100 100
 		return new APIEnvironment($this, $environment);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	protected function project404Response() {
107 107
 		$projectName = Convert::raw2xml($this->getRequest()->latestParam('Project'));
108
-		return new SS_HTTPResponse('Project "' . $projectName . '" not found.', 404);
108
+		return new SS_HTTPResponse('Project "'.$projectName.'" not found.', 404);
109 109
 	}
110 110
 
111 111
 	/**
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	protected function environment404Response() {
115 115
 		$envName = Convert::raw2xml($this->getRequest()->latestParam('Environment'));
116
-		return new SS_HTTPResponse('Environment "' . $envName . '" not found.', 404);
116
+		return new SS_HTTPResponse('Environment "'.$envName.'" not found.', 404);
117 117
 	}
118 118
 
119 119
 	/**
Please login to merge, or discard this patch.
code/tasks/MigrateDeploymentStatusTask.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 	public function run($request) {
6 6
 		$log = function($message) {
7
-			$message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message;
8
-			echo $message . PHP_EOL;
7
+			$message = sprintf('[%s] ', date('Y-m-d H:i:s')).$message;
8
+			echo $message.PHP_EOL;
9 9
 		};
10 10
 
11 11
 		if (!Director::is_cli()) {
Please login to merge, or discard this patch.
code/tasks/SyncProjectsAndEnvironments.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@  discard block
 block discarded – undo
9 9
 		$remove = true;
10 10
 		$dryRun = true;
11 11
 
12
-		if($request && $request->requestVar('remove') !== null) {
12
+		if ($request && $request->requestVar('remove') !== null) {
13 13
 			$remove = (bool)$request->requestVar('remove');
14 14
 		}
15 15
 
16
-		if($request && $request->requestVar('dryrun') !== null) {
16
+		if ($request && $request->requestVar('dryrun') !== null) {
17 17
 			$dryRun = (bool)$request->requestVar('dryrun');
18 18
 		}
19 19
 
20
-		if($dryRun) {
20
+		if ($dryRun) {
21 21
 			echo "Running in dry run mode, no changes commited, ";
22
-			echo "the output shows a prediction on what will happen." . PHP_EOL;
23
-			echo "To skip dryrun, run the task like this:" . PHP_EOL;
24
-			echo "./framework/sake dev/tasks/SyncProjectsAndEnvironments dryrun=0" . PHP_EOL . PHP_EOL;
22
+			echo "the output shows a prediction on what will happen.".PHP_EOL;
23
+			echo "To skip dryrun, run the task like this:".PHP_EOL;
24
+			echo "./framework/sake dev/tasks/SyncProjectsAndEnvironments dryrun=0".PHP_EOL.PHP_EOL;
25 25
 			sleep(3);
26 26
 		}
27 27
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 		// Sync projects
32 32
 		$projects = DNProject::get();
33
-		if($remove) {
33
+		if ($remove) {
34 34
 			$this->echoHeader('Removing obsolete projects');
35 35
 			$this->removeObsoleteProjects($projectPaths, $dryRun);
36 36
 		}
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 		$this->syncProjectPaths($projectPaths, $dryRun);
39 39
 
40 40
 		$this->echoHeader('Syncing environment files');
41
-		foreach($projects as $project) {
41
+		foreach ($projects as $project) {
42 42
 			$this->echoHeader($project->Name);
43 43
 			// Sync environments for each project
44 44
 			$environmentPaths = $data->getEnvironmentPaths($project->Name);
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
 		}, $paths);
63 63
 
64 64
 		$removeList = $list->filter('Filename:not', $basePaths);
65
-		if($removeList->count() === 0) {
65
+		if ($removeList->count() === 0) {
66 66
 			return;
67 67
 		}
68 68
 
69
-		foreach($removeList as $remove) {
70
-			$this->message('Removing "' . basename($remove->Name) . '" from db');
71
-			if(!$dryRun) {
69
+		foreach ($removeList as $remove) {
70
+			$this->message('Removing "'.basename($remove->Name).'" from db');
71
+			if (!$dryRun) {
72 72
 				$removeList->remove($remove);
73 73
 			}
74 74
 		}
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	protected function removeObsoleteProjects($paths, $dryrun = false) {
85 85
 		$removeList = DNProject::get()->filter('Name:not', $paths);
86
-		if($removeList->count() == 0) {
86
+		if ($removeList->count() == 0) {
87 87
 			return;
88 88
 		}
89 89
 
90
-		foreach($removeList as $remove) {
91
-			$this->message($remove->Name . ' ' . $remove->Path);
92
-			if(!$dryrun) {
90
+		foreach ($removeList as $remove) {
91
+			$this->message($remove->Name.' '.$remove->Path);
92
+			if (!$dryrun) {
93 93
 				$removeList->remove($remove);
94 94
 			}
95 95
 		}
@@ -106,22 +106,22 @@  discard block
 block discarded – undo
106 106
 		$list = $project->Environments();
107 107
 
108 108
 		// Normalise paths in DB
109
-		foreach($list as $item) {
109
+		foreach ($list as $item) {
110 110
 			$real = realpath($item->Filename);
111
-			if($real && $real != $item->Filename) {
111
+			if ($real && $real != $item->Filename) {
112 112
 				$item->Filename = $real;
113 113
 				$item->write();
114 114
 			}
115 115
 		}
116 116
 
117
-		foreach($paths as $path) {
117
+		foreach ($paths as $path) {
118 118
 			$path = basename($path);
119
-			if($list->filter('Filename', $path)->count()) {
119
+			if ($list->filter('Filename', $path)->count()) {
120 120
 				continue;
121 121
 			}
122 122
 
123
-			$this->message('Adding "' . basename($path) . '" to db');
124
-			if(!$dryRun) {
123
+			$this->message('Adding "'.basename($path).'" to db');
124
+			if (!$dryRun) {
125 125
 				$environment = DNEnvironment::create_from_path($path);
126 126
 				$environment->ProjectID = $project->ID;
127 127
 				$environment->write();
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 	 * @param boolean $dryRun
137 137
 	 */
138 138
 	public function syncProjectPaths($paths, $dryRun = false) {
139
-		foreach($paths as $path) {
140
-			if(!DNProject::get()->filter('Name', $path)->count()) {
139
+		foreach ($paths as $path) {
140
+			if (!DNProject::get()->filter('Name', $path)->count()) {
141 141
 				$this->message($path);
142
-				if(!$dryRun) {
142
+				if (!$dryRun) {
143 143
 					DNProject::create_from_path($path)->write();
144 144
 				}
145 145
 			}
@@ -150,20 +150,20 @@  discard block
 block discarded – undo
150 150
 	 * @param string $text
151 151
 	 */
152 152
 	protected function message($text) {
153
-		if(PHP_SAPI !== 'cli') {
154
-			$text = '<p>' . $text . '</p>' . PHP_EOL;
153
+		if (PHP_SAPI !== 'cli') {
154
+			$text = '<p>'.$text.'</p>'.PHP_EOL;
155 155
 		}
156
-		echo ' - ' . $text . PHP_EOL;
156
+		echo ' - '.$text.PHP_EOL;
157 157
 	}
158 158
 
159 159
 	/**
160 160
 	 * @param string $text
161 161
 	 */
162 162
 	protected function echoHeader($text) {
163
-		if(PHP_SAPI !== 'cli') {
164
-			echo '<h2>' . $text . '</h2>' . PHP_EOL;
163
+		if (PHP_SAPI !== 'cli') {
164
+			echo '<h2>'.$text.'</h2>'.PHP_EOL;
165 165
 		} else {
166
-			echo '# ' . $text . PHP_EOL;
166
+			echo '# '.$text.PHP_EOL;
167 167
 		}
168 168
 	}
169 169
 }
Please login to merge, or discard this patch.
code/model/GitonomyCache.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
7 7
 	public static $cache = array();
8 8
 
9 9
 	public static function getIncludingBranches($commit) {
10
-		$cacheKey = 'getIncludingBranches-' . $commit->getRepository()->getPath() . '-' . $commit->gethash();
11
-		if(!isset(self::$cache[$cacheKey])) {
10
+		$cacheKey = 'getIncludingBranches-'.$commit->getRepository()->getPath().'-'.$commit->gethash();
11
+		if (!isset(self::$cache[$cacheKey])) {
12 12
 			self::$cache[$cacheKey] = $commit->getIncludingBranches();
13 13
 		}
14 14
 		return self::$cache[$cacheKey];
Please login to merge, or discard this patch.
code/model/DNBranchList.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -58,20 +58,20 @@  discard block
 block discarded – undo
58 58
 
59 59
 		try {
60 60
 			$repository = new Gitonomy\Git\Repository($this->project->getLocalCVSPath());
61
-		} catch(Exception $e) {
61
+		} catch (Exception $e) {
62 62
 			return $branches;
63 63
 		}
64 64
 
65
-		foreach($repository->getReferences()->getBranches() as $branch) {
65
+		foreach ($repository->getReferences()->getBranches() as $branch) {
66 66
 			/** @var DNBranch $obj */
67 67
 			$obj = DNBranch::create($branch, $this->project, $this->data);
68
-			if($branch->getName() == 'master') {
68
+			if ($branch->getName() == 'master') {
69 69
 				$firstBranch = array($branch->getName() => $obj);
70 70
 			} else {
71 71
 				$branches[$branch->getName()] = $obj;
72 72
 			}
73 73
 		}
74
-		if($firstBranch) {
74
+		if ($firstBranch) {
75 75
 			$branches = $firstBranch + $branches;
76 76
 		}
77 77
 
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	 * @return string
87 87
 	 */
88 88
 	public function byName($name) {
89
-		if($this->loaded === false) {
89
+		if ($this->loaded === false) {
90 90
 			$this->getIterator();
91 91
 		}
92 92
 
93
-		if(isset($this->items[$name])) {
93
+		if (isset($this->items[$name])) {
94 94
 			return $this->items[$name];
95 95
 		}
96 96
 
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 	 * @return ArrayIterator
105 105
 	 */
106 106
 	public function getIterator() {
107
-		if($this->loaded === false) {
107
+		if ($this->loaded === false) {
108 108
 			$this->items = $this->getReferences();
109 109
 			$this->loaded = true;
110 110
 		}
111
-		foreach($this->items as $i => $item) {
112
-			if(is_array($item)) {
111
+		foreach ($this->items as $i => $item) {
112
+			if (is_array($item)) {
113 113
 				$this->items[$i] = new ArrayData($item);
114 114
 			}
115 115
 		}
Please login to merge, or discard this patch.
code/model/DNDataArchive.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	}
122 122
 
123 123
 	public function onBeforeWrite() {
124
-		if(!$this->AuthorID) {
124
+		if (!$this->AuthorID) {
125 125
 			$this->AuthorID = Member::currentUserID();
126 126
 		}
127 127
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @return string The human-readable size of this archive file
180 180
 	 */
181 181
 	public function FileSize() {
182
-		if($this->ArchiveFile()->exists()) {
182
+		if ($this->ArchiveFile()->exists()) {
183 183
 			return $this->ArchiveFile()->getSize();
184 184
 		} else {
185 185
 			return "N/A";
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	}
188 188
 
189 189
 	public function getModeNice() {
190
-		if($this->Mode == 'all') {
190
+		if ($this->Mode == 'all') {
191 191
 			return 'database and assets';
192 192
 		} else {
193 193
 			return $this->Mode;
@@ -223,12 +223,12 @@  discard block
 block discarded – undo
223 223
 	 */
224 224
 	public function canRestore($member = null) {
225 225
 		$memberID = $member ? $member->ID : Member::currentUserID();
226
-		if(!$memberID) {
226
+		if (!$memberID) {
227 227
 			return false;
228 228
 		}
229 229
 
230
-		$key = $memberID . '-' . $this->EnvironmentID;
231
-		if(!isset(self::$_cache_can_restore[$key])) {
230
+		$key = $memberID.'-'.$this->EnvironmentID;
231
+		if (!isset(self::$_cache_can_restore[$key])) {
232 232
 			self::$_cache_can_restore[$key] = $this->Environment()->canUploadArchive($member);
233 233
 		}
234 234
 
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
 	 */
245 245
 	public function canDownload($member = null) {
246 246
 		$memberID = $member ? $member->ID : Member::currentUserID();
247
-		if(!$memberID) {
247
+		if (!$memberID) {
248 248
 			return false;
249 249
 		}
250 250
 
251
-		$key = $memberID . '-' . $this->EnvironmentID;
252
-		if(!isset(self::$_cache_can_download[$key])) {
251
+		$key = $memberID.'-'.$this->EnvironmentID;
252
+		if (!isset(self::$_cache_can_download[$key])) {
253 253
 			self::$_cache_can_download[$key] = $this->Environment()->canDownloadArchive($member);
254 254
 		}
255 255
 		return self::$_cache_can_download[$key];
@@ -274,27 +274,27 @@  discard block
 block discarded – undo
274 274
 	 * @return boolean true if $member can upload archives linked to this environment, false if they can't.
275 275
 	 */
276 276
 	public function canMoveTo($targetEnv, $member = null) {
277
-		if($this->Environment()->Project()->ID != $targetEnv->Project()->ID) {
277
+		if ($this->Environment()->Project()->ID != $targetEnv->Project()->ID) {
278 278
 			// We don't permit moving snapshots between projects at this stage.
279 279
 			return false;
280 280
 		}
281 281
 
282
-		if(!$member) {
282
+		if (!$member) {
283 283
 			$member = Member::currentUser();
284 284
 		}
285 285
 
286 286
 		// Must be logged in to check permissions
287
-		if(!$member) {
287
+		if (!$member) {
288 288
 			return false;
289 289
 		}
290 290
 
291 291
 		// Admin can always move.
292
-		if(Permission::checkMember($member, 'ADMIN')) {
292
+		if (Permission::checkMember($member, 'ADMIN')) {
293 293
 			return true;
294 294
 		}
295 295
 
296 296
 		// Checks if the user can actually access the archive.
297
-		if(!$this->canDownload($member)) {
297
+		if (!$this->canDownload($member)) {
298 298
 			return false;
299 299
 		}
300 300
 
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 	 * @return bool
404 404
 	 */
405 405
 	public function extractArchive($workingDir = null) {
406
-		if(!is_dir($workingDir)) {
406
+		if (!is_dir($workingDir)) {
407 407
 			mkdir($workingDir, 0700, true);
408 408
 		}
409 409
 
@@ -422,28 +422,28 @@  discard block
 block discarded – undo
422 422
 		));
423 423
 		$process->setTimeout(3600);
424 424
 		$process->run();
425
-		if(!$process->isSuccessful()) {
425
+		if (!$process->isSuccessful()) {
426 426
 			$cleanupFn();
427 427
 			throw new RuntimeException(sprintf('Could not extract the sspak file: %s', $process->getErrorOutput()));
428 428
 		}
429 429
 
430 430
 		// Extract database.sql.gz to <workingdir>/database.sql
431
-		if(file_exists($workingDir . DIRECTORY_SEPARATOR . 'database.sql.gz')) {
431
+		if (file_exists($workingDir.DIRECTORY_SEPARATOR.'database.sql.gz')) {
432 432
 			$process = new AbortableProcess('gunzip database.sql.gz', $workingDir);
433 433
 			$process->setTimeout(3600);
434 434
 			$process->run();
435
-			if(!$process->isSuccessful()) {
435
+			if (!$process->isSuccessful()) {
436 436
 				$cleanupFn();
437 437
 				throw new RuntimeException(sprintf('Could not extract the db archive: %s', $process->getErrorOutput()));
438 438
 			}
439 439
 		}
440 440
 
441 441
 		// Extract assets.tar.gz to <workingdir>/assets/
442
-		if(file_exists($workingDir . DIRECTORY_SEPARATOR . 'assets.tar.gz')) {
442
+		if (file_exists($workingDir.DIRECTORY_SEPARATOR.'assets.tar.gz')) {
443 443
 			$process = new AbortableProcess('tar xzf assets.tar.gz', $workingDir);
444 444
 			$process->setTimeout(3600);
445 445
 			$process->run();
446
-			if(!$process->isSuccessful()) {
446
+			if (!$process->isSuccessful()) {
447 447
 				$cleanupFn();
448 448
 				throw new RuntimeException(sprintf('Could not extract the assets archive: %s', $process->getErrorOutput()));
449 449
 			}
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 
468 468
 		$file = $this->ArchiveFile()->FullPath;
469 469
 
470
-		if(!is_readable($file)) {
470
+		if (!is_readable($file)) {
471 471
 			$result->error(sprintf('SSPak file "%s" cannot be read.', $file));
472 472
 			return $result;
473 473
 		}
@@ -475,19 +475,19 @@  discard block
 block discarded – undo
475 475
 		$process = new AbortableProcess(sprintf('tar -tf %s', escapeshellarg($file)));
476 476
 		$process->setTimeout(120);
477 477
 		$process->run();
478
-		if(!$process->isSuccessful()) {
478
+		if (!$process->isSuccessful()) {
479 479
 			throw new RuntimeException(sprintf('Could not list files in archive: %s', $process->getErrorOutput()));
480 480
 		}
481 481
 
482 482
 		$output = explode(PHP_EOL, $process->getOutput());
483 483
 		$files = array_filter($output);
484 484
 
485
-		if(in_array($mode, array('all', 'db')) && !in_array('database.sql.gz', $files)) {
485
+		if (in_array($mode, array('all', 'db')) && !in_array('database.sql.gz', $files)) {
486 486
 			$result->error('The snapshot is missing the database.');
487 487
 			return $result;
488 488
 		}
489 489
 
490
-		if(in_array($mode, array('all', 'assets')) && !in_array('assets.tar.gz', $files)) {
490
+		if (in_array($mode, array('all', 'assets')) && !in_array('assets.tar.gz', $files)) {
491 491
 			$result->error('The snapshot is missing assets.');
492 492
 			return $result;
493 493
 		}
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
 			sprintf('find %s -type f -exec chmod 644 {} +', escapeshellarg($workingDir))
518 518
 		);
519 519
 
520
-		foreach($fixCmds as $cmd) {
520
+		foreach ($fixCmds as $cmd) {
521 521
 			$process = new AbortableProcess($cmd);
522 522
 			$process->setTimeout(3600);
523 523
 			$process->run();
524
-			if(!$process->isSuccessful()) {
524
+			if (!$process->isSuccessful()) {
525 525
 				throw new RuntimeException($process->getErrorOutput());
526 526
 			}
527 527
 		}
@@ -540,11 +540,11 @@  discard block
 block discarded – undo
540 540
 	 */
541 541
 	public function setArchiveFromFiles($workingDir) {
542 542
 		$commands = array();
543
-		if($this->Mode == 'db') {
543
+		if ($this->Mode == 'db') {
544 544
 			$commands[] = 'gzip database.sql';
545 545
 			$commands[] = sprintf('tar -cf %s database.sql.gz', $this->ArchiveFile()->FullPath);
546 546
 			$commands[] = 'rm -f database.sql.gz';
547
-		} elseif($this->Mode == 'assets') {
547
+		} elseif ($this->Mode == 'assets') {
548 548
 			$commands[] = 'GZIP=-1 tar --dereference -czf assets.tar.gz assets';
549 549
 			$commands[] = sprintf('tar -cf %s assets.tar.gz', $this->ArchiveFile()->FullPath);
550 550
 			$commands[] = 'rm -f assets.tar.gz';
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 		$process = new AbortableProcess(implode(' && ', $commands), $workingDir);
559 559
 		$process->setTimeout(3600);
560 560
 		$process->run();
561
-		if(!$process->isSuccessful()) {
561
+		if (!$process->isSuccessful()) {
562 562
 			throw new RuntimeException($process->getErrorOutput());
563 563
 		}
564 564
 
Please login to merge, or discard this patch.