@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | // MySQL Dump Parser |
4 | 4 | // SNUFFKIN/ Alex 2004 |
5 | 5 | |
6 | -class SqlParser { |
|
6 | +class SqlParser{ |
|
7 | 7 | public $host; |
8 | 8 | public $dbname; |
9 | 9 | public $prefix; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | public $connection_method; |
28 | 28 | public $ignoreDuplicateErrors; |
29 | 29 | |
30 | - public function __construct($host, $user, $password, $db, $prefix='modx_', $adminname, $adminemail, $adminpass, $connection_charset= 'utf8', $managerlanguage='english', $connection_method = 'SET CHARACTER SET', $auto_template_logic = 'parent') { |
|
30 | + public function __construct($host, $user, $password, $db, $prefix = 'modx_', $adminname, $adminemail, $adminpass, $connection_charset = 'utf8', $managerlanguage = 'english', $connection_method = 'SET CHARACTER SET', $auto_template_logic = 'parent'){ |
|
31 | 31 | $this->host = $host; |
32 | 32 | $this->dbname = $db; |
33 | 33 | $this->prefix = $prefix; |
@@ -43,28 +43,28 @@ discard block |
||
43 | 43 | $this->autoTemplateLogic = $auto_template_logic; |
44 | 44 | } |
45 | 45 | |
46 | - public function connect() { |
|
46 | + public function connect(){ |
|
47 | 47 | $this->conn = mysqli_connect($this->host, $this->user, $this->password); |
48 | 48 | mysqli_select_db($this->conn, $this->dbname); |
49 | 49 | if (function_exists('mysqli_set_charset')) mysqli_set_charset($this->conn, $this->connection_charset); |
50 | 50 | |
51 | 51 | $this->dbVersion = 3.23; // assume version 3.23 |
52 | - if(function_exists("mysqli_get_server_info")) { |
|
52 | + if (function_exists("mysqli_get_server_info")) { |
|
53 | 53 | $ver = mysqli_get_server_info($this->conn); |
54 | - $this->dbMODx = version_compare($ver,"4.0.2"); |
|
54 | + $this->dbMODx = version_compare($ver, "4.0.2"); |
|
55 | 55 | $this->dbVersion = (float) $ver; // Typecasting (float) instead of floatval() [PHP < 4.2] |
56 | 56 | } |
57 | 57 | |
58 | - mysqli_query($this->conn,"{$this->connection_method} {$this->connection_charset}"); |
|
58 | + mysqli_query($this->conn, "{$this->connection_method} {$this->connection_charset}"); |
|
59 | 59 | } |
60 | 60 | |
61 | - public function process($filename) { |
|
61 | + public function process($filename){ |
|
62 | 62 | global $custom_placeholders; |
63 | 63 | |
64 | 64 | // check to make sure file exists |
65 | 65 | if (!file_exists($filename)) { |
66 | 66 | $this->mysqlErrors[] = array("error" => "File '$filename' not found"); |
67 | - $this->installFailed = true ; |
|
67 | + $this->installFailed = true; |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | $idata = str_replace("\r", '', $idata); |
80 | 80 | |
81 | 81 | // check if in upgrade mode |
82 | - if ($this->mode=="upd") { |
|
82 | + if ($this->mode == "upd") { |
|
83 | 83 | // remove non-upgradeable parts |
84 | - $s = strpos($idata,"non-upgrade-able[["); |
|
85 | - $e = strpos($idata,"]]non-upgrade-able")+17; |
|
86 | - if($s && $e) $idata = str_replace(substr($idata,$s,$e-$s)," Removed non upgradeable items",$idata); |
|
84 | + $s = strpos($idata, "non-upgrade-able[["); |
|
85 | + $e = strpos($idata, "]]non-upgrade-able") + 17; |
|
86 | + if ($s && $e) $idata = str_replace(substr($idata, $s, $e - $s), " Removed non upgradeable items", $idata); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | // replace {} tags |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | /*$idata = str_replace('{VERSION}', $modx_version, $idata);*/ |
100 | 100 | |
101 | 101 | // Replace custom placeholders |
102 | - foreach($custom_placeholders as $key=>$val) { |
|
102 | + foreach ($custom_placeholders as $key=>$val) { |
|
103 | 103 | if (strpos($idata, '{'.$key.'}') !== false) { |
104 | 104 | $idata = str_replace('{'.$key.'}', $val, $idata); |
105 | 105 | } |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | $sql_array = explode("\n\n", $idata); |
109 | 109 | |
110 | 110 | $num = 0; |
111 | - foreach($sql_array as $sql_entry) { |
|
111 | + foreach ($sql_array as $sql_entry) { |
|
112 | 112 | $sql_do = trim($sql_entry, "\r\n; "); |
113 | 113 | |
114 | 114 | if (preg_match('/^\#/', $sql_do)) continue; |
115 | 115 | |
116 | 116 | // strip out comments and \n for mysql 3.x |
117 | - if ($this->dbVersion <4.0) { |
|
118 | - $sql_do = preg_replace("~COMMENT.*[^']?'.*[^']?'~","",$sql_do); |
|
117 | + if ($this->dbVersion < 4.0) { |
|
118 | + $sql_do = preg_replace("~COMMENT.*[^']?'.*[^']?'~", "", $sql_do); |
|
119 | 119 | $sql_do = str_replace('\r', "", $sql_do); |
120 | 120 | $sql_do = str_replace('\n', "", $sql_do); |
121 | 121 | } |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | |
124 | 124 | $num = $num + 1; |
125 | 125 | if ($sql_do) mysqli_query($this->conn, $sql_do); |
126 | - if(mysqli_error($this->conn)) { |
|
126 | + if (mysqli_error($this->conn)) { |
|
127 | 127 | // Ignore duplicate and drop errors - Raymond |
128 | - if ($this->ignoreDuplicateErrors){ |
|
129 | - if (mysqli_errno($this->conn) == 1060 || mysqli_errno($this->conn) == 1061 || mysqli_errno($this->conn) == 1062 ||mysqli_errno($this->conn) == 1091) continue; |
|
128 | + if ($this->ignoreDuplicateErrors) { |
|
129 | + if (mysqli_errno($this->conn) == 1060 || mysqli_errno($this->conn) == 1061 || mysqli_errno($this->conn) == 1062 || mysqli_errno($this->conn) == 1091) continue; |
|
130 | 130 | } |
131 | 131 | // End Ignore duplicate |
132 | 132 | $this->mysqlErrors[] = array("error" => mysqli_error($this->conn), "sql" => $sql_do); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | - public function close() { |
|
138 | + public function close(){ |
|
139 | 139 | mysqli_close($this->conn); |
140 | 140 | } |
141 | 141 | } |