Completed
Pull Request — master (#313)
by Thomas
15:47 queued 06:00
created
htdocs/okapi/views/menu.inc.php 1 patch
Braces   +14 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,9 +23,10 @@  discard block
 block discarded – undo
23 23
     public static function get_menu_html($current_path = null)
24 24
     {
25 25
         $chunks = array();
26
-        if (Okapi::$version_number)
27
-            $chunks[] = "<div class='revision'>ver. ".Okapi::$version_number.
26
+        if (Okapi::$version_number) {
27
+                    $chunks[] = "<div class='revision'>ver. ".Okapi::$version_number.
28 28
                 " (".substr(Okapi::$git_revision, 0, 7).")</div>";
29
+        }
29 30
         $chunks[] = "<div class='main'>";
30 31
         $chunks[] = self::link($current_path, "introduction.html", "Introduction");
31 32
         $chunks[] = self::link($current_path, "signup.html", "Sign up");
@@ -43,24 +44,24 @@  discard block
 block discarded – undo
43 44
         # We'll break them up into modules, for readability.
44 45
 
45 46
         $module_methods = array();
46
-        foreach ($methodnames as $methodname)
47
-        {
47
+        foreach ($methodnames as $methodname) {
48 48
             $pos = strrpos($methodname, "/");
49 49
             $modulename = substr($methodname, 0, $pos);
50 50
             $method_short_name = substr($methodname, $pos + 1);
51
-            if (!isset($module_methods[$modulename]))
52
-                $module_methods[$modulename] = array();
51
+            if (!isset($module_methods[$modulename])) {
52
+                            $module_methods[$modulename] = array();
53
+            }
53 54
             $module_methods[$modulename][] = $method_short_name;
54 55
         }
55 56
         $modulenames = array_keys($module_methods);
56 57
         sort($modulenames);
57 58
 
58
-        foreach ($modulenames as $modulename)
59
-        {
59
+        foreach ($modulenames as $modulename) {
60 60
             $chunks[] = "<div class='module'>$modulename</div>";
61 61
             $chunks[] = "<div class='methods'>";
62
-            foreach ($module_methods[$modulename] as $method_short_name)
63
-                $chunks[] = self::link($current_path, "$modulename/$method_short_name.html", "$method_short_name");
62
+            foreach ($module_methods[$modulename] as $method_short_name) {
63
+                            $chunks[] = self::link($current_path, "$modulename/$method_short_name.html", "$method_short_name");
64
+            }
64 65
             $chunks[] = "</div>";
65 66
         }
66 67
         return implode("", $chunks);
@@ -72,21 +73,17 @@  discard block
 block discarded – undo
72 73
             new OkapiInternalRequest(new OkapiInternalConsumer(), null, array()));
73 74
         $site_url = Settings::get('SITE_URL');
74 75
 
75
-        foreach ($installations as &$inst_ref)
76
-        {
76
+        foreach ($installations as &$inst_ref) {
77 77
             # $inst_ref['site_url'] and $site_url can have different protocols
78 78
             # (http / https). We compare only the domain parts and use
79 79
             # $site_url (which has the current request's protocol) for the menu
80 80
             # so that the menu works properly.
81 81
 
82
-            if (self::domains_are_equal($inst_ref['site_url'], $site_url))
83
-            {
82
+            if (self::domains_are_equal($inst_ref['site_url'], $site_url)) {
84 83
                 $inst_ref['site_url'] = $site_url;
85 84
                 $inst_ref['okapi_base_url'] = $site_url . 'okapi/';
86 85
                 $inst_ref['selected'] = true;
87
-            }
88
-            else
89
-            {
86
+            } else {
90 87
                 $inst_ref['selected'] = false;
91 88
             }
92 89
         }
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/comparator.inc.php 1 patch
Braces   +133 added lines, -214 removed lines patch added patch discarded remove patch
@@ -87,8 +87,7 @@  discard block
 block discarded – undo
87 87
     */
88 88
     function setConfig($config=array())
89 89
     {
90
-        if (is_array($config))
91
-        {
90
+        if (is_array($config)) {
92 91
             $this->config = array_merge($this->config, $config);
93 92
         }
94 93
     }
@@ -105,18 +104,15 @@  discard block
 block discarded – undo
105 104
     {
106 105
         $result = $asString?'':array();
107 106
         $compRes = $this->compare($source, $dest);
108
-        if (empty($compRes))
109
-        {
107
+        if (empty($compRes)) {
110 108
             return $result;
111 109
         }
112 110
         $compRes = $this->filterDiffs($compRes);
113
-        if (empty($compRes))
114
-        {
111
+        if (empty($compRes)) {
115 112
             return $result;
116 113
         }
117 114
         $result = $this->getDiffSql($compRes);
118
-        if ($asString)
119
-        {
115
+        if ($asString) {
120 116
             $result = implode(";\r\n", $result).';';
121 117
         }
122 118
         return $result;
@@ -128,53 +124,35 @@  discard block
 block discarded – undo
128 124
     function filterDiffs($compRes)
129 125
     {
130 126
         $result = array();
131
-        if (is_array($this->config['updateTypes']))
132
-        {
127
+        if (is_array($this->config['updateTypes'])) {
133 128
             $updateActions = $this->config['updateTypes'];
134
-        }
135
-        else
136
-        {
129
+        } else {
137 130
             $updateActions = array_map('trim', explode(',', $this->config['updateTypes']));
138 131
         }
139 132
         $allowedActions = array('create', 'drop', 'add', 'remove', 'modify');
140 133
         $updateActions = array_intersect($updateActions, $allowedActions);
141
-        foreach($compRes as $table=>$info)
142
-        {
143
-            if ($info['sourceOrphan'])
144
-            {
145
-                if (in_array('create', $updateActions))
146
-                {
134
+        foreach($compRes as $table=>$info) {
135
+            if ($info['sourceOrphan']) {
136
+                if (in_array('create', $updateActions)) {
147 137
                     $result[$table] = $info;
148 138
                 }
149
-            }
150
-            elseif ($info['destOrphan'])
151
-            {
152
-                if (in_array('drop', $updateActions))
153
-                {
139
+            } elseif ($info['destOrphan']) {
140
+                if (in_array('drop', $updateActions)) {
154 141
                     $result[$table] = $info;
155 142
                 }
156
-            }
157
-            elseif($info['differs'])
158
-            {
143
+            } elseif($info['differs']) {
159 144
                 $resultInfo = $info;
160 145
                 unset($resultInfo['differs']);
161
-                foreach ($info['differs'] as $diff)
162
-                {
163
-                    if (empty($diff['dest']) && in_array('add', $updateActions))
164
-                    {
146
+                foreach ($info['differs'] as $diff) {
147
+                    if (empty($diff['dest']) && in_array('add', $updateActions)) {
165 148
                         $resultInfo['differs'][] = $diff;
166
-                    }
167
-                    elseif (empty($diff['source']) && in_array('remove', $updateActions))
168
-                    {
149
+                    } elseif (empty($diff['source']) && in_array('remove', $updateActions)) {
169 150
                         $resultInfo['differs'][] = $diff;
170
-                    }
171
-                    elseif(in_array('modify', $updateActions))
172
-                    {
151
+                    } elseif(in_array('modify', $updateActions)) {
173 152
                         $resultInfo['differs'][] = $diff;
174 153
                     }
175 154
                 }
176
-                if (!empty($resultInfo['differs']))
177
-                {
155
+                if (!empty($resultInfo['differs'])) {
178 156
                     $result[$table] = $resultInfo;
179 157
                 }
180 158
             }
@@ -188,23 +166,16 @@  discard block
 block discarded – undo
188 166
     */
189 167
     function getDiffInfo($compRes)
190 168
     {
191
-        if (!is_array($compRes))
192
-        {
169
+        if (!is_array($compRes)) {
193 170
             return false;
194 171
         }
195 172
         $result = array('sourceOrphans'=>array(), 'destOrphans'=>array(), 'different'=>array());
196
-        foreach($compRes as $table=>$info)
197
-        {
198
-            if ($info['sourceOrphan'])
199
-            {
173
+        foreach($compRes as $table=>$info) {
174
+            if ($info['sourceOrphan']) {
200 175
                 $result['sourceOrphans'][] = $table;
201
-            }
202
-            elseif ($info['destOrphan'])
203
-            {
176
+            } elseif ($info['destOrphan']) {
204 177
                 $result['destOrphans'][] = $table;
205
-            }
206
-            else
207
-            {
178
+            } else {
208 179
                 $result['different'][] = $table;
209 180
             }
210 181
         }
@@ -239,32 +210,28 @@  discard block
 block discarded – undo
239 210
         $sourceOrphans = array_diff($sourceTabNames, $common);
240 211
         $all = array_unique(array_merge($destTabNames, $sourceTabNames));
241 212
         sort($all);
242
-        foreach ($all as $tab)
243
-        {
213
+        foreach ($all as $tab) {
244 214
             $info = array('destOrphan'=>false, 'sourceOrphan'=>false, 'differs'=>false);
245
-            if(in_array($tab, $destOrphans))
246
-            {
215
+            if(in_array($tab, $destOrphans)) {
247 216
                 $info['destOrphan'] = true;
248
-            }
249
-            elseif (in_array($tab, $sourceOrphans))
250
-            {
217
+            } elseif (in_array($tab, $sourceOrphans)) {
251 218
                 $info['sourceOrphan'] = true;
252
-            }
253
-            else
254
-            {
219
+            } else {
255 220
                 $destSql = $this->getTabSql($this->destStruct, $tab, true);
256 221
                 $sourceSql = $this->getTabSql($this->sourceStruct, $tab, true);
257 222
                 $diffs = $this->compareSql($sourceSql, $destSql);
258
-                if ($diffs===false)
259
-                {
223
+                if ($diffs===false) {
260 224
                     trigger_error('[WARNING] error parsing definition of table "'.$tab.'" - skipped');
261 225
                     continue;
262
-                }
263
-                elseif (!empty($diffs))//not empty array
226
+                } elseif (!empty($diffs)) {
227
+                    //not empty array
264 228
                 {
265 229
                     $info['differs'] = $diffs;
266 230
                 }
267
-                else continue;//empty array
231
+                } else {
232
+                    continue;
233
+                }
234
+                //empty array
268 235
             }
269 236
             $result[$tab] = $info;
270 237
         }
@@ -279,12 +246,13 @@  discard block
 block discarded – undo
279 246
     function getTableList($struct)
280 247
     {
281 248
         $result = array();
282
-        if (preg_match_all('/CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?(?:`?(\w+)`?\.)?`?(\w+)`?/i', $struct, $m))
283
-        {
284
-            foreach($m[2] as $match)//m[1] is a database name if any
249
+        if (preg_match_all('/CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?(?:`?(\w+)`?\.)?`?(\w+)`?/i', $struct, $m)) {
250
+            foreach($m[2] as $match) {
251
+                //m[1] is a database name if any
285 252
             {
286 253
                 $result[] = $match;
287 254
             }
255
+            }
288 256
         }
289 257
         return $result;
290 258
     }
@@ -302,25 +270,20 @@  discard block
 block discarded – undo
302 270
         $result = '';
303 271
         /* create table should be single line in this case*/
304 272
         //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))
306
-        {
273
+        if (preg_match('/(CREATE(?:\s*TEMPORARY)?\s*TABLE\s*(?:IF NOT EXISTS\s*)?)(?:`?(\w+)`?\.)?(`?('.$tab.')`?(\W|$))/i', $struct, $m, PREG_OFFSET_CAPTURE)) {
307 274
             $tableDef = $m[0][0];
308 275
             $start = $m[0][1];
309 276
             $database = $m[2][0];
310 277
             $offset = $start+strlen($m[0][0]);
311 278
             $end = $this->getDelimPos($struct, $offset);
312
-            if ($end === false)
313
-            {
279
+            if ($end === false) {
314 280
                 $result = substr($struct, $start);
315
-            }
316
-            else
317
-            {
281
+            } else {
318 282
                 $result = substr($struct, $start, $end-$start);//already without ';'
319 283
             }
320 284
         }
321 285
         $result = trim($result);
322
-        if ($database && $removeDatabase)
323
-        {
286
+        if ($database && $removeDatabase) {
324 287
             $result = str_replace($tableDef, $m[1][0].$m[3][0], $result);
325 288
         }
326 289
         return $result;
@@ -335,8 +298,7 @@  discard block
 block discarded – undo
335 298
         $result = array();
336 299
         //find opening bracket, get the prefix along with it
337 300
         $openBracketPos = $this->getDelimPos($sql, 0, '(');
338
-        if ($openBracketPos===false)
339
-        {
301
+        if ($openBracketPos===false) {
340 302
             trigger_error('[WARNING] can not find opening bracket in table definition');
341 303
             return false;
342 304
         }
@@ -344,19 +306,16 @@  discard block
 block discarded – undo
344 306
         $result[] = trim($prefix);
345 307
         $body = substr($sql, strlen($prefix));//fields, indexes and part after closing bracket
346 308
         //split by commas, get part by part
347
-        while(($commaPos = $this->getDelimPos($body, 0, ',', true))!==false)
348
-        {
309
+        while(($commaPos = $this->getDelimPos($body, 0, ',', true))!==false) {
349 310
             $part = trim(substr($body, 0, $commaPos+1));//read another part and shorten $body
350
-            if ($part)
351
-            {
311
+            if ($part) {
352 312
                 $result[] = $part;
353 313
             }
354 314
             $body = substr($body, $commaPos+1);
355 315
         }
356 316
         //here we have last field (or index) definition + part after closing bracket (ENGINE, ect)
357 317
         $closeBracketPos = $this->getDelimRpos($body, 0, ')');
358
-        if ($closeBracketPos===false)
359
-        {
318
+        if ($closeBracketPos===false) {
360 319
             trigger_error('[WARNING] can not find closing bracket in table definition');
361 320
             return false;
362 321
         }
@@ -366,8 +325,7 @@  discard block
 block discarded – undo
366 325
         //get the suffix part along with the closing bracket
367 326
         $suffix = substr($body, $closeBracketPos);
368 327
         $suffix = trim($suffix);
369
-        if ($suffix)
370
-        {
328
+        if ($suffix) {
371 329
             $result[] = $suffix;
372 330
         }
373 331
         return $result;
@@ -390,29 +348,32 @@  discard block
 block discarded – undo
390 348
         $result = array();
391 349
         //split with comma delimiter, not line breaks
392 350
         $sourceParts =  $this->splitTabSql($sourceSql);
393
-        if ($sourceParts===false)//error parsing sql
351
+        if ($sourceParts===false) {
352
+            //error parsing sql
394 353
         {
395 354
             trigger_error('[WARNING] error parsing source sql');
355
+        }
396 356
             return false;
397 357
         }
398 358
         $destParts = $this->splitTabSql($destSql);
399
-        if ($destParts===false)
400
-        {
359
+        if ($destParts===false) {
401 360
             trigger_error('[WARNING] error parsing destination sql');
402 361
             return false;
403 362
         }
404 363
         $sourcePartsIndexed = array();
405 364
         $destPartsIndexed = array();
406
-        foreach($sourceParts as $line)
407
-        {
365
+        foreach($sourceParts as $line) {
408 366
             $lineInfo = $this->processLine($line);
409
-            if (!$lineInfo) continue;
367
+            if (!$lineInfo) {
368
+                continue;
369
+            }
410 370
             $sourcePartsIndexed[$lineInfo['key']] = $lineInfo['line'];
411 371
         }
412
-        foreach($destParts as $line)
413
-        {
372
+        foreach($destParts as $line) {
414 373
             $lineInfo = $this->processLine($line);
415
-            if (!$lineInfo) continue;
374
+            if (!$lineInfo) {
375
+                continue;
376
+            }
416 377
             $destPartsIndexed[$lineInfo['key']] = $lineInfo['line'];
417 378
         }
418 379
         $sourceKeys = array_keys($sourcePartsIndexed);
@@ -420,8 +381,7 @@  discard block
 block discarded – undo
420 381
         $all = array_unique(array_merge($sourceKeys, $destKeys));
421 382
         sort($all);//fields first, then indexes - because fields are prefixed with '!'
422 383
 
423
-        foreach ($all as $key)
424
-        {
384
+        foreach ($all as $key) {
425 385
             $info = array('source'=>'', 'dest'=>'');
426 386
             $inSource= in_array($key, $sourceKeys);
427 387
             $inDest= in_array($key, $destKeys);
@@ -429,20 +389,16 @@  discard block
 block discarded – undo
429 389
             $destOrphan = $inDest && !$inSource;
430 390
             $different =  $inSource && $inDest &&
431 391
             strcasecmp($this->normalizeString($destPartsIndexed[$key]), $this->normalizeString($sourcePartsIndexed[$key]));
432
-            if ($sourceOrphan)
433
-            {
392
+            if ($sourceOrphan) {
434 393
                 $info['source'] = $sourcePartsIndexed[$key];
435
-            }
436
-            elseif ($destOrphan)
437
-            {
394
+            } elseif ($destOrphan) {
438 395
                 $info['dest'] = $destPartsIndexed[$key];
439
-            }
440
-            elseif ($different)
441
-            {
396
+            } elseif ($different) {
442 397
                 $info['source'] = $sourcePartsIndexed[$key];
443 398
                 $info['dest'] = $destPartsIndexed[$key];
399
+            } else {
400
+                continue;
444 401
             }
445
-            else continue;
446 402
             $result[] = $info;
447 403
         }
448 404
         return $result;
@@ -461,34 +417,35 @@  discard block
 block discarded – undo
461 417
         $options = $this->config;
462 418
         $result = array('key'=>'', 'line'=>'');
463 419
         $line = rtrim(trim($line), ',');
464
-        if (preg_match('/^(CREATE\s+TABLE)|(\) ENGINE=)/i', $line))//first or last table definition line
420
+        if (preg_match('/^(CREATE\s+TABLE)|(\) ENGINE=)/i', $line)) {
421
+            //first or last table definition line
465 422
         {
466 423
             return false;
467 424
         }
425
+        }
468 426
         //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
427
+        if (preg_match('/^(PRIMARY\s+KEY)|(((UNIQUE\s+)|(FULLTEXT\s+))?KEY\s+`?\w+`?)/i', $line, $m)) {
428
+            //key definition
470 429
         {
471 430
             $key = $m[0];
472 431
         }
473
-        elseif (preg_match('/^`?\w+`?/i', $line, $m))//field definition
432
+        } elseif (preg_match('/^`?\w+`?/i', $line, $m)) {
433
+            //field definition
474 434
         {
475
-            $key = '!'.$m[0];//to make sure fields will be synchronised before the keys
435
+            $key = '!'.$m[0];
476 436
         }
477
-        else
478
-        {
437
+        //to make sure fields will be synchronised before the keys
438
+        } else {
479 439
             return false;//line has no valuable info (empty or comment)
480 440
         }
481 441
         //$key = str_replace('`', '', $key);
482
-        if (!empty($options['varcharDefaultIgnore']))
483
-        {
442
+        if (!empty($options['varcharDefaultIgnore'])) {
484 443
             $line = preg_replace("/(var)?char\(([0-9]+)\)\s+NOT\s+NULL\s+default\s+''/i", '$1char($2) NOT NULL', $line);
485 444
         }
486
-        if (!empty($options['intDefaultIgnore']))
487
-        {
445
+        if (!empty($options['intDefaultIgnore'])) {
488 446
             $line = preg_replace("/((?:big)|(?:tiny))?int\(([0-9]+)\)\s+NOT\s+NULL\s+default\s+'0'/i", '$1int($2) NOT NULL', $line);
489 447
         }
490
-        if (!empty($options['ignoreIncrement']))
491
-        {
448
+        if (!empty($options['ignoreIncrement'])) {
492 449
             $line = preg_replace("/ AUTO_INCREMENT=[0-9]+/i", '', $line);
493 450
         }
494 451
         $result['key'] = $this->normalizeString($key);
@@ -508,52 +465,42 @@  discard block
 block discarded – undo
508 465
     {
509 466
         $options = $this->config;
510 467
         $sqls = array();
511
-        if (!is_array($diff) || empty($diff))
512
-        {
468
+        if (!is_array($diff) || empty($diff)) {
513 469
             return $sqls;
514 470
         }
515
-        foreach($diff as $tab=>$info)
516
-        {
517
-            if ($info['sourceOrphan'])//delete it
471
+        foreach($diff as $tab=>$info) {
472
+            if ($info['sourceOrphan']) {
473
+                //delete it
518 474
             {
519 475
                 $sqls[] = 'DROP TABLE `'.$tab.'`';
520 476
             }
521
-            elseif ($info['destOrphan'])//create destination table in source
477
+            } elseif ($info['destOrphan']) {
478
+                //create destination table in source
522 479
             {
523 480
                 $database = '';
481
+            }
524 482
                 $destSql = $this->getTabSql($this->destStruct, $tab, $database);
525
-                if (!empty($options['ignoreIncrement']))
526
-                {
483
+                if (!empty($options['ignoreIncrement'])) {
527 484
                     $destSql = preg_replace("/\s*AUTO_INCREMENT=[0-9]+/i", '', $destSql);
528 485
                 }
529
-                if (!empty($options['ingoreIfNotExists']))
530
-                {
486
+                if (!empty($options['ingoreIfNotExists'])) {
531 487
                     $destSql = preg_replace("/IF NOT EXISTS\s*/i", '', $destSql);
532 488
                 }
533
-                if (!empty($options['forceIfNotExists']))
534
-                {
489
+                if (!empty($options['forceIfNotExists'])) {
535 490
                     $destSql = preg_replace('/(CREATE(?:\s*TEMPORARY)?\s*TABLE\s*)(?:IF\sNOT\sEXISTS\s*)?(`?\w+`?)/i', '$1IF NOT EXISTS $2', $destSql);
536 491
                 }
537 492
                 $sqls[] = $destSql;
538
-            }
539
-            else
540
-            {
541
-                foreach($info['differs'] as $finfo)
542
-                {
493
+            } else {
494
+                foreach($info['differs'] as $finfo) {
543 495
                     $inDest = !empty($finfo['dest']);
544 496
                     $inSource = !empty($finfo['source']);
545
-                    if ($inSource && !$inDest)
546
-                    {
497
+                    if ($inSource && !$inDest) {
547 498
                         $sql = $finfo['source'];
548 499
                         $action = 'drop';
549
-                    }
550
-                    elseif ($inDest && !$inSource)
551
-                    {
500
+                    } elseif ($inDest && !$inSource) {
552 501
                         $sql = $finfo['dest'];
553 502
                         $action = 'add';
554
-                    }
555
-                    else
556
-                    {
503
+                    } else {
557 504
                         $sql = $finfo['dest'];
558 505
                         $action = 'modify';
559 506
                     }
@@ -579,65 +526,47 @@  discard block
 block discarded – undo
579 526
         $action = strtolower($action);
580 527
         $keyField = '`?\w`?(?:\(\d+\))?';//matches `name`(10)
581 528
         $keyFieldList = '(?:'.$keyField.'(?:,\s?)?)+';//matches `name`(10),`desc`(255)
582
-        if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\('.$keyFieldList.'\))/i', $sql, $m))
583
-        {   //key and index operations
529
+        if (preg_match('/((?:PRIMARY )|(?:UNIQUE )|(?:FULLTEXT ))?KEY `?(\w+)?`?\s(\('.$keyFieldList.'\))/i', $sql, $m)) {
530
+//key and index operations
584 531
             $type = strtolower(trim($m[1]));
585 532
             $name = trim($m[2]);
586 533
             $fields = trim($m[3]);
587
-            switch($action)
588
-            {
534
+            switch($action) {
589 535
                 case 'drop':
590
-                    if ($type=='primary')
591
-                    {
536
+                    if ($type=='primary') {
592 537
                         $result.= 'DROP PRIMARY KEY';
593
-                    }
594
-                    else
595
-                    {
538
+                    } else {
596 539
                         $result.= 'DROP INDEX `'.$name.'`';
597 540
                     }
598 541
                 break;
599 542
                 case 'add':
600
-                    if ($type=='primary')
601
-                    {
543
+                    if ($type=='primary') {
602 544
                         $result.= 'ADD PRIMARY KEY '.$fields;
603
-                    }
604
-                    elseif ($type=='')
605
-                    {
545
+                    } elseif ($type=='') {
606 546
                         $result.= 'ADD INDEX `'.$name.'` '.$fields;
607
-                    }
608
-                    else
609
-                    {
547
+                    } else {
610 548
                         $result .='ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique
611 549
                     }
612 550
                 break;
613 551
                 case 'modify':
614
-                    if ($type=='primary')
615
-                    {
552
+                    if ($type=='primary') {
616 553
                         $result.='DROP PRIMARY KEY, ADD PRIMARY KEY '.$fields;
617
-                    }
618
-                    elseif ($type=='')
619
-                    {
554
+                    } elseif ($type=='') {
620 555
                         $result.='DROP INDEX `'.$name.'`, ADD INDEX `'.$name.'` '.$fields;
621
-                    }
622
-                    else
623
-                    {
556
+                    } else {
624 557
                         $result.='DROP INDEX `'.$name.'`, ADD '.strtoupper($type).' `'.$name.'` '.$fields;//fulltext or unique
625 558
                     }
626 559
                 break;
627 560
 
628 561
             }
629
-        }
630
-        else //fields operations
562
+        } else //fields operations
631 563
         {
632 564
             $sql = rtrim(trim($sql), ',');
633 565
             $result.= strtoupper($action);
634
-            if ($action=='drop')
635
-            {
566
+            if ($action=='drop') {
636 567
                 $spacePos = strpos($sql, ' ');
637 568
                 $result.= ' '.substr($sql, 0, $spacePos);
638
-            }
639
-            else
640
-            {
569
+            } else {
641 570
                 $result.= ' '.$sql;
642 571
             }
643 572
         }
@@ -657,76 +586,69 @@  discard block
 block discarded – undo
657 586
         $rbs = '\\\\';  //reg - escaped backslash
658 587
         $regPrefix = "(?<!$rbs)(?:$rbs{2})*";
659 588
         $reg = $regPrefix.'("|\')|(/\\*)|(\\*/)|(-- )|(\r\n|\r|\n)|';
660
-        if ($skipInBrackets)
661
-        {
589
+        if ($skipInBrackets) {
662 590
             $reg.='(\(|\))|';
663
-        }
664
-        else
665
-        {
591
+        } else {
666 592
             $reg.='()';
667 593
         }
668 594
         $reg .= '('.preg_quote($delim).')';
669
-        while (preg_match('%'.$reg.'%', $string, $m, PREG_OFFSET_CAPTURE, $offset))
670
-        {
595
+        while (preg_match('%'.$reg.'%', $string, $m, PREG_OFFSET_CAPTURE, $offset)) {
671 596
             $offset = $m[0][1]+strlen($m[0][0]);
672
-            if (end($stack)=='/*')
673
-            {
674
-                if (!empty($m[3][0]))
675
-                {
597
+            if (end($stack)=='/*') {
598
+                if (!empty($m[3][0])) {
676 599
                     array_pop($stack);
677 600
                 }
678 601
                 continue;//here we could also simplify regexp
679 602
             }
680
-            if (end($stack)=='-- ')
681
-            {
682
-                if (!empty($m[5][0]))
683
-                {
603
+            if (end($stack)=='-- ') {
604
+                if (!empty($m[5][0])) {
684 605
                     array_pop($stack);
685 606
                 }
686 607
                 continue;//here we could also simplify regexp
687 608
             }
688 609
 
689
-            if (!empty($m[7][0]))// ';' found
610
+            if (!empty($m[7][0])) {
611
+                // ';' found
690 612
             {
691 613
                 if (empty($stack))
692 614
                 {
693 615
                     return $m[7][1];
694
-                }
695
-                else
696
-                {
616
+            }
617
+                } else {
697 618
                     //var_dump($stack, substr($string, $offset-strlen($m[0][0])));
698 619
                 }
699 620
             }
700
-            if (!empty($m[6][0]))// '(' or ')' found
621
+            if (!empty($m[6][0])) {
622
+                // '(' or ')' found
701 623
             {
702 624
                 if (empty($stack) && $m[6][0]=='(')
703 625
                 {
704 626
                     array_push($stack, $m[6][0]);
705
-                }
706
-                elseif($m[6][0]==')' && end($stack)=='(')
707
-                {
627
+            }
628
+                } elseif($m[6][0]==')' && end($stack)=='(') {
708 629
                     array_pop($stack);
709 630
                 }
710
-            }
711
-            elseif (!empty($m[1][0]))// ' or " found
631
+            } elseif (!empty($m[1][0])) {
632
+                // ' or " found
712 633
             {
713 634
                 if (end($stack)==$m[1][0])
714 635
                 {
715 636
                     array_pop($stack);
716
-                }
717
-                else
718
-                {
637
+            }
638
+                } else {
719 639
                     array_push($stack, $m[1][0]);
720 640
                 }
721
-            }
722
-            elseif (!empty($m[2][0])) // opening comment / *
641
+            } elseif (!empty($m[2][0])) {
642
+                // opening comment / *
723 643
             {
724 644
                 array_push($stack, $m[2][0]);
725 645
             }
726
-            elseif (!empty($m[4][0])) // opening comment --
646
+            } elseif (!empty($m[4][0])) {
647
+                // opening comment --
727 648
             {
728 649
                 array_push($stack, $m[4][0]);
729 650
             }
651
+            }
730 652
         }
731 653
         return false;
732 654
     }
@@ -738,15 +660,12 @@  discard block
 block discarded – undo
738 660
     function getDelimRpos($string, $offset=0, $delim=';', $skipInBrackets=false)
739 661
     {
740 662
         $pos = $this->getDelimPos($string, $offset, $delim, $skipInBrackets);
741
-        if ($pos===false)
742
-        {
663
+        if ($pos===false) {
743 664
             return false;
744 665
         }
745
-        do
746
-        {
666
+        do {
747 667
             $newPos=$this->getDelimPos($string, $pos+1, $delim, $skipInBrackets);
748
-            if ($newPos !== false)
749
-            {
668
+            if ($newPos !== false) {
750 669
                 $pos = $newPos;
751 670
             }
752 671
         }
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/dbstruct.php 1 patch
Braces   +25 added lines, -31 removed lines patch added patch discarded remove patch
@@ -39,13 +39,16 @@  discard block
 block discarded – undo
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
 
@@ -65,12 +68,10 @@  discard block
 block discarded – undo
65 68
 
66 69
         $response = new OkapiHttpResponse();
67 70
         $response->content_type = "text/plain; charset=utf-8";
68
-        if (isset($_GET['compare_to']))
69
-        {
71
+        if (isset($_GET['compare_to'])) {
70 72
             self::requireSafe($_GET['compare_to']);
71 73
             $scheme = parse_url($_GET['compare_to'], PHP_URL_SCHEME);
72
-            if (in_array($scheme, array('http', 'https')))
73
-            {
74
+            if (in_array($scheme, array('http', 'https'))) {
74 75
                 try {
75 76
                     $alternate_struct = @file_get_contents($_GET['compare_to']);
76 77
                 } catch (Exception $e) {
@@ -84,16 +85,13 @@  discard block
 block discarded – undo
84 85
                     "-- better to use manual diff instead.\n\n";
85 86
                 require_once("comparator.inc.php");
86 87
                 $updater = new \dbStructUpdater();
87
-                if (isset($_GET['reverse']) && ($_GET['reverse'] == 'true'))
88
-                {
88
+                if (isset($_GET['reverse']) && ($_GET['reverse'] == 'true')) {
89 89
                     $response->body .=
90 90
                         "-- REVERSE MODE. The following will alter [2], so that it has the structure of [1].\n".
91 91
                         "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n".
92 92
                         "-- 2. ".$_GET['compare_to']." (".md5($alternate_struct).")\n\n";
93 93
                     $alters = $updater->getUpdates($alternate_struct, $struct);
94
-                }
95
-                else
96
-                {
94
+                } else {
97 95
                     $response->body .=
98 96
                         "-- The following will alter [1], so that it has the structure of [2].\n".
99 97
                         "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n".
@@ -101,31 +99,27 @@  discard block
 block discarded – undo
101 99
                     $alters = $updater->getUpdates($struct, $alternate_struct);
102 100
                 }
103 101
                 # Add semicolons
104
-                foreach ($alters as &$alter_ref)
105
-                    $alter_ref .= ";";
102
+                foreach ($alters as &$alter_ref) {
103
+                                    $alter_ref .= ";";
104
+                }
106 105
                 # Comment out all differences containing "okapi_". These should be executed
107 106
                 # by OKAPI update scripts.
108
-                foreach ($alters as &$alter_ref)
109
-                {
110
-                    if (strpos($alter_ref, "okapi_") !== false)
111
-                    {
107
+                foreach ($alters as &$alter_ref) {
108
+                    if (strpos($alter_ref, "okapi_") !== false) {
112 109
                         $lines = explode("\n", $alter_ref);
113 110
                         $alter_ref = "-- Probably you should NOT execute this one. Use okapi/update instead.\n-- {{{\n--   ".
114 111
                             implode("\n--   ", $lines)."\n-- }}}";
115 112
                     }
116 113
                 }
117
-                if (count($alters) > 0)
118
-                    $response->body .= implode("\n", $alters)."\n";
119
-                else
120
-                    $response->body .= "-- No differences found\n";
121
-            }
122
-            else
123
-            {
114
+                if (count($alters) > 0) {
115
+                                    $response->body .= implode("\n", $alters)."\n";
116
+                } else {
117
+                                    $response->body .= "-- No differences found\n";
118
+                }
119
+            } else {
124 120
                 $response->body = "HTTP(S) only!";
125 121
             }
126
-        }
127
-        else
128
-        {
122
+        } else {
129 123
             $response->body = $struct;
130 124
         }
131 125
         return $response;
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/attrlist.php 1 patch
Braces   +32 added lines, -43 removed lines patch added patch discarded remove patch
@@ -26,33 +26,37 @@  discard block
 block discarded – undo
26 26
         ob_start();
27 27
 
28 28
         print "Cache Types:\n\n";
29
-        foreach (self::get_all_cachetypes() as $id => $name)
30
-            print "$id: $name\n";
29
+        foreach (self::get_all_cachetypes() as $id => $name) {
30
+                    print "$id: $name\n";
31
+        }
31 32
 
32 33
         print "\nLog Types:\n\n";
33
-        foreach (self::get_all_logtypes() as $id => $name)
34
-            print "$id: $name\n";
34
+        foreach (self::get_all_logtypes() as $id => $name) {
35
+                    print "$id: $name\n";
36
+        }
35 37
 
36 38
         print "\nAttributes:\n\n";
37 39
         require_once($GLOBALS['rootpath'].'okapi/services/attrs/attr_helper.inc.php');
38 40
         $internal2acode = AttrHelper::get_internal_id_to_acode_mapping();
39 41
         $dict = self::get_all_attribute_names();
40
-        foreach ($dict as $internal_id => $langs)
41
-        {
42
+        foreach ($dict as $internal_id => $langs) {
42 43
             print $internal_id.": ";
43 44
             $langkeys = array_keys($langs);
44 45
             sort($langkeys);
45
-            if (in_array('en', $langkeys))
46
-                print strtoupper($langs['en']);
47
-            else
48
-                print ">>>> ENGLISH NAME UNSET! <<<<";
49
-            if (isset($internal2acode[$internal_id]))
50
-                print " - ".$internal2acode[$internal_id];
51
-            else
52
-                print " - >>>> MISSING A-CODE MAPPING <<<<";
46
+            if (in_array('en', $langkeys)) {
47
+                            print strtoupper($langs['en']);
48
+            } else {
49
+                            print ">>>> ENGLISH NAME UNSET! <<<<";
50
+            }
51
+            if (isset($internal2acode[$internal_id])) {
52
+                            print " - ".$internal2acode[$internal_id];
53
+            } else {
54
+                            print " - >>>> MISSING A-CODE MAPPING <<<<";
55
+            }
53 56
             print "\n";
54
-            foreach ($langkeys as $langkey)
55
-                print "        $langkey: ".$langs[$langkey]."\n";
57
+            foreach ($langkeys as $langkey) {
58
+                            print "        $langkey: ".$langs[$langkey]."\n";
59
+            }
56 60
         }
57 61
 
58 62
         print "\nAttribute notices:\n\n";
@@ -60,30 +64,24 @@  discard block
 block discarded – undo
60 64
         print "(the last one ( ) can be safely ignored)\n\n";
61 65
 
62 66
         $attrdict = AttrHelper::get_attrdict();
63
-        foreach ($dict as $internal_id => $langs)
64
-        {
65
-            if (!isset($internal2acode[$internal_id]))
66
-            {
67
+        foreach ($dict as $internal_id => $langs) {
68
+            if (!isset($internal2acode[$internal_id])) {
67 69
                 print "(!) Attribute ".$internal_id." is not mapped to any A-code.\n";
68 70
                 continue;
69 71
             }
70 72
             $acode = $internal2acode[$internal_id];
71 73
             $attr = $attrdict[$acode];
72
-            foreach ($langs as $lang => $value)
73
-            {
74
-                if ($lang == 'en')
75
-                {
74
+            foreach ($langs as $lang => $value) {
75
+                if ($lang == 'en') {
76 76
                     continue;
77 77
                 }
78
-                if (!isset($attr['names'][$lang]))
79
-                {
78
+                if (!isset($attr['names'][$lang])) {
80 79
                     print "(-) Attribute $acode is missing a name in the '$lang' language.\n";
81 80
                     print "    Local name: $value\n";
82 81
                     print "    OKAPI name: >> none <<\n";
83 82
                     continue;
84 83
                 }
85
-                if ($attr['names'][$lang] !== $value)
86
-                {
84
+                if ($attr['names'][$lang] !== $value) {
87 85
                     print "( ) Attribute $acode has a different name in the '$lang' language\n";
88 86
                     print "    Local name: $value\n";
89 87
                     print "    OKAPI name: ".$attr['names'][$lang]."\n";
@@ -103,16 +101,13 @@  discard block
 block discarded – undo
103 101
      */
104 102
     private static function get_all_attribute_names()
105 103
     {
106
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
107
-        {
104
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
108 105
             # OCPL branch uses cache_attrib table to store attribute names. It has
109 106
             # different structure than the OCDE cache_attrib table. OCPL does not
110 107
             # have translation tables.
111 108
 
112 109
             $rs = Db::query("select id, language, text_long from cache_attrib order by id");
113
-        }
114
-        else
115
-        {
110
+        } else {
116 111
             # OCDE branch uses translation tables. Let's make a select which will
117 112
             # produce results compatible with the one above.
118 113
 
@@ -141,14 +136,11 @@  discard block
 block discarded – undo
141 136
      */
142 137
     private static function get_all_cachetypes()
143 138
     {
144
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
145
-        {
139
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
146 140
             # OCPL branch does not store cache types in many languages (just two).
147 141
 
148 142
             $rs = Db::query("select id, en from cache_type order by id");
149
-        }
150
-        else
151
-        {
143
+        } else {
152 144
             # OCDE branch uses translation tables.
153 145
 
154 146
             $rs = Db::query("
@@ -176,14 +168,11 @@  discard block
 block discarded – undo
176 168
      */
177 169
     private static function get_all_logtypes()
178 170
     {
179
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
180
-        {
171
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
181 172
             # OCPL branch does not store cache types in many languages (just two).
182 173
 
183 174
             $rs = Db::query("select id, en from log_types order by id");
184
-        }
185
-        else
186
-        {
175
+        } else {
187 176
             # OCDE branch uses translation tables.
188 177
 
189 178
             $rs = Db::query("
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/tilereport.php 1 patch
Braces   +6 added lines, -13 removed lines patch added patch discarded remove patch
@@ -57,21 +57,16 @@  discard block
 block discarded – undo
57 57
         $calls = array('A' => 0, 'B' => 0, 'C' => 0, 'D' => 0);
58 58
         $runtime = array('A' => 0.0, 'B' => 0.0, 'C' => 0.0, 'D' => 0.0);
59 59
 
60
-        while (list($name, $c, $r) = Db::fetch_row($rs))
61
-        {
62
-            if ($name == 'services/caches/map/tile')
63
-            {
60
+        while (list($name, $c, $r) = Db::fetch_row($rs)) {
61
+            if ($name == 'services/caches/map/tile') {
64 62
                 $total_calls = $c;
65 63
                 $total_runtime = $r;
66
-            }
67
-            elseif (strpos($name, 'extra/caches/map/tile/checkpoint') === 0)
68
-            {
64
+            } elseif (strpos($name, 'extra/caches/map/tile/checkpoint') === 0) {
69 65
                 $calls[$name[32]] = $c;
70 66
                 $runtime[$name[32]] = $r;
71 67
             }
72 68
         }
73
-        if ($total_calls != $calls['A'])
74
-        {
69
+        if ($total_calls != $calls['A']) {
75 70
             print "Partial results. Only ".$calls['A']." out of $total_calls are covered.\n";
76 71
             print "All other will count as \"unaccounted for\".\n\n";
77 72
             $total_calls = $calls['A'];
@@ -82,8 +77,7 @@  discard block
 block discarded – undo
82 77
 
83 78
         $perc = function($a, $b) { return ($b > 0) ? sprintf("%.1f", 100 * $a / $b)."%" : "(?)"; };
84 79
         $avg = function($a, $b) { return ($b > 0) ? sprintf("%.4f", $a / $b)."s" : "(?)"; };
85
-        $get_stats = function() use (&$calls_left, &$runtime_left, &$total_calls, &$total_runtime, &$perc)
86
-        {
80
+        $get_stats = function() use (&$calls_left, &$runtime_left, &$total_calls, &$total_runtime, &$perc) {
87 81
             return (
88 82
                 str_pad($perc($calls_left, $total_calls), 6, " ", STR_PAD_LEFT).
89 83
                 str_pad($perc($runtime_left, $total_runtime), 7, " ", STR_PAD_LEFT)
@@ -151,8 +145,7 @@  discard block
 block discarded – undo
151 145
             where score is not null
152 146
             group by floor(log2(score))
153 147
         ");
154
-        while (list($log2, $count, $size) = Db::fetch_row($rs))
155
-        {
148
+        while (list($log2, $count, $size) = Db::fetch_row($rs)) {
156 149
             print $count." elements ($size bytes) with score between ".pow(2, $log2)." and ".pow(2, $log2 + 1).".\n";
157 150
         }
158 151
 
Please login to merge, or discard this patch.
htdocs/okapi/views/devel/cronreport.php 1 patch
Braces   +28 added lines, -24 removed lines patch added patch discarded remove patch
@@ -28,47 +28,51 @@
 block discarded – undo
28 28
 
29 29
         require_once($GLOBALS['rootpath']."okapi/cronjobs.php");
30 30
         $schedule = Cache::get("cron_schedule");
31
-        if ($schedule == null)
32
-            $schedule = array();
31
+        if ($schedule == null) {
32
+                    $schedule = array();
33
+        }
33 34
         print "Nearest event: ";
34
-        if (Okapi::get_var('cron_nearest_event'))
35
-            print "in ".(Okapi::get_var('cron_nearest_event') - time())." seconds.\n\n";
36
-        else
37
-            print "NOT SET\n\n";
35
+        if (Okapi::get_var('cron_nearest_event')) {
36
+                    print "in ".(Okapi::get_var('cron_nearest_event') - time())." seconds.\n\n";
37
+        } else {
38
+                    print "NOT SET\n\n";
39
+        }
38 40
         $cronjobs = CronJobController::get_enabled_cronjobs();
39 41
         usort($cronjobs, function($a, $b) {
40 42
             $cmp = function($a, $b) { return ($a < $b) ? -1 : (($a > $b) ? 1 : 0); };
41 43
             $by_type = $cmp($a->get_type(), $b->get_type());
42
-            if ($by_type != 0)
43
-                return $by_type;
44
+            if ($by_type != 0) {
45
+                            return $by_type;
46
+            }
44 47
             return $cmp($a->get_name(), $b->get_name());
45 48
         });
46 49
         print str_pad("TYPE", 11)."  ".str_pad("NAME", 40)."  SCHEDULE\n";
47 50
         print str_pad("----", 11)."  ".str_pad("----", 40)."  --------\n";
48
-        foreach ($cronjobs as $cronjob)
49
-        {
51
+        foreach ($cronjobs as $cronjob) {
50 52
             $type = $cronjob->get_type();
51 53
             $name = $cronjob->get_name();
52 54
             print str_pad($type, 11)."  ".str_pad($name, 40)."  ";
53
-            if (!isset($schedule[$name]))
54
-                print "NOT YET SCHEDULED\n";
55
-            elseif ($schedule[$name] <= time())
56
-                print "DELAYED: should be run ".(time() - $schedule[$name])." seconds ago\n";
57
-            else
58
-                print "scheduled to run in ".str_pad($schedule[$name] - time(), 6, " ", STR_PAD_LEFT)." seconds\n";
55
+            if (!isset($schedule[$name])) {
56
+                            print "NOT YET SCHEDULED\n";
57
+            } elseif ($schedule[$name] <= time()) {
58
+                            print "DELAYED: should be run ".(time() - $schedule[$name])." seconds ago\n";
59
+            } else {
60
+                            print "scheduled to run in ".str_pad($schedule[$name] - time(), 6, " ", STR_PAD_LEFT)." seconds\n";
61
+            }
59 62
         }
60 63
         print "\n";
61 64
         print "Crontab last ping: ";
62
-        if (Cache::get('crontab_last_ping'))
63
-            print (time() - Cache::get('crontab_last_ping'))." seconds ago";
64
-        else
65
-            print "NEVER";
65
+        if (Cache::get('crontab_last_ping')) {
66
+                    print (time() - Cache::get('crontab_last_ping'))." seconds ago";
67
+        } else {
68
+                    print "NEVER";
69
+        }
66 70
         print " (crontab_check_counter: ".Cache::get('crontab_check_counter').").\n";
67 71
         print "clog_revisions_daily: ";
68
-        if (Cache::get('clog_revisions_daily'))
69
-        {
70
-            foreach (Cache::get('clog_revisions_daily') as $time => $rev)
71
-                print "$rev ";
72
+        if (Cache::get('clog_revisions_daily')) {
73
+            foreach (Cache::get('clog_revisions_daily') as $time => $rev) {
74
+                            print "$rev ";
75
+            }
72 76
             print "\n";
73 77
         } else {
74 78
             print "NULL\n";
Please login to merge, or discard this patch.
htdocs/okapi/views/update.php 1 patch
Braces   +217 added lines, -121 removed lines patch added patch discarded remove patch
@@ -25,14 +25,12 @@  discard block
 block discarded – undo
25 25
 {
26 26
     public static function get_current_version()
27 27
     {
28
-        try
29
-        {
28
+        try {
30 29
             return Okapi::get_var('db_version', 0) + 0;
31
-        }
32
-        catch (Exception $e)
33
-        {
34
-            if (strpos($e->getMessage(), "okapi_vars' doesn't exist") !== false)
35
-                return 0;
30
+        } catch (Exception $e) {
31
+            if (strpos($e->getMessage(), "okapi_vars' doesn't exist") !== false) {
32
+                            return 0;
33
+            }
36 34
             throw $e;
37 35
         }
38 36
     }
@@ -40,13 +38,12 @@  discard block
 block discarded – undo
40 38
     public static function get_max_version()
41 39
     {
42 40
         $max_db_version = 0;
43
-        foreach (get_class_methods(__CLASS__) as $name)
44
-        {
45
-            if (strpos($name, "ver") === 0)
46
-            {
41
+        foreach (get_class_methods(__CLASS__) as $name) {
42
+            if (strpos($name, "ver") === 0) {
47 43
                 $ver = substr($name, 3) + 0;
48
-                if ($ver > $max_db_version)
49
-                    $max_db_version = $ver;
44
+                if ($ver > $max_db_version) {
45
+                                    $max_db_version = $ver;
46
+                }
50 47
             }
51 48
         }
52 49
         return $max_db_version;
@@ -67,13 +64,10 @@  discard block
 block discarded – undo
67 64
         $lock = OkapiLock::get('db-update');
68 65
         $lock->acquire();
69 66
 
70
-        try
71
-        {
67
+        try {
72 68
             self::_call();
73 69
             $lock->release();
74
-        }
75
-        catch (Exception $e)
76
-        {
70
+        } catch (Exception $e) {
77 71
             # Error occured. Make sure the lock is released and rethrow.
78 72
 
79 73
             $lock->release();
@@ -91,16 +85,12 @@  discard block
 block discarded – undo
91 85
         $current_ver = self::get_current_version();
92 86
         $max_ver = self::get_max_version();
93 87
         self::out("Current OKAPI database version: $current_ver\n");
94
-        if ($current_ver == 0 && ((!isset($_GET['install'])) || ($_GET['install'] != 'true')))
95
-        {
88
+        if ($current_ver == 0 && ((!isset($_GET['install'])) || ($_GET['install'] != 'true'))) {
96 89
             self::out("Current OKAPI settings are:\n\n".Settings::describe_settings()."\n\n".
97 90
                 "Make sure they are correct, then append '?install=true' to your query.");
98
-            try
99
-            {
91
+            try {
100 92
                 Db::select_value("select 1 from caches limit 1");
101
-            }
102
-            catch (Exception $e)
103
-            {
93
+            } catch (Exception $e) {
104 94
                 self::out(
105 95
                     "\n\n".
106 96
                     "IMPORTANT: If you're trying to install OKAPI on an empty database then\n".
@@ -110,19 +100,14 @@  discard block
 block discarded – undo
110 100
                 );
111 101
             }
112 102
             return;
113
-        }
114
-        elseif ($max_ver == $current_ver)
115
-        {
103
+        } elseif ($max_ver == $current_ver) {
116 104
             self::out("It is up-to-date.\n\n");
117
-        }
118
-        elseif ($max_ver < $current_ver)
119
-            throw new Exception();
120
-        else
121
-        {
105
+        } elseif ($max_ver < $current_ver) {
106
+                    throw new Exception();
107
+        } else {
122 108
             self::out("Updating to version $max_ver... PLEASE WAIT\n\n");
123 109
 
124
-            while ($current_ver < $max_ver)
125
-            {
110
+            while ($current_ver < $max_ver) {
126 111
                 $version_to_apply = $current_ver + 1;
127 112
                 self::out("Applying mutation #$version_to_apply...");
128 113
                 try {
@@ -280,29 +265,73 @@  discard block
 block discarded – undo
280 265
         ");
281 266
     }
282 267
 
283
-    private static function ver9() { Db::execute("alter table okapi_consumers modify column `key` varchar(20) not null"); }
284
-    private static function ver10() { Db::execute("alter table okapi_consumers modify column secret varchar(40) not null"); }
285
-    private static function ver11() { Db::execute("alter table okapi_tokens modify column `key` varchar(20) not null"); }
286
-    private static function ver12() { Db::execute("alter table okapi_tokens modify column secret varchar(40) not null"); }
287
-    private static function ver13() { Db::execute("alter table okapi_tokens modify column consumer_key varchar(20) not null"); }
288
-    private static function ver14() { Db::execute("alter table okapi_tokens modify column verifier varchar(10) default null"); }
289
-    private static function ver15() { Db::execute("alter table okapi_authorizations modify column consumer_key varchar(20) not null"); }
290
-    private static function ver16() { Db::execute("alter table okapi_nonces modify column consumer_key varchar(20) not null"); }
291
-    private static function ver17() { Db::execute("alter table okapi_nonces modify column `key` varchar(255) not null"); }
292
-    private static function ver18() { Db::execute("alter table okapi_cache_logs modify column consumer_key varchar(20) not null"); }
293
-    private static function ver19() { Db::execute("alter table okapi_vars modify column `var` varchar(32) not null"); }
294
-
295
-    private static function ver20() { Db::execute("alter table okapi_consumers modify column `key` varchar(20) collate utf8_bin not null"); }
296
-    private static function ver21() { Db::execute("alter table okapi_consumers modify column secret varchar(40) collate utf8_bin not null"); }
297
-    private static function ver22() { Db::execute("alter table okapi_tokens modify column `key` varchar(20) collate utf8_bin not null"); }
298
-    private static function ver23() { Db::execute("alter table okapi_tokens modify column secret varchar(40) collate utf8_bin not null"); }
299
-    private static function ver24() { Db::execute("alter table okapi_tokens modify column consumer_key varchar(20) collate utf8_bin not null"); }
300
-    private static function ver25() { Db::execute("alter table okapi_tokens modify column verifier varchar(10) collate utf8_bin default null"); }
301
-    private static function ver26() { Db::execute("alter table okapi_authorizations modify column consumer_key varchar(20) collate utf8_bin not null"); }
302
-    private static function ver27() { Db::execute("alter table okapi_nonces modify column consumer_key varchar(20) collate utf8_bin not null"); }
303
-    private static function ver28() { Db::execute("alter table okapi_nonces modify column `key` varchar(255) collate utf8_bin not null"); }
304
-    private static function ver29() { Db::execute("alter table okapi_cache_logs modify column consumer_key varchar(20) collate utf8_bin not null"); }
305
-    private static function ver30() { Db::execute("alter table okapi_vars modify column `var` varchar(32) collate utf8_bin not null"); }
268
+    private static function ver9()
269
+    {
270
+Db::execute("alter table okapi_consumers modify column `key` varchar(20) not null"); }
271
+    private static function ver10()
272
+    {
273
+Db::execute("alter table okapi_consumers modify column secret varchar(40) not null"); }
274
+    private static function ver11()
275
+    {
276
+Db::execute("alter table okapi_tokens modify column `key` varchar(20) not null"); }
277
+    private static function ver12()
278
+    {
279
+Db::execute("alter table okapi_tokens modify column secret varchar(40) not null"); }
280
+    private static function ver13()
281
+    {
282
+Db::execute("alter table okapi_tokens modify column consumer_key varchar(20) not null"); }
283
+    private static function ver14()
284
+    {
285
+Db::execute("alter table okapi_tokens modify column verifier varchar(10) default null"); }
286
+    private static function ver15()
287
+    {
288
+Db::execute("alter table okapi_authorizations modify column consumer_key varchar(20) not null"); }
289
+    private static function ver16()
290
+    {
291
+Db::execute("alter table okapi_nonces modify column consumer_key varchar(20) not null"); }
292
+    private static function ver17()
293
+    {
294
+Db::execute("alter table okapi_nonces modify column `key` varchar(255) not null"); }
295
+    private static function ver18()
296
+    {
297
+Db::execute("alter table okapi_cache_logs modify column consumer_key varchar(20) not null"); }
298
+    private static function ver19()
299
+    {
300
+Db::execute("alter table okapi_vars modify column `var` varchar(32) not null"); }
301
+
302
+    private static function ver20()
303
+    {
304
+Db::execute("alter table okapi_consumers modify column `key` varchar(20) collate utf8_bin not null"); }
305
+    private static function ver21()
306
+    {
307
+Db::execute("alter table okapi_consumers modify column secret varchar(40) collate utf8_bin not null"); }
308
+    private static function ver22()
309
+    {
310
+Db::execute("alter table okapi_tokens modify column `key` varchar(20) collate utf8_bin not null"); }
311
+    private static function ver23()
312
+    {
313
+Db::execute("alter table okapi_tokens modify column secret varchar(40) collate utf8_bin not null"); }
314
+    private static function ver24()
315
+    {
316
+Db::execute("alter table okapi_tokens modify column consumer_key varchar(20) collate utf8_bin not null"); }
317
+    private static function ver25()
318
+    {
319
+Db::execute("alter table okapi_tokens modify column verifier varchar(10) collate utf8_bin default null"); }
320
+    private static function ver26()
321
+    {
322
+Db::execute("alter table okapi_authorizations modify column consumer_key varchar(20) collate utf8_bin not null"); }
323
+    private static function ver27()
324
+    {
325
+Db::execute("alter table okapi_nonces modify column consumer_key varchar(20) collate utf8_bin not null"); }
326
+    private static function ver28()
327
+    {
328
+Db::execute("alter table okapi_nonces modify column `key` varchar(255) collate utf8_bin not null"); }
329
+    private static function ver29()
330
+    {
331
+Db::execute("alter table okapi_cache_logs modify column consumer_key varchar(20) collate utf8_bin not null"); }
332
+    private static function ver30()
333
+    {
334
+Db::execute("alter table okapi_vars modify column `var` varchar(32) collate utf8_bin not null"); }
306 335
 
307 336
     private static function ver31()
308 337
     {
@@ -337,12 +366,9 @@  discard block
 block discarded – undo
337 366
 
338 367
     private static function ver33()
339 368
     {
340
-        try
341
-        {
369
+        try {
342 370
             Db::execute("alter table cache_logs add key `uuid` (`uuid`)");
343
-        }
344
-        catch (Exception $e)
345
-        {
371
+        } catch (Exception $e) {
346 372
             // key exists
347 373
         }
348 374
     }
@@ -373,11 +399,21 @@  discard block
 block discarded – undo
373 399
         );
374 400
     }
375 401
 
376
-    private static function ver36() { Db::execute("alter table okapi_cache modify column `key` varchar(64) not null"); }
377
-    private static function ver37() { Db::execute("delete from okapi_vars where var='last_clog_update'"); }
378
-    private static function ver38() { Db::execute("alter table okapi_clog modify column data mediumblob"); }
379
-    private static function ver39() { Db::execute("delete from okapi_clog"); }
380
-    private static function ver40() { Db::execute("alter table okapi_cache modify column value mediumblob"); }
402
+    private static function ver36()
403
+    {
404
+Db::execute("alter table okapi_cache modify column `key` varchar(64) not null"); }
405
+    private static function ver37()
406
+    {
407
+Db::execute("delete from okapi_vars where var='last_clog_update'"); }
408
+    private static function ver38()
409
+    {
410
+Db::execute("alter table okapi_clog modify column data mediumblob"); }
411
+    private static function ver39()
412
+    {
413
+Db::execute("delete from okapi_clog"); }
414
+    private static function ver40()
415
+    {
416
+Db::execute("alter table okapi_cache modify column value mediumblob"); }
381 417
 
382 418
     private static function ver41()
383 419
     {
@@ -389,7 +425,9 @@  discard block
 block discarded – undo
389 425
         Cache::delete('cron_schedule');
390 426
     }
391 427
 
392
-    private static function ver42() { Db::execute("delete from okapi_cache where length(value) = 65535"); }
428
+    private static function ver42()
429
+    {
430
+Db::execute("delete from okapi_cache where length(value) = 65535"); }
393 431
 
394 432
     private static function ver43()
395 433
     {
@@ -408,9 +446,15 @@  discard block
 block discarded – undo
408 446
         Okapi::mail_from_okapi($emails, "A change in the 'replicate' module.", ob_get_clean());
409 447
     }
410 448
 
411
-    private static function ver44() { Db::execute("alter table caches add column okapi_syncbase timestamp not null after last_modified;"); }
412
-    private static function ver45() { Db::execute("update caches set okapi_syncbase=last_modified;"); }
413
-    private static function ver46() { /* no longer necessary */ }
449
+    private static function ver44()
450
+    {
451
+Db::execute("alter table caches add column okapi_syncbase timestamp not null after last_modified;"); }
452
+    private static function ver45()
453
+    {
454
+Db::execute("update caches set okapi_syncbase=last_modified;"); }
455
+    private static function ver46()
456
+    {
457
+/* no longer necessary */ }
414 458
 
415 459
     private static function ver47()
416 460
     {
@@ -451,8 +495,12 @@  discard block
 block discarded – undo
451 495
         print "on this procedure, please submit them to our issue tracker.\n\n";
452 496
     }
453 497
 
454
-    private static function ver49() { Db::execute("alter table caches add key okapi_syncbase (okapi_syncbase);"); }
455
-    private static function ver50() { /* no longer necessary */ }
498
+    private static function ver49()
499
+    {
500
+Db::execute("alter table caches add key okapi_syncbase (okapi_syncbase);"); }
501
+    private static function ver50()
502
+    {
503
+/* no longer necessary */ }
456 504
 
457 505
     private static function ver51()
458 506
     {
@@ -468,13 +516,16 @@  discard block
 block discarded – undo
468 516
         # It doesn't do that anymore. Instead, it adds a separate column for itself (okapi_syncbase).
469 517
     }
470 518
 
471
-    private static function ver53() { Db::execute("alter table cache_logs add column okapi_syncbase timestamp not null after last_modified;"); }
472
-    private static function ver54() { Db::execute("update cache_logs set okapi_syncbase=last_modified;"); }
519
+    private static function ver53()
520
+    {
521
+Db::execute("alter table cache_logs add column okapi_syncbase timestamp not null after last_modified;"); }
522
+    private static function ver54()
523
+    {
524
+Db::execute("update cache_logs set okapi_syncbase=last_modified;"); }
473 525
 
474 526
     private static function ver55()
475 527
     {
476
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
477
-        {
528
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
478 529
             # OCPL does not have cache_logs_archived table.
479 530
             return;
480 531
         }
@@ -483,8 +534,7 @@  discard block
 block discarded – undo
483 534
 
484 535
     private static function ver56()
485 536
     {
486
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
487
-        {
537
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
488 538
             # OCPL does not have cache_logs_archived table.
489 539
             return;
490 540
         }
@@ -544,13 +594,11 @@  discard block
 block discarded – undo
544 594
         #
545 595
         $row = Db::select_row("show create table cache_logs");
546 596
         $stmt = $row["Create Table"];
547
-        if (strpos($stmt, "timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'") > 0)
548
-        {
597
+        if (strpos($stmt, "timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'") > 0) {
549 598
             Db::execute("alter table cache_logs modify column last_modified datetime not null;");
550 599
             Db::execute("alter table cache_logs modify column okapi_syncbase timestamp not null;");
551 600
             Db::execute("update cache_logs set okapi_syncbase=now() where okapi_syncbase='0000-00-00 00:00:00';");
552
-            if (Settings::get('OC_BRANCH') == 'oc.de')
553
-            {
601
+            if (Settings::get('OC_BRANCH') == 'oc.de') {
554 602
                 Db::execute("alter table cache_logs_archived modify column last_modified datetime not null;");
555 603
                 Db::execute("alter table cache_logs_archived modify column okapi_syncbase timestamp not null;");
556 604
                 Db::execute("update cache_logs_archived set okapi_syncbase=now() where okapi_syncbase='0000-00-00 00:00:00';");
@@ -558,12 +606,13 @@  discard block
 block discarded – undo
558 606
         }
559 607
     }
560 608
 
561
-    private static function ver61() { Db::execute("alter table cache_logs add key okapi_syncbase (okapi_syncbase);"); }
609
+    private static function ver61()
610
+    {
611
+Db::execute("alter table cache_logs add key okapi_syncbase (okapi_syncbase);"); }
562 612
 
563 613
     private static function ver62()
564 614
     {
565
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
566
-        {
615
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
567 616
             # OCPL does not have cache_logs_archived table.
568 617
             return;
569 618
         }
@@ -602,20 +651,28 @@  discard block
 block discarded – undo
602 651
         ");
603 652
     }
604 653
 
605
-    private static function ver65() { Db::execute("alter table okapi_tile_status engine=innodb;"); }
606
-    private static function ver66() { Db::execute("alter table okapi_tile_caches engine=innodb;"); }
654
+    private static function ver65()
655
+    {
656
+Db::execute("alter table okapi_tile_status engine=innodb;"); }
657
+    private static function ver66()
658
+    {
659
+Db::execute("alter table okapi_tile_caches engine=innodb;"); }
607 660
 
608 661
     private static function ver67()
609 662
     {
610 663
         # Remove unused locks (these might have been created in previous versions of OKAPI).
611 664
 
612
-        for ($z=0; $z<=2; $z++)
613
-            for ($x=0; $x<(1<<$z); $x++)
614
-                for ($y=0; $y<(1<<$z); $y++)
615
-                {
665
+        for ($z=0; $z<=2; $z++) {
666
+                    for ($x=0;
667
+        }
668
+        $x<(1<<$z); $x++) {
669
+                            for ($y=0;
670
+            }
671
+            $y<(1<<$z); $y++) {
616 672
                     $lockname = "tile-computation-$z-$x-$y";
617
-                    if (OkapiLock::exists($lockname))
618
-                        OkapiLock::get($lockname)->remove();
673
+                    if (OkapiLock::exists($lockname)) {
674
+                                            OkapiLock::get($lockname)->remove();
675
+                    }
619 676
                 }
620 677
     }
621 678
 
@@ -623,13 +680,12 @@  discard block
 block discarded – undo
623 680
     {
624 681
         # Once again, remove unused locks.
625 682
 
626
-        for ($z=0; $z<=21; $z++)
627
-        {
628
-            foreach (array("", "-0", "-1") as $suffix)
629
-            {
683
+        for ($z=0; $z<=21; $z++) {
684
+            foreach (array("", "-0", "-1") as $suffix) {
630 685
                 $lockname = "tile-$z$suffix";
631
-                if (OkapiLock::exists($lockname))
632
-                    OkapiLock::get($lockname)->remove();
686
+                if (OkapiLock::exists($lockname)) {
687
+                                    OkapiLock::get($lockname)->remove();
688
+                }
633 689
             }
634 690
         }
635 691
     }
@@ -652,12 +708,24 @@  discard block
 block discarded – undo
652 708
         ");
653 709
     }
654 710
 
655
-    private static function ver71() { Db::execute("alter table okapi_cache add column score float(4,2) default null after `key`"); }
656
-    private static function ver72() { Db::execute("alter table okapi_cache change column expires expires datetime after score"); }
657
-    private static function ver73() { Db::execute("update okapi_cache set score=1, expires=date_add(now(), interval 360 day) where `key` like 'tile/%'"); }
658
-    private static function ver74() { Db::execute("update okapi_cache set score=1, expires=date_add(now(), interval 360 day) where `key` like 'tilecaption/%'"); }
659
-    private static function ver75() { Db::execute("alter table okapi_cache modify column score float default null"); }
660
-    private static function ver76() { Db::execute("update okapi_cache set expires=date_add(now(), interval 100 year) where `key` like 'clog#geocache#%'"); }
711
+    private static function ver71()
712
+    {
713
+Db::execute("alter table okapi_cache add column score float(4,2) default null after `key`"); }
714
+    private static function ver72()
715
+    {
716
+Db::execute("alter table okapi_cache change column expires expires datetime after score"); }
717
+    private static function ver73()
718
+    {
719
+Db::execute("update okapi_cache set score=1, expires=date_add(now(), interval 360 day) where `key` like 'tile/%'"); }
720
+    private static function ver74()
721
+    {
722
+Db::execute("update okapi_cache set score=1, expires=date_add(now(), interval 360 day) where `key` like 'tilecaption/%'"); }
723
+    private static function ver75()
724
+    {
725
+Db::execute("alter table okapi_cache modify column score float default null"); }
726
+    private static function ver76()
727
+    {
728
+Db::execute("update okapi_cache set expires=date_add(now(), interval 100 year) where `key` like 'clog#geocache#%'"); }
661 729
 
662 730
     private static function ver77()
663 731
     {
@@ -682,16 +750,36 @@  discard block
 block discarded – undo
682 750
         ");
683 751
     }
684 752
 
685
-    private static function ver79() { Db::execute("alter table okapi_search_results engine=MyISAM"); }
686
-    private static function ver80() { Db::execute("alter table okapi_search_sets add column date_created datetime not null"); }
687
-    private static function ver81() { Db::execute("alter table okapi_search_sets add column expires datetime not null"); }
688
-    private static function ver82() { CronJobController::reset_job_schedule("FulldumpGeneratorJob"); }
689
-    private static function ver83() { Db::execute("alter table okapi_stats_temp engine=InnoDB"); }
690
-    private static function ver84() { Db::execute("truncate okapi_nonces;"); }
691
-    private static function ver85() { Db::execute("alter table okapi_nonces drop primary key;"); }
692
-    private static function ver86() { Db::execute("alter table okapi_nonces change column `key` nonce_hash varchar(32) character set utf8 collate utf8_bin not null;"); }
693
-    private static function ver87() { Db::execute("alter table okapi_nonces add primary key (consumer_key, nonce_hash);"); }
694
-    private static function ver88() { Db::execute("alter table okapi_consumers add column admin tinyint not null default 0;"); }
753
+    private static function ver79()
754
+    {
755
+Db::execute("alter table okapi_search_results engine=MyISAM"); }
756
+    private static function ver80()
757
+    {
758
+Db::execute("alter table okapi_search_sets add column date_created datetime not null"); }
759
+    private static function ver81()
760
+    {
761
+Db::execute("alter table okapi_search_sets add column expires datetime not null"); }
762
+    private static function ver82()
763
+    {
764
+CronJobController::reset_job_schedule("FulldumpGeneratorJob"); }
765
+    private static function ver83()
766
+    {
767
+Db::execute("alter table okapi_stats_temp engine=InnoDB"); }
768
+    private static function ver84()
769
+    {
770
+Db::execute("truncate okapi_nonces;"); }
771
+    private static function ver85()
772
+    {
773
+Db::execute("alter table okapi_nonces drop primary key;"); }
774
+    private static function ver86()
775
+    {
776
+Db::execute("alter table okapi_nonces change column `key` nonce_hash varchar(32) character set utf8 collate utf8_bin not null;"); }
777
+    private static function ver87()
778
+    {
779
+Db::execute("alter table okapi_nonces add primary key (consumer_key, nonce_hash);"); }
780
+    private static function ver88()
781
+    {
782
+Db::execute("alter table okapi_consumers add column admin tinyint not null default 0;"); }
695 783
 
696 784
     private static function ver89()
697 785
     {
@@ -706,10 +794,18 @@  discard block
 block discarded – undo
706 794
         ReplicateCommon::verify_clog_consistency(true, $new_geocache_fields);
707 795
     }
708 796
 
709
-    private static function ver90() { Db::execute("alter table okapi_consumers change column admin bflags tinyint not null default 0;"); }
710
-    private static function ver91() { Db::execute("delete from okapi_tile_status"); }
711
-    private static function ver92() { Db::execute("delete from okapi_tile_caches"); }
712
-    private static function ver93() { Db::execute("alter table okapi_tile_caches add column name_crc int(10) unsigned not null default 0;"); }
797
+    private static function ver90()
798
+    {
799
+Db::execute("alter table okapi_consumers change column admin bflags tinyint not null default 0;"); }
800
+    private static function ver91()
801
+    {
802
+Db::execute("delete from okapi_tile_status"); }
803
+    private static function ver92()
804
+    {
805
+Db::execute("delete from okapi_tile_caches"); }
806
+    private static function ver93()
807
+    {
808
+Db::execute("alter table okapi_tile_caches add column name_crc int(10) unsigned not null default 0;"); }
713 809
 
714 810
     private static function ver94()
715 811
     {
Please login to merge, or discard this patch.
htdocs/okapi/views/signup.php 1 patch
Braces   +16 added lines, -18 removed lines patch added patch discarded remove patch
@@ -18,30 +18,28 @@
 block discarded – undo
18 18
 {
19 19
     public static function call()
20 20
     {
21
-        if (isset($_REQUEST['posted']))
22
-        {
21
+        if (isset($_REQUEST['posted'])) {
23 22
             $appname = isset($_REQUEST['appname']) ? $_REQUEST['appname'] : "";
24 23
             $appname = trim($appname);
25 24
             $appurl = isset($_REQUEST['appurl']) ? $_REQUEST['appurl'] : "";
26 25
             $email = isset($_REQUEST['email']) ? $_REQUEST['email'] : "";
27 26
             $accepted_terms = isset($_REQUEST['terms']) ? $_REQUEST['terms'] : "";
28 27
             $ok = false;
29
-            if (!$appname)
30
-                $notice = "Please provide a valid application name.";
31
-            elseif (mb_strlen($appname) > 100)
32
-                $notice = "Application name should be less than 100 characters long.";
33
-            elseif (mb_strlen($appurl) > 250)
34
-                $notice = "Application URL should be less than 250 characters long.";
35
-            elseif ($appurl && (substr($appurl, 0, 7) != "http://") && (substr($appurl, 0, 8) != "https://"))
36
-                $notice = "Application homepage URL should start with http(s)://. (Note: this URL is OPTIONAL and it is NOT for OAuth callback.)";
37
-            elseif (!$email)
38
-                $notice = "Please provide a valid email address.";
39
-            elseif (mb_strlen($email) > 70)
40
-                $notice = "Email address should be less than 70 characters long.";
41
-            elseif (!$accepted_terms)
42
-                $notice = "You have to read and accept OKAPI Terms of Use.";
43
-            else
44
-            {
28
+            if (!$appname) {
29
+                            $notice = "Please provide a valid application name.";
30
+            } elseif (mb_strlen($appname) > 100) {
31
+                            $notice = "Application name should be less than 100 characters long.";
32
+            } elseif (mb_strlen($appurl) > 250) {
33
+                            $notice = "Application URL should be less than 250 characters long.";
34
+            } elseif ($appurl && (substr($appurl, 0, 7) != "http://") && (substr($appurl, 0, 8) != "https://")) {
35
+                            $notice = "Application homepage URL should start with http(s)://. (Note: this URL is OPTIONAL and it is NOT for OAuth callback.)";
36
+            } elseif (!$email) {
37
+                            $notice = "Please provide a valid email address.";
38
+            } elseif (mb_strlen($email) > 70) {
39
+                            $notice = "Email address should be less than 70 characters long.";
40
+            } elseif (!$accepted_terms) {
41
+                            $notice = "You have to read and accept OKAPI Terms of Use.";
42
+            } else {
45 43
                 $ok = true;
46 44
                 Okapi::register_new_consumer($appname, $appurl, $email);
47 45
                 $notice = "Consumer Key generated successfully.\nCheck your email!";
Please login to merge, or discard this patch.
htdocs/okapi/views/method_doc.php 1 patch
Braces   +2 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,13 +22,10 @@
 block discarded – undo
22 22
         require_once($GLOBALS['rootpath'].'okapi/service_runner.php');
23 23
         require_once($GLOBALS['rootpath'].'okapi/views/menu.inc.php');
24 24
 
25
-        try
26
-        {
25
+        try {
27 26
             $method = OkapiServiceRunner::call('services/apiref/method', new OkapiInternalRequest(
28 27
                 null, null, array('name' => $methodname)));
29
-        }
30
-        catch (BadRequest $e)
31
-        {
28
+        } catch (BadRequest $e) {
32 29
             throw new Http404();
33 30
         }
34 31
         $vars = array(
Please login to merge, or discard this patch.