@@ -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 |  	public function putdb($sspak, $dropdb) { | 
                                                        
| 74 | 73 | $details = $this->details();  | 
                                                        
@@ -135,6 +134,9 @@ discard block  | 
                                                    ||
| 135 | 134 | fclose($stream);  | 
                                                        
| 136 | 135 | }  | 
                                                        
| 137 | 136 | |
| 137 | + /**  | 
                                                        |
| 138 | + * @param SSPakFile $sspak  | 
                                                        |
| 139 | + */  | 
                                                        |
| 138 | 140 |  	public function putassets($sspak) { | 
                                                        
| 139 | 141 | $details = $this->details();  | 
                                                        
| 140 | 142 | $assetsPath = $details['assets_path'];  | 
                                                        
@@ -16,7 +16,9 @@ discard block  | 
                                                    ||
| 16 | 16 | * Calls sniff once and then caches  | 
                                                        
| 17 | 17 | */  | 
                                                        
| 18 | 18 |  	public 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 |  	public 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 |  	public function execSudo($command) { | 
                                                        
| 47 | 53 |  		if($this->sudo) { | 
                                                        
| 48 | - if(is_array($command)) $command = $this->executor->commandArrayToString($command);  | 
                                                        |
| 54 | +			if(is_array($command)) { | 
                                                        |
| 55 | + $command = $this->executor->commandArrayToString($command);  | 
                                                        |
| 56 | + }  | 
                                                        |
| 49 | 57 | // Try running sudo without asking for a password  | 
                                                        
| 50 | 58 |  			try { | 
                                                        
| 51 | 59 |  				return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command); | 
                                                        
@@ -16,7 +16,7 @@ discard block  | 
                                                    ||
| 16 | 16 | * Calls sniff once and then caches  | 
                                                        
| 17 | 17 | */  | 
                                                        
| 18 | 18 |  	public 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 |  	public function sniff() { | 
                                                        
| 27 | 27 | global $snifferFileContent;  | 
                                                        
| 28 | 28 | |
| 29 | - if(!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT . 'src/sspak-sniffer.php');  | 
                                                        |
| 29 | + if (!$snifferFileContent) $snifferFileContent = file_get_contents(PACKAGE_ROOT.'src/sspak-sniffer.php');  | 
                                                        |
| 30 | 30 | |
| 31 | - $remoteSniffer = '/tmp/sspak-sniffer-' . rand(100000,999999) . '.php';  | 
                                                        |
| 31 | + $remoteSniffer = '/tmp/sspak-sniffer-'.rand(100000, 999999).'.php';  | 
                                                        |
| 32 | 32 | $this->uploadContent($snifferFileContent, $remoteSniffer);  | 
                                                        
| 33 | 33 | |
| 34 | 34 |  		$result = $this->execSudo(array('/usr/bin/env', 'php', $remoteSniffer, $this->path)); | 
                                                        
| 35 | 35 | $this->unlink($remoteSniffer);  | 
                                                        
| 36 | 36 | |
| 37 | 37 | $parsed = @unserialize($result['output']);  | 
                                                        
| 38 | -		if(!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n"); | 
                                                        |
| 38 | +		if (!$parsed) throw new Exception("Could not parse sspak-sniffer content:\n{$result['output']}\n"); | 
                                                        |
| 39 | 39 | return $parsed;  | 
                                                        
| 40 | 40 | }  | 
                                                        
| 41 | 41 | |
@@ -44,19 +44,19 @@ discard block  | 
                                                    ||
| 44 | 44 | * @param string $command Shell command, either a fully escaped string or an array  | 
                                                        
| 45 | 45 | */  | 
                                                        
| 46 | 46 |  	public function execSudo($command) { | 
                                                        
| 47 | -		if($this->sudo) { | 
                                                        |
| 48 | - if(is_array($command)) $command = $this->executor->commandArrayToString($command);  | 
                                                        |
| 47 | +		if ($this->sudo) { | 
                                                        |
| 48 | + if (is_array($command)) $command = $this->executor->commandArrayToString($command);  | 
                                                        |
| 49 | 49 | // Try running sudo without asking for a password  | 
                                                        
| 50 | 50 |  			try { | 
                                                        
| 51 | -				return $this->exec("sudo -n -u " . escapeshellarg($this->sudo) . " " . $command); | 
                                                        |
| 51 | +				return $this->exec("sudo -n -u ".escapeshellarg($this->sudo)." ".$command); | 
                                                        |
| 52 | 52 | |
| 53 | 53 | // Otherwise capture SUDO password ourselves and pass it in through STDIN  | 
                                                        
| 54 | -			} catch(Exception $e) { | 
                                                        |
| 54 | +			} catch (Exception $e) { | 
                                                        |
| 55 | 55 | echo "[sspak sudo] Enter your password: ";  | 
                                                        
| 56 | - $stdin = fopen( 'php://stdin', 'r');  | 
                                                        |
| 56 | +				$stdin = fopen('php://stdin', 'r'); | 
                                                        |
| 57 | 57 | $password = fgets($stdin);  | 
                                                        
| 58 | 58 | |
| 59 | -				return $this->exec("sudo -S -p '' -u " . escapeshellarg($this->sudo) . " " . $command, array('inputContent' => $password)); | 
                                                        |
| 59 | +				return $this->exec("sudo -S -p '' -u ".escapeshellarg($this->sudo)." ".$command, array('inputContent' => $password)); | 
                                                        |
| 60 | 60 | }  | 
                                                        
| 61 | 61 | |
| 62 | 62 |  		} else { | 
                                                        
@@ -75,8 +75,8 @@ discard block  | 
                                                    ||
| 75 | 75 | |
| 76 | 76 | // Check the database type  | 
                                                        
| 77 | 77 | $dbFunction = 'putdb_'.$details['db_type'];  | 
                                                        
| 78 | -		if(!method_exists($this,$dbFunction)) { | 
                                                        |
| 79 | -			throw new Exception("Can't process database type '" . $details['db_type'] . "'"); | 
                                                        |
| 78 | +		if (!method_exists($this, $dbFunction)) { | 
                                                        |
| 79 | +			throw new Exception("Can't process database type '".$details['db_type']."'"); | 
                                                        |
| 80 | 80 | }  | 
                                                        
| 81 | 81 | |
| 82 | 82 | // Extract DB direct from sspak file  | 
                                                        
@@ -95,7 +95,7 @@ discard block  | 
                                                    ||
| 95 | 95 | $hostArg = '';  | 
                                                        
| 96 | 96 | $portArg = '';  | 
                                                        
| 97 | 97 |  		if (!empty($conf['db_server']) && $conf['db_server'] != 'localhost') { | 
                                                        
| 98 | -			if (strpos($conf['db_server'], ':')!==false) { | 
                                                        |
| 98 | +			if (strpos($conf['db_server'], ':') !== false) { | 
                                                        |
| 99 | 99 | // Handle "server:port" format.  | 
                                                        
| 100 | 100 |  				$server = explode(':', $conf['db_server'], 2); | 
                                                        
| 101 | 101 |  				$hostArg = escapeshellarg("--host=".$server[0]); | 
                                                        
@@ -104,9 +104,9 @@ discard block  | 
                                                    ||
| 104 | 104 |  				$hostArg = escapeshellarg("--host=".$conf['db_server']); | 
                                                        
| 105 | 105 | }  | 
                                                        
| 106 | 106 | }  | 
                                                        
| 107 | - $dbCommand = "create database if not exists `" . addslashes($conf['db_database']) . "`";  | 
                                                        |
| 108 | -		if($dropdb) { | 
                                                        |
| 109 | - $dbCommand = "drop database if exists `" . addslashes($conf['db_database']) . "`; " . $dbCommand;  | 
                                                        |
| 107 | + $dbCommand = "create database if not exists `".addslashes($conf['db_database'])."`";  | 
                                                        |
| 108 | +		if ($dropdb) { | 
                                                        |
| 109 | + $dbCommand = "drop database if exists `".addslashes($conf['db_database'])."`; ".$dbCommand;  | 
                                                        |
| 110 | 110 | }  | 
                                                        
| 111 | 111 | |
| 112 | 112 |  		$this->exec("echo '$dbCommand' | mysql $usernameArg $passwordArg $hostArg $portArg"); | 
                                                        
@@ -126,7 +126,7 @@ discard block  | 
                                                    ||
| 126 | 126 | |
| 127 | 127 | // Create database if needed  | 
                                                        
| 128 | 128 |  		$result = $this->exec("echo \"select count(*) from pg_catalog.pg_database where datname = $databaseArg\" | $passwordArg psql $usernameArg $hostArg $databaseArg -qt"); | 
                                                        
| 129 | -		if(trim($result['output']) == '0') { | 
                                                        |
| 129 | +		if (trim($result['output']) == '0') { | 
                                                        |
| 130 | 130 |  			$this->exec("$passwordArg createdb $usernameArg $hostArg $databaseArg"); | 
                                                        
| 131 | 131 | }  | 
                                                        
| 132 | 132 | |
@@ -144,7 +144,7 @@ discard block  | 
                                                    ||
| 144 | 144 |  		$assetsPathExec = $this->exec("if [ -L {$assetsPath} ]; then readlink -f {$assetsPath}; else echo {$assetsPath}; fi"); | 
                                                        
| 145 | 145 | $assetsPath = trim($assetsPathExec["output"]);  | 
                                                        
| 146 | 146 | |
| 147 | - $assetsOldPath = $assetsPath . '.old';  | 
                                                        |
| 147 | + $assetsOldPath = $assetsPath.'.old';  | 
                                                        |
| 148 | 148 | $assetsParentArg = escapeshellarg(dirname($assetsPath));  | 
                                                        
| 149 | 149 | |
| 150 | 150 | // Move existing assets to assets.old  | 
                                                        
@@ -167,7 +167,7 @@ discard block  | 
                                                    ||
| 167 | 167 | */  | 
                                                        
| 168 | 168 |  	public function putgit($details) { | 
                                                        
| 169 | 169 |  		$this->exec(array('git', 'clone', $details['remote'], $this->path)); | 
                                                        
| 170 | -		$this->exec("cd $this->path && git checkout " . escapeshellarg($details['branch'])); | 
                                                        |
| 170 | +		$this->exec("cd $this->path && git checkout ".escapeshellarg($details['branch'])); | 
                                                        |
| 171 | 171 | return true;  | 
                                                        
| 172 | 172 | }  | 
                                                        
| 173 | 173 | }  |