-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupgrade.php
693 lines (566 loc) · 25.8 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<?php
/**
*
* @category modules
* @package oneforall
* @author WBCE Community
* @copyright 2004-2009, Ryan Djurovich
* @copyright 2009-2010, Website Baker Org. e.V.
* @copyright 2019-, WBCE Community
* @link https://www.wbce.org/
* @license http://www.gnu.org/licenses/gpl.html
* @platform WBCE
*
*/
//Prevent this file from being accessed directly
if (defined('WB_PATH') == false) {
exit("Cannot access this file directly");
}
// Database
global $database;
// Include path
$inc_path = dirname(__FILE__);
// Get module name
require_once($inc_path.'/info.php');
// Include the config.php file (deprecated)
if (is_file($inc_path.'/config.php')) {
require_once($inc_path.'/config.php');
} else {
// No config.php then get the general settings from db
$sql = "SELECT `name`, `value` FROM `".TABLE_PREFIX."mod_".$mod_name."_general_settings`";
$query_settings = $database->query($sql);
while ($setting = $query_settings->fetchRow(MYSQLI_ASSOC)) {
// Convert setting_name to a var like $media_extensions
$var = $setting['name'];
$$var = $setting['value'];
// Convert strings to boolean
if ($setting['value'] === 'true') {
$$var = true;
} else if ($setting['value'] === 'false') {
$$var = false;
} else if ($setting['value'] === 'null') {
$$var = null;
}
}
}
// Setup styles to help id errors
echo '
<style type="text/css">
h1 {
color: #333;
margin: 60px 0 20px 0;
}
li.mod_'.$mod_name.'_step {
margin-bottom: 25px;
}
li.mod_'.$mod_name.'_step span.title {
font-weight: bold;
}
.mod_'.$mod_name.'_good {
color: green;
}
.mod_'.$mod_name.'_bad {
color: red;
}
.mod_'.$mod_name.'_ok {
color: blue;
}
.mod_'.$mod_name.'_warn {
color: orange;
}
.mod_'.$mod_name.'_conclusion {
margin-top: 60px;
padding: 15px 10px;
text-align: center;
color: blue;
border: solid 1px blue;
background-color: #DCEAFE;
}
.mod_'.$mod_name.'_error {
color: red;
border: solid 1px red;
background-color: #FFDCD9;
}
.mod_'.$mod_name.'_success {
color: green;
border: solid 1px green;
background-color: #D4FFD1;
}
.mod_'.$mod_name.'_conclusion_title {
font-weight: bold;
font-size: 14px;
margin-bottom: 5px;
}
</style>
';
// ***********************
// RENAME MODULE IF NEEDED
// ***********************
// Start
$error = 0;
$continue = true;
echo '<h1>Upgrading Module '.$module_name.' (OneForAll)</h1>';
echo '<ol>';
// Check module name for not allowed characters
if ($continue) {
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Check module name</span><br>';
if (!preg_match('/^[a-zA-Z0-9_ -]{3,20}$/', $module_name)) {
echo '<span class="mod_'.$mod_name.'_bad">Allowed characters for the module name are a-z, A-Z, 0-9, - (hyphen), _ (underscore) and spaces.<br>Min 3, max 20 characters.<br>Please change the name of your module in the <code>info.php</code> file.</span>';
$continue = false; $error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Module name "'.$module_name.'" is ok.</span>';
}
echo '</li>';
}
// Check if the module is registered in the database
if ($continue) {
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Check if the module is registered in the database</span><br>';
$query_tables = $database->query("SHOW TABLES LIKE '".TABLE_PREFIX."mod_".$mod_name."%'");
if ($query_tables->numRows() >= 5) {
echo '<span class="mod_'.$mod_name.'_good">The module "'.$module_name.'" is registered in the database.</span>';
} else {
echo '<span class="mod_'.$mod_name.'_bad">There is no module like "'.$module_name.'" registered in the database.<br>Please change the name of your module in the <code>info.php</code> file.</span>';
$continue = false; $error++;
}
echo '</li>';
}
// On manual installation rename module directory
// Old and new directory pathes
$old_dir = $inc_path;
$new_dir = WB_PATH.'/modules/'.$module_directory;
// Rename module directory only when manual installation
if ($continue && !isset($action)) {
echo '<li class="mod_'.$mod_name.'_step"><span class="title">On manual installation rename module directory</span><br>';
// Check if the name of the module directory does not exist yet
if ($old_dir != $new_dir && is_dir($new_dir)) {
echo '<span class="mod_'.$mod_name.'_bad">A module directory with the name "'.$module_directory.'" is already in use.<br>Please change the name of your module in the <code>info.php</code> file.</span>';
$continue = false; $error++;
} else {
// Rename directory
if (!rename($old_dir, $new_dir)) {
echo '<span class="mod_'.$mod_name.'_bad">'.$MESSAGE['MEDIA']['CANNOT_RENAME'].'</span>';
$continue = false; $error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Renamed module directory to "'.$module_directory.'" successfully.</span>';
}
}
echo '</li>';
}
// *****************************************
// CONVERT SOME FILES TO THE NEW MODULE NAME
// *****************************************
if ($continue && $mod_name != 'oneforall') {
// For css and js add 'mod_' to the module name
$needle = 'mod_oneforall';
$replace = 'mod_'.$mod_name;
// Convert the frontend stylesheet to the new module name
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Convert the frontend stylesheet to the new module name</span><br>';
$search_file = 'frontend.css';
$file_path = $new_dir.'/'.$search_file;
$file_contents = file_get_contents($file_path);
// Check if the file is converted yet
$num = substr_count($file_contents, $replace);
if ($num > 0) {
echo '<span class="mod_'.$mod_name.'_ok">Found <strong>'.$num.' occurrences</strong> of "'.$replace.'".<br>It seems that the file has already been converted</span><br><strong>or</strong><br><span class="mod_'.$mod_name.'_bad">id and class names in your frontend stylesheet might be inconsistent.<br>Please check the file <code>'.$search_file.'</code> manually.</span>';
} else {
$file_contents = str_replace($needle, $replace, $file_contents, $count);
// Write replaced string back to file
if (file_put_contents($file_path, $file_contents) === false) {
echo '<span class="mod_'.$mod_name.'_bad">Failed to modify the frontend stylesheet <code>'.$search_file.'</code>.<br>Please modify it manually by replacing the placeholders <code>'.$needle.'</code> by the new module name "'.$replace.'".</span>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Modified the frontend stylesheet <code>'.$search_file.'</code> successfully. Replaced "'.$needle.'" '.$count.' times.</span>';
}
}
echo '</li>';
unset($file_contents);
// Convert the backend stylesheet to the new module name
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Convert the backend stylesheet to the new module name</span><br>';
$search_file = 'backend.css';
$file_path = $new_dir.'/'.$search_file;
$file_contents = file_get_contents($file_path);
// Check if the file is converted yet
$num = substr_count($file_contents, $replace);
if ($num > 0) {
echo '<span class="mod_'.$mod_name.'_ok">Found <strong>'.$num.' occurrences</strong> of "'.$replace.'".<br>It seems that the file has already been converted</span><br><strong>or</strong><br><span class="mod_'.$mod_name.'_bad"> id and class names in your backend stylesheet might be inconsistent.<br>Please check the file <code>'.$search_file.'</code> manually.</span>';
} else {
$file_contents = str_replace($needle, $replace, $file_contents, $count);
// Write replaced string back to file
if (file_put_contents($file_path, $file_contents) === false) {
echo '<span class="mod_'.$mod_name.'_bad">Failed to modify the backend stylesheet <code>'.$search_file.'</code>.<br>Please modify it manually by replacing the placeholders <code>'.$needle.'</code> by the new module name "'.$replace.'".</span>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Modified the backend stylesheet <code>'.$search_file.'</code> successfully. Replaced "'.$needle.'" '.$count.' times.</span>';
}
}
echo '</li>';
unset($file_contents);
// Convert the backend javascript file to the new module name
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Convert the backend javascript file to the new module name</span><br>';
$search_file = 'backend.js';
$file_path = $new_dir.'/'.$search_file;
$file_contents = file_get_contents($file_path);
// Check if the file is converted yet
$num = substr_count($file_contents, $replace);
if ($num > 0) {
echo '<span class="mod_'.$mod_name.'_ok">Found <strong>'.$num.' occurrences</strong> of "'.$replace.'".<br>It seems that the file has already been converted</span><br><strong>or</strong><br><span class="mod_'.$mod_name.'_bad"> id and class names in your backend javascript file might be inconsistent.<br>Please check the file <code>'.$search_file.'</code> manually.</span>';
} else {
$file_contents = str_replace($needle, $replace, $file_contents, $count);
// Write replaced string back to file
if (file_put_contents($file_path, $file_contents) === false) {
echo '<span class="mod_'.$mod_name.'_bad">Failed to modify the backend javascript file <code>'.$search_file.'</code>.<br>Please modify it manually by replacing the placeholders <code>'.$needle.'</code> by the new module name "'.$replace.'".</span>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Modified the backend javascript file <code>'.$search_file.'</code> successfully. Replaced "'.$needle.'" '.$count.' times.</span>';
}
}
echo '</li>';
unset($file_contents);
// Convert the search file to the new module name
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Convert the search file to the new module name</span><br>';
// php file just uses the plain module name
$needle = 'oneforall';
$replace = $mod_name;
$search_file = 'search.php';
$file_path = $new_dir.'/'.$search_file;
$file_contents = file_get_contents($file_path);
// Check if the file is converted yet
$num = substr_count($file_contents, $replace);
if ($num > 0) {
echo '<span class="mod_'.$mod_name.'_ok">Found <strong>'.$num.' occurrences</strong> of "'.$replace.'".<br>It seems that the file has already been converted</span><br><strong>or</strong><br><span class="mod_'.$mod_name.'_bad"> your search file is inconsistent.<br>Please check the file <code>'.$search_file.'</code> manually.</span>';
} else {
$file_contents = str_replace($needle, $replace, $file_contents, $count);
// Write replaced string back to file
if (file_put_contents($file_path, $file_contents) === false) {
echo '<span class="mod_'.$mod_name.'_bad">Failed to modify the search file <code>'.$search_file.'</code>.<br>Please modify it manually by replacing the 2 placeholders <code>'.$needle.'</code> by the new module name "'.$replace.'".</span>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Modified the search file <code>'.$search_file.'</code> successfully. Replaced "'.$needle.'" '.$count.' times.</span>';
}
}
echo '</li>';
unset($file_contents);
}
// *******************************************
// ONEFORALL UPGRADE STARTING FROM VERSION 0.5
// *******************************************
// Modify media field path
if ($continue) {
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Modify media field path</span><br>';
$query_fields = $database->query("SELECT field_id FROM `".TABLE_PREFIX."mod_".$mod_name."_fields` WHERE type = 'media'");
if ($query_fields->numRows() > 0) {
while ($field = $query_fields->fetchRow()) {
$field_id = $field['field_id'];
$sql = "UPDATE `".TABLE_PREFIX."mod_".$mod_name."_item_fields`
SET value = REPLACE(value, '".MEDIA_DIRECTORY."', '')
WHERE value LIKE '%media%'
AND field_id = '".$field_id."'";
if ($database->query($sql)) {
echo '<span class="mod_'.$mod_name.'_good">Changed media field id='.$field_id.' paths successfully to paths not containing the media directory "'.MEDIA_DIRECTORY.'".</span>';
} else {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span>';
$error++;
}
}
} else {
echo '<span class="mod_'.$mod_name.'_ok">No media fields found. Update not needed.</span>';
}
echo '</li>';
}
// Add field 'description' to table 'items', if not exists
if ($continue) {
$table_name = TABLE_PREFIX.'mod_'.$mod_name.'_items';
$field_name = 'description';
$parameter = "TEXT NOT NULL AFTER `link`";
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Add field "'.$field_name.'" to table "'.$table_name.'"</span><br>';
// Check if field exists
if (!$database->field_exists($table_name, $field_name)) {
// Add it to the database
$database->field_add($table_name, $field_name, $parameter);
// Print error else success message
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Added field "'.$field_name.'" successfully to table "'.$table_name.'".</span>';
}
} else {
// Field already exists
echo '<span class="mod_'.$mod_name.'_ok">Field "'.$field_name.'" already exists.</span>';
}
echo '</li>';
}
// *********************************************
// ONEFORALL UPGRADE STARTING FROM VERSION 1.0.0
// *********************************************
// Add field 'scheduling' to table 'items', if not exists
if ($continue) {
$table_name = TABLE_PREFIX.'mod_'.$mod_name.'_items';
$field_name = 'scheduling';
$parameter = "VARCHAR(255) NOT NULL DEFAULT '' AFTER `active`";
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Add field "'.$field_name.'" to table "'.$table_name.'"</span><br>';
// Check if field exists
if (!$database->field_exists($table_name, $field_name)) {
// Add it to the database
$database->field_add($table_name, $field_name, $parameter);
// Print error else success message
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Added field "'.$field_name.'" successfully to table "'.$table_name.'".</span>';
}
} else {
// Field already exists
echo '<span class="mod_'.$mod_name.'_ok">Field "'.$field_name.'" already exists.</span>';
}
echo '</li>';
}
// Display only one oneforall item on detail pages even when we have multiple oneforall sections on a page
// Update all module access files and add the constant ITEM_SID (item section id)
if ($continue) {
echo '<li class="mod_'.$mod_name.'_step"><span class="title">Update all module access files and add the constant ITEM_SID (item section id)</span><br>';
// Print warning if item detail pages are disabled in the general settings
if (!$view_detail_pages) {
echo '<span class="mod_'.$mod_name.'_warn"><strong>WARNING:</strong><br>The generation of item detail pages is disabled in the general settings. Existing item access files will be deleted but not recreated.</span><br>If you need item detail pages edit the setting "View detail pages" in the general settings and run this upgrade script again.<br><br>';
}
// Get all items of this module
$sql = "SELECT i.item_id, i.section_id, i.link AS item_link,
p.page_id, p.link AS page_link
FROM `".TABLE_PREFIX."mod_".$mod_name."_items` i
INNER JOIN `".TABLE_PREFIX."sections` s
ON i.section_id = s.section_id
INNER JOIN `".TABLE_PREFIX."pages` p
ON s.page_id = p.page_id
WHERE s.module = '".$mod_name."'";
$query_items = $database->query($sql);
$num_items = $query_items->numRows();
$count_files = 0;
if ($num_items > 0) {
while ($item = $query_items->fetchRow()) {
// Item data from db
$item_id = $item['item_id'];
$section_id = $item['section_id'];
$item_link = $item['item_link'];
$page_id = $item['page_id'];
$page_link = $item['page_link'];
// Generate access file only if the item link is existing
if (!empty($item_link)) {
// Access file name and full path to the access file
$access_file = $item_link.PAGE_EXTENSION;
$full_path = WB_PATH.PAGES_DIRECTORY.$page_link.$access_file;
// Delete existing access file
if (is_writable($full_path)) {
unlink($full_path);
echo '<span class="mod_'.$mod_name.'_good">Deleted old access file "'.$access_file.'" successfully.</span><br>';
} else {
echo '<span class="mod_'.$mod_name.'_bad">Could not delete old access file "'.$access_file.'".</span><br>';
}
// Only update module access files if item detail pages are enabled in the general settings
if ($view_detail_pages) {
// The depth of the page directory in the directory hierarchy
// 'PAGES_DIRECTORY' is at depth 1
$pages_dir_depth = count(explode('/', $page_link))-1;
// Work-out how many ../'s we need to get to the index page
$index_location = '../';
for ($i = 0; $i < $pages_dir_depth; $i++) {
$index_location .= '../';
}
// Create new access file
$content = ''.
'<?php
$page_id = '.$page_id.';
$section_id = '.$section_id.';
$item_id = '.$item_id.';
$item_sid = '.$section_id.';
define("ITEM_ID", $item_id);
define("ITEM_SID", $item_sid);
require("'.$index_location.'config.php");
require(WB_PATH."/index.php");
?>';
if ($handle = fopen($full_path, 'w')) {
fwrite($handle, $content);
fclose($handle);
change_mode($full_path);
echo ' <span class="mod_'.$mod_name.'_good">Created new access file "'.$access_file.'" successfully.</span><br><br>';
$count_files++;
} else {
echo '<span class="mod_'.$mod_name.'_bad">Could not create new access file "'.$access_file.'".</span><br><br>';
$error++;
}
}
}
else {
echo '<span class="mod_'.$mod_name.'_bad">Could not create new access file for <strong>item id '.$item_id.'</strong> since there is no item link saved in the database.</span><br>This might be because the generation of item detail pages had been disabled in the general settings earlier.<br>You can fix it by <a href="'.WB_URL.'/modules/'.$mod_name.'/modify_item.php?page_id='.$page_id.'§ion_id='.$section_id.'&item_id='.$item_id.'" title="Go to the item page and re-save it manually …" target="_blank">re-saving this item manually</a>.<br><br>';
}
}
}
// Feedback about number of created access files
if ($num_items == $count_files) {
echo '<span class="mod_'.$mod_name.'_good"><strong>Created all '.$num_items.' access files successfully.</strong></span>';
} else {
echo '<span class="mod_'.$mod_name.'_ok"><strong>Created '.$count_files.' of '.$num_items.' new access files.</strong></span>';
}
}
// *********************************************
// ONEFORALL UPGRADE STARTING FROM VERSION 1.1.0
// *********************************************
// Make mysql strict compatible (TEXT NOT NULL => TEXT NULL)
// Change db engine and table charset at the same query
echo '<br><li class="mod_'.$mod_name.'_step"><span class="title">Adopt all database tables to fit mysql strict mode.</span><br>';
$sql = "ALTER TABLE `".TABLE_PREFIX."mod_".$mod_name."_fields`"
."MODIFY COLUMN `extra` TEXT NULL,"
."MODIFY COLUMN `template` TEXT NULL,"
."ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;";
$database->query($sql);
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span><br>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Altered table "'.TABLE_PREFIX.'mod_'.$mod_name.'_fields" successfully.</span><br>';
}
$sql = "ALTER TABLE `".TABLE_PREFIX."mod_".$mod_name."_images`"
."MODIFY COLUMN `caption` TEXT NULL,"
."ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;";
$database->query($sql);
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span><br>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Altered table "'.TABLE_PREFIX.'mod_'.$mod_name.'_images" successfully.</span><br>';
}
$sql = "ALTER TABLE `".TABLE_PREFIX."mod_".$mod_name."_items`"
."MODIFY COLUMN `link` TEXT NULL,"
."MODIFY COLUMN `description` TEXT NULL,"
."ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;";
$database->query($sql);
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span><br>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Altered table "'.TABLE_PREFIX.'mod_'.$mod_name.'_items" successfully.</span><br>';
}
$sql = "ALTER TABLE `".TABLE_PREFIX."mod_".$mod_name."_item_fields`"
."MODIFY COLUMN `value` TEXT NULL,"
."ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;";
$database->query($sql);
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span><br>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Altered table "'.TABLE_PREFIX.'mod_'.$mod_name.'_item_fields" successfully.</span><br>';
}
$sql = "ALTER TABLE `".TABLE_PREFIX."mod_".$mod_name."_page_settings`"
."MODIFY COLUMN `header` TEXT NULL,"
."MODIFY COLUMN `item_loop` TEXT NULL,"
."MODIFY COLUMN `footer` TEXT NULL,"
."MODIFY COLUMN `item_header` TEXT NULL,"
."MODIFY COLUMN `item_footer` TEXT NULL,"
."ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;";
$database->query($sql);
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span><br>';
$error++;
} else {
echo '<span class="mod_'.$mod_name.'_good">Altered table "'.TABLE_PREFIX.'mod_'.$mod_name.'_page_settings" successfully.</span><br>';
}
echo '</li>';
// Add general settings table
echo '<br><li class="mod_'.$mod_name.'_step"><span class="title">Create table general settings and add default settings.</span><br>';
$query_table = $database->query("SHOW TABLES LIKE '".TABLE_PREFIX."mod_".$mod_name."_general_settings'");
if ($query_table->numRows()) {
echo '<span class="mod_'.$mod_name.'_ok">Database table "'.TABLE_PREFIX.'mod_'.$mod_name.'_general_settings" exists, update not needed.</span><br />';
}
else {
$sql = "CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."mod_".$mod_name."_general_settings` ( "
."`id` INT(11) NOT NULL AUTO_INCREMENT,"
."`name` VARCHAR(100) NOT NULL,"
."`value` TEXT NULL,"
."PRIMARY KEY (`id`)"
." ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$database->query($sql);
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span><br>';
$error++;
}
else {
echo '<span class="mod_'.$mod_name.'_good">Created table "'.TABLE_PREFIX.'mod_'.$mod_name.'_general_settings" successfully.</span><br>';
}
// Add all default general settings to the new table
$general_settings = array();
$name = $value = '';
$config_file = $inc_path.'/config.php';
$default_general_settings_file = $inc_path.'/default_general_settings.php';
// Get default settings from the new default_general_settings.php file
// Note: Included module config.php already in line 32
require_once($default_general_settings_file);
// Compare new settings with existing ones from the old config.php
// Loop through all new settings
foreach ($general_settings as $name => $value) {
// This has been an array in old config.php eg. $img_resize['maxwidth']
if (in_array($name, array('imgresize', 'resize_quality', 'resize_maxwidth', 'resize_maxheight'))) {
$resize_i = str_replace('resize_', '', $name);
$$name = $img_resize[$resize_i];
}
// If old setting is available overwrite new one with old one
if (isset($$name)) {
$general_settings[$name] = $$name;
}
}
// Insert general settings into db
$unlink_config = true;
foreach ($general_settings as $name => $value) {
if ($value === true || $value === 'yes') {
$value = 'true';
} else if ($value === false) {
$value = 'false';
} else if ($value === '' || $value === null) {
$value = 'null';
}
$database->query("INSERT INTO `".TABLE_PREFIX."mod_".$mod_name."_general_settings` (`name`, `value`) VALUES ('".$name."', '".$value."')");
if ($database->is_error()) {
echo '<span class="mod_'.$mod_name.'_bad">'.$database->get_error().'</span><br>';
$unlink_config = false;
$error++;
}
else {
echo '<span class="mod_'.$mod_name.'_good">Added general setting "'.$name.'" to the new table successfully.</span><br>';
}
}
if ($unlink_config && is_file($config_file)) {
if (unlink($config_file)) {
echo '<span class="mod_'.$mod_name.'_good"><strong>Deleted "config.php" successfully. All general settings are now saved in the database.</strong></span><br>';
}
}
}
echo '</li>';
// **************************************
// STOP FOR DEBUGGING - DISPLAY ERROR LOG
// **************************************
if ($error == 0) {
$go_to = '';
$class = ' mod_'.$mod_name.'_success';
$title = 'Module '.$module_name.' upgraded successfully';
$text = 'Please check the upgrade log carefully.';
} else {
$go_to = '?advanced';
$class = ' mod_'.$mod_name.'_error';
$title = 'Error while upgrading module '.$module_name;
$text = 'Please check the upgrade log carefully and fix the reported error(s).<br><strong>Then try again using the manual execution of the module upgrade!</strong><br>See "Add-ons" > "Modules" > "Advanced" > "Execute module files manually" …';
}
?>
</ol>
<div class="mod_<?php echo $mod_name; ?>_conclusion<?php echo $class ?>">
<p class="mod_<?php echo $mod_name; ?>_conclusion_title"><?php echo $title ?></p>
<p><?php echo $text ?><br><br><strong>Save a copy for later use!</strong> Then click …</p>
<form action="">
<input type="button" value="OK" onclick="location.href='index.php<?php echo $go_to; ?>'" style="width: 30%;">
</form>
</div>
<?php
// Print admin footer
$admin->print_footer();
?>
<script language="javascript" type="text/javascript">
stop();
</script>