@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\logs\images\delete; |
4 | 4 | |
5 | -use Exception; |
|
6 | 5 | use okapi\Okapi; |
7 | 6 | use okapi\Db; |
8 | 7 | use okapi\OkapiRequest; |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | $image_row = Db::select_row(" |
32 | 32 | select id, node, url, local |
33 | 33 | from pictures |
34 | - where uuid = '".$image_uuid_escaped."' |
|
34 | + where uuid = '".$image_uuid_escaped . "' |
|
35 | 35 | "); |
36 | 36 | Db::execute(" |
37 | - delete from pictures where uuid = '".$image_uuid_escaped."' |
|
37 | + delete from pictures where uuid = '".$image_uuid_escaped . "' |
|
38 | 38 | "); |
39 | 39 | |
40 | 40 | # Remember that OCPL picture sequence numbers are always 1, and |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | localID, uuid, type, removed_date, node |
53 | 53 | ) |
54 | 54 | VALUES ( |
55 | - ".$image_row['id']." |
|
56 | - '".$image_uuid_escaped."', |
|
55 | + ".$image_row['id'] . " |
|
56 | + '".$image_uuid_escaped . "', |
|
57 | 57 | 6, |
58 | 58 | NOW(), |
59 | 59 | ".$image_row['node'] |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | set |
73 | 73 | picturescount = greatest(0, picturescount - 1), |
74 | 74 | last_modified = NOW() |
75 | - where id = '".Db::escape_string($log_internal_id)."' |
|
75 | + where id = '".Db::escape_string($log_internal_id) . "' |
|
76 | 76 | "); |
77 | 77 | } |
78 | 78 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | if ($image_row['local']) { |
82 | 82 | $filename = basename($image_row['url']); |
83 | - unlink(Settings::get('IMAGES_DIR').'/'.$filename); |
|
83 | + unlink(Settings::get('IMAGES_DIR') . '/' . $filename); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $result = array( |
@@ -44,8 +44,7 @@ |
||
44 | 44 | if (Settings::get('OC_BRANCH') == 'oc.de') |
45 | 45 | { |
46 | 46 | # OCDE does all the housekeeping by triggers |
47 | - } |
|
48 | - else |
|
47 | + } else |
|
49 | 48 | { |
50 | 49 | Db::execute(" |
51 | 50 | INSERT INTO removed_objects ( |
@@ -17,6 +17,9 @@ discard block |
||
17 | 17 | |
18 | 18 | class LogImagesCommon |
19 | 19 | { |
20 | + /** |
|
21 | + * @param OkapiRequest $request |
|
22 | + */ |
|
20 | 23 | function validate_image_uuid($request) |
21 | 24 | { |
22 | 25 | $image_uuid = $request->get_parameter('image_uuid'); |
@@ -63,6 +66,9 @@ discard block |
||
63 | 66 | } |
64 | 67 | |
65 | 68 | |
69 | + /** |
|
70 | + * @param OkapiRequest $request |
|
71 | + */ |
|
66 | 72 | function validate_position($request) |
67 | 73 | { |
68 | 74 | $position = $request->get_parameter('position'); |
@@ -87,6 +93,7 @@ discard block |
||
87 | 93 | * |
88 | 94 | * This function is always called when adding images. When editing images, |
89 | 95 | * it is called only for OCDE and if the position parameter was supplied. |
96 | + * @param integer $end_offset |
|
90 | 97 | */ |
91 | 98 | |
92 | 99 | static function prepare_position($log_internal_id, $position, $end_offset) |
@@ -7,12 +7,9 @@ |
||
7 | 7 | namespace okapi\services\logs\images; |
8 | 8 | |
9 | 9 | use Exception; |
10 | -use okapi\Okapi; |
|
11 | 10 | use okapi\Db; |
12 | -use okapi\OkapiRequest; |
|
13 | 11 | use okapi\InvalidParam; |
14 | 12 | use okapi\Settings; |
15 | -use okapi\BadRequest; |
|
16 | 13 | |
17 | 14 | |
18 | 15 | class LogImagesCommon |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | pictures.node |
37 | 37 | from cache_logs |
38 | 38 | join pictures on pictures.object_id = cache_logs.id |
39 | - where pictures.object_type = 1 and pictures.uuid = '".Db::escape_string($image_uuid)."' |
|
39 | + where pictures.object_type = 1 and pictures.uuid = '".Db::escape_string($image_uuid) . "' |
|
40 | 40 | "); |
41 | 41 | $row = Db::fetch_assoc($rs); |
42 | 42 | Db::free_result($rs); |
43 | 43 | if (!$row) { |
44 | 44 | throw new InvalidParam( |
45 | 45 | 'image_uuid', |
46 | - "There is no log entry image with uuid '".$image_uuid."'." |
|
46 | + "There is no log entry image with uuid '" . $image_uuid . "'." |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | if ($row['node'] != Settings::get('OC_NODE_ID')) { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | $position = $request->get_parameter('position'); |
69 | 69 | if ($position !== null && !preg_match("/^-?[0-9]+$/", $position)) { |
70 | - throw new InvalidParam('position', "'".$position."' is not an integer number."); |
|
70 | + throw new InvalidParam('position', "'" . $position . "' is not an integer number."); |
|
71 | 71 | } |
72 | 72 | return $position; |
73 | 73 | } |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | Db::execute('lock tables pictures write'); |
102 | 102 | } |
103 | 103 | |
104 | - $log_images_count = Db::select_value(" |
|
104 | + $log_images_count = Db::select_value(" |
|
105 | 105 | select count(*) |
106 | 106 | from pictures |
107 | - where object_type = 1 and object_id = '".Db::escape_string($log_internal_id)."' |
|
107 | + where object_type = 1 and object_id = '".Db::escape_string($log_internal_id) . "' |
|
108 | 108 | "); |
109 | 109 | |
110 | 110 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $seq = Db::select_value(" |
123 | 123 | select max(seq) |
124 | 124 | from pictures |
125 | - where object_type = 1 and object_id = '".Db::escape_string($log_internal_id)."' |
|
125 | + where object_type = 1 and object_id = '".Db::escape_string($log_internal_id) . "' |
|
126 | 126 | ") + $end_offset; |
127 | 127 | } else if ($position <= 0) { |
128 | 128 | $position = 0; |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | $seq = Db::select_value(" |
132 | 132 | select seq |
133 | 133 | from pictures |
134 | - where object_type = 1 and object_id = '".Db::escape_string($log_internal_id)."' |
|
134 | + where object_type = 1 and object_id = '".Db::escape_string($log_internal_id) . "' |
|
135 | 135 | order by seq |
136 | - limit ".($position+0).", 1 |
|
136 | + limit ".($position + 0) . ", 1 |
|
137 | 137 | "); |
138 | 138 | } |
139 | 139 | } |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | function validate_image_uuid($request) |
21 | 21 | { |
22 | 22 | $image_uuid = $request->get_parameter('image_uuid'); |
23 | - if (!$image_uuid) |
|
24 | - throw new ParamMissing('image_uuid'); |
|
23 | + if (!$image_uuid) { |
|
24 | + throw new ParamMissing('image_uuid'); |
|
25 | + } |
|
25 | 26 | |
26 | 27 | # When uploading images, OCPL stores the user_id of the uploader |
27 | 28 | # in the 'pictures' table. This is redundant to cache_logs.user_id, |
@@ -114,8 +115,7 @@ discard block |
||
114 | 115 | |
115 | 116 | $position = $log_images_count; |
116 | 117 | $seq = 1; |
117 | - } |
|
118 | - else |
|
118 | + } else |
|
119 | 119 | { |
120 | 120 | if ($position === null || $position >= $log_images_count) { |
121 | 121 | $position = $log_images_count - 1 + $end_offset; |
@@ -713,6 +713,9 @@ discard block |
||
713 | 713 | return Okapi::formatted_response($request, $result); |
714 | 714 | } |
715 | 715 | |
716 | + /** |
|
717 | + * @param integer $when |
|
718 | + */ |
|
716 | 719 | private static function increment_cache_stats($cache_internal_id, $when, $logtype) |
717 | 720 | { |
718 | 721 | if (Settings::get('OC_BRANCH') == 'oc.de') |
@@ -788,6 +791,10 @@ discard block |
||
788 | 791 | } |
789 | 792 | } |
790 | 793 | |
794 | + /** |
|
795 | + * @param integer $when |
|
796 | + * @param integer $text_html |
|
797 | + */ |
|
791 | 798 | private static function insert_log_row( |
792 | 799 | $consumer_key, $cache_internal_id, $user_internal_id, $logtype, $when, |
793 | 800 | $formatted_comment, $text_html, $needs_maintenance2 |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | 'when', "'$tmp' is not in a valid format or is not a valid date." |
71 | 71 | ); |
72 | 72 | } |
73 | - if ($when > time() + 5*60) { |
|
73 | + if ($when > time() + 5 * 60) { |
|
74 | 74 | throw new CannotPublishException(_( |
75 | - "You are trying to publish a log entry with a date in ". |
|
76 | - "future. Cache log entries are allowed to be published in ". |
|
75 | + "You are trying to publish a log entry with a date in " . |
|
76 | + "future. Cache log entries are allowed to be published in " . |
|
77 | 77 | "the past, but NOT in the future." |
78 | 78 | )); |
79 | 79 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | $rating = $request->get_parameter('rating'); |
94 | - if ($rating !== null && (!in_array($rating, array(1,2,3,4,5)))) { |
|
94 | + if ($rating !== null && (!in_array($rating, array(1, 2, 3, 4, 5)))) { |
|
95 | 95 | throw new InvalidParam( |
96 | 96 | 'rating', "If present, it must be an integer in the 1..5 scale." |
97 | 97 | ); |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | # (which will be returned IF the rest of the query will meet all the |
108 | 108 | # requirements). |
109 | 109 | |
110 | - self::$success_message .= " ".sprintf(_( |
|
111 | - "However, your cache rating was ignored, because %s does not ". |
|
110 | + self::$success_message .= " " . sprintf(_( |
|
111 | + "However, your cache rating was ignored, because %s does not " . |
|
112 | 112 | "have a rating system." |
113 | 113 | ), Okapi::get_normalized_site_name()); |
114 | 114 | $rating = null; |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | # (which will be returned IF the rest of the query will meet all the |
133 | 133 | # requirements). |
134 | 134 | |
135 | - self::$success_message .= " ".sprintf(_( |
|
136 | - "However, your cache recommendation was ignored, because ". |
|
135 | + self::$success_message .= " " . sprintf(_( |
|
136 | + "However, your cache recommendation was ignored, because " . |
|
137 | 137 | "%s does not allow recommending event caches." |
138 | 138 | ), Okapi::get_normalized_site_name()); |
139 | 139 | $recommend = null; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $needs_maintenance2 = $request->get_parameter('needs_maintenance2'); |
148 | 148 | if ($needs_maintenance && $needs_maintenance2) { |
149 | 149 | throw new BadRequest( |
150 | - "You cannot use both of these parameters at the same time: ". |
|
150 | + "You cannot use both of these parameters at the same time: " . |
|
151 | 151 | "needs_maintenance and needs_maintenance2." |
152 | 152 | ); |
153 | 153 | } |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | ) { |
182 | 182 | # If not supported, just ignore it. |
183 | 183 | |
184 | - self::$success_message .= " ".sprintf(_( |
|
185 | - "However, your \"does not need maintenance\" flag was ignored, because ". |
|
184 | + self::$success_message .= " " . sprintf(_( |
|
185 | + "However, your \"does not need maintenance\" flag was ignored, because " . |
|
186 | 186 | "%s does not yet support this feature." |
187 | 187 | ), Okapi::get_normalized_site_name()); |
188 | 188 | $needs_maintenance2 = 'null'; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | { |
213 | 213 | if (!in_array($logtype, array('Will attend', 'Attended', 'Comment'))) { |
214 | 214 | throw new CannotPublishException(_( |
215 | - 'This cache is an Event cache. You cannot "Find" it (but '. |
|
215 | + 'This cache is an Event cache. You cannot "Find" it (but ' . |
|
216 | 216 | 'you can attend it, or comment on it)!' |
217 | 217 | )); |
218 | 218 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | { |
222 | 222 | if (in_array($logtype, array('Will attend', 'Attended'))) { |
223 | 223 | throw new CannotPublishException(_( |
224 | - 'This cache is NOT an Event cache. You cannot "Attend" it '. |
|
224 | + 'This cache is NOT an Event cache. You cannot "Attend" it ' . |
|
225 | 225 | '(but you can find it, or comment on it)!' |
226 | 226 | )); |
227 | 227 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | $valid_password = Db::select_value(" |
243 | 243 | select logpw |
244 | 244 | from caches |
245 | - where cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
245 | + where cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
246 | 246 | "); |
247 | 247 | $supplied_password = $request->get_parameter('password'); |
248 | 248 | if (!$supplied_password) { |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | select 1 |
359 | 359 | from cache_logs |
360 | 360 | where |
361 | - user_id = '".Db::escape_string($request->token->user_id)."' |
|
362 | - and cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
361 | + user_id = '".Db::escape_string($request->token->user_id) . "' |
|
362 | + and cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
363 | 363 | for update |
364 | 364 | "); |
365 | 365 | |
@@ -378,12 +378,12 @@ discard block |
||
378 | 378 | select uuid |
379 | 379 | from cache_logs |
380 | 380 | where |
381 | - user_id = '".Db::escape_string($request->token->user_id)."' |
|
382 | - and cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
383 | - and type = '".Db::escape_string(Okapi::logtypename2id($logtype))."' |
|
384 | - and date = from_unixtime('".Db::escape_string($when)."') |
|
385 | - and text = '".Db::escape_string($formatted_comment)."' |
|
386 | - ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and deleted = 0" : "")." |
|
381 | + user_id = '".Db::escape_string($request->token->user_id) . "' |
|
382 | + and cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
383 | + and type = '".Db::escape_string(Okapi::logtypename2id($logtype)) . "' |
|
384 | + and date = from_unixtime('".Db::escape_string($when) . "') |
|
385 | + and text = '".Db::escape_string($formatted_comment) . "' |
|
386 | + ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and deleted = 0" : "") . " |
|
387 | 387 | limit 1 |
388 | 388 | "); |
389 | 389 | if ($duplicate_uuid != null) |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | elseif ($on_duplicate == 'user_error') |
397 | 397 | { |
398 | 398 | throw new CannotPublishException(_( |
399 | - "You have already submitted a log entry with exactly ". |
|
399 | + "You have already submitted a log entry with exactly " . |
|
400 | 400 | "the same contents." |
401 | 401 | )); |
402 | 402 | } |
@@ -416,20 +416,20 @@ discard block |
||
416 | 416 | select 1 |
417 | 417 | from cache_logs |
418 | 418 | where |
419 | - user_id = '".Db::escape_string($user['internal_id'])."' |
|
420 | - and cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
421 | - and type = '".Db::escape_string(Okapi::logtypename2id("Found it"))."' |
|
422 | - and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")." |
|
419 | + user_id = '".Db::escape_string($user['internal_id']) . "' |
|
420 | + and cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
421 | + and type = '".Db::escape_string(Okapi::logtypename2id("Found it")) . "' |
|
422 | + and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true") . " |
|
423 | 423 | "); |
424 | 424 | if ($has_already_found_it) { |
425 | 425 | throw new CannotPublishException(_( |
426 | - "You have already submitted a \"Found it\" log entry once. ". |
|
426 | + "You have already submitted a \"Found it\" log entry once. " . |
|
427 | 427 | "Now you may submit \"Comments\" only!" |
428 | 428 | )); |
429 | 429 | } |
430 | 430 | if ($user['uuid'] == $cache['owner']['uuid']) { |
431 | 431 | throw new CannotPublishException(_( |
432 | - "You are the owner of this cache. You may submit ". |
|
432 | + "You are the owner of this cache. You may submit " . |
|
433 | 433 | "\"Comments\" only!" |
434 | 434 | )); |
435 | 435 | } |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | select 1 |
447 | 447 | from scores |
448 | 448 | where |
449 | - user_id = '".Db::escape_string($user['internal_id'])."' |
|
450 | - and cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
449 | + user_id = '".Db::escape_string($user['internal_id']) . "' |
|
450 | + and cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
451 | 451 | "); |
452 | 452 | if ($has_already_rated) { |
453 | 453 | throw new CannotPublishException(_( |
454 | - "You have already rated this cache once. Your rating ". |
|
454 | + "You have already rated this cache once. Your rating " . |
|
455 | 455 | "cannot be changed." |
456 | 456 | )); |
457 | 457 | } |
@@ -467,8 +467,8 @@ discard block |
||
467 | 467 | select 1 |
468 | 468 | from cache_rating |
469 | 469 | where |
470 | - user_id = '".Db::escape_string($user['internal_id'])."' |
|
471 | - and cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
470 | + user_id = '".Db::escape_string($user['internal_id']) . "' |
|
471 | + and cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
472 | 472 | "); |
473 | 473 | if ($already_recommended) { |
474 | 474 | throw new CannotPublishException(_( |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | |
479 | 479 | # Check the number of recommendations. |
480 | 480 | |
481 | - $founds = $user['caches_found'] + 1; // +1, because he'll find THIS ONE in a moment |
|
481 | + $founds = $user['caches_found'] + 1; // +1, because he'll find THIS ONE in a moment |
|
482 | 482 | |
483 | 483 | # Note: caches_found includes the number of attended events (both on |
484 | 484 | # OCDE and OCPL). OCPL does not allow recommending events, but the |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | $rcmds_left = floor($founds / 10.0) - $user['rcmds_given']; |
489 | 489 | if ($rcmds_left <= 0) { |
490 | 490 | throw new CannotPublishException(_( |
491 | - "You don't have any recommendations to give. Find more ". |
|
491 | + "You don't have any recommendations to give. Find more " . |
|
492 | 492 | "caches first!" |
493 | 493 | )); |
494 | 494 | } |
@@ -615,17 +615,17 @@ discard block |
||
615 | 615 | update caches |
616 | 616 | set |
617 | 617 | score = ( |
618 | - score*votes + '".Db::escape_string($db_score)."' |
|
618 | + score*votes + '".Db::escape_string($db_score) . "' |
|
619 | 619 | ) / (votes + 1), |
620 | 620 | votes = votes + 1 |
621 | - where cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
621 | + where cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
622 | 622 | "); |
623 | 623 | Db::execute(" |
624 | 624 | insert into scores (user_id, cache_id, score) |
625 | 625 | values ( |
626 | - '".Db::escape_string($user['internal_id'])."', |
|
627 | - '".Db::escape_string($cache['internal_id'])."', |
|
628 | - '".Db::escape_string($db_score)."' |
|
626 | + '".Db::escape_string($user['internal_id']) . "', |
|
627 | + '".Db::escape_string($cache['internal_id']) . "', |
|
628 | + '".Db::escape_string($db_score) . "' |
|
629 | 629 | ); |
630 | 630 | "); |
631 | 631 | } |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | Db::execute(" |
640 | 640 | insert into cache_rating (user_id, cache_id, rating_date) |
641 | 641 | values ( |
642 | - '".Db::escape_string($user['internal_id'])."', |
|
643 | - '".Db::escape_string($cache['internal_id'])."', |
|
644 | - from_unixtime('".Db::escape_string($when)."') |
|
642 | + '".Db::escape_string($user['internal_id']) . "', |
|
643 | + '".Db::escape_string($cache['internal_id']) . "', |
|
644 | + from_unixtime('".Db::escape_string($when) . "') |
|
645 | 645 | ); |
646 | 646 | "); |
647 | 647 | } |
@@ -650,8 +650,8 @@ discard block |
||
650 | 650 | Db::execute(" |
651 | 651 | insert into cache_rating (user_id, cache_id) |
652 | 652 | values ( |
653 | - '".Db::escape_string($user['internal_id'])."', |
|
654 | - '".Db::escape_string($cache['internal_id'])."' |
|
653 | + '".Db::escape_string($user['internal_id']) . "', |
|
654 | + '".Db::escape_string($cache['internal_id']) . "' |
|
655 | 655 | ); |
656 | 656 | "); |
657 | 657 | } |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | # We need to delete the copy of stats-picture for this user. Otherwise, |
665 | 665 | # the legacy OC code won't detect that the picture needs to be refreshed. |
666 | 666 | |
667 | - $filepath = Okapi::get_var_dir().'/images/statpics/statpic'.$user['internal_id'].'.jpg'; |
|
667 | + $filepath = Okapi::get_var_dir() . '/images/statpics/statpic' . $user['internal_id'] . '.jpg'; |
|
668 | 668 | if (file_exists($filepath)) { |
669 | 669 | unlink($filepath); |
670 | 670 | } |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | founds = founds + 1, |
733 | 733 | last_found = greatest( |
734 | 734 | ifnull(last_found, 0), |
735 | - from_unixtime('".Db::escape_string($when)."') |
|
735 | + from_unixtime('".Db::escape_string($when) . "') |
|
736 | 736 | ) |
737 | - where cache_id = '".Db::escape_string($cache_internal_id)."' |
|
737 | + where cache_id = '".Db::escape_string($cache_internal_id) . "' |
|
738 | 738 | "); |
739 | 739 | } |
740 | 740 | elseif ($logtype == "Didn't find it") |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | Db::execute(" |
743 | 743 | update caches |
744 | 744 | set notfounds = notfounds + 1 |
745 | - where cache_id = '".Db::escape_string($cache_internal_id)."' |
|
745 | + where cache_id = '".Db::escape_string($cache_internal_id) . "' |
|
746 | 746 | "); |
747 | 747 | } |
748 | 748 | elseif ($logtype == 'Comment') |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | Db::execute(" |
751 | 751 | update caches |
752 | 752 | set notes = notes + 1 |
753 | - where cache_id = '".Db::escape_string($cache_internal_id)."' |
|
753 | + where cache_id = '".Db::escape_string($cache_internal_id) . "' |
|
754 | 754 | "); |
755 | 755 | } |
756 | 756 | else |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | Db::execute(" |
784 | 784 | update user |
785 | 785 | set $field_to_increment = $field_to_increment + 1 |
786 | - where user_id = '".Db::escape_string($user_internal_id)."' |
|
786 | + where user_id = '" . Db::escape_string($user_internal_id) . "' |
|
787 | 787 | "); |
788 | 788 | } |
789 | 789 | } |
@@ -812,19 +812,19 @@ discard block |
||
812 | 812 | Db::execute(" |
813 | 813 | insert into cache_logs ( |
814 | 814 | uuid, cache_id, user_id, type, date, text, text_html, |
815 | - last_modified, date_created, node".$needs_maintenance_field_SQL." |
|
815 | + last_modified, date_created, node".$needs_maintenance_field_SQL . " |
|
816 | 816 | ) values ( |
817 | - '".Db::escape_string($log_uuid)."', |
|
818 | - '".Db::escape_string($cache_internal_id)."', |
|
819 | - '".Db::escape_string($user_internal_id)."', |
|
820 | - '".Db::escape_string(Okapi::logtypename2id($logtype))."', |
|
821 | - from_unixtime('".Db::escape_string($when)."'), |
|
822 | - '".Db::escape_string($formatted_comment)."', |
|
823 | - '".Db::escape_string($text_html)."', |
|
817 | + '".Db::escape_string($log_uuid) . "', |
|
818 | + '".Db::escape_string($cache_internal_id) . "', |
|
819 | + '".Db::escape_string($user_internal_id) . "', |
|
820 | + '".Db::escape_string(Okapi::logtypename2id($logtype)) . "', |
|
821 | + from_unixtime('".Db::escape_string($when) . "'), |
|
822 | + '".Db::escape_string($formatted_comment) . "', |
|
823 | + '".Db::escape_string($text_html) . "', |
|
824 | 824 | now(), |
825 | 825 | now(), |
826 | - '".Db::escape_string(Settings::get('OC_NODE_ID'))."' |
|
827 | - ".$needs_maintenance_SQL." |
|
826 | + '".Db::escape_string(Settings::get('OC_NODE_ID')) . "' |
|
827 | + ".$needs_maintenance_SQL . " |
|
828 | 828 | ); |
829 | 829 | "); |
830 | 830 | $log_internal_id = Db::last_insert_id(); |
@@ -835,9 +835,9 @@ discard block |
||
835 | 835 | Db::execute(" |
836 | 836 | insert into okapi_submitted_objects (object_type, object_id, consumer_key) |
837 | 837 | values ( |
838 | - ".Okapi::OBJECT_TYPE_CACHE_LOG.", |
|
839 | - '".Db::escape_string($log_internal_id)."', |
|
840 | - '".Db::escape_string($consumer_key)."' |
|
838 | + ".Okapi::OBJECT_TYPE_CACHE_LOG . ", |
|
839 | + '".Db::escape_string($log_internal_id) . "', |
|
840 | + '".Db::escape_string($consumer_key) . "' |
|
841 | 841 | ); |
842 | 842 | "); |
843 | 843 |
@@ -43,10 +43,14 @@ discard block |
||
43 | 43 | # "call"). |
44 | 44 | |
45 | 45 | $cache_code = $request->get_parameter('cache_code'); |
46 | - if (!$cache_code) throw new ParamMissing('cache_code'); |
|
46 | + if (!$cache_code) { |
|
47 | + throw new ParamMissing('cache_code'); |
|
48 | + } |
|
47 | 49 | |
48 | 50 | $logtype = $request->get_parameter('logtype'); |
49 | - if (!$logtype) throw new ParamMissing('logtype'); |
|
51 | + if (!$logtype) { |
|
52 | + throw new ParamMissing('logtype'); |
|
53 | + } |
|
50 | 54 | if (!in_array($logtype, array( |
51 | 55 | 'Found it', "Didn't find it", 'Comment', 'Will attend', 'Attended' |
52 | 56 | ))) { |
@@ -54,12 +58,17 @@ discard block |
||
54 | 58 | } |
55 | 59 | |
56 | 60 | $comment = $request->get_parameter('comment'); |
57 | - if (!$comment) $comment = ""; |
|
61 | + if (!$comment) { |
|
62 | + $comment = ""; |
|
63 | + } |
|
58 | 64 | |
59 | 65 | $comment_format = $request->get_parameter('comment_format'); |
60 | - if (!$comment_format) $comment_format = "auto"; |
|
61 | - if (!in_array($comment_format, array('auto', 'html', 'plaintext'))) |
|
62 | - throw new InvalidParam('comment_format', $comment_format); |
|
66 | + if (!$comment_format) { |
|
67 | + $comment_format = "auto"; |
|
68 | + } |
|
69 | + if (!in_array($comment_format, array('auto', 'html', 'plaintext'))) { |
|
70 | + throw new InvalidParam('comment_format', $comment_format); |
|
71 | + } |
|
63 | 72 | |
64 | 73 | $tmp = $request->get_parameter('when'); |
65 | 74 | if ($tmp) |
@@ -77,8 +86,7 @@ discard block |
||
77 | 86 | "the past, but NOT in the future." |
78 | 87 | )); |
79 | 88 | } |
80 | - } |
|
81 | - else { |
|
89 | + } else { |
|
82 | 90 | $when = time(); |
83 | 91 | } |
84 | 92 | |
@@ -115,9 +123,12 @@ discard block |
||
115 | 123 | } |
116 | 124 | |
117 | 125 | $recommend = $request->get_parameter('recommend'); |
118 | - if (!$recommend) $recommend = 'false'; |
|
119 | - if (!in_array($recommend, array('true', 'false'))) |
|
120 | - throw new InvalidParam('recommend', "Unknown option: '$recommend'."); |
|
126 | + if (!$recommend) { |
|
127 | + $recommend = 'false'; |
|
128 | + } |
|
129 | + if (!in_array($recommend, array('true', 'false'))) { |
|
130 | + throw new InvalidParam('recommend', "Unknown option: '$recommend'."); |
|
131 | + } |
|
121 | 132 | $recommend = ($recommend == 'true'); |
122 | 133 | if ($recommend && $logtype != 'Found it') |
123 | 134 | { |
@@ -125,8 +136,7 @@ discard block |
||
125 | 136 | throw new BadRequest( |
126 | 137 | "Recommending is allowed only for 'Found it' and 'Attended' logs." |
127 | 138 | ); |
128 | - } |
|
129 | - else if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
139 | + } else if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
130 | 140 | |
131 | 141 | # We will remove the recommendation request and change the success message |
132 | 142 | # (which will be returned IF the rest of the query will meet all the |
@@ -156,9 +166,7 @@ discard block |
||
156 | 166 | # Parse $needs_maintenance and get rid of it. |
157 | 167 | |
158 | 168 | if ($needs_maintenance) { |
159 | - if ($needs_maintenance == 'true') { $needs_maintenance2 = 'true'; } |
|
160 | - else if ($needs_maintenance == 'false') { $needs_maintenance2 = 'null'; } |
|
161 | - else { |
|
169 | + if ($needs_maintenance == 'true') { $needs_maintenance2 = 'true'; } else if ($needs_maintenance == 'false') { $needs_maintenance2 = 'null'; } else { |
|
162 | 170 | throw new InvalidParam( |
163 | 171 | 'needs_maintenance', "Unknown option: '$needs_maintenance'." |
164 | 172 | ); |
@@ -216,16 +224,14 @@ discard block |
||
216 | 224 | 'you can attend it, or comment on it)!' |
217 | 225 | )); |
218 | 226 | } |
219 | - } |
|
220 | - else # type != event |
|
227 | + } else # type != event |
|
221 | 228 | { |
222 | 229 | if (in_array($logtype, array('Will attend', 'Attended'))) { |
223 | 230 | throw new CannotPublishException(_( |
224 | 231 | 'This cache is NOT an Event cache. You cannot "Attend" it '. |
225 | 232 | '(but you can find it, or comment on it)!' |
226 | 233 | )); |
227 | - } |
|
228 | - else if (!in_array($logtype, array('Found it', "Didn't find it", 'Comment'))) { |
|
234 | + } else if (!in_array($logtype, array('Found it', "Didn't find it", 'Comment'))) { |
|
229 | 235 | throw new Exception("Unknown log entry - should be documented here."); |
230 | 236 | } |
231 | 237 | } |
@@ -276,8 +282,7 @@ discard block |
||
276 | 282 | if (Settings::get('OC_BRANCH') == 'oc.de') |
277 | 283 | { |
278 | 284 | $value_for_text_html_field = 0; |
279 | - } |
|
280 | - else |
|
285 | + } else |
|
281 | 286 | { |
282 | 287 | # 'text_html' = 0 (false) is broken in OCPL code and has been |
283 | 288 | # deprecated; OCPL code was changed to always set it to 1 (true). |
@@ -289,8 +294,7 @@ discard block |
||
289 | 294 | |
290 | 295 | $value_for_text_html_field = 1; |
291 | 296 | } |
292 | - } |
|
293 | - elseif ($comment_format == 'auto') |
|
297 | + } elseif ($comment_format == 'auto') |
|
294 | 298 | { |
295 | 299 | # 'Auto' is for backward compatibility. Before the "comment_format" |
296 | 300 | # was introduced, OKAPI used a weird format in between (it allowed |
@@ -298,8 +302,7 @@ discard block |
||
298 | 302 | |
299 | 303 | $formatted_comment = nl2br($comment); |
300 | 304 | $value_for_text_html_field = 1; |
301 | - } |
|
302 | - else |
|
305 | + } else |
|
303 | 306 | { |
304 | 307 | $formatted_comment = $comment; |
305 | 308 | |
@@ -318,8 +321,7 @@ discard block |
||
318 | 321 | |
319 | 322 | $purifier = new \OcHTMLPurifier($opt); |
320 | 323 | $formatted_comment = $purifier->purify($formatted_comment); |
321 | - } |
|
322 | - else |
|
324 | + } else |
|
323 | 325 | { |
324 | 326 | # TODO: Add OCPL HTML filtering. |
325 | 327 | # See https://github.com/opencaching/okapi/issues/412. |
@@ -392,8 +394,7 @@ discard block |
||
392 | 394 | { |
393 | 395 | # Act as if the log has been submitted successfully. |
394 | 396 | return $duplicate_uuid; |
395 | - } |
|
396 | - elseif ($on_duplicate == 'user_error') |
|
397 | + } elseif ($on_duplicate == 'user_error') |
|
397 | 398 | { |
398 | 399 | throw new CannotPublishException(_( |
399 | 400 | "You have already submitted a log entry with exactly ". |
@@ -511,8 +512,7 @@ discard block |
||
511 | 512 | $logtype = 'Needs maintenance'; |
512 | 513 | $second_logtype = null; |
513 | 514 | $second_formatted_comment = null; |
514 | - } |
|
515 | - elseif ($logtype == 'Found it') |
|
515 | + } elseif ($logtype == 'Found it') |
|
516 | 516 | { |
517 | 517 | # If "Found it", then we'll issue two log entries: one "Found |
518 | 518 | # it" with the original comment, and second one "Needs |
@@ -520,8 +520,7 @@ discard block |
||
520 | 520 | |
521 | 521 | $second_logtype = 'Needs maintenance'; |
522 | 522 | $second_formatted_comment = ""; |
523 | - } |
|
524 | - elseif ($logtype == "Didn't find it") |
|
523 | + } elseif ($logtype == "Didn't find it") |
|
525 | 524 | { |
526 | 525 | # If "Didn't find it", then we'll issue two log entries, but this time |
527 | 526 | # we'll do this the other way around. The first "Didn't find it" entry |
@@ -532,8 +531,7 @@ discard block |
||
532 | 531 | $second_logtype = 'Needs maintenance'; |
533 | 532 | $second_formatted_comment = $formatted_comment; |
534 | 533 | $formatted_comment = ""; |
535 | - } |
|
536 | - else if ($logtype == 'Will attend' || $logtype == 'Attended') |
|
534 | + } else if ($logtype == 'Will attend' || $logtype == 'Attended') |
|
537 | 535 | { |
538 | 536 | # OC branches which allow maintenance logs, still don't allow them on |
539 | 537 | # event caches. |
@@ -541,12 +539,10 @@ discard block |
||
541 | 539 | throw new CannotPublishException(_( |
542 | 540 | "Event caches cannot \"need maintenance\"." |
543 | 541 | )); |
544 | - } |
|
545 | - else { |
|
542 | + } else { |
|
546 | 543 | throw new Exception(); |
547 | 544 | } |
548 | - } |
|
549 | - else |
|
545 | + } else |
|
550 | 546 | { |
551 | 547 | # User didn't check the "Needs maintenance" flag OR "Needs maintenance" |
552 | 548 | # log type isn't supported by this server. |
@@ -644,8 +640,7 @@ discard block |
||
644 | 640 | from_unixtime('".Db::escape_string($when)."') |
645 | 641 | ); |
646 | 642 | "); |
647 | - } |
|
648 | - else |
|
643 | + } else |
|
649 | 644 | { |
650 | 645 | Db::execute(" |
651 | 646 | insert into cache_rating (user_id, cache_id) |
@@ -680,7 +675,9 @@ discard block |
||
680 | 675 | # This is the "real" entry point. A wrapper for the _call method. |
681 | 676 | |
682 | 677 | $langpref = $request->get_parameter('langpref'); |
683 | - if (!$langpref) $langpref = "en"; |
|
678 | + if (!$langpref) { |
|
679 | + $langpref = "en"; |
|
680 | + } |
|
684 | 681 | |
685 | 682 | # Error messages thrown via CannotPublishException exceptions should be localized. |
686 | 683 | # They will be delivered for end user to display in his language. |
@@ -698,8 +695,7 @@ discard block |
||
698 | 695 | 'log_uuids' => $log_uuids |
699 | 696 | ); |
700 | 697 | Okapi::gettext_domain_restore(); |
701 | - } |
|
702 | - catch (CannotPublishException $e) |
|
698 | + } catch (CannotPublishException $e) |
|
703 | 699 | { |
704 | 700 | Okapi::gettext_domain_restore(); |
705 | 701 | $result = array( |
@@ -719,8 +715,7 @@ discard block |
||
719 | 715 | { |
720 | 716 | # OCDE handles cache stats updates using triggers. So, they are already |
721 | 717 | # incremented properly. |
722 | - } |
|
723 | - else |
|
718 | + } else |
|
724 | 719 | { |
725 | 720 | # OCPL doesn't use triggers for this. We need to update manually. |
726 | 721 | |
@@ -736,24 +731,21 @@ discard block |
||
736 | 731 | ) |
737 | 732 | where cache_id = '".Db::escape_string($cache_internal_id)."' |
738 | 733 | "); |
739 | - } |
|
740 | - elseif ($logtype == "Didn't find it") |
|
734 | + } elseif ($logtype == "Didn't find it") |
|
741 | 735 | { |
742 | 736 | Db::execute(" |
743 | 737 | update caches |
744 | 738 | set notfounds = notfounds + 1 |
745 | 739 | where cache_id = '".Db::escape_string($cache_internal_id)."' |
746 | 740 | "); |
747 | - } |
|
748 | - elseif ($logtype == 'Comment') |
|
741 | + } elseif ($logtype == 'Comment') |
|
749 | 742 | { |
750 | 743 | Db::execute(" |
751 | 744 | update caches |
752 | 745 | set notes = notes + 1 |
753 | 746 | where cache_id = '".Db::escape_string($cache_internal_id)."' |
754 | 747 | "); |
755 | - } |
|
756 | - else |
|
748 | + } else |
|
757 | 749 | { |
758 | 750 | # This log type is not represented in cache stats. |
759 | 751 | } |
@@ -766,8 +758,7 @@ discard block |
||
766 | 758 | { |
767 | 759 | # OCDE handles cache stats updates using triggers. So, they are already |
768 | 760 | # incremented properly. |
769 | - } |
|
770 | - else |
|
761 | + } else |
|
771 | 762 | { |
772 | 763 | # OCPL doesn't have triggers for this. We need to update manually. |
773 | 764 |
@@ -165,6 +165,7 @@ discard block |
||
165 | 165 | * well as long as only log entry fields are replicated which update |
166 | 166 | * some cache_logs column when changed (by OKAPI or OC code). See |
167 | 167 | * https://github.com/opencaching/okapi/issues/382 for further discussion. |
168 | + * @param string[] $geocache_ignored_fields |
|
168 | 169 | */ |
169 | 170 | public static function verify_clog_consistency( |
170 | 171 | $force_all=false, $geocache_ignored_fields = null |
@@ -269,6 +270,13 @@ discard block |
||
269 | 270 | * In normal mode, update the changelog and don't return anything. |
270 | 271 | * In fulldump mode, return the generated changelog entries *instead* of |
271 | 272 | * updating it. |
273 | + * @param string $feeder_method |
|
274 | + * @param string $object_type |
|
275 | + * @param string $feeder_keys_param |
|
276 | + * @param string $key_name |
|
277 | + * @param string $fields |
|
278 | + * @param boolean $fulldump_mode |
|
279 | + * @param boolean $use_cache |
|
272 | 280 | */ |
273 | 281 | private static function generate_changelog_entries($feeder_method, $object_type, $feeder_keys_param, |
274 | 282 | $key_name, $key_values, $fields, $fulldump_mode, $use_cache, $cache_timeout = 86400) |
@@ -5,11 +5,6 @@ |
||
5 | 5 | use Exception; |
6 | 6 | use okapi\Okapi; |
7 | 7 | use okapi\Db; |
8 | -use okapi\OkapiRequest; |
|
9 | -use okapi\ParamMissing; |
|
10 | -use okapi\InvalidParam; |
|
11 | -use okapi\BadRequest; |
|
12 | -use okapi\DoesNotExist; |
|
13 | 8 | use okapi\OkapiInternalRequest; |
14 | 9 | use okapi\OkapiInternalConsumer; |
15 | 10 | use okapi\OkapiServiceRunner; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | /** Check for modifications in the database and update the changelog table accordingly. */ |
74 | 74 | public static function update_clog_table() |
75 | 75 | { |
76 | - $now = Db::select_value("select date_add(now(), interval -1 minute)"); # See issue 157. |
|
76 | + $now = Db::select_value("select date_add(now(), interval -1 minute)"); # See issue 157. |
|
77 | 77 | $last_update = Okapi::get_var('last_clog_update'); |
78 | 78 | if ($last_update === null) |
79 | 79 | $last_update = Db::select_value("select date_add(now(), interval -1 day)"); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $cache_codes = Db::select_column(" |
94 | 94 | select wp_oc |
95 | 95 | from caches |
96 | - where okapi_syncbase > '".Db::escape_string($last_update)."'; |
|
96 | + where okapi_syncbase > '".Db::escape_string($last_update) . "'; |
|
97 | 97 | "); |
98 | 98 | $cache_code_groups = Okapi::make_groups($cache_codes, 50); |
99 | 99 | unset($cache_codes); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $log_uuids = Db::select_column(" |
115 | 115 | select uuid |
116 | 116 | from cache_logs |
117 | - where okapi_syncbase > '".Db::escape_string($last_update)."' |
|
117 | + where okapi_syncbase > '".Db::escape_string($last_update) . "' |
|
118 | 118 | limit $offset, 10000; |
119 | 119 | "); |
120 | 120 | if (count($log_uuids) == 0) |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $DELETED_uuids = Db::select_column(" |
139 | 139 | select uuid |
140 | 140 | from cache_logs_archived |
141 | - where okapi_syncbase > '".Db::escape_string($last_update)."' |
|
141 | + where okapi_syncbase > '".Db::escape_string($last_update) . "' |
|
142 | 142 | "); |
143 | 143 | $deleted_uuid_groups = Okapi::make_groups($DELETED_uuids, 100); |
144 | 144 | unset($DELETED_uuids); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * https://github.com/opencaching/okapi/issues/382 for further discussion. |
168 | 168 | */ |
169 | 169 | public static function verify_clog_consistency( |
170 | - $force_all=false, $geocache_ignored_fields = null |
|
170 | + $force_all = false, $geocache_ignored_fields = null |
|
171 | 171 | ) |
172 | 172 | { |
173 | 173 | set_time_limit(0); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $cache_codes = Db::select_column(" |
185 | 185 | select wp_oc |
186 | 186 | from caches |
187 | - ".($force_all ? "" : "where okapi_syncbase < date_add(now(), interval -1 day)")." |
|
187 | + ".($force_all ? "" : "where okapi_syncbase < date_add(now(), interval -1 day)") . " |
|
188 | 188 | "); |
189 | 189 | $cache_code_groups = Okapi::make_groups($cache_codes, 50); |
190 | 190 | unset($cache_codes); |
@@ -228,13 +228,13 @@ discard block |
||
228 | 228 | # vars which is to be emailed to OKAPI developers. |
229 | 229 | |
230 | 230 | if (count($two_examples) == 0) |
231 | - $two_examples[0] = $entry; /* The first entry */ |
|
232 | - $two_examples[1] = $entry; /* The last entry */ |
|
231 | + $two_examples[0] = $entry; /* The first entry */ |
|
232 | + $two_examples[1] = $entry; /* The last entry */ |
|
233 | 233 | |
234 | 234 | Db::execute(" |
235 | 235 | update caches |
236 | 236 | set okapi_syncbase = now() |
237 | - where wp_oc = '".Db::escape_string($cache_code)."' |
|
237 | + where wp_oc = '".Db::escape_string($cache_code) . "' |
|
238 | 238 | "); |
239 | 239 | $sum += 1; |
240 | 240 | } |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | $cache_keys1 = array(); |
281 | 281 | $cache_keys2 = array(); |
282 | 282 | foreach ($key_values as $key) |
283 | - $cache_keys1[] = 'clog#'.$object_type.'#'.$key; |
|
283 | + $cache_keys1[] = 'clog#' . $object_type . '#' . $key; |
|
284 | 284 | foreach ($key_values as $key) |
285 | - $cache_keys2[] = 'clogmd5#'.$object_type.'#'.$key; |
|
285 | + $cache_keys2[] = 'clogmd5#' . $object_type . '#' . $key; |
|
286 | 286 | $cached_values1 = Cache::get_many($cache_keys1); |
287 | 287 | $cached_values2 = Cache::get_many($cache_keys2); |
288 | 288 | if (!$fulldump_mode) |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | # Get the current values for objects. Compare them with their previous versions |
298 | 298 | # and generate changelog entries. |
299 | 299 | |
300 | - require_once($GLOBALS['rootpath'].'okapi/service_runner.php'); |
|
300 | + require_once($GLOBALS['rootpath'] . 'okapi/service_runner.php'); |
|
301 | 301 | $current_values = OkapiServiceRunner::call($feeder_method, new OkapiInternalRequest( |
302 | 302 | new OkapiInternalConsumer(), null, array( |
303 | 303 | $feeder_keys_param => implode("|", $key_values), |
@@ -314,14 +314,14 @@ discard block |
||
314 | 314 | { |
315 | 315 | # First, compare the cached hash. The hash has much longer lifetime |
316 | 316 | # than the actual cached object. |
317 | - $cached_md5 = $cached_values2['clogmd5#'.$object_type.'#'.$key]; |
|
317 | + $cached_md5 = $cached_values2['clogmd5#' . $object_type . '#' . $key]; |
|
318 | 318 | $current_md5 = md5(serialize($object)); |
319 | 319 | if ($cached_md5 == $current_md5) |
320 | 320 | { |
321 | 321 | # The object was not changed since it was last replaced. |
322 | 322 | continue; |
323 | 323 | } |
324 | - $diff = self::get_diff($cached_values1['clog#'.$object_type.'#'.$key], $object); |
|
324 | + $diff = self::get_diff($cached_values1['clog#' . $object_type . '#' . $key], $object); |
|
325 | 325 | if (count($diff) == 0) |
326 | 326 | { |
327 | 327 | # Md5 differs, but diff does not. Weird, but it can happen |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | if ($use_cache) |
340 | 340 | { |
341 | 341 | # Save the last-published state of the object, for future comparison. |
342 | - $cached_values2['clogmd5#'.$object_type.'#'.$key] = $current_md5; |
|
343 | - $cached_values1['clog#'.$object_type.'#'.$key] = $object; |
|
342 | + $cached_values2['clogmd5#' . $object_type . '#' . $key] = $current_md5; |
|
343 | + $cached_values1['clog#' . $object_type . '#' . $key] = $object; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | else |
347 | 347 | { |
348 | 348 | # Currently, the object does not exist. |
349 | - if ($use_cache && ($cached_values1['clog#'.$object_type.'#'.$key] === false)) |
|
349 | + if ($use_cache && ($cached_values1['clog#' . $object_type . '#' . $key] === false)) |
|
350 | 350 | { |
351 | 351 | # No need to delete, we have already published its deletion. |
352 | 352 | continue; |
@@ -359,8 +359,8 @@ discard block |
||
359 | 359 | if ($use_cache) |
360 | 360 | { |
361 | 361 | # Cache the fact, that the object was deleted. |
362 | - $cached_values2['clogmd5#'.$object_type.'#'.$key] = false; |
|
363 | - $cached_values1['clog#'.$object_type.'#'.$key] = false; |
|
362 | + $cached_values2['clogmd5#' . $object_type . '#' . $key] = false; |
|
363 | + $cached_values1['clog#' . $object_type . '#' . $key] = false; |
|
364 | 364 | } |
365 | 365 | } |
366 | 366 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | $data_values[] = gzdeflate(serialize($entry)); |
381 | 381 | Db::execute(" |
382 | 382 | insert into okapi_clog (data) |
383 | - values ('".implode("'),('", array_map('\okapi\Db::escape_string', $data_values))."'); |
|
383 | + values ('".implode("'),('", array_map('\okapi\Db::escape_string', $data_values)) . "'); |
|
384 | 384 | "); |
385 | 385 | } |
386 | 386 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | if ($use_cache) |
390 | 390 | { |
391 | 391 | Cache::set_many($cached_values1, $cache_timeout); |
392 | - Cache::set_many($cached_values2, null); # make it persistent |
|
392 | + Cache::set_many($cached_values2, null); # make it persistent |
|
393 | 393 | } |
394 | 394 | } |
395 | 395 | } |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | public static function check_since_param($since) |
402 | 402 | { |
403 | 403 | $first_id = Db::select_value(" |
404 | - select id from okapi_clog where id > '".Db::escape_string($since)."' limit 1 |
|
404 | + select id from okapi_clog where id > '".Db::escape_string($since) . "' limit 1 |
|
405 | 405 | "); |
406 | 406 | if ($first_id === null) |
407 | 407 | return true; # okay, since points to the newest revision |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | if ($to < $from) |
450 | 450 | return array(); |
451 | 451 | if ($to - $from > self::$chunk_size) |
452 | - throw new Exception("You should not get chunksize bigger than ".self::$chunk_size." entries at one time."); |
|
452 | + throw new Exception("You should not get chunksize bigger than " . self::$chunk_size . " entries at one time."); |
|
453 | 453 | |
454 | 454 | # Check if we already have this chunk in cache. |
455 | 455 | |
456 | - $cache_key = 'clog_chunk#'.$from.'-'.$to; |
|
456 | + $cache_key = 'clog_chunk#' . $from . '-' . $to; |
|
457 | 457 | $chunk = Cache::get($cache_key); |
458 | 458 | if ($chunk === null) |
459 | 459 | { |
460 | 460 | $rs = Db::query(" |
461 | 461 | select id, data |
462 | 462 | from okapi_clog |
463 | - where id between '".Db::escape_string($from)."' and '".Db::escape_string($to)."' |
|
463 | + where id between '".Db::escape_string($from) . "' and '" . Db::escape_string($to) . "' |
|
464 | 464 | order by id |
465 | 465 | "); |
466 | 466 | $chunk = array(); |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | |
496 | 496 | $revision = self::get_revision(); |
497 | 497 | $generated_at = date('c', time()); |
498 | - $dir = Okapi::get_var_dir()."/okapi-db-dump"; |
|
498 | + $dir = Okapi::get_var_dir() . "/okapi-db-dump"; |
|
499 | 499 | $i = 1; |
500 | 500 | $json_files = array(); |
501 | 501 | |
@@ -513,8 +513,8 @@ discard block |
||
513 | 513 | unset($cache_codes); |
514 | 514 | foreach ($cache_code_groups as $cache_codes) |
515 | 515 | { |
516 | - $basename = "part".str_pad($i, 5, "0", STR_PAD_LEFT); |
|
517 | - $json_files[] = $basename.".json"; |
|
516 | + $basename = "part" . str_pad($i, 5, "0", STR_PAD_LEFT); |
|
517 | + $json_files[] = $basename . ".json"; |
|
518 | 518 | $entries = self::generate_changelog_entries('services/caches/geocaches', 'geocache', 'cache_codes', |
519 | 519 | 'code', $cache_codes, self::$logged_cache_fields, true, false); |
520 | 520 | $filtered = array(); |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | $log_uuids = Db::select_column(" |
538 | 538 | select uuid |
539 | 539 | from cache_logs |
540 | - where ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")." |
|
540 | + where ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true") . " |
|
541 | 541 | order by uuid |
542 | 542 | limit $offset, 10000 |
543 | 543 | "); |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | unset($log_uuids); |
549 | 549 | foreach ($log_uuid_groups as $log_uuids) |
550 | 550 | { |
551 | - $basename = "part".str_pad($i, 5, "0", STR_PAD_LEFT); |
|
552 | - $json_files[] = $basename.".json"; |
|
551 | + $basename = "part" . str_pad($i, 5, "0", STR_PAD_LEFT); |
|
552 | + $json_files[] = $basename . ".json"; |
|
553 | 553 | $entries = self::generate_changelog_entries('services/logs/entries', 'log', 'log_uuids', |
554 | 554 | 'uuid', $log_uuids, self::$logged_log_entry_fields, true, false); |
555 | 555 | $filtered = array(); |
@@ -588,8 +588,8 @@ discard block |
||
588 | 588 | # (bzip2 is MUCH slower). |
589 | 589 | |
590 | 590 | $use_bzip2 = true; |
591 | - $dumpfilename = "okapi-dump.tar.".($use_bzip2 ? "bz2" : "gz"); |
|
592 | - shell_exec("tar --directory $dir -c".($use_bzip2 ? "j" : "z")."f $dir/$dumpfilename index.json ".implode(" ", $json_files). " 2>&1"); |
|
591 | + $dumpfilename = "okapi-dump.tar." . ($use_bzip2 ? "bz2" : "gz"); |
|
592 | + shell_exec("tar --directory $dir -c" . ($use_bzip2 ? "j" : "z") . "f $dir/$dumpfilename index.json " . implode(" ", $json_files) . " 2>&1"); |
|
593 | 593 | |
594 | 594 | # Delete temporary files. |
595 | 595 | |
@@ -598,14 +598,14 @@ discard block |
||
598 | 598 | # Move the archive one directory upwards, replacing the previous one. |
599 | 599 | # Remove the temporary directory. |
600 | 600 | |
601 | - shell_exec("mv -f $dir/$dumpfilename ".Okapi::get_var_dir()); |
|
601 | + shell_exec("mv -f $dir/$dumpfilename " . Okapi::get_var_dir()); |
|
602 | 602 | shell_exec("rmdir $dir"); |
603 | 603 | |
604 | 604 | # Update the database info. |
605 | 605 | |
606 | - $metadata['meta']['filepath'] = Okapi::get_var_dir().'/'.$dumpfilename; |
|
606 | + $metadata['meta']['filepath'] = Okapi::get_var_dir() . '/' . $dumpfilename; |
|
607 | 607 | $metadata['meta']['content_type'] = ($use_bzip2 ? "application/octet-stream" : "application/x-gzip"); |
608 | - $metadata['meta']['public_filename'] = 'okapi-dump-r'.$metadata['revision'].'.tar.'.($use_bzip2 ? "bz2" : "gz"); |
|
608 | + $metadata['meta']['public_filename'] = 'okapi-dump-r' . $metadata['revision'] . '.tar.' . ($use_bzip2 ? "bz2" : "gz"); |
|
609 | 609 | $metadata['meta']['uncompressed_size'] = $size; |
610 | 610 | $metadata['meta']['compressed_size'] = filesize($metadata['meta']['filepath']); |
611 | 611 | Cache::set("last_fulldump", $metadata, 10 * 86400); |
@@ -40,8 +40,9 @@ discard block |
||
40 | 40 | if ($cache == null) |
41 | 41 | { |
42 | 42 | $cache = Db::select_value("select min(id) from okapi_clog"); |
43 | - if ($cache === null) |
|
44 | - $cache = 1; |
|
43 | + if ($cache === null) { |
|
44 | + $cache = 1; |
|
45 | + } |
|
45 | 46 | $cache -= 1; |
46 | 47 | } |
47 | 48 | return $cache; |
@@ -54,19 +55,22 @@ discard block |
||
54 | 55 | */ |
55 | 56 | private static function get_diff($old, $new) |
56 | 57 | { |
57 | - if (!$old) |
|
58 | - return $new; |
|
58 | + if (!$old) { |
|
59 | + return $new; |
|
60 | + } |
|
59 | 61 | $changed_keys = array(); |
60 | 62 | foreach ($new as $key => $value) |
61 | 63 | { |
62 | - if (!array_key_exists($key, $old)) |
|
63 | - $changed_keys[] = $key; |
|
64 | - elseif ($old[$key] != $new[$key]) |
|
65 | - $changed_keys[] = $key; |
|
64 | + if (!array_key_exists($key, $old)) { |
|
65 | + $changed_keys[] = $key; |
|
66 | + } elseif ($old[$key] != $new[$key]) { |
|
67 | + $changed_keys[] = $key; |
|
68 | + } |
|
66 | 69 | } |
67 | 70 | $changed = array(); |
68 | - foreach ($changed_keys as $key) |
|
69 | - $changed[$key] = $new[$key]; |
|
71 | + foreach ($changed_keys as $key) { |
|
72 | + $changed[$key] = $new[$key]; |
|
73 | + } |
|
70 | 74 | return $changed; |
71 | 75 | } |
72 | 76 | |
@@ -75,8 +79,9 @@ discard block |
||
75 | 79 | { |
76 | 80 | $now = Db::select_value("select date_add(now(), interval -1 minute)"); # See issue 157. |
77 | 81 | $last_update = Okapi::get_var('last_clog_update'); |
78 | - if ($last_update === null) |
|
79 | - $last_update = Db::select_value("select date_add(now(), interval -1 day)"); |
|
82 | + if ($last_update === null) { |
|
83 | + $last_update = Db::select_value("select date_add(now(), interval -1 day)"); |
|
84 | + } |
|
80 | 85 | |
81 | 86 | # Usually this will be fast. But, for example, if admin changes ALL the |
82 | 87 | # caches, this will take forever. But we still want it to finish properly |
@@ -117,8 +122,9 @@ discard block |
||
117 | 122 | where okapi_syncbase > '".Db::escape_string($last_update)."' |
118 | 123 | limit $offset, 10000; |
119 | 124 | "); |
120 | - if (count($log_uuids) == 0) |
|
121 | - break; |
|
125 | + if (count($log_uuids) == 0) { |
|
126 | + break; |
|
127 | + } |
|
122 | 128 | $offset += 10000; |
123 | 129 | $log_uuid_groups = Okapi::make_groups($log_uuids, 100); |
124 | 130 | unset($log_uuids); |
@@ -202,8 +208,9 @@ discard block |
||
202 | 208 | ); |
203 | 209 | foreach ($entries as $entry) |
204 | 210 | { |
205 | - if ($entry['object_type'] != 'geocache') |
|
206 | - continue; |
|
211 | + if ($entry['object_type'] != 'geocache') { |
|
212 | + continue; |
|
213 | + } |
|
207 | 214 | $cache_code = $entry['object_key']['code']; |
208 | 215 | |
209 | 216 | if (($entry['change_type'] == 'replace') && ($geocache_ignored_fields != null)) { |
@@ -227,8 +234,10 @@ discard block |
||
227 | 234 | # We will story the first and the last entry in the $two_examples |
228 | 235 | # vars which is to be emailed to OKAPI developers. |
229 | 236 | |
230 | - if (count($two_examples) == 0) |
|
231 | - $two_examples[0] = $entry; /* The first entry */ |
|
237 | + if (count($two_examples) == 0) { |
|
238 | + $two_examples[0] = $entry; |
|
239 | + } |
|
240 | + /* The first entry */ |
|
232 | 241 | $two_examples[1] = $entry; /* The last entry */ |
233 | 242 | |
234 | 243 | Db::execute(" |
@@ -279,10 +288,12 @@ discard block |
||
279 | 288 | { |
280 | 289 | $cache_keys1 = array(); |
281 | 290 | $cache_keys2 = array(); |
282 | - foreach ($key_values as $key) |
|
283 | - $cache_keys1[] = 'clog#'.$object_type.'#'.$key; |
|
284 | - foreach ($key_values as $key) |
|
285 | - $cache_keys2[] = 'clogmd5#'.$object_type.'#'.$key; |
|
291 | + foreach ($key_values as $key) { |
|
292 | + $cache_keys1[] = 'clog#'.$object_type.'#'.$key; |
|
293 | + } |
|
294 | + foreach ($key_values as $key) { |
|
295 | + $cache_keys2[] = 'clogmd5#'.$object_type.'#'.$key; |
|
296 | + } |
|
286 | 297 | $cached_values1 = Cache::get_many($cache_keys1); |
287 | 298 | $cached_values2 = Cache::get_many($cache_keys2); |
288 | 299 | if (!$fulldump_mode) |
@@ -342,8 +353,7 @@ discard block |
||
342 | 353 | $cached_values2['clogmd5#'.$object_type.'#'.$key] = $current_md5; |
343 | 354 | $cached_values1['clog#'.$object_type.'#'.$key] = $object; |
344 | 355 | } |
345 | - } |
|
346 | - else |
|
356 | + } else |
|
347 | 357 | { |
348 | 358 | # Currently, the object does not exist. |
349 | 359 | if ($use_cache && ($cached_values1['clog#'.$object_type.'#'.$key] === false)) |
@@ -368,16 +378,16 @@ discard block |
||
368 | 378 | if ($fulldump_mode) |
369 | 379 | { |
370 | 380 | return $entries; |
371 | - } |
|
372 | - else |
|
381 | + } else |
|
373 | 382 | { |
374 | 383 | # Save the entries to the clog table. |
375 | 384 | |
376 | 385 | if (count($entries) > 0) |
377 | 386 | { |
378 | 387 | $data_values = array(); |
379 | - foreach ($entries as $entry) |
|
380 | - $data_values[] = gzdeflate(serialize($entry)); |
|
388 | + foreach ($entries as $entry) { |
|
389 | + $data_values[] = gzdeflate(serialize($entry)); |
|
390 | + } |
|
381 | 391 | Db::execute(" |
382 | 392 | insert into okapi_clog (data) |
383 | 393 | values ('".implode("'),('", array_map('\okapi\Db::escape_string', $data_values))."'); |
@@ -403,10 +413,14 @@ discard block |
||
403 | 413 | $first_id = Db::select_value(" |
404 | 414 | select id from okapi_clog where id > '".Db::escape_string($since)."' limit 1 |
405 | 415 | "); |
406 | - if ($first_id === null) |
|
407 | - return true; # okay, since points to the newest revision |
|
408 | - if ($first_id == $since + 1) |
|
409 | - return true; # okay, revision $since + 1 is present |
|
416 | + if ($first_id === null) { |
|
417 | + return true; |
|
418 | + } |
|
419 | + # okay, since points to the newest revision |
|
420 | + if ($first_id == $since + 1) { |
|
421 | + return true; |
|
422 | + } |
|
423 | + # okay, revision $since + 1 is present |
|
410 | 424 | |
411 | 425 | # If we're here, then this means that $first_id > $since + 1. |
412 | 426 | # Revision $since + 1 is already deleted, $since must be too old! |
@@ -432,10 +446,11 @@ discard block |
||
432 | 446 | # user wants), then we'll give him 80. If user wants less than half of what we |
433 | 447 | # have (ex. 30), then we'll give him only his 30. |
434 | 448 | |
435 | - if ($current_revision - $since > $since - $last_chunk_cut) |
|
436 | - return array($last_chunk_cut + 1, $current_revision); |
|
437 | - else |
|
438 | - return array($since + 1, $current_revision); |
|
449 | + if ($current_revision - $since > $since - $last_chunk_cut) { |
|
450 | + return array($last_chunk_cut + 1, $current_revision); |
|
451 | + } else { |
|
452 | + return array($since + 1, $current_revision); |
|
453 | + } |
|
439 | 454 | } |
440 | 455 | $prev_chunk_cut = $since - ($since % self::$chunk_size); |
441 | 456 | return array($prev_chunk_cut + 1, $prev_chunk_cut + self::$chunk_size); |
@@ -446,10 +461,12 @@ discard block |
||
446 | 461 | */ |
447 | 462 | public static function get_chunk($from, $to) |
448 | 463 | { |
449 | - if ($to < $from) |
|
450 | - return array(); |
|
451 | - if ($to - $from > self::$chunk_size) |
|
452 | - throw new Exception("You should not get chunksize bigger than ".self::$chunk_size." entries at one time."); |
|
464 | + if ($to < $from) { |
|
465 | + return array(); |
|
466 | + } |
|
467 | + if ($to - $from > self::$chunk_size) { |
|
468 | + throw new Exception("You should not get chunksize bigger than ".self::$chunk_size." entries at one time."); |
|
469 | + } |
|
453 | 470 | |
454 | 471 | # Check if we already have this chunk in cache. |
455 | 472 | |
@@ -475,10 +492,11 @@ discard block |
||
475 | 492 | # be ever accessed after the next revision appears, so there is not point |
476 | 493 | # in storing them that long. |
477 | 494 | |
478 | - if (($from % self::$chunk_size === 0) && ($to % self::$chunk_size === 0)) |
|
479 | - $timeout = 10 * 86400; |
|
480 | - else |
|
481 | - $timeout = 86400; |
|
495 | + if (($from % self::$chunk_size === 0) && ($to % self::$chunk_size === 0)) { |
|
496 | + $timeout = 10 * 86400; |
|
497 | + } else { |
|
498 | + $timeout = 86400; |
|
499 | + } |
|
482 | 500 | Cache::set($cache_key, $chunk, $timeout); |
483 | 501 | } |
484 | 502 | |
@@ -518,9 +536,10 @@ discard block |
||
518 | 536 | $entries = self::generate_changelog_entries('services/caches/geocaches', 'geocache', 'cache_codes', |
519 | 537 | 'code', $cache_codes, self::$logged_cache_fields, true, false); |
520 | 538 | $filtered = array(); |
521 | - foreach ($entries as $entry) |
|
522 | - if ($entry['change_type'] == 'replace') |
|
539 | + foreach ($entries as $entry) { |
|
540 | + if ($entry['change_type'] == 'replace') |
|
523 | 541 | $filtered[] = $entry; |
542 | + } |
|
524 | 543 | unset($entries); |
525 | 544 | file_put_contents("$dir/$basename.json", json_encode($filtered)); |
526 | 545 | unset($filtered); |
@@ -541,8 +560,9 @@ discard block |
||
541 | 560 | order by uuid |
542 | 561 | limit $offset, 10000 |
543 | 562 | "); |
544 | - if (count($log_uuids) == 0) |
|
545 | - break; |
|
563 | + if (count($log_uuids) == 0) { |
|
564 | + break; |
|
565 | + } |
|
546 | 566 | $offset += 10000; |
547 | 567 | $log_uuid_groups = Okapi::make_groups($log_uuids, 500); |
548 | 568 | unset($log_uuids); |
@@ -553,9 +573,10 @@ discard block |
||
553 | 573 | $entries = self::generate_changelog_entries('services/logs/entries', 'log', 'log_uuids', |
554 | 574 | 'uuid', $log_uuids, self::$logged_log_entry_fields, true, false); |
555 | 575 | $filtered = array(); |
556 | - foreach ($entries as $entry) |
|
557 | - if ($entry['change_type'] == 'replace') |
|
576 | + foreach ($entries as $entry) { |
|
577 | + if ($entry['change_type'] == 'replace') |
|
558 | 578 | $filtered[] = $entry; |
579 | + } |
|
559 | 580 | unset($entries); |
560 | 581 | file_put_contents("$dir/$basename.json", json_encode($filtered)); |
561 | 582 | unset($filtered); |
@@ -581,8 +602,9 @@ discard block |
||
581 | 602 | # Compute uncompressed size. |
582 | 603 | |
583 | 604 | $size = filesize("$dir/index.json"); |
584 | - foreach ($json_files as $filename) |
|
585 | - $size += filesize("$dir/$filename"); |
|
605 | + foreach ($json_files as $filename) { |
|
606 | + $size += filesize("$dir/$filename"); |
|
607 | + } |
|
586 | 608 | |
587 | 609 | # Create JSON archive. We use tar options: -j for bzip2, -z for gzip |
588 | 610 | # (bzip2 is MUCH slower). |
@@ -9,7 +9,6 @@ |
||
9 | 9 | use okapi\OkapiRequest; |
10 | 10 | use okapi\ParamMissing; |
11 | 11 | use okapi\InvalidParam; |
12 | -use okapi\services\caches\search\SearchAssistant; |
|
13 | 12 | |
14 | 13 | class WebService |
15 | 14 | { |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | if (!$user_uuids) throw new ParamMissing('user_uuids'); |
32 | 32 | $user_uuids = explode("|", $user_uuids); |
33 | 33 | if (count($user_uuids) > 500) |
34 | - throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ". |
|
35 | - "is 500. You provided ".count($user_uuids)." user IDs."); |
|
34 | + throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users " . |
|
35 | + "is 500. You provided " . count($user_uuids) . " user IDs."); |
|
36 | 36 | $fields = $request->get_parameter('fields'); |
37 | 37 | if (!$fields) |
38 | 38 | throw new ParamMissing('fields'); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $rs = Db::query(" |
44 | 44 | select user_id, uuid, username, admin, latitude, longitude, date_created |
45 | 45 | from user |
46 | - where uuid in ('".implode("','", array_map('\okapi\Db::escape_string', $user_uuids))."') |
|
46 | + where uuid in ('".implode("','", array_map('\okapi\Db::escape_string', $user_uuids)) . "') |
|
47 | 47 | "); |
48 | 48 | $results = array(); |
49 | 49 | $id2uuid = array(); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | case 'uuid': $entry['uuid'] = $row['uuid']; break; |
61 | 61 | case 'username': $entry['username'] = $row['username']; break; |
62 | - case 'profile_url': $entry['profile_url'] = Settings::get('SITE_URL')."viewprofile.php?userid=".$row['user_id']; break; |
|
62 | + case 'profile_url': $entry['profile_url'] = Settings::get('SITE_URL') . "viewprofile.php?userid=" . $row['user_id']; break; |
|
63 | 63 | case 'is_admin': |
64 | 64 | if (!$request->token) { |
65 | 65 | $entry['is_admin'] = null; |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | # does not make sense. |
87 | 87 | $entry['home_location'] = null; |
88 | 88 | } else { |
89 | - $entry['home_location'] = round($row['latitude'], 6)."|".round($row['longitude'], 6); |
|
89 | + $entry['home_location'] = round($row['latitude'], 6) . "|" . round($row['longitude'], 6); |
|
90 | 90 | } |
91 | 91 | break; |
92 | - default: throw new Exception("Missing field case: ".$field); |
|
92 | + default: throw new Exception("Missing field case: " . $field); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | $results[$row['uuid']] = $entry; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $rs = Db::query(" |
114 | 114 | select user_id, founds_count, notfounds_count, hidden_count |
115 | 115 | from user |
116 | - where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid)))."') |
|
116 | + where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid))) . "') |
|
117 | 117 | "); |
118 | 118 | } |
119 | 119 | else |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | user u |
131 | 131 | left join stat_user su |
132 | 132 | on su.user_id = u.user_id |
133 | - where u.user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid)))."') |
|
133 | + where u.user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid))) . "') |
|
134 | 134 | "); |
135 | 135 | } |
136 | 136 | |
137 | 137 | while ($row = Db::fetch_assoc($rs)) |
138 | 138 | { |
139 | - $extras[$row['user_id']] = array();; |
|
139 | + $extras[$row['user_id']] = array(); ; |
|
140 | 140 | $extra_ref = &$extras[$row['user_id']]; |
141 | 141 | $extra_ref['caches_found'] = 0 + $row['founds_count']; |
142 | 142 | $extra_ref['caches_notfound'] = 0 + $row['notfounds_count']; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $rs = Db::query(" |
150 | 150 | select user_id, count(*) as rcmds_given |
151 | 151 | from cache_rating |
152 | - where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid)))."') |
|
152 | + where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid))) . "') |
|
153 | 153 | group by user_id |
154 | 154 | "); |
155 | 155 | $rcmds_counts = array(); |
@@ -28,18 +28,23 @@ discard block |
||
28 | 28 | public static function call(OkapiRequest $request) |
29 | 29 | { |
30 | 30 | $user_uuids = $request->get_parameter('user_uuids'); |
31 | - if (!$user_uuids) throw new ParamMissing('user_uuids'); |
|
31 | + if (!$user_uuids) { |
|
32 | + throw new ParamMissing('user_uuids'); |
|
33 | + } |
|
32 | 34 | $user_uuids = explode("|", $user_uuids); |
33 | - if (count($user_uuids) > 500) |
|
34 | - throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ". |
|
35 | + if (count($user_uuids) > 500) { |
|
36 | + throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ". |
|
35 | 37 | "is 500. You provided ".count($user_uuids)." user IDs."); |
38 | + } |
|
36 | 39 | $fields = $request->get_parameter('fields'); |
37 | - if (!$fields) |
|
38 | - throw new ParamMissing('fields'); |
|
40 | + if (!$fields) { |
|
41 | + throw new ParamMissing('fields'); |
|
42 | + } |
|
39 | 43 | $fields = explode("|", $fields); |
40 | - foreach ($fields as $field) |
|
41 | - if (!in_array($field, self::$valid_field_names)) |
|
44 | + foreach ($fields as $field) { |
|
45 | + if (!in_array($field, self::$valid_field_names)) |
|
42 | 46 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
47 | + } |
|
43 | 48 | $rs = Db::query(" |
44 | 49 | select user_id, uuid, username, admin, latitude, longitude, date_created |
45 | 50 | from user |
@@ -115,8 +120,7 @@ discard block |
||
115 | 120 | from user |
116 | 121 | where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid)))."') |
117 | 122 | "); |
118 | - } |
|
119 | - else |
|
123 | + } else |
|
120 | 124 | { |
121 | 125 | # OCDE stores user stats in 'stat_user' table. |
122 | 126 | |
@@ -153,8 +157,9 @@ discard block |
||
153 | 157 | group by user_id |
154 | 158 | "); |
155 | 159 | $rcmds_counts = array(); |
156 | - while ($row = Db::fetch_assoc($rs)) |
|
157 | - $rcmds_counts[$row['user_id']] = $row['rcmds_given']; |
|
160 | + while ($row = Db::fetch_assoc($rs)) { |
|
161 | + $rcmds_counts[$row['user_id']] = $row['rcmds_given']; |
|
162 | + } |
|
158 | 163 | foreach ($extras as $user_id => &$extra_ref) |
159 | 164 | { |
160 | 165 | $extra_ref['rcmds_given'] = isset($rcmds_counts[$user_id]) ? 0 + $rcmds_counts[$user_id] : 0; |
@@ -165,18 +170,21 @@ discard block |
||
165 | 170 | |
166 | 171 | foreach (array('caches_found', 'caches_notfound', 'caches_hidden', 'rcmds_given') as $field) |
167 | 172 | { |
168 | - if (!in_array($field, $fields)) |
|
169 | - continue; |
|
170 | - foreach ($results as $uuid => &$result_ref) |
|
171 | - $result_ref[$field] = $extras[$uuid2id[$uuid]][$field]; |
|
173 | + if (!in_array($field, $fields)) { |
|
174 | + continue; |
|
175 | + } |
|
176 | + foreach ($results as $uuid => &$result_ref) { |
|
177 | + $result_ref[$field] = $extras[$uuid2id[$uuid]][$field]; |
|
178 | + } |
|
172 | 179 | } |
173 | 180 | } |
174 | 181 | |
175 | 182 | # Check which user IDs were not found and mark them with null. |
176 | 183 | |
177 | - foreach ($user_uuids as $user_uuid) |
|
178 | - if (!isset($results[$user_uuid])) |
|
184 | + foreach ($user_uuids as $user_uuid) { |
|
185 | + if (!isset($results[$user_uuid])) |
|
179 | 186 | $results[$user_uuid] = null; |
187 | + } |
|
180 | 188 | |
181 | 189 | return Okapi::formatted_response($request, $results); |
182 | 190 | } |
@@ -2,11 +2,9 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\views\apps\authorize; |
4 | 4 | |
5 | -use Exception; |
|
6 | 5 | use okapi\Okapi; |
7 | 6 | use okapi\Db; |
8 | 7 | use okapi\OkapiHttpResponse; |
9 | -use okapi\OkapiHttpRequest; |
|
10 | 8 | use okapi\OkapiRedirectResponse; |
11 | 9 | use okapi\Settings; |
12 | 10 | use okapi\Locales; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | okapi_consumers c, |
42 | 42 | okapi_tokens t |
43 | 43 | where |
44 | - t.`key` = '".Db::escape_string($token_key)."' |
|
44 | + t.`key` = '".Db::escape_string($token_key) . "' |
|
45 | 45 | and t.consumer_key = c.`key` |
46 | 46 | and t.user_id is null |
47 | 47 | "); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | # by the user, who knows nothing on tokens and OAuth. Let's be nice then! |
55 | 55 | |
56 | 56 | $vars = array( |
57 | - 'okapi_base_url' => Settings::get('SITE_URL')."okapi/", |
|
57 | + 'okapi_base_url' => Settings::get('SITE_URL') . "okapi/", |
|
58 | 58 | 'token' => $token, |
59 | 59 | 'token_expired' => true, |
60 | 60 | 'site_name' => Okapi::get_normalized_site_name(), |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | # Determine which user is logged in to OC. |
76 | 76 | |
77 | - require_once($GLOBALS['rootpath']."okapi/lib/oc_session.php"); |
|
77 | + require_once($GLOBALS['rootpath'] . "okapi/lib/oc_session.php"); |
|
78 | 78 | $OC_user_id = OCSession::get_user_id(); |
79 | 79 | |
80 | 80 | # Ensure a user is logged in (or force re-login). |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | foreach ($cookies as $cookie) { |
112 | 112 | $parts = explode('=', $cookie); |
113 | 113 | $name = trim($parts[0]); |
114 | - setcookie($name, '', time()-1000); |
|
115 | - setcookie($name, '', time()-1000, '/'); |
|
114 | + setcookie($name, '', time() - 1000); |
|
115 | + setcookie($name, '', time() - 1000, '/'); |
|
116 | 116 | foreach (self::getPossibleCookieDomains() as $domain) { |
117 | - setcookie($name, '', time()-1000, '/', $domain); |
|
117 | + setcookie($name, '', time() - 1000, '/', $domain); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - $after_login = "okapi/apps/authorize?oauth_token=$token_key".(($langpref != Settings::get('SITELANG'))?"&langpref=".$langpref:""); |
|
127 | - $login_url = Settings::get('SITE_URL').$login_page."target=".urlencode($after_login) |
|
128 | - ."&langpref=".$langpref; |
|
126 | + $after_login = "okapi/apps/authorize?oauth_token=$token_key" . (($langpref != Settings::get('SITELANG')) ? "&langpref=" . $langpref : ""); |
|
127 | + $login_url = Settings::get('SITE_URL') . $login_page . "target=" . urlencode($after_login) |
|
128 | + ."&langpref=" . $langpref; |
|
129 | 129 | return new OkapiRedirectResponse($login_url); |
130 | 130 | } |
131 | 131 | |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | select 1 |
138 | 138 | from okapi_authorizations |
139 | 139 | where |
140 | - user_id = '".Db::escape_string($OC_user_id)."' |
|
141 | - and consumer_key = '".Db::escape_string($token['consumer_key'])."' |
|
140 | + user_id = '".Db::escape_string($OC_user_id) . "' |
|
141 | + and consumer_key = '".Db::escape_string($token['consumer_key']) . "' |
|
142 | 142 | ", 0); |
143 | 143 | |
144 | 144 | if (!$authorized) |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | Db::execute(" |
154 | 154 | insert ignore into okapi_authorizations (consumer_key, user_id) |
155 | 155 | values ( |
156 | - '".Db::escape_string($token['consumer_key'])."', |
|
157 | - '".Db::escape_string($OC_user_id)."' |
|
156 | + '".Db::escape_string($token['consumer_key']) . "', |
|
157 | + '".Db::escape_string($OC_user_id) . "' |
|
158 | 158 | ); |
159 | 159 | "); |
160 | 160 | $authorized = true; |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | |
167 | 167 | if ($token['callback']) { |
168 | 168 | return new OkapiRedirectResponse( |
169 | - $token['callback'].$callback_concat_char."error=access_denied". |
|
170 | - "&oauth_token=".$token['key'] |
|
169 | + $token['callback'] . $callback_concat_char . "error=access_denied" . |
|
170 | + "&oauth_token=" . $token['key'] |
|
171 | 171 | ); |
172 | 172 | } else { |
173 | 173 | # Consumer did not provide a callback URL (oauth_callback=oob). |
174 | 174 | # We'll have to redirect to the Opencaching main page then... |
175 | - return new OkapiRedirectResponse(Settings::get('SITE_URL')."index.php"); |
|
175 | + return new OkapiRedirectResponse(Settings::get('SITE_URL') . "index.php"); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | # Not yet authorized. Display an authorization request. |
182 | 182 | $vars = array( |
183 | - 'okapi_base_url' => Settings::get('SITE_URL')."okapi/", |
|
183 | + 'okapi_base_url' => Settings::get('SITE_URL') . "okapi/", |
|
184 | 184 | 'token' => $token, |
185 | 185 | 'site_name' => Okapi::get_normalized_site_name(), |
186 | 186 | 'site_url' => Settings::get('SITE_URL'), |
@@ -202,19 +202,19 @@ discard block |
||
202 | 202 | |
203 | 203 | Db::execute(" |
204 | 204 | update okapi_tokens |
205 | - set user_id = '".Db::escape_string($OC_user_id)."' |
|
206 | - where `key` = '".Db::escape_string($token_key)."'; |
|
205 | + set user_id = '".Db::escape_string($OC_user_id) . "' |
|
206 | + where `key` = '".Db::escape_string($token_key) . "'; |
|
207 | 207 | "); |
208 | 208 | |
209 | 209 | # Redirect to the callback_url. |
210 | 210 | |
211 | 211 | if ($token['callback']) { |
212 | - return new OkapiRedirectResponse($token['callback'].$callback_concat_char."oauth_token=".$token_key."&oauth_verifier=".$token['verifier']); |
|
212 | + return new OkapiRedirectResponse($token['callback'] . $callback_concat_char . "oauth_token=" . $token_key . "&oauth_verifier=" . $token['verifier']); |
|
213 | 213 | } else { |
214 | 214 | # Consumer did not provide a callback URL (probably the user is using a desktop |
215 | 215 | # or mobile application). We'll just have to display the verifier to the user. |
216 | - return new OkapiRedirectResponse(Settings::get('SITE_URL')."okapi/apps/authorized?oauth_token=".$token_key |
|
217 | - ."&oauth_verifier=".$token['verifier']."&langpref=".$langpref); |
|
216 | + return new OkapiRedirectResponse(Settings::get('SITE_URL') . "okapi/apps/authorized?oauth_token=" . $token_key |
|
217 | + ."&oauth_verifier=" . $token['verifier'] . "&langpref=" . $langpref); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $segments = explode(".", $domain); |
230 | 230 | $results = array(); |
231 | 231 | for ($to_skip = 0; $to_skip <= count($segments) - 2; $to_skip++) { |
232 | - $results[] = ".".implode(".", array_slice($segments, $to_skip)); |
|
232 | + $results[] = "." . implode(".", array_slice($segments, $to_skip)); |
|
233 | 233 | $results[] = implode(".", array_slice($segments, $to_skip)); |
234 | 234 | } |
235 | 235 | return $results; |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | $langpref = isset($_GET['langpref']) ? $_GET['langpref'] : Settings::get('SITELANG'); |
21 | 21 | $langprefs = explode("|", $langpref); |
22 | 22 | $locales = array(); |
23 | - foreach (Locales::$languages as $lang => $attrs) |
|
24 | - $locales[$attrs['locale']] = $attrs; |
|
23 | + foreach (Locales::$languages as $lang => $attrs) { |
|
24 | + $locales[$attrs['locale']] = $attrs; |
|
25 | + } |
|
25 | 26 | |
26 | 27 | # Current implementation of the "interactivity" parameter is: If developer |
27 | 28 | # wants to "confirm_user", then just log out the current user before we |
@@ -96,8 +97,7 @@ discard block |
||
96 | 97 | # that's exactly the relogin that we want. |
97 | 98 | |
98 | 99 | $login_page .= 'action=logout&'; |
99 | - } |
|
100 | - else |
|
100 | + } else |
|
101 | 101 | { |
102 | 102 | # OCPL uses REAL MAGIC for session handling. I don't get ANY of it. |
103 | 103 | # The logout.php DOES NOT support the "target" parameter, so we |
@@ -158,8 +158,7 @@ discard block |
||
158 | 158 | ); |
159 | 159 | "); |
160 | 160 | $authorized = true; |
161 | - } |
|
162 | - else |
|
161 | + } else |
|
163 | 162 | { |
164 | 163 | # User denied access. Nothing sensible to do now. Will try to report |
165 | 164 | # back to the Consumer application with an error. |
@@ -175,8 +174,7 @@ discard block |
||
175 | 174 | return new OkapiRedirectResponse(Settings::get('SITE_URL')."index.php"); |
176 | 175 | } |
177 | 176 | } |
178 | - } |
|
179 | - else |
|
177 | + } else |
|
180 | 178 | { |
181 | 179 | # Not yet authorized. Display an authorization request. |
182 | 180 | $vars = array( |
@@ -215,6 +215,7 @@ discard block |
||
215 | 215 | * Makes comparison of the given database structures, support some options |
216 | 216 | * @access private |
217 | 217 | * @param string $source and $dest are strings - database tables structures |
218 | + * @param string $dest |
|
218 | 219 | * @return array |
219 | 220 | * - table (array) |
220 | 221 | * - destOrphan (boolean) |
@@ -376,8 +377,8 @@ discard block |
||
376 | 377 | /** |
377 | 378 | * returns array of fields or keys definitions that differs in the given tables structure |
378 | 379 | * @access private |
379 | - * @param sring $sourceSql table structure |
|
380 | - * @param sring $destSql right table structure |
|
380 | + * @param string $sourceSql table structure |
|
381 | + * @param string $destSql right table structure |
|
381 | 382 | * supports some $options |
382 | 383 | * @return array |
383 | 384 | * - [0] |
@@ -734,6 +735,7 @@ discard block |
||
734 | 735 | /** |
735 | 736 | * works the same as getDelimPos except returns position of the first occurence of the delimiter starting from |
736 | 737 | * the end of the string |
738 | + * @param string $string |
|
737 | 739 | */ |
738 | 740 | function getDelimRpos($string, $offset=0, $delim=';', $skipInBrackets=false) |
739 | 741 | { |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | var $config = array();//updater configuration |
58 | 58 | |
59 | 59 | /** |
60 | - * Constructor |
|
61 | - * @access public |
|
62 | - */ |
|
60 | + * Constructor |
|
61 | + * @access public |
|
62 | + */ |
|
63 | 63 | function __construct() |
64 | 64 | { |
65 | 65 | $this->init(); |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | - * merges current updater config with the given one |
|
86 | - * @param assoc_array $config new configuration values |
|
87 | - */ |
|
85 | + * merges current updater config with the given one |
|
86 | + * @param assoc_array $config new configuration values |
|
87 | + */ |
|
88 | 88 | function setConfig($config=array()) |
89 | 89 | { |
90 | 90 | if (is_array($config)) |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Returns array of update SQL with default options, $source, $dest - database structures |
|
98 | - * @access public |
|
99 | - * @param string $source structure dump of database to update |
|
100 | - * @param string $dest structure dump of the reference database |
|
101 | - * @param bool $asString if true - result will be a string, otherwise - array |
|
102 | - * @return array|string update sql statements - in array or string (separated with ';') |
|
103 | - */ |
|
97 | + * Returns array of update SQL with default options, $source, $dest - database structures |
|
98 | + * @access public |
|
99 | + * @param string $source structure dump of database to update |
|
100 | + * @param string $dest structure dump of the reference database |
|
101 | + * @param bool $asString if true - result will be a string, otherwise - array |
|
102 | + * @return array|string update sql statements - in array or string (separated with ';') |
|
103 | + */ |
|
104 | 104 | function getUpdates($source, $dest, $asString=false) |
105 | 105 | { |
106 | 106 | $result = $asString?'':array(); |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Filters comparison result and lefts only sync actions allowed by 'updateTypes' option |
|
127 | - */ |
|
126 | + * Filters comparison result and lefts only sync actions allowed by 'updateTypes' option |
|
127 | + */ |
|
128 | 128 | function filterDiffs($compRes) |
129 | 129 | { |
130 | 130 | $result = array(); |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | - * Gets structured general info about the databases diff : |
|
187 | - * array(sourceOrphans=>array(...), destOrphans=>array(...), different=>array(...)) |
|
188 | - */ |
|
186 | + * Gets structured general info about the databases diff : |
|
187 | + * array(sourceOrphans=>array(...), destOrphans=>array(...), different=>array(...)) |
|
188 | + */ |
|
189 | 189 | function getDiffInfo($compRes) |
190 | 190 | { |
191 | 191 | if (!is_array($compRes)) |
@@ -212,19 +212,19 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Makes comparison of the given database structures, support some options |
|
216 | - * @access private |
|
217 | - * @param string $source and $dest are strings - database tables structures |
|
218 | - * @return array |
|
219 | - * - table (array) |
|
220 | - * - destOrphan (boolean) |
|
221 | - * - sourceOrphan (boolean) |
|
222 | - * - differs (array) OR (boolean) false if no diffs |
|
223 | - * - [0](array) |
|
224 | - * - source (string) structure definition line in the out-of-date table |
|
225 | - * - dest (string) structure definition line in the reference table |
|
226 | - * - [1](array) ... |
|
227 | - */ |
|
215 | + * Makes comparison of the given database structures, support some options |
|
216 | + * @access private |
|
217 | + * @param string $source and $dest are strings - database tables structures |
|
218 | + * @return array |
|
219 | + * - table (array) |
|
220 | + * - destOrphan (boolean) |
|
221 | + * - sourceOrphan (boolean) |
|
222 | + * - differs (array) OR (boolean) false if no diffs |
|
223 | + * - [0](array) |
|
224 | + * - source (string) structure definition line in the out-of-date table |
|
225 | + * - dest (string) structure definition line in the reference table |
|
226 | + * - [1](array) ... |
|
227 | + */ |
|
228 | 228 | function compare($source, $dest) |
229 | 229 | { |
230 | 230 | $this->sourceStruct = $source; |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Retrieves list of table names from the database structure dump |
|
276 | - * @access private |
|
277 | - * @param string $struct database structure listing |
|
278 | - */ |
|
275 | + * Retrieves list of table names from the database structure dump |
|
276 | + * @access private |
|
277 | + * @param string $struct database structure listing |
|
278 | + */ |
|
279 | 279 | function getTableList($struct) |
280 | 280 | { |
281 | 281 | $result = array(); |
@@ -290,13 +290,13 @@ discard block |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | - * Retrieves table structure definition from the database structure dump |
|
294 | - * @access private |
|
295 | - * @param string $struct database structure listing |
|
296 | - * @param string $tab table name |
|
297 | - * @param bool $removeDatabase - either to remove database name in "CREATE TABLE database.tab"-like declarations |
|
298 | - * @return string table structure definition |
|
299 | - */ |
|
293 | + * Retrieves table structure definition from the database structure dump |
|
294 | + * @access private |
|
295 | + * @param string $struct database structure listing |
|
296 | + * @param string $tab table name |
|
297 | + * @param bool $removeDatabase - either to remove database name in "CREATE TABLE database.tab"-like declarations |
|
298 | + * @return string table structure definition |
|
299 | + */ |
|
300 | 300 | function getTabSql($struct, $tab, $removeDatabase=true) |
301 | 301 | { |
302 | 302 | $result = ''; |
@@ -327,9 +327,9 @@ discard block |
||
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * Splits table sql into indexed array |
|
331 | - * |
|
332 | - */ |
|
330 | + * Splits table sql into indexed array |
|
331 | + * |
|
332 | + */ |
|
333 | 333 | function splitTabSql($sql) |
334 | 334 | { |
335 | 335 | $result = array(); |
@@ -374,17 +374,17 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
377 | - * returns array of fields or keys definitions that differs in the given tables structure |
|
378 | - * @access private |
|
379 | - * @param sring $sourceSql table structure |
|
380 | - * @param sring $destSql right table structure |
|
381 | - * supports some $options |
|
382 | - * @return array |
|
383 | - * - [0] |
|
384 | - * - source (string) out-of-date table field definition |
|
385 | - * - dest (string) reference table field definition |
|
386 | - * - [1]... |
|
387 | - */ |
|
377 | + * returns array of fields or keys definitions that differs in the given tables structure |
|
378 | + * @access private |
|
379 | + * @param sring $sourceSql table structure |
|
380 | + * @param sring $destSql right table structure |
|
381 | + * supports some $options |
|
382 | + * @return array |
|
383 | + * - [0] |
|
384 | + * - source (string) out-of-date table field definition |
|
385 | + * - dest (string) reference table field definition |
|
386 | + * - [1]... |
|
387 | + */ |
|
388 | 388 | function compareSql($sourceSql, $destSql)//$sourceSql, $destSql |
389 | 389 | { |
390 | 390 | $result = array(); |
@@ -449,13 +449,13 @@ discard block |
||
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
452 | - * Transforms table structure defnition line into key=>value pair where the key is a string that uniquely |
|
453 | - * defines field or key desribed |
|
454 | - * @access private |
|
455 | - * @param string $line field definition string |
|
456 | - * @return array array with single key=>value pair as described in the description |
|
457 | - * implements some options |
|
458 | - */ |
|
452 | + * Transforms table structure defnition line into key=>value pair where the key is a string that uniquely |
|
453 | + * defines field or key desribed |
|
454 | + * @access private |
|
455 | + * @param string $line field definition string |
|
456 | + * @return array array with single key=>value pair as described in the description |
|
457 | + * implements some options |
|
458 | + */ |
|
459 | 459 | function processLine($line) |
460 | 460 | { |
461 | 461 | $options = $this->config; |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
500 | - * Takes an output of compare() method to generate the set of sql needed to update source table to make it |
|
501 | - * look as a destination one |
|
502 | - * @access private |
|
503 | - * @param array $diff compare() method output |
|
504 | - * @return array list of sql statements |
|
505 | - * supports query generation options |
|
506 | - */ |
|
500 | + * Takes an output of compare() method to generate the set of sql needed to update source table to make it |
|
501 | + * look as a destination one |
|
502 | + * @access private |
|
503 | + * @param array $diff compare() method output |
|
504 | + * @return array list of sql statements |
|
505 | + * supports query generation options |
|
506 | + */ |
|
507 | 507 | function getDiffSql($diff)//maybe add option to ommit or force 'IF NOT EXISTS', skip autoincrement |
508 | 508 | { |
509 | 509 | $options = $this->config; |
@@ -566,13 +566,13 @@ discard block |
||
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Compiles update sql |
|
570 | - * @access private |
|
571 | - * @param string $action - 'drop', 'add' or 'modify' |
|
572 | - * @param string $tab table name |
|
573 | - * @param string $sql definition of the element to change |
|
574 | - * @return string update sql |
|
575 | - */ |
|
569 | + * Compiles update sql |
|
570 | + * @access private |
|
571 | + * @param string $action - 'drop', 'add' or 'modify' |
|
572 | + * @param string $tab table name |
|
573 | + * @param string $sql definition of the element to change |
|
574 | + * @return string update sql |
|
575 | + */ |
|
576 | 576 | function getActionSql($action, $tab, $sql) |
577 | 577 | { |
578 | 578 | $result = 'ALTER TABLE `'.$tab.'` '; |
@@ -645,12 +645,12 @@ discard block |
||
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | - * Searches for the position of the next delimiter which is not inside string literal like 'this ; ' or |
|
649 | - * like "this ; ". |
|
650 | - * |
|
651 | - * Handles escaped \" and \'. Also handles sql comments. |
|
652 | - * Actualy it is regex-based Finit State Machine (FSN) |
|
653 | - */ |
|
648 | + * Searches for the position of the next delimiter which is not inside string literal like 'this ; ' or |
|
649 | + * like "this ; ". |
|
650 | + * |
|
651 | + * Handles escaped \" and \'. Also handles sql comments. |
|
652 | + * Actualy it is regex-based Finit State Machine (FSN) |
|
653 | + */ |
|
654 | 654 | function getDelimPos($string, $offset=0, $delim=';', $skipInBrackets=false) |
655 | 655 | { |
656 | 656 | $stack = array(); |
@@ -732,9 +732,9 @@ discard block |
||
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
735 | - * works the same as getDelimPos except returns position of the first occurence of the delimiter starting from |
|
736 | - * the end of the string |
|
737 | - */ |
|
735 | + * works the same as getDelimPos except returns position of the first occurence of the delimiter starting from |
|
736 | + * the end of the string |
|
737 | + */ |
|
738 | 738 | function getDelimRpos($string, $offset=0, $delim=';', $skipInBrackets=false) |
739 | 739 | { |
740 | 740 | $pos = $this->getDelimPos($string, $offset, $delim, $skipInBrackets); |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | */ |
53 | 53 | class dbStructUpdater |
54 | 54 | { |
55 | - var $sourceStruct = '';//structure dump of the reference database |
|
56 | - var $destStruct = '';//structure dump of database to update |
|
57 | - var $config = array();//updater configuration |
|
55 | + var $sourceStruct = ''; //structure dump of the reference database |
|
56 | + var $destStruct = ''; //structure dump of database to update |
|
57 | + var $config = array(); //updater configuration |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Constructor |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * merges current updater config with the given one |
86 | 86 | * @param assoc_array $config new configuration values |
87 | 87 | */ |
88 | - function setConfig($config=array()) |
|
88 | + function setConfig($config = array()) |
|
89 | 89 | { |
90 | 90 | if (is_array($config)) |
91 | 91 | { |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param bool $asString if true - result will be a string, otherwise - array |
102 | 102 | * @return array|string update sql statements - in array or string (separated with ';') |
103 | 103 | */ |
104 | - function getUpdates($source, $dest, $asString=false) |
|
104 | + function getUpdates($source, $dest, $asString = false) |
|
105 | 105 | { |
106 | - $result = $asString?'':array(); |
|
106 | + $result = $asString ? '' : array(); |
|
107 | 107 | $compRes = $this->compare($source, $dest); |
108 | 108 | if (empty($compRes)) |
109 | 109 | { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $result = $this->getDiffSql($compRes); |
118 | 118 | if ($asString) |
119 | 119 | { |
120 | - $result = implode(";\r\n", $result).';'; |
|
120 | + $result = implode(";\r\n", $result) . ';'; |
|
121 | 121 | } |
122 | 122 | return $result; |
123 | 123 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | } |
139 | 139 | $allowedActions = array('create', 'drop', 'add', 'remove', 'modify'); |
140 | 140 | $updateActions = array_intersect($updateActions, $allowedActions); |
141 | - foreach($compRes as $table=>$info) |
|
141 | + foreach ($compRes as $table=>$info) |
|
142 | 142 | { |
143 | 143 | if ($info['sourceOrphan']) |
144 | 144 | { |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $result[$table] = $info; |
155 | 155 | } |
156 | 156 | } |
157 | - elseif($info['differs']) |
|
157 | + elseif ($info['differs']) |
|
158 | 158 | { |
159 | 159 | $resultInfo = $info; |
160 | 160 | unset($resultInfo['differs']); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | { |
169 | 169 | $resultInfo['differs'][] = $diff; |
170 | 170 | } |
171 | - elseif(in_array('modify', $updateActions)) |
|
171 | + elseif (in_array('modify', $updateActions)) |
|
172 | 172 | { |
173 | 173 | $resultInfo['differs'][] = $diff; |
174 | 174 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | $result = array('sourceOrphans'=>array(), 'destOrphans'=>array(), 'different'=>array()); |
196 | - foreach($compRes as $table=>$info) |
|
196 | + foreach ($compRes as $table=>$info) |
|
197 | 197 | { |
198 | 198 | if ($info['sourceOrphan']) |
199 | 199 | { |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | foreach ($all as $tab) |
243 | 243 | { |
244 | 244 | $info = array('destOrphan'=>false, 'sourceOrphan'=>false, 'differs'=>false); |
245 | - if(in_array($tab, $destOrphans)) |
|
245 | + if (in_array($tab, $destOrphans)) |
|
246 | 246 | { |
247 | 247 | $info['destOrphan'] = true; |
248 | 248 | } |
@@ -255,16 +255,16 @@ discard block |
||
255 | 255 | $destSql = $this->getTabSql($this->destStruct, $tab, true); |
256 | 256 | $sourceSql = $this->getTabSql($this->sourceStruct, $tab, true); |
257 | 257 | $diffs = $this->compareSql($sourceSql, $destSql); |
258 | - if ($diffs===false) |
|
258 | + if ($diffs === false) |
|
259 | 259 | { |
260 | - trigger_error('[WARNING] error parsing definition of table "'.$tab.'" - skipped'); |
|
260 | + trigger_error('[WARNING] error parsing definition of table "' . $tab . '" - skipped'); |
|
261 | 261 | continue; |
262 | 262 | } |
263 | 263 | elseif (!empty($diffs))//not empty array |
264 | 264 | { |
265 | 265 | $info['differs'] = $diffs; |
266 | 266 | } |
267 | - else continue;//empty array |
|
267 | + else continue; //empty array |
|
268 | 268 | } |
269 | 269 | $result[$tab] = $info; |
270 | 270 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $result = array(); |
282 | 282 | if (preg_match_all('/CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?(?:`?(\w+)`?\.)?`?(\w+)`?/i', $struct, $m)) |
283 | 283 | { |
284 | - foreach($m[2] as $match)//m[1] is a database name if any |
|
284 | + foreach ($m[2] as $match)//m[1] is a database name if any |
|
285 | 285 | { |
286 | 286 | $result[] = $match; |
287 | 287 | } |
@@ -297,17 +297,17 @@ discard block |
||
297 | 297 | * @param bool $removeDatabase - either to remove database name in "CREATE TABLE database.tab"-like declarations |
298 | 298 | * @return string table structure definition |
299 | 299 | */ |
300 | - function getTabSql($struct, $tab, $removeDatabase=true) |
|
300 | + function getTabSql($struct, $tab, $removeDatabase = true) |
|
301 | 301 | { |
302 | 302 | $result = ''; |
303 | 303 | /* create table should be single line in this case*/ |
304 | 304 | //1 - part before database, 2-database name, 3 - part after database |
305 | - if (preg_match('/(CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?)(?:`?(\w+)`?\.)?(`?('.$tab.')`?(\W|$))/i', $struct, $m, PREG_OFFSET_CAPTURE)) |
|
305 | + if (preg_match('/(CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?)(?:`?(\w+)`?\.)?(`?(' . $tab . ')`?(\W|$))/i', $struct, $m, PREG_OFFSET_CAPTURE)) |
|
306 | 306 | { |
307 | 307 | $tableDef = $m[0][0]; |
308 | 308 | $start = $m[0][1]; |
309 | 309 | $database = $m[2][0]; |
310 | - $offset = $start+strlen($m[0][0]); |
|
310 | + $offset = $start + strlen($m[0][0]); |
|
311 | 311 | $end = $this->getDelimPos($struct, $offset); |
312 | 312 | if ($end === false) |
313 | 313 | { |
@@ -315,13 +315,13 @@ discard block |
||
315 | 315 | } |
316 | 316 | else |
317 | 317 | { |
318 | - $result = substr($struct, $start, $end-$start);//already without ';' |
|
318 | + $result = substr($struct, $start, $end - $start); //already without ';' |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | $result = trim($result); |
322 | 322 | if ($database && $removeDatabase) |
323 | 323 | { |
324 | - $result = str_replace($tableDef, $m[1][0].$m[3][0], $result); |
|
324 | + $result = str_replace($tableDef, $m[1][0] . $m[3][0], $result); |
|
325 | 325 | } |
326 | 326 | return $result; |
327 | 327 | } |
@@ -335,27 +335,27 @@ discard block |
||
335 | 335 | $result = array(); |
336 | 336 | //find opening bracket, get the prefix along with it |
337 | 337 | $openBracketPos = $this->getDelimPos($sql, 0, '('); |
338 | - if ($openBracketPos===false) |
|
338 | + if ($openBracketPos === false) |
|
339 | 339 | { |
340 | 340 | trigger_error('[WARNING] can not find opening bracket in table definition'); |
341 | 341 | return false; |
342 | 342 | } |
343 | - $prefix = substr($sql, 0, $openBracketPos+1);//prefix can not be empty, so do not check it, just trim |
|
343 | + $prefix = substr($sql, 0, $openBracketPos + 1); //prefix can not be empty, so do not check it, just trim |
|
344 | 344 | $result[] = trim($prefix); |
345 | - $body = substr($sql, strlen($prefix));//fields, indexes and part after closing bracket |
|
345 | + $body = substr($sql, strlen($prefix)); //fields, indexes and part after closing bracket |
|
346 | 346 | //split by commas, get part by part |
347 | - while(($commaPos = $this->getDelimPos($body, 0, ',', true))!==false) |
|
347 | + while (($commaPos = $this->getDelimPos($body, 0, ',', true)) !== false) |
|
348 | 348 | { |
349 | - $part = trim(substr($body, 0, $commaPos+1));//read another part and shorten $body |
|
349 | + $part = trim(substr($body, 0, $commaPos + 1)); //read another part and shorten $body |
|
350 | 350 | if ($part) |
351 | 351 | { |
352 | 352 | $result[] = $part; |
353 | 353 | } |
354 | - $body = substr($body, $commaPos+1); |
|
354 | + $body = substr($body, $commaPos + 1); |
|
355 | 355 | } |
356 | 356 | //here we have last field (or index) definition + part after closing bracket (ENGINE, ect) |
357 | 357 | $closeBracketPos = $this->getDelimRpos($body, 0, ')'); |
358 | - if ($closeBracketPos===false) |
|
358 | + if ($closeBracketPos === false) |
|
359 | 359 | { |
360 | 360 | trigger_error('[WARNING] can not find closing bracket in table definition'); |
361 | 361 | return false; |
@@ -389,27 +389,27 @@ discard block |
||
389 | 389 | { |
390 | 390 | $result = array(); |
391 | 391 | //split with comma delimiter, not line breaks |
392 | - $sourceParts = $this->splitTabSql($sourceSql); |
|
393 | - if ($sourceParts===false)//error parsing sql |
|
392 | + $sourceParts = $this->splitTabSql($sourceSql); |
|
393 | + if ($sourceParts === false)//error parsing sql |
|
394 | 394 | { |
395 | 395 | trigger_error('[WARNING] error parsing source sql'); |
396 | 396 | return false; |
397 | 397 | } |
398 | 398 | $destParts = $this->splitTabSql($destSql); |
399 | - if ($destParts===false) |
|
399 | + if ($destParts === false) |
|
400 | 400 | { |
401 | 401 | trigger_error('[WARNING] error parsing destination sql'); |
402 | 402 | return false; |
403 | 403 | } |
404 | 404 | $sourcePartsIndexed = array(); |
405 | 405 | $destPartsIndexed = array(); |
406 | - foreach($sourceParts as $line) |
|
406 | + foreach ($sourceParts as $line) |
|
407 | 407 | { |
408 | 408 | $lineInfo = $this->processLine($line); |
409 | 409 | if (!$lineInfo) continue; |
410 | 410 | $sourcePartsIndexed[$lineInfo['key']] = $lineInfo['line']; |
411 | 411 | } |
412 | - foreach($destParts as $line) |
|
412 | + foreach ($destParts as $line) |
|
413 | 413 | { |
414 | 414 | $lineInfo = $this->processLine($line); |
415 | 415 | if (!$lineInfo) continue; |
@@ -418,16 +418,16 @@ discard block |
||
418 | 418 | $sourceKeys = array_keys($sourcePartsIndexed); |
419 | 419 | $destKeys = array_keys($destPartsIndexed); |
420 | 420 | $all = array_unique(array_merge($sourceKeys, $destKeys)); |
421 | - sort($all);//fields first, then indexes - because fields are prefixed with '!' |
|
421 | + sort($all); //fields first, then indexes - because fields are prefixed with '!' |
|
422 | 422 | |
423 | 423 | foreach ($all as $key) |
424 | 424 | { |
425 | 425 | $info = array('source'=>'', 'dest'=>''); |
426 | - $inSource= in_array($key, $sourceKeys); |
|
427 | - $inDest= in_array($key, $destKeys); |
|
426 | + $inSource = in_array($key, $sourceKeys); |
|
427 | + $inDest = in_array($key, $destKeys); |
|
428 | 428 | $sourceOrphan = $inSource && !$inDest; |
429 | 429 | $destOrphan = $inDest && !$inSource; |
430 | - $different = $inSource && $inDest && |
|
430 | + $different = $inSource && $inDest && |
|
431 | 431 | strcasecmp($this->normalizeString($destPartsIndexed[$key]), $this->normalizeString($sourcePartsIndexed[$key])); |
432 | 432 | if ($sourceOrphan) |
433 | 433 | { |
@@ -472,11 +472,11 @@ discard block |
||
472 | 472 | } |
473 | 473 | elseif (preg_match('/^`?\w+`?/i', $line, $m))//field definition |
474 | 474 | { |
475 | - $key = '!'.$m[0];//to make sure fields will be synchronised before the keys |
|
475 | + $key = '!' . $m[0]; //to make sure fields will be synchronised before the keys |
|
476 | 476 | } |
477 | 477 | else |
478 | 478 | { |
479 | - return false;//line has no valuable info (empty or comment) |
|
479 | + return false; //line has no valuable info (empty or comment) |
|
480 | 480 | } |
481 | 481 | //$key = str_replace('`', '', $key); |
482 | 482 | if (!empty($options['varcharDefaultIgnore'])) |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | $line = preg_replace("/ AUTO_INCREMENT=[0-9]+/i", '', $line); |
493 | 493 | } |
494 | 494 | $result['key'] = $this->normalizeString($key); |
495 | - $result['line']= $line; |
|
495 | + $result['line'] = $line; |
|
496 | 496 | return $result; |
497 | 497 | } |
498 | 498 | |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | { |
513 | 513 | return $sqls; |
514 | 514 | } |
515 | - foreach($diff as $tab=>$info) |
|
515 | + foreach ($diff as $tab=>$info) |
|
516 | 516 | { |
517 | 517 | if ($info['sourceOrphan'])//delete it |
518 | 518 | { |
519 | - $sqls[] = 'DROP TABLE `'.$tab.'`'; |
|
519 | + $sqls[] = 'DROP TABLE `' . $tab . '`'; |
|
520 | 520 | } |
521 | 521 | elseif ($info['destOrphan'])//create destination table in source |
522 | 522 | { |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | } |
539 | 539 | else |
540 | 540 | { |
541 | - foreach($info['differs'] as $finfo) |
|
541 | + foreach ($info['differs'] as $finfo) |
|
542 | 542 | { |
543 | 543 | $inDest = !empty($finfo['dest']); |
544 | 544 | $inSource = !empty($finfo['source']); |
@@ -575,53 +575,53 @@ discard block |
||
575 | 575 | */ |
576 | 576 | function getActionSql($action, $tab, $sql) |
577 | 577 | { |
578 | - $result = 'ALTER TABLE `'.$tab.'` '; |
|
578 | + $result = 'ALTER TABLE `' . $tab . '` '; |
|
579 | 579 | $action = strtolower($action); |
580 | - $keyField = '`?\w`?(?:\(\d+\))?';//matches `name`(10) |
|
581 | - $keyFieldList = '(?:'.$keyField.'(?:,\s?)?)+';//matches `name`(10),`desc`(255) |
|
582 | - if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\('.$keyFieldList.'\))/i', $sql, $m)) |
|
580 | + $keyField = '`?\w`?(?:\(\d+\))?'; //matches `name`(10) |
|
581 | + $keyFieldList = '(?:' . $keyField . '(?:,\s?)?)+'; //matches `name`(10),`desc`(255) |
|
582 | + if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\(' . $keyFieldList . '\))/i', $sql, $m)) |
|
583 | 583 | { //key and index operations |
584 | 584 | $type = strtolower(trim($m[1])); |
585 | 585 | $name = trim($m[2]); |
586 | 586 | $fields = trim($m[3]); |
587 | - switch($action) |
|
587 | + switch ($action) |
|
588 | 588 | { |
589 | 589 | case 'drop': |
590 | - if ($type=='primary') |
|
590 | + if ($type == 'primary') |
|
591 | 591 | { |
592 | - $result.= 'DROP PRIMARY KEY'; |
|
592 | + $result .= 'DROP PRIMARY KEY'; |
|
593 | 593 | } |
594 | 594 | else |
595 | 595 | { |
596 | - $result.= 'DROP INDEX `'.$name.'`'; |
|
596 | + $result .= 'DROP INDEX `' . $name . '`'; |
|
597 | 597 | } |
598 | 598 | break; |
599 | 599 | case 'add': |
600 | - if ($type=='primary') |
|
600 | + if ($type == 'primary') |
|
601 | 601 | { |
602 | - $result.= 'ADD PRIMARY KEY '.$fields; |
|
602 | + $result .= 'ADD PRIMARY KEY ' . $fields; |
|
603 | 603 | } |
604 | - elseif ($type=='') |
|
604 | + elseif ($type == '') |
|
605 | 605 | { |
606 | - $result.= 'ADD INDEX `'.$name.'` '.$fields; |
|
606 | + $result .= 'ADD INDEX `' . $name . '` ' . $fields; |
|
607 | 607 | } |
608 | 608 | else |
609 | 609 | { |
610 | - $result .='ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique |
|
610 | + $result .= 'ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields; //fulltext or unique |
|
611 | 611 | } |
612 | 612 | break; |
613 | 613 | case 'modify': |
614 | - if ($type=='primary') |
|
614 | + if ($type == 'primary') |
|
615 | 615 | { |
616 | - $result.='DROP PRIMARY KEY, ADD PRIMARY KEY '.$fields; |
|
616 | + $result .= 'DROP PRIMARY KEY, ADD PRIMARY KEY ' . $fields; |
|
617 | 617 | } |
618 | - elseif ($type=='') |
|
618 | + elseif ($type == '') |
|
619 | 619 | { |
620 | - $result.='DROP INDEX `'.$name.'`, ADD INDEX `'.$name.'` '.$fields; |
|
620 | + $result .= 'DROP INDEX `' . $name . '`, ADD INDEX `' . $name . '` ' . $fields; |
|
621 | 621 | } |
622 | 622 | else |
623 | 623 | { |
624 | - $result.='DROP INDEX `'.$name.'`, ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique |
|
624 | + $result .= 'DROP INDEX `' . $name . '`, ADD ' . strtoupper($type) . ' `' . $name . '` ' . $fields; //fulltext or unique |
|
625 | 625 | } |
626 | 626 | break; |
627 | 627 | |
@@ -630,15 +630,15 @@ discard block |
||
630 | 630 | else //fields operations |
631 | 631 | { |
632 | 632 | $sql = rtrim(trim($sql), ','); |
633 | - $result.= strtoupper($action); |
|
634 | - if ($action=='drop') |
|
633 | + $result .= strtoupper($action); |
|
634 | + if ($action == 'drop') |
|
635 | 635 | { |
636 | 636 | $spacePos = strpos($sql, ' '); |
637 | - $result.= ' '.substr($sql, 0, $spacePos); |
|
637 | + $result .= ' ' . substr($sql, 0, $spacePos); |
|
638 | 638 | } |
639 | 639 | else |
640 | 640 | { |
641 | - $result.= ' '.$sql; |
|
641 | + $result .= ' ' . $sql; |
|
642 | 642 | } |
643 | 643 | } |
644 | 644 | return $result; |
@@ -651,39 +651,39 @@ discard block |
||
651 | 651 | * Handles escaped \" and \'. Also handles sql comments. |
652 | 652 | * Actualy it is regex-based Finit State Machine (FSN) |
653 | 653 | */ |
654 | - function getDelimPos($string, $offset=0, $delim=';', $skipInBrackets=false) |
|
654 | + function getDelimPos($string, $offset = 0, $delim = ';', $skipInBrackets = false) |
|
655 | 655 | { |
656 | 656 | $stack = array(); |
657 | - $rbs = '\\\\'; //reg - escaped backslash |
|
657 | + $rbs = '\\\\'; //reg - escaped backslash |
|
658 | 658 | $regPrefix = "(?<!$rbs)(?:$rbs{2})*"; |
659 | - $reg = $regPrefix.'("|\')|(/\\*)|(\\*/)|(-- )|(\r\n|\r|\n)|'; |
|
659 | + $reg = $regPrefix . '("|\')|(/\\*)|(\\*/)|(-- )|(\r\n|\r|\n)|'; |
|
660 | 660 | if ($skipInBrackets) |
661 | 661 | { |
662 | - $reg.='(\(|\))|'; |
|
662 | + $reg .= '(\(|\))|'; |
|
663 | 663 | } |
664 | 664 | else |
665 | 665 | { |
666 | - $reg.='()'; |
|
666 | + $reg .= '()'; |
|
667 | 667 | } |
668 | - $reg .= '('.preg_quote($delim).')'; |
|
669 | - while (preg_match('%'.$reg.'%', $string, $m, PREG_OFFSET_CAPTURE, $offset)) |
|
668 | + $reg .= '(' . preg_quote($delim) . ')'; |
|
669 | + while (preg_match('%' . $reg . '%', $string, $m, PREG_OFFSET_CAPTURE, $offset)) |
|
670 | 670 | { |
671 | - $offset = $m[0][1]+strlen($m[0][0]); |
|
672 | - if (end($stack)=='/*') |
|
671 | + $offset = $m[0][1] + strlen($m[0][0]); |
|
672 | + if (end($stack) == '/*') |
|
673 | 673 | { |
674 | 674 | if (!empty($m[3][0])) |
675 | 675 | { |
676 | 676 | array_pop($stack); |
677 | 677 | } |
678 | - continue;//here we could also simplify regexp |
|
678 | + continue; //here we could also simplify regexp |
|
679 | 679 | } |
680 | - if (end($stack)=='-- ') |
|
680 | + if (end($stack) == '-- ') |
|
681 | 681 | { |
682 | 682 | if (!empty($m[5][0])) |
683 | 683 | { |
684 | 684 | array_pop($stack); |
685 | 685 | } |
686 | - continue;//here we could also simplify regexp |
|
686 | + continue; //here we could also simplify regexp |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | if (!empty($m[7][0]))// ';' found |
@@ -699,18 +699,18 @@ discard block |
||
699 | 699 | } |
700 | 700 | if (!empty($m[6][0]))// '(' or ')' found |
701 | 701 | { |
702 | - if (empty($stack) && $m[6][0]=='(') |
|
702 | + if (empty($stack) && $m[6][0] == '(') |
|
703 | 703 | { |
704 | 704 | array_push($stack, $m[6][0]); |
705 | 705 | } |
706 | - elseif($m[6][0]==')' && end($stack)=='(') |
|
706 | + elseif ($m[6][0] == ')' && end($stack) == '(') |
|
707 | 707 | { |
708 | 708 | array_pop($stack); |
709 | 709 | } |
710 | 710 | } |
711 | 711 | elseif (!empty($m[1][0]))// ' or " found |
712 | 712 | { |
713 | - if (end($stack)==$m[1][0]) |
|
713 | + if (end($stack) == $m[1][0]) |
|
714 | 714 | { |
715 | 715 | array_pop($stack); |
716 | 716 | } |
@@ -735,22 +735,22 @@ discard block |
||
735 | 735 | * works the same as getDelimPos except returns position of the first occurence of the delimiter starting from |
736 | 736 | * the end of the string |
737 | 737 | */ |
738 | - function getDelimRpos($string, $offset=0, $delim=';', $skipInBrackets=false) |
|
738 | + function getDelimRpos($string, $offset = 0, $delim = ';', $skipInBrackets = false) |
|
739 | 739 | { |
740 | 740 | $pos = $this->getDelimPos($string, $offset, $delim, $skipInBrackets); |
741 | - if ($pos===false) |
|
741 | + if ($pos === false) |
|
742 | 742 | { |
743 | 743 | return false; |
744 | 744 | } |
745 | 745 | do |
746 | 746 | { |
747 | - $newPos=$this->getDelimPos($string, $pos+1, $delim, $skipInBrackets); |
|
747 | + $newPos = $this->getDelimPos($string, $pos + 1, $delim, $skipInBrackets); |
|
748 | 748 | if ($newPos !== false) |
749 | 749 | { |
750 | 750 | $pos = $newPos; |
751 | 751 | } |
752 | 752 | } |
753 | - while($newPos!==false); |
|
753 | + while ($newPos !== false); |
|
754 | 754 | return $pos; |
755 | 755 | } |
756 | 756 |
@@ -131,8 +131,7 @@ discard block |
||
131 | 131 | if (is_array($this->config['updateTypes'])) |
132 | 132 | { |
133 | 133 | $updateActions = $this->config['updateTypes']; |
134 | - } |
|
135 | - else |
|
134 | + } else |
|
136 | 135 | { |
137 | 136 | $updateActions = array_map('trim', explode(',', $this->config['updateTypes'])); |
138 | 137 | } |
@@ -146,15 +145,13 @@ discard block |
||
146 | 145 | { |
147 | 146 | $result[$table] = $info; |
148 | 147 | } |
149 | - } |
|
150 | - elseif ($info['destOrphan']) |
|
148 | + } elseif ($info['destOrphan']) |
|
151 | 149 | { |
152 | 150 | if (in_array('drop', $updateActions)) |
153 | 151 | { |
154 | 152 | $result[$table] = $info; |
155 | 153 | } |
156 | - } |
|
157 | - elseif($info['differs']) |
|
154 | + } elseif($info['differs']) |
|
158 | 155 | { |
159 | 156 | $resultInfo = $info; |
160 | 157 | unset($resultInfo['differs']); |
@@ -163,12 +160,10 @@ discard block |
||
163 | 160 | if (empty($diff['dest']) && in_array('add', $updateActions)) |
164 | 161 | { |
165 | 162 | $resultInfo['differs'][] = $diff; |
166 | - } |
|
167 | - elseif (empty($diff['source']) && in_array('remove', $updateActions)) |
|
163 | + } elseif (empty($diff['source']) && in_array('remove', $updateActions)) |
|
168 | 164 | { |
169 | 165 | $resultInfo['differs'][] = $diff; |
170 | - } |
|
171 | - elseif(in_array('modify', $updateActions)) |
|
166 | + } elseif(in_array('modify', $updateActions)) |
|
172 | 167 | { |
173 | 168 | $resultInfo['differs'][] = $diff; |
174 | 169 | } |
@@ -198,12 +193,10 @@ discard block |
||
198 | 193 | if ($info['sourceOrphan']) |
199 | 194 | { |
200 | 195 | $result['sourceOrphans'][] = $table; |
201 | - } |
|
202 | - elseif ($info['destOrphan']) |
|
196 | + } elseif ($info['destOrphan']) |
|
203 | 197 | { |
204 | 198 | $result['destOrphans'][] = $table; |
205 | - } |
|
206 | - else |
|
199 | + } else |
|
207 | 200 | { |
208 | 201 | $result['different'][] = $table; |
209 | 202 | } |
@@ -245,12 +238,10 @@ discard block |
||
245 | 238 | if(in_array($tab, $destOrphans)) |
246 | 239 | { |
247 | 240 | $info['destOrphan'] = true; |
248 | - } |
|
249 | - elseif (in_array($tab, $sourceOrphans)) |
|
241 | + } elseif (in_array($tab, $sourceOrphans)) |
|
250 | 242 | { |
251 | 243 | $info['sourceOrphan'] = true; |
252 | - } |
|
253 | - else |
|
244 | + } else |
|
254 | 245 | { |
255 | 246 | $destSql = $this->getTabSql($this->destStruct, $tab, true); |
256 | 247 | $sourceSql = $this->getTabSql($this->sourceStruct, $tab, true); |
@@ -259,12 +250,15 @@ discard block |
||
259 | 250 | { |
260 | 251 | trigger_error('[WARNING] error parsing definition of table "'.$tab.'" - skipped'); |
261 | 252 | continue; |
262 | - } |
|
263 | - elseif (!empty($diffs))//not empty array |
|
253 | + } elseif (!empty($diffs)) { |
|
254 | + //not empty array |
|
264 | 255 | { |
265 | 256 | $info['differs'] = $diffs; |
266 | 257 | } |
267 | - else continue;//empty array |
|
258 | + } else { |
|
259 | + continue; |
|
260 | + } |
|
261 | + //empty array |
|
268 | 262 | } |
269 | 263 | $result[$tab] = $info; |
270 | 264 | } |
@@ -281,10 +275,12 @@ discard block |
||
281 | 275 | $result = array(); |
282 | 276 | if (preg_match_all('/CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?(?:`?(\w+)`?\.)?`?(\w+)`?/i', $struct, $m)) |
283 | 277 | { |
284 | - foreach($m[2] as $match)//m[1] is a database name if any |
|
278 | + foreach($m[2] as $match) { |
|
279 | + //m[1] is a database name if any |
|
285 | 280 | { |
286 | 281 | $result[] = $match; |
287 | 282 | } |
283 | + } |
|
288 | 284 | } |
289 | 285 | return $result; |
290 | 286 | } |
@@ -312,8 +308,7 @@ discard block |
||
312 | 308 | if ($end === false) |
313 | 309 | { |
314 | 310 | $result = substr($struct, $start); |
315 | - } |
|
316 | - else |
|
311 | + } else |
|
317 | 312 | { |
318 | 313 | $result = substr($struct, $start, $end-$start);//already without ';' |
319 | 314 | } |
@@ -390,9 +385,11 @@ discard block |
||
390 | 385 | $result = array(); |
391 | 386 | //split with comma delimiter, not line breaks |
392 | 387 | $sourceParts = $this->splitTabSql($sourceSql); |
393 | - if ($sourceParts===false)//error parsing sql |
|
388 | + if ($sourceParts===false) { |
|
389 | + //error parsing sql |
|
394 | 390 | { |
395 | 391 | trigger_error('[WARNING] error parsing source sql'); |
392 | + } |
|
396 | 393 | return false; |
397 | 394 | } |
398 | 395 | $destParts = $this->splitTabSql($destSql); |
@@ -406,13 +403,17 @@ discard block |
||
406 | 403 | foreach($sourceParts as $line) |
407 | 404 | { |
408 | 405 | $lineInfo = $this->processLine($line); |
409 | - if (!$lineInfo) continue; |
|
406 | + if (!$lineInfo) { |
|
407 | + continue; |
|
408 | + } |
|
410 | 409 | $sourcePartsIndexed[$lineInfo['key']] = $lineInfo['line']; |
411 | 410 | } |
412 | 411 | foreach($destParts as $line) |
413 | 412 | { |
414 | 413 | $lineInfo = $this->processLine($line); |
415 | - if (!$lineInfo) continue; |
|
414 | + if (!$lineInfo) { |
|
415 | + continue; |
|
416 | + } |
|
416 | 417 | $destPartsIndexed[$lineInfo['key']] = $lineInfo['line']; |
417 | 418 | } |
418 | 419 | $sourceKeys = array_keys($sourcePartsIndexed); |
@@ -432,17 +433,16 @@ discard block |
||
432 | 433 | if ($sourceOrphan) |
433 | 434 | { |
434 | 435 | $info['source'] = $sourcePartsIndexed[$key]; |
435 | - } |
|
436 | - elseif ($destOrphan) |
|
436 | + } elseif ($destOrphan) |
|
437 | 437 | { |
438 | 438 | $info['dest'] = $destPartsIndexed[$key]; |
439 | - } |
|
440 | - elseif ($different) |
|
439 | + } elseif ($different) |
|
441 | 440 | { |
442 | 441 | $info['source'] = $sourcePartsIndexed[$key]; |
443 | 442 | $info['dest'] = $destPartsIndexed[$key]; |
443 | + } else { |
|
444 | + continue; |
|
444 | 445 | } |
445 | - else continue; |
|
446 | 446 | $result[] = $info; |
447 | 447 | } |
448 | 448 | return $result; |
@@ -461,20 +461,25 @@ discard block |
||
461 | 461 | $options = $this->config; |
462 | 462 | $result = array('key'=>'', 'line'=>''); |
463 | 463 | $line = rtrim(trim($line), ','); |
464 | - if (preg_match('/^(CREATE\s+TABLE)|(\) ENGINE=)/i', $line))//first or last table definition line |
|
464 | + if (preg_match('/^(CREATE\s+TABLE)|(\) ENGINE=)/i', $line)) { |
|
465 | + //first or last table definition line |
|
465 | 466 | { |
466 | 467 | return false; |
467 | 468 | } |
469 | + } |
|
468 | 470 | //if (preg_match('/^(PRIMARY KEY)|(((UNIQUE )|(FULLTEXT ))?KEY `?\w+`?)/i', $line, $m))//key definition |
469 | - if (preg_match('/^(PRIMARY\s+KEY)|(((UNIQUE\s+)|(FULLTEXT\s+))?KEY\s+`?\w+`?)/i', $line, $m))//key definition |
|
471 | + if (preg_match('/^(PRIMARY\s+KEY)|(((UNIQUE\s+)|(FULLTEXT\s+))?KEY\s+`?\w+`?)/i', $line, $m)) { |
|
472 | + //key definition |
|
470 | 473 | { |
471 | 474 | $key = $m[0]; |
472 | 475 | } |
473 | - elseif (preg_match('/^`?\w+`?/i', $line, $m))//field definition |
|
476 | + } elseif (preg_match('/^`?\w+`?/i', $line, $m)) { |
|
477 | + //field definition |
|
474 | 478 | { |
475 | - $key = '!'.$m[0];//to make sure fields will be synchronised before the keys |
|
479 | + $key = '!'.$m[0]; |
|
476 | 480 | } |
477 | - else |
|
481 | + //to make sure fields will be synchronised before the keys |
|
482 | + } else |
|
478 | 483 | { |
479 | 484 | return false;//line has no valuable info (empty or comment) |
480 | 485 | } |
@@ -514,13 +519,16 @@ discard block |
||
514 | 519 | } |
515 | 520 | foreach($diff as $tab=>$info) |
516 | 521 | { |
517 | - if ($info['sourceOrphan'])//delete it |
|
522 | + if ($info['sourceOrphan']) { |
|
523 | + //delete it |
|
518 | 524 | { |
519 | 525 | $sqls[] = 'DROP TABLE `'.$tab.'`'; |
520 | 526 | } |
521 | - elseif ($info['destOrphan'])//create destination table in source |
|
527 | + } elseif ($info['destOrphan']) { |
|
528 | + //create destination table in source |
|
522 | 529 | { |
523 | 530 | $database = ''; |
531 | + } |
|
524 | 532 | $destSql = $this->getTabSql($this->destStruct, $tab, $database); |
525 | 533 | if (!empty($options['ignoreIncrement'])) |
526 | 534 | { |
@@ -535,8 +543,7 @@ discard block |
||
535 | 543 | $destSql = preg_replace('/(CREATE(?:\s*TEMPORARY)?\s*TABLE\s*)(?:IF\sNOT\sEXISTS\s*)?(`?\w+`?)/i', '$1IF NOT EXISTS $2', $destSql); |
536 | 544 | } |
537 | 545 | $sqls[] = $destSql; |
538 | - } |
|
539 | - else |
|
546 | + } else |
|
540 | 547 | { |
541 | 548 | foreach($info['differs'] as $finfo) |
542 | 549 | { |
@@ -546,13 +553,11 @@ discard block |
||
546 | 553 | { |
547 | 554 | $sql = $finfo['source']; |
548 | 555 | $action = 'drop'; |
549 | - } |
|
550 | - elseif ($inDest && !$inSource) |
|
556 | + } elseif ($inDest && !$inSource) |
|
551 | 557 | { |
552 | 558 | $sql = $finfo['dest']; |
553 | 559 | $action = 'add'; |
554 | - } |
|
555 | - else |
|
560 | + } else |
|
556 | 561 | { |
557 | 562 | $sql = $finfo['dest']; |
558 | 563 | $action = 'modify'; |
@@ -590,8 +595,7 @@ discard block |
||
590 | 595 | if ($type=='primary') |
591 | 596 | { |
592 | 597 | $result.= 'DROP PRIMARY KEY'; |
593 | - } |
|
594 | - else |
|
598 | + } else |
|
595 | 599 | { |
596 | 600 | $result.= 'DROP INDEX `'.$name.'`'; |
597 | 601 | } |
@@ -600,12 +604,10 @@ discard block |
||
600 | 604 | if ($type=='primary') |
601 | 605 | { |
602 | 606 | $result.= 'ADD PRIMARY KEY '.$fields; |
603 | - } |
|
604 | - elseif ($type=='') |
|
607 | + } elseif ($type=='') |
|
605 | 608 | { |
606 | 609 | $result.= 'ADD INDEX `'.$name.'` '.$fields; |
607 | - } |
|
608 | - else |
|
610 | + } else |
|
609 | 611 | { |
610 | 612 | $result .='ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique |
611 | 613 | } |
@@ -614,20 +616,17 @@ discard block |
||
614 | 616 | if ($type=='primary') |
615 | 617 | { |
616 | 618 | $result.='DROP PRIMARY KEY, ADD PRIMARY KEY '.$fields; |
617 | - } |
|
618 | - elseif ($type=='') |
|
619 | + } elseif ($type=='') |
|
619 | 620 | { |
620 | 621 | $result.='DROP INDEX `'.$name.'`, ADD INDEX `'.$name.'` '.$fields; |
621 | - } |
|
622 | - else |
|
622 | + } else |
|
623 | 623 | { |
624 | 624 | $result.='DROP INDEX `'.$name.'`, ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique |
625 | 625 | } |
626 | 626 | break; |
627 | 627 | |
628 | 628 | } |
629 | - } |
|
630 | - else //fields operations |
|
629 | + } else //fields operations |
|
631 | 630 | { |
632 | 631 | $sql = rtrim(trim($sql), ','); |
633 | 632 | $result.= strtoupper($action); |
@@ -635,8 +634,7 @@ discard block |
||
635 | 634 | { |
636 | 635 | $spacePos = strpos($sql, ' '); |
637 | 636 | $result.= ' '.substr($sql, 0, $spacePos); |
638 | - } |
|
639 | - else |
|
637 | + } else |
|
640 | 638 | { |
641 | 639 | $result.= ' '.$sql; |
642 | 640 | } |
@@ -660,8 +658,7 @@ discard block |
||
660 | 658 | if ($skipInBrackets) |
661 | 659 | { |
662 | 660 | $reg.='(\(|\))|'; |
663 | - } |
|
664 | - else |
|
661 | + } else |
|
665 | 662 | { |
666 | 663 | $reg.='()'; |
667 | 664 | } |
@@ -686,47 +683,51 @@ discard block |
||
686 | 683 | continue;//here we could also simplify regexp |
687 | 684 | } |
688 | 685 | |
689 | - if (!empty($m[7][0]))// ';' found |
|
686 | + if (!empty($m[7][0])) { |
|
687 | + // ';' found |
|
690 | 688 | { |
691 | 689 | if (empty($stack)) |
692 | 690 | { |
693 | 691 | return $m[7][1]; |
694 | - } |
|
695 | - else |
|
692 | + } |
|
693 | + } else |
|
696 | 694 | { |
697 | 695 | //var_dump($stack, substr($string, $offset-strlen($m[0][0]))); |
698 | 696 | } |
699 | 697 | } |
700 | - if (!empty($m[6][0]))// '(' or ')' found |
|
698 | + if (!empty($m[6][0])) { |
|
699 | + // '(' or ')' found |
|
701 | 700 | { |
702 | 701 | if (empty($stack) && $m[6][0]=='(') |
703 | 702 | { |
704 | 703 | array_push($stack, $m[6][0]); |
705 | - } |
|
706 | - elseif($m[6][0]==')' && end($stack)=='(') |
|
704 | + } |
|
705 | + } elseif($m[6][0]==')' && end($stack)=='(') |
|
707 | 706 | { |
708 | 707 | array_pop($stack); |
709 | 708 | } |
710 | - } |
|
711 | - elseif (!empty($m[1][0]))// ' or " found |
|
709 | + } elseif (!empty($m[1][0])) { |
|
710 | + // ' or " found |
|
712 | 711 | { |
713 | 712 | if (end($stack)==$m[1][0]) |
714 | 713 | { |
715 | 714 | array_pop($stack); |
716 | - } |
|
717 | - else |
|
715 | + } |
|
716 | + } else |
|
718 | 717 | { |
719 | 718 | array_push($stack, $m[1][0]); |
720 | 719 | } |
721 | - } |
|
722 | - elseif (!empty($m[2][0])) // opening comment / * |
|
720 | + } elseif (!empty($m[2][0])) { |
|
721 | + // opening comment / * |
|
723 | 722 | { |
724 | 723 | array_push($stack, $m[2][0]); |
725 | 724 | } |
726 | - elseif (!empty($m[4][0])) // opening comment -- |
|
725 | + } elseif (!empty($m[4][0])) { |
|
726 | + // opening comment -- |
|
727 | 727 | { |
728 | 728 | array_push($stack, $m[4][0]); |
729 | 729 | } |
730 | + } |
|
730 | 731 | } |
731 | 732 | return false; |
732 | 733 | } |
@@ -3,15 +3,8 @@ |
||
3 | 3 | namespace okapi\views\devel\dbstruct; |
4 | 4 | |
5 | 5 | use Exception; |
6 | -use okapi\Okapi; |
|
7 | 6 | use okapi\Settings; |
8 | -use okapi\Cache; |
|
9 | -use okapi\Db; |
|
10 | -use okapi\OkapiRequest; |
|
11 | -use okapi\OkapiRedirectResponse; |
|
12 | 7 | use okapi\OkapiHttpResponse; |
13 | -use okapi\ParamMissing; |
|
14 | -use okapi\InvalidParam; |
|
15 | 8 | use okapi\OkapiServiceRunner; |
16 | 9 | use okapi\OkapiInternalRequest; |
17 | 10 | use okapi\OkapiInternalConsumer; |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | |
40 | 40 | ini_set('memory_limit', '16M'); |
41 | 41 | $shell_arguments = "mysqldump --no-data -h$dbserver -u$user -p$password $dbname"; |
42 | - if (!strpos($shell_arguments,"--no-data")) |
|
42 | + if (!strpos($shell_arguments, "--no-data")) |
|
43 | 43 | throw new Exception("wrong database dump arguments"); |
44 | 44 | $struct = shell_exec($shell_arguments); |
45 | 45 | if (strlen($struct) > 1000000) |
46 | 46 | throw new Exception("something went terribly wrong while dumping table structures"); |
47 | - if (stripos($struct,"dumping data") !== FALSE) |
|
47 | + if (stripos($struct, "dumping data") !== FALSE) |
|
48 | 48 | throw new Exception("something went terribly wrong while dumping table structures"); |
49 | 49 | |
50 | 50 | # Remove the "AUTO_INCREMENT=..." values. They break the diffs. |
@@ -74,30 +74,30 @@ discard block |
||
74 | 74 | try { |
75 | 75 | $alternate_struct = @file_get_contents($_GET['compare_to']); |
76 | 76 | } catch (Exception $e) { |
77 | - throw new BadRequest("Failed to load ".$_GET['compare_to']); |
|
77 | + throw new BadRequest("Failed to load " . $_GET['compare_to']); |
|
78 | 78 | } |
79 | 79 | $response->body = |
80 | - "-- Automatically generated database diff. Use with caution!\n". |
|
81 | - "-- Differences obtained with help of cool library by Kirill Gerasimenko.\n\n". |
|
82 | - "-- Note: The following script has some limitations. It will render database\n". |
|
83 | - "-- structure compatible, but not necessarilly EXACTLY the same. It might be\n". |
|
80 | + "-- Automatically generated database diff. Use with caution!\n" . |
|
81 | + "-- Differences obtained with help of cool library by Kirill Gerasimenko.\n\n" . |
|
82 | + "-- Note: The following script has some limitations. It will render database\n" . |
|
83 | + "-- structure compatible, but not necessarilly EXACTLY the same. It might be\n" . |
|
84 | 84 | "-- better to use manual diff instead.\n\n"; |
85 | 85 | require_once("comparator.inc.php"); |
86 | 86 | $updater = new \dbStructUpdater(); |
87 | 87 | if (isset($_GET['reverse']) && ($_GET['reverse'] == 'true')) |
88 | 88 | { |
89 | 89 | $response->body .= |
90 | - "-- REVERSE MODE. The following will alter [2], so that it has the structure of [1].\n". |
|
91 | - "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n". |
|
92 | - "-- 2. ".$_GET['compare_to']." (".md5($alternate_struct).")\n\n"; |
|
90 | + "-- REVERSE MODE. The following will alter [2], so that it has the structure of [1].\n" . |
|
91 | + "-- 1. " . Settings::get('SITE_URL') . "okapi/devel/dbstruct (" . md5($struct) . ")\n" . |
|
92 | + "-- 2. " . $_GET['compare_to'] . " (" . md5($alternate_struct) . ")\n\n"; |
|
93 | 93 | $alters = $updater->getUpdates($alternate_struct, $struct); |
94 | 94 | } |
95 | 95 | else |
96 | 96 | { |
97 | 97 | $response->body .= |
98 | - "-- The following will alter [1], so that it has the structure of [2].\n". |
|
99 | - "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n". |
|
100 | - "-- 2. ".$_GET['compare_to']." (".md5($alternate_struct).")\n\n"; |
|
98 | + "-- The following will alter [1], so that it has the structure of [2].\n" . |
|
99 | + "-- 1. " . Settings::get('SITE_URL') . "okapi/devel/dbstruct (" . md5($struct) . ")\n" . |
|
100 | + "-- 2. " . $_GET['compare_to'] . " (" . md5($alternate_struct) . ")\n\n"; |
|
101 | 101 | $alters = $updater->getUpdates($struct, $alternate_struct); |
102 | 102 | } |
103 | 103 | # Add semicolons |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | if (strpos($alter_ref, "okapi_") !== false) |
111 | 111 | { |
112 | 112 | $lines = explode("\n", $alter_ref); |
113 | - $alter_ref = "-- Probably you should NOT execute this one. Use okapi/update instead.\n-- {{{\n-- ". |
|
114 | - implode("\n-- ", $lines)."\n-- }}}"; |
|
113 | + $alter_ref = "-- Probably you should NOT execute this one. Use okapi/update instead.\n-- {{{\n-- " . |
|
114 | + implode("\n-- ", $lines) . "\n-- }}}"; |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | if (count($alters) > 0) |
118 | - $response->body .= implode("\n", $alters)."\n"; |
|
118 | + $response->body .= implode("\n", $alters) . "\n"; |
|
119 | 119 | else |
120 | 120 | $response->body .= "-- No differences found\n"; |
121 | 121 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | private static function requireSafe($url) |
138 | 138 | { |
139 | - require_once($GLOBALS['rootpath'].'okapi/service_runner.php'); |
|
139 | + require_once($GLOBALS['rootpath'] . 'okapi/service_runner.php'); |
|
140 | 140 | $installations = OkapiServiceRunner::call( |
141 | 141 | "services/apisrv/installations", |
142 | 142 | new OkapiInternalRequest( |
@@ -145,16 +145,16 @@ discard block |
||
145 | 145 | ); |
146 | 146 | $allowed = array(); |
147 | 147 | foreach ($installations as $i) { |
148 | - $allowed_url = $i['okapi_base_url']."devel/dbstruct"; |
|
148 | + $allowed_url = $i['okapi_base_url'] . "devel/dbstruct"; |
|
149 | 149 | $allowed[] = $allowed_url; |
150 | 150 | if ($url == $allowed_url) { |
151 | 151 | return; |
152 | 152 | } |
153 | 153 | } |
154 | 154 | throw new BadRequest( |
155 | - "The following URL is not on our whitelist: \"".$url."\".\n\n". |
|
156 | - "Please use one of the following:\n". |
|
157 | - "\"".implode("\",\n\"", $allowed)."\"." |
|
155 | + "The following URL is not on our whitelist: \"" . $url . "\".\n\n" . |
|
156 | + "Please use one of the following:\n" . |
|
157 | + "\"" . implode("\",\n\"", $allowed) . "\"." |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | } |
@@ -39,13 +39,16 @@ discard block |
||
39 | 39 | |
40 | 40 | ini_set('memory_limit', '16M'); |
41 | 41 | $shell_arguments = "mysqldump --no-data -h$dbserver -u$user -p$password $dbname"; |
42 | - if (!strpos($shell_arguments,"--no-data")) |
|
43 | - throw new Exception("wrong database dump arguments"); |
|
42 | + if (!strpos($shell_arguments,"--no-data")) { |
|
43 | + throw new Exception("wrong database dump arguments"); |
|
44 | + } |
|
44 | 45 | $struct = shell_exec($shell_arguments); |
45 | - if (strlen($struct) > 1000000) |
|
46 | - throw new Exception("something went terribly wrong while dumping table structures"); |
|
47 | - if (stripos($struct,"dumping data") !== FALSE) |
|
48 | - throw new Exception("something went terribly wrong while dumping table structures"); |
|
46 | + if (strlen($struct) > 1000000) { |
|
47 | + throw new Exception("something went terribly wrong while dumping table structures"); |
|
48 | + } |
|
49 | + if (stripos($struct,"dumping data") !== FALSE) { |
|
50 | + throw new Exception("something went terribly wrong while dumping table structures"); |
|
51 | + } |
|
49 | 52 | |
50 | 53 | # Remove the "AUTO_INCREMENT=..." values. They break the diffs. |
51 | 54 | |
@@ -91,8 +94,7 @@ discard block |
||
91 | 94 | "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n". |
92 | 95 | "-- 2. ".$_GET['compare_to']." (".md5($alternate_struct).")\n\n"; |
93 | 96 | $alters = $updater->getUpdates($alternate_struct, $struct); |
94 | - } |
|
95 | - else |
|
97 | + } else |
|
96 | 98 | { |
97 | 99 | $response->body .= |
98 | 100 | "-- The following will alter [1], so that it has the structure of [2].\n". |
@@ -101,8 +103,9 @@ discard block |
||
101 | 103 | $alters = $updater->getUpdates($struct, $alternate_struct); |
102 | 104 | } |
103 | 105 | # Add semicolons |
104 | - foreach ($alters as &$alter_ref) |
|
105 | - $alter_ref .= ";"; |
|
106 | + foreach ($alters as &$alter_ref) { |
|
107 | + $alter_ref .= ";"; |
|
108 | + } |
|
106 | 109 | # Comment out all differences containing "okapi_". These should be executed |
107 | 110 | # by OKAPI update scripts. |
108 | 111 | foreach ($alters as &$alter_ref) |
@@ -114,17 +117,16 @@ discard block |
||
114 | 117 | implode("\n-- ", $lines)."\n-- }}}"; |
115 | 118 | } |
116 | 119 | } |
117 | - if (count($alters) > 0) |
|
118 | - $response->body .= implode("\n", $alters)."\n"; |
|
119 | - else |
|
120 | - $response->body .= "-- No differences found\n"; |
|
121 | - } |
|
122 | - else |
|
120 | + if (count($alters) > 0) { |
|
121 | + $response->body .= implode("\n", $alters)."\n"; |
|
122 | + } else { |
|
123 | + $response->body .= "-- No differences found\n"; |
|
124 | + } |
|
125 | + } else |
|
123 | 126 | { |
124 | 127 | $response->body = "HTTP(S) only!"; |
125 | 128 | } |
126 | - } |
|
127 | - else |
|
129 | + } else |
|
128 | 130 | { |
129 | 131 | $response->body = $struct; |
130 | 132 | } |
@@ -3,21 +3,11 @@ |
||
3 | 3 | namespace okapi\views\tilestress; |
4 | 4 | |
5 | 5 | use Exception; |
6 | - |
|
7 | -use okapi\Okapi; |
|
8 | -use okapi\Cache; |
|
9 | 6 | use okapi\Db; |
10 | -use okapi\OkapiRequest; |
|
11 | -use okapi\OkapiRedirectResponse; |
|
12 | -use okapi\OkapiHttpResponse; |
|
13 | -use okapi\ParamMissing; |
|
14 | -use okapi\InvalidParam; |
|
15 | 7 | use okapi\OkapiServiceRunner; |
16 | 8 | use okapi\OkapiInternalRequest; |
17 | 9 | use okapi\OkapiInternalConsumer; |
18 | 10 | use okapi\OkapiInternalAccessToken; |
19 | -use okapi\Settings; |
|
20 | -use okapi\OkapiLock; |
|
21 | 11 | use okapi\OkapiExceptionHandler; |
22 | 12 | |
23 | 13 | require_once($GLOBALS['rootpath']."okapi/service_runner.php"); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | use okapi\OkapiLock; |
21 | 21 | use okapi\OkapiExceptionHandler; |
22 | 22 | |
23 | -require_once($GLOBALS['rootpath']."okapi/service_runner.php"); |
|
23 | +require_once($GLOBALS['rootpath'] . "okapi/service_runner.php"); |
|
24 | 24 | |
25 | 25 | class View |
26 | 26 | { |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $tiles = array(); |
69 | - for ($xx=$x; $xx<$x+4; $xx++) |
|
70 | - for ($yy=$y; $yy<$y+4; $yy++) |
|
69 | + for ($xx = $x; $xx < $x + 4; $xx++) |
|
70 | + for ($yy = $y; $yy < $y + 4; $yy++) |
|
71 | 71 | $tiles[] = array($xx, $yy); |
72 | 72 | srand(); |
73 | 73 | shuffle($tiles); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | foreach ($tiles as $tile) |
76 | 76 | { |
77 | 77 | list($x, $y) = $tile; |
78 | - self::out("Loading ".str_pad("($z, $x, $y)... ", 30)); |
|
78 | + self::out("Loading " . str_pad("($z, $x, $y)... ", 30)); |
|
79 | 79 | $time_started = microtime(true); |
80 | 80 | try { |
81 | 81 | $response = OkapiServiceRunner::call('services/caches/map/tile', new OkapiInternalRequest( |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | array('z' => "$z", 'x' => "$x", 'y' => "$y"))); |
84 | 84 | $runtime = microtime(true) - $time_started; |
85 | 85 | $ds = floor($runtime * 100); |
86 | - self::out(str_repeat("#", $ds)." "); |
|
86 | + self::out(str_repeat("#", $ds) . " "); |
|
87 | 87 | $b = floor(strlen($response->get_body()) / 256); |
88 | - self::out(str_repeat("@", $b)."\n"); |
|
88 | + self::out(str_repeat("@", $b) . "\n"); |
|
89 | 89 | } catch (Exception $e) { |
90 | - self::out("\n\n".OkapiExceptionHandler::get_exception_info($e)); |
|
90 | + self::out("\n\n" . OkapiExceptionHandler::get_exception_info($e)); |
|
91 | 91 | die(); |
92 | 92 | } |
93 | 93 | } |
@@ -66,9 +66,12 @@ |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $tiles = array(); |
69 | - for ($xx=$x; $xx<$x+4; $xx++) |
|
70 | - for ($yy=$y; $yy<$y+4; $yy++) |
|
71 | - $tiles[] = array($xx, $yy); |
|
69 | + for ($xx=$x; $xx<$x+4; $xx++) { |
|
70 | + for ($yy=$y; |
|
71 | + } |
|
72 | + $yy<$y+4; $yy++) { |
|
73 | + $tiles[] = array($xx, $yy); |
|
74 | + } |
|
72 | 75 | srand(); |
73 | 76 | shuffle($tiles); |
74 | 77 |