Index: trunk/extensions/LocalisationUpdate/LocalisationUpdate.class.php |
— | — | @@ -123,6 +123,10 @@ |
124 | 124 | $changedCount = 0; |
125 | 125 | |
126 | 126 | // For each language |
| 127 | + if(!is_array($files)) { |
| 128 | + self::myLog("CRITICAL ERROR: \$files is not an array in file ".(__FILE__)." at line ".(__LINE__)); |
| 129 | + return 0; |
| 130 | + } |
127 | 131 | sort($files); |
128 | 132 | foreach ( $files as $file ) { |
129 | 133 | $svnfile = $svndir . "/" . $file; |
— | — | @@ -164,6 +168,7 @@ |
165 | 169 | } |
166 | 170 | |
167 | 171 | public static function getFileContents( $basefile ) { |
| 172 | + $basefilecontents = ""; |
168 | 173 | // use cURL to get the SVN contents |
169 | 174 | if ( preg_match( "/^http/", $basefile ) ) { |
170 | 175 | $basefilecontents = Http::get( $basefile ); |
— | — | @@ -193,11 +198,8 @@ |
194 | 199 | $langcode = strtolower( $m[1] ); |
195 | 200 | |
196 | 201 | $basefilecontents = self::getFileContents( $basefile ); |
197 | | - if ( $basefilecontents === false ) return array(); // Failed |
| 202 | + if ( $basefilecontents === false || $basefilecontents === "" ) return array(); // Failed |
198 | 203 | |
199 | | - $basehash = ""; |
200 | | - $comparehash = ""; |
201 | | - |
202 | 204 | // Only get the part we need |
203 | 205 | $basefilecontents = self::cleanupFile( $basefilecontents ); |
204 | 206 | |
— | — | @@ -217,7 +219,7 @@ |
218 | 220 | eval( $basefilecontents ); |
219 | 221 | |
220 | 222 | $comparefilecontents = self::getFileContents( $comparefile ); |
221 | | - if ( $comparefilecontents === false ) return array(); // Failed |
| 223 | + if ( $comparefilecontents === false || $comparefilecontents === "" ) return array(); // Failed |
222 | 224 | |
223 | 225 | // only get the stuff we need |
224 | 226 | $comparefilecontents = self::cleanupFile( $comparefilecontents ); |
— | — | @@ -254,11 +256,13 @@ |
255 | 257 | $changedStrings = array_diff_assoc( $base_messages, $compare_messages ); |
256 | 258 | |
257 | 259 | // If we want to save the differences |
258 | | - if ( $saveResults ) { |
| 260 | + if ( $saveResults === true && !empty($changedStrings)) { |
259 | 261 | self::myLog( "--Checking languagecode {$langcode}--" ); |
260 | 262 | // The save them |
261 | 263 | $updates = self::saveChanges( $changedStrings, $forbiddenKeys, $base_messages, $langcode ); |
262 | 264 | self::myLog( "{$updates} messages updated for {$langcode}." ); |
| 265 | + } elseif($saveResult === true) { |
| 266 | + self::myLog( "--{$langcode} hasn't changed--" ); |
263 | 267 | } |
264 | 268 | |
265 | 269 | return $changedStrings; |
— | — | @@ -287,6 +291,11 @@ |
288 | 292 | |
289 | 293 | // Count the updates |
290 | 294 | $updates = 0; |
| 295 | + if(!is_array($changedStrings)) { |
| 296 | + self::myLog("CRITICAL ERROR: \$changedStrings is not an array in file ".(__FILE__)." at line ".(__LINE__)); |
| 297 | + return 0; |
| 298 | + } |
| 299 | + |
291 | 300 | foreach ( $changedStrings as $key => $value ) { |
292 | 301 | // If this message wasn't changed in english |
293 | 302 | if ( !array_key_exists( $key , $forbiddenKeys ) ) { |
— | — | @@ -326,7 +335,11 @@ |
327 | 336 | // And we only want message arrays |
328 | 337 | preg_match_all( "/\\\$messages(.*\s)*?\);/", $contents, $results ); |
329 | 338 | // But we want them all in one string |
330 | | - $contents = implode( "\n\n", $results[0] ); |
| 339 | + if(!empty($results[0]) && is_array($results[0])) { |
| 340 | + $contents = implode( "\n\n", $results[0] ); |
| 341 | + } else { |
| 342 | + $contents = ""; |
| 343 | + } |
331 | 344 | |
332 | 345 | // And we hate the windows vs linux linebreaks |
333 | 346 | $contents = preg_replace( "/\\\r/", "", $contents ); |
— | — | @@ -340,11 +353,8 @@ |
341 | 354 | $base_messages = array(); |
342 | 355 | |
343 | 356 | $basefilecontents = self::getFileContents( $basefile ); |
344 | | - if ( $basefilecontents === false ) return array(); // Failed |
| 357 | + if ( $basefilecontents === false || $basefilecontents === "" ) return array(); // Failed |
345 | 358 | |
346 | | - $basehash = ""; |
347 | | - $comparehash = ""; |
348 | | - |
349 | 359 | // Cleanup the file where needed |
350 | 360 | $basefilecontents = self::cleanupExtensionFile( $basefilecontents ); |
351 | 361 | |
— | — | @@ -365,7 +375,7 @@ |
366 | 376 | eval( $basefilecontents ); |
367 | 377 | |
368 | 378 | $comparefilecontents = self::getFileContents( $comparefile ); |
369 | | - if ( $comparefilecontents === false ) return array(); // Failed |
| 379 | + if ( $comparefilecontents === false || $comparefilecontents === "" ) return array(); // Failed |
370 | 380 | |
371 | 381 | // Only get what we need |
372 | 382 | $comparefilecontents = self::cleanupExtensionFile( $comparefilecontents ); |
— | — | @@ -392,10 +402,16 @@ |
393 | 403 | // Update counter |
394 | 404 | $updates = 0; |
395 | 405 | |
| 406 | + if(!is_array($base_messages)) |
| 407 | + $base_messages = array(); |
| 408 | + |
396 | 409 | if ( empty( $base_messages['en'] ) ) { |
397 | 410 | $base_messages['en'] = array(); |
398 | 411 | } |
399 | 412 | |
| 413 | + if(!is_array($compare_messages)) |
| 414 | + $compare_messages = array(); |
| 415 | + |
400 | 416 | if ( empty( $compare_messages['en'] ) ) { |
401 | 417 | $compare_messages['en'] = array(); |
402 | 418 | } |