-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathupdate_routines.php
2130 lines (1630 loc) · 66.1 KB
/
update_routines.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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
/**
*
* Update routines from older e107 versions to current.
*
* Also links to plugin update routines.
*
* 2-stage process - routines identify whether update is required, and then execute as instructed.
*/
// [debug=8] shows the operations on major table update
require_once('../class2.php');
require_once(e_HANDLER.'db_table_admin_class.php');
e107::includeLan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_e107_update.php');
// Modified update routine - combines checking and update code into one block per function
// - reduces code size typically 30%.
// - keeping check and update code together should improve clarity/reduce mis-types etc
// @todo: how do we handle update of multi-language tables?
// If following line uncommented, enables a test routine
// define('TEST_UPDATE',TRUE);
$update_debug = TRUE; // TRUE gives extra messages in places
//$update_debug = TRUE; // TRUE gives extra messages in places
if (defined('TEST_UPDATE')) $update_debug = TRUE;
//if (!defined('LAN_UPDATE_8')) { define('LAN_UPDATE_8', ''); }
//if (!defined('LAN_UPDATE_9')) { define('LAN_UPDATE_9', ''); }
// Determine which installed plugins have an update file - save the path and the installed version in an array
$dbupdateplugs = array(); // Array of paths to installed plugins which have a checking routine
$dbupdatep = array(); // Array of plugin upgrade actions (similar to $dbupdate)
$dbupdate = array(); // Array of core upgrade actions
global $e107cache;
if(is_readable(e_ADMIN.'ver.php'))
{
include(e_ADMIN.'ver.php');
}
$mes = e107::getMessage();
/*
// If $dont_check_update is both defined and TRUE on entry, a check for update is done only once per 24 hours.
$dont_check_update = varset($dont_check_update, FALSE);
if ($dont_check_update === TRUE)
{
$dont_check_update = FALSE;
if ($tempData = $e107cache->retrieve_sys('nq_admin_updatecheck',3600, TRUE))
{ // See when we last checked for an admin update
list($last_time, $dont_check_update, $last_ver) = explode(',',$tempData);
if ($last_ver != $e107info['e107_version'])
{
$dont_check_update = FALSE; // Do proper check on version change
}
}
}
*/
$dont_check_update = false;
if (!$dont_check_update)
{
/*
if ($sql->db_Select('plugin', 'plugin_id, plugin_version, plugin_path', 'plugin_installflag=1'))
{
while ($row = $sql->db_Fetch())
{ // Mark plugins for update which have a specific update file, or a plugin.php file to check
if(is_readable(e_PLUGIN.$row['plugin_path'].'/'.$row['plugin_path'].'_update_check.php') || is_readable(e_PLUGIN.$row['plugin_path'].'/plugin.php') || is_readable(e_PLUGIN.$row['plugin_path'].'/'.$row['plugin_path'].'_setup.php'))
{
$dbupdateplugs[$row['plugin_path']] = $row['plugin_version'];
//TODO - Add support for {plugins}_setup.php upgrade check and routine.
}
}
}
*/
if($dbupdateplugs = e107::getConfig('core')->get('plug_installed'))
{
// Read in each update file - this will add an entry to the $dbupdatep array if a potential update exists
foreach ($dbupdateplugs as $path => $ver)
{
if(!is_file(e_PLUGIN.$path."/plugin.xml"))
{
$fname = e_PLUGIN.$path.'/'.$path.'_update_check.php'; // DEPRECATED - left for BC only.
if (is_readable($fname)) include_once($fname);
}
$fname = e_PLUGIN.$path.'/'.$path.'_setup.php';
if (is_readable($fname))
{
$dbupdatep[$path] = $path ; // ' 0.7.x forums '.LAN_UPDATE_9.' 0.8 forums';
include_once($fname);
}
}
}
// List of potential updates
if (defined('TEST_UPDATE'))
{
$dbupdate['test_code'] = 'Test update routine';
}
// set 'master' to true to prevent other upgrades from running before it is complete.
$LAN_UPDATE_4 = deftrue('LAN_UPDATE_4',"Update from [x] to [y]"); // in case language-pack hasn't been upgraded.
$LAN_UPDATE_5 = deftrue('LAN_UPDATE_5', "Core database structure");
// $dbupdate['218_to_219'] = array('master'=>false, 'title'=> e107::getParser()->lanVars($LAN_UPDATE_4, array('2.1.8','2.1.9')), 'message'=> null, 'hide_when_complete'=>true);
// $dbupdate['217_to_218'] = array('master'=>false, 'title'=> e107::getParser()->lanVars($LAN_UPDATE_4, array('2.1.7','2.1.8')), 'message'=> null, 'hide_when_complete'=>true);
$dbupdate['706_to_800'] = array('master'=>true, 'title'=> e107::getParser()->lanVars($LAN_UPDATE_4, array('1.x','2.0')), 'message'=> LAN_UPDATE_29, 'hide_when_complete'=>true);
$dbupdate['20x_to_220'] = array('master'=>true, 'title'=> e107::getParser()->lanVars($LAN_UPDATE_4, array('2.x','2.2.0')), 'message'=> null, 'hide_when_complete'=>false);
// always run these last.
$dbupdate['core_database'] = array('master'=>false, 'title'=> $LAN_UPDATE_5);
$dbupdate['core_prefs'] = array('master'=>true, 'title'=> LAN_UPDATE_13); // Prefs check
// $dbupdate['70x_to_706'] = LAN_UPDATE_8.' .70x '.LAN_UPDATE_9.' .706';
} // End if (!$dont_check_update)
// New in v2.x ------------------------------------------------
class e107Update
{
var $core = array();
var $updates = 0;
var $disabled = 0;
function __construct($core=null)
{
$mes = e107::getMessage();
$this->core = $core;
if(varset($_POST['update_core']) && is_array($_POST['update_core']))
{
$func = key($_POST['update_core']);
$this->updateCore($func);
}
if(varset($_POST['update']) && is_array($_POST['update'])) // Do plugin updates
{
$func = key($_POST['update']);
$this->updatePlugin($func);
}
// $dbv = e107::getSingleton('db_verify', e_HANDLER."db_verify_class.php");
// $dbv->clearCache();
$this->renderForm();
}
function updateCore($func='')
{
$mes = e107::getMessage();
$tp = e107::getParser();
$sql = e107::getDb();
// foreach($this->core as $func => $data)
// {
if(function_exists('update_'.$func)) // Legacy Method.
{
$installed = call_user_func("update_".$func);
//?! (LAN_UPDATE == $_POST[$func])
if(vartrue($_POST['update_core'][$func]) && !$installed)
{
if(function_exists("update_".$func))
{
// $message = LAN_UPDATE_7." ".$func;
$message = $tp->lanVars(LAN_UPDATE_7, $this->core[$func]['title']);
$error = call_user_func("update_".$func, "do");
if($error != '')
{
$mes->add($message, E_MESSAGE_ERROR);
$mes->add($error, E_MESSAGE_ERROR);
}
else
{
$mes->add($message, E_MESSAGE_SUCCESS);
e107::getCache()->clear_sys('Update_core');
}
}
}
}
else
{
$mes->addDebug("could not run 'update_".$func);
}
//}
}
function updatePlugin($path)
{
e107::getPlugin()->install_plugin_xml($path, 'upgrade');
// e107::getPlugin()->save_addon_prefs(); // Rebuild addon prefs.
e107::getMessage()->reset(E_MESSAGE_INFO);
e107::getMessage()->addSuccess(LAN_UPDATED." : ".$path);
}
function plugins()
{
if(!$list = e107::getPlugin()->updateRequired())
{
return false;
}
$frm = e107::getForm();
$tp = e107::getParser();
$text = "";
uksort($list, "strnatcasecmp");
foreach($list as $path=>$val)
{
$name = !empty($val['@attributes']['lan']) ? $tp->toHTML($val['@attributes']['lan'],false,'TITLE') : $val['@attributes']['name'];
$text .= "<tr>
<td>".$name."</td>
<td>".$frm->admin_button('update['.$path.']', LAN_UPDATE, 'warning', '', 'disabled='.$this->disabled)."</td>
</tr>";
}
return $text;
}
function core()
{
$frm = e107::getForm();
$mes = e107::getMessage();
$sql = e107::getDb();
$text = "";
foreach($this->core as $func => $data)
{
$text2 = '';
if(function_exists("update_".$func))
{
if(call_user_func("update_".$func))
{
if(empty($data['hide_when_complete']))
{
$text2 .= "<td>".$data['title']."</td>";
$text2 .= "<td>".ADMIN_TRUE_ICON."</td>";
}
}
else
{
$text2 .= "<td>".$data['title']."</td>";
if(vartrue($data['message']))
{
$mes->addInfo($data['message']);
}
$this->updates ++;
$text2 .= "<td>".$frm->admin_button('update_core['.$func.']', LAN_UPDATE, 'warning', '', "id=e-{$func}&disabled=".$this->disabled)."</td>";
if($data['master'] == true)
{
$this->disabled = 1;
}
}
if(!empty($text2))
{
$text .= "<tr>".$text2."</tr>\n";
}
}
}
return $text;
}
function renderForm()
{
$ns = e107::getRender();
$mes = e107::getMessage();
$caption = LAN_UPDATE;
$text = "
<form method='post' action='".e_ADMIN."e107_update.php'>
<fieldset id='core-e107-update'>
<legend>{$caption}</legend>
<table class='table adminlist'>
<colgroup>
<col style='width: 60%' />
<col style='width: 40%' />
</colgroup>
<thead>
<tr>
<th>".LAN_UPDATE_55."</th>
<th class='last'>".LAN_UPDATE_2."</th>
</tr>
</thead>
<tbody>
";
$text .= $this->core();
$text .= $this->plugins();
$text .= "
</tbody>
</table>
</fieldset>
</form>
";
$ns->tablerender(LAN_UPDATES,$mes->render() . $text);
}
}
/**
* Master routine to call to check for updates
*/
function update_check()
{
$ns = e107::getRender();
$e107cache = e107::getCache();
$sql = e107::getDb();
$mes = e107::getMessage();
global $dont_check_update, $e107info;
global $dbupdate, $dbupdatep, $e107cache;
$update_needed = FALSE;
if ($dont_check_update === FALSE)
{
$dbUpdatesPref = array();
$skip = e107::getPref('db_updates');
foreach($dbupdate as $func => $rmks) // See which core functions need update
{
if(!empty($skip[$func]) && (!deftrue('e_DEBUG') || E107_DBG_TIMEDETAILS)) // skip version checking when debug is off and check already done.
{
continue;
}
if(function_exists('update_' . $func))
{
e107::getDebug()->logTime('Check Core Update_' . $func . ' ');
if(!call_user_func('update_' . $func, false))
{
$dbUpdatesPref[$func] = 0;
$update_needed = true;
break;
}
elseif(strpos($func, 'core_') !==0) // skip the pref and table check.
{
$dbUpdatesPref[$func] = 1;
}
}
}
e107::getConfig()->set('db_updates', $dbUpdatesPref)->save(false,true,false);
// Now check plugins - XXX DEPRECATED
foreach($dbupdatep as $func => $rmks)
{
if(function_exists('update_' . $func))
{
// $sql->db_Mark_Time('Check Core Update_'.$func.' ');
if(!call_user_func('update_' . $func, false))
{
$update_needed = true;
break;
}
}
}
// New in v2.x
if(e107::getPlugin()->updateRequired('boolean'))
{
$update_needed = TRUE;
}
// $e107cache->set_sys('nq_admin_updatecheck', time().','.($update_needed ? '2,' : '1,').$e107info['e107_version'], TRUE);
}
else
{
$update_needed = ($dont_check_update == '2');
}
return $update_needed;
}
//XXX to be reworked eventually - for checking remote 'new versions' of plugins and installed theme.
// require_once(e_HANDLER.'e_upgrade_class.php');
// $upg = new e_upgrade;
// $upg->checkSiteTheme();
// $upg->checkAllPlugins();
//--------------------------------------------
// Check current prefs against latest list
//--------------------------------------------
function update_core_prefs($type='')
{
global $e107info; // $pref, $pref must be kept as global
$pref = e107::getConfig('core', true, true)->getPref();
$admin_log = e107::getAdminLog();
$do_save = FALSE;
$should = get_default_prefs();
$just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing if an update is needed
foreach ($should as $k => $v)
{
if ($k && !array_key_exists($k,$pref))
{
if ($just_check) return update_needed('Missing pref: '.$k);
// $pref[$k] = $v;
e107::getConfig()->set($k,$v);
$admin_log->logMessage($k.' => '.$v, E_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
$do_save = TRUE;
}
}
if ($do_save)
{
//save_prefs();
e107::getConfig('core')->save(false,true);
$admin_log->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
$admin_log->flushMessages('UPDATE_03',E_LOG_INFORMATIVE);
//e107::getLog()->add('UPDATE_03',LAN_UPDATE_14.$e107info['e107_version'].'[!br!]'.implode(', ',$accum),E_LOG_INFORMATIVE,''); // Log result of actual update
}
return $just_check;
}
if (defined('TEST_UPDATE'))
{
//--------------------------------------------
// Test routine - to activate, define TEST_UPDATE
//--------------------------------------------
function update_test_code($type='')
{
global $sql,$ns, $pref;
$just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed
//--------------**************---------------
// Add your test code in here
//--------------**************---------------
//--------------**************---------------
// End of test code
//--------------**************---------------
return $just_check;
}
} // End of test routine
// generic database structure update.
function update_core_database($type = '')
{
$just_check = ($type == 'do') ? FALSE : TRUE;
// require_once(e_HANDLER."db_verify_class.php");
// $dbv = new db_verify;
/** @var db_verify $dbv */
$dbv = e107::getSingleton('db_verify', e_HANDLER."db_verify_class.php");
$log = e107::getAdminLog();
if($plugUpgradeReq = e107::getPlugin()->updateRequired())
{
$exclude = array_keys($plugUpgradeReq); // search xxxxx_setup.php and check for 'upgrade_required()' == true.
asort($exclude);
}
else
{
$exclude = false;
}
$dbv->compareAll($exclude); // core & plugins, but not plugins calling for an update with xxxxx_setup.php
if($dbv->errors())
{
if ($just_check)
{
$mes = e107::getMessage();
// $mes->addDebug(print_a($dbv->errors,true));
$log->addDebug(print_a($dbv->errors,true));
$tables = implode(", ", array_keys($dbv->errors));
return update_needed("Database Tables require updating: <b>".$tables."</b>");
}
$dbv->compileResults();
$dbv->runFix(); // Fix entire core database structure and plugins too.
}
return $just_check;
}
/*
function update_218_to_219($type='')
{
$sql = e107::getDb();
$just_check = ($type == 'do') ? false : true;
// add common video and audio media categories if missing.
$count = $sql->select("core_media_cat","*","media_cat_category = '_common_video' LIMIT 1 ");
if(!$count)
{
if ($just_check) return update_needed('Media-Manager is missing the video and audio categories and needs to be updated.');
$sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_video', '(Common Videos)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
$sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_audio', '(Common Audio)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
}
return $just_check;
}*/
/**
* @param string $type
* @return bool true = no update required, and false if update required.
*/
/* function update_217_to_218($type='')
{
$just_check = ($type == 'do') ? false : true;
$e_user_list = e107::getPref('e_user_list');
e107::getPlug()->clearCache()->buildAddonPrefLists();
if(empty($e_user_list['user'])) // check e107_plugins/user/e_user.php is registered.
{
if($just_check)
{
return update_needed("user/e_user.php need to be registered"); // NO LAN.
}
}
// Make sure, that the pref "post_script" contains one of the allowed userclasses
// Close possible security hole
if (!array_key_exists(e107::getPref('post_script'), e107::getUserClass()->uc_required_class_list('nobody,admin,main,classes,no-excludes', true)))
{
if ($just_check)
{
return update_needed("Pref 'Class which can post < script > and similar tags' contains an invalid value"); // NO LAN.
}
else
{
e107::getConfig()->setPref('post_script', 255)->save(false, true);
}
}
return $just_check;
}*/
/**
* @param string $type
* @return bool true = no update required, and false if update required.
*/
function update_20x_to_220($type='')
{
$sql = e107::getDb();
$log = e107::getLog();
$just_check = ($type == 'do') ? false : true;
$pref = e107::getPref();
if(!$sql->select('core_media_cat', 'media_cat_id', "media_cat_category = '_icon_svg' LIMIT 1"))
{
if($just_check)
{
return update_needed("Missing Media-category for SVG");
}
$query = "INSERT INTO `#core_media_cat` (media_cat_id, media_cat_owner, media_cat_category, media_cat_title, media_cat_sef, media_cat_diz, media_cat_class, media_cat_image, media_cat_order) VALUES (NULL, '_icon', '_icon_svg', 'Icons SVG', '', 'Available where icons are used in admin.', '253', '', '0');";
$sql->gen($query);
}
if(isset($pref['e_header_list']['social']))
{
if($just_check)
{
return update_needed("Social Plugin Needs to be refreshed. ");
}
e107::getPlugin()->refresh('social');
}
if(empty($pref['themecss'])) // FIX
{
if($just_check)
{
return update_needed("Theme CSS pref value is blank.");
}
e107::getConfig()->set('themecss','style.css')->save(false,true,false);
}
// User is marked as not installed.
if($sql->select('plugin', 'plugin_id', "plugin_path = 'user' AND plugin_installflag != 1 LIMIT 1"))
{
if($just_check)
{
return update_needed("Plugin table 'user' value needs to be reset.");
}
$sql->delete('plugin', "plugin_path = 'user'");
//e107::getPlug()->clearCache();
}
// Make sure, that the pref "post_script" contains one of the allowed userclasses
// Close possible security hole
if (!array_key_exists(e107::getPref('post_script'), e107::getUserClass()->uc_required_class_list('nobody,admin,main,classes,no-excludes', true)))
{
if ($just_check)
{
return update_needed("Pref 'Class which can post < script > and similar tags' contains an invalid value"); // NO LAN.
}
else
{
e107::getConfig()->setPref('post_script', 255)->save(false, true);
}
}
// add common video and audio media categories if missing.
$count = $sql->select("core_media_cat","*","media_cat_category = '_common_video' LIMIT 1 ");
if(!$count)
{
if ($just_check) return update_needed('Media-Manager is missing the video and audio categories and needs to be updated.');
$sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_video', '(Common Videos)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
$sql->gen("INSERT INTO `".MPREFIX."core_media_cat` VALUES(0, '_common', '_common_audio', '(Common Audio)', '', 'Media in this category will be available in all areas of admin. ', 253, '', 0);");
}
return $just_check;
}
//--------------------------------------------
// Upgrade later versions of 0.7.x to 0.8
//--------------------------------------------
function update_706_to_800($type='')
{
global $pref, $e107info;
global $sysprefs, $eArrayStorage;
//$mes = new messageLog; // Combined logging and message displaying handler
//$mes = e107::getMessage();
$log = e107::getAdminLog(); // Used for combined logging and message displaying
$sql = e107::getDb();
$sql2 = e107::getDb('sql2');
$tp = e107::getParser();
$ns = e107::getRender();
e107::getCache()->clearAll('db');
e107::getCache()->clear_sys('Config');
e107::getMessage()->setUnique();
// List of unwanted $pref values which can go
$obs_prefs = array('frontpage_type','rss_feeds', 'log_lvcount', 'zone', 'upload_allowedfiletype', 'real', 'forum_user_customtitle',
'utf-compatmode','frontpage_method','standards_mode','image_owner','im_quality', 'signup_option_timezone',
'modules', 'plug_sc', 'plug_bb', 'plug_status', 'plug_latest', 'subnews_hide_news', 'upload_storagetype',
'signup_remote_emailcheck'
);
// List of DB tables not required (includes a few from 0.6xx)
$obs_tables = array('flood', 'stat_info', 'stat_counter', 'stat_last', 'session', 'preset', 'tinymce');
// List of DB tables newly required (defined in core_sql.php) (The existing dblog table gets renamed)
// No Longer required. - automatically checked against core_sql.php.
// $new_tables = array('audit_log', 'dblog', 'news_rewrite', 'core_media', 'core_media_cat','cron', 'mail_recipients', 'mail_content');
// List of core prefs that need to be converted from serialized to e107ArrayStorage.
$serialized_prefs = array("'emote'", "'menu_pref'", "'search_prefs'", "'emote_default'", "'pm_prefs'");
// List of changed DB tables (defined in core_sql.php)
// No Longer required. - automatically checked against core_sql.php.
// (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
// $changed_tables = array('user', 'dblog', 'admin_log', 'userclass_classes', 'banlist', 'menus',
// 'plugin', 'news', 'news_category', 'online', 'page', 'links', 'comments');
// List of changed DB tables from core plugins (defined in pluginname_sql.php file)
// key = plugin directory name. Data = comma-separated list of tables to check
// (primarily those which have changed significantly; for the odd field write some explicit code - it'll run faster)
// No Longer required. - automatically checked by db-verify
/* $pluginChangedTables = array('linkwords' => 'linkwords',
'featurebox' => 'featurebox',
'links_page' => 'links_page',
'poll' => 'polls',
'content' => 'pcontent'
);
*/
/*
$setCorePrefs = array( //modified prefs during upgrade.
'adminstyle' => 'infopanel',
'admintheme' => 'bootstrap',
'admincss' => 'admin_style.css',
'resize_dimensions' => array(
'news-image' => array('w' => 250, 'h' => 250),
'news-bbcode' => array('w' => 250, 'h' => 250),
'page-bbcode' => array('w' => 250, 'h' => 250)
)
);
*/
$do_save = TRUE;
// List of changed menu locations.
$changeMenuPaths = array(
array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'),
array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'),
array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'),
array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'),
array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'),
array('oldpath' => 'siteinfo_menu', 'newpath' => 'siteinfo', 'menu' => 'latestnews_menu'),
array('oldpath' => 'compliance_menu', 'newpath' => 'siteinfo', 'menu' => 'compliance_menu'),
array('oldpath' => 'powered_by_menu', 'newpath' => 'siteinfo', 'menu' => 'powered_by_menu'),
array('oldpath' => 'sitebutton_menu', 'newpath' => 'siteinfo', 'menu' => 'sitebutton_menu'),
array('oldpath' => 'counter_menu', 'newpath' => 'siteinfo', 'menu' => 'counter_menu'),
array('oldpath' => 'usertheme_menu', 'newpath' => 'user', 'menu' => 'usertheme_menu'),
array('oldpath' => 'userlanguage_menu', 'newpath' => 'user', 'menu' => 'userlanguage_menu'),
array('oldpath' => 'lastseen_menu', 'newpath' => 'online', 'menu' => 'lastseen_menu'),
array('oldpath' => 'other_news_menu', 'newpath' => 'news', 'menu' => 'other_news_menu'),
array('oldpath' => 'other_news_menu', 'newpath' => 'news', 'menu' => 'other_news2_menu'),
array('oldpath' => 'user_menu', 'newpath' => 'user', 'menu' => 'usertheme_menu'),
array('oldpath' => 'user_menu', 'newpath' => 'user', 'menu' => 'userlanguage_menu'),
array('oldpath' => 'poll_menu', 'newpath' => 'poll', 'menu' => 'poll_menu'),
array('oldpath' => 'banner_menu', 'newpath' => 'banner', 'menu' => 'banner_menu'),
array('oldpath' => 'online_menu', 'newpath' => 'online', 'menu' => 'online_menu'),
);
// List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
$ip_upgrade = array('download_requests' => 'download_request_ip',
'submitnews' => 'submitnews_ip',
'tmp' => 'tmp_ip',
'chatbox' => 'cb_ip'
);
$db_parser = new db_table_admin; // Class to read table defs and process them
$do_save = FALSE; // Set TRUE to update prefs when update complete
$updateMessages = array(); // Used to log actions for the admin log - TODO: will go once all converted to new class
$just_check = ($type == 'do') ? FALSE : TRUE; // TRUE if we're just seeing whether an update is needed
// if (!$just_check)
// {
// foreach(vartrue($setCorePrefs) as $k=>$v)
// {
// $pref[$k] = $v;
// }
// }
if (!$just_check)
{
$log->logMessage(LAN_UPDATE_14.$e107info['e107_version'], E_MESSAGE_NODISPLAY);
}
$statusTexts = array(E_MESSAGE_SUCCESS => 'Success', E_MESSAGE_ERROR => 'Fail', E_MESSAGE_INFO => 'Info');
if($pref['admintheme'] == 'bootstrap')//TODO Force an admin theme update or not?
{
if ($just_check) return update_needed('pref: Admin theme upgrade to bootstrap3 ');
$pref['admintheme'] = 'bootstrap3';
$pref['admincss'] = 'admin_dark.css';
$do_save = true;
}
// convert all serialized core prefs to e107 ArrayStorage;
$serialz_qry = "SUBSTRING( e107_value,1,5)!='array' AND e107_value !='' ";
$serialz_qry .= "AND e107_name IN (".implode(",",$serialized_prefs).") ";
if(e107::getDb()->select("core", "*", $serialz_qry))
{
if($just_check) return update_needed('Convert serialized core prefs');
while ($row = e107::getDb()->fetch())
{
$status = e107::getDb('sql2')->update('core',"e107_value=\"".convert_serialized($row['e107_value'])."\" WHERE e107_name='".$row['e107_name']."'") ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$log->addDebug(LAN_UPDATE_22.$row['e107_name'].": ". $status);
}
}
if(e107::getDb()->select("core", "*", "e107_name='pm_prefs' LIMIT 1"))
{
if ($just_check) return update_needed('Rename the pm prefs');
e107::getDb()->update("core", "e107_name='plugin_pm' WHERE e107_name = 'pm_prefs'");
}
//@TODO de-serialize the user_prefs also.
// Banlist
if(!$sql->field('banlist','banlist_id'))
{
if ($just_check) return update_needed('Banlist table requires updating.');
$sql->gen("ALTER TABLE #banlist DROP PRIMARY KEY");
$sql->gen("ALTER TABLE `#banlist` ADD `banlist_id` INT( 11 ) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
}
// Move the maximum online counts from menu prefs to a separate pref - 'history'
e107::getCache()->clear_sys('Config');
$menuConfig = e107::getConfig('menu',true,true);
if ($menuConfig->get('most_members_online') || $menuConfig->get('most_guests_online') || $menuConfig->get('most_online_datestamp'))
{
$status = E_MESSAGE_DEBUG;
if ($just_check) return update_needed('Move online counts from menupref');
$newPrefs = e107::getConfig('history');
foreach (array('most_members_online', 'most_guests_online', 'most_online_datestamp') as $v)
{
if (FALSE === $newPrefs->get($v, FALSE))
{
if (FALSE !== $menuConfig->get($v, FALSE))
{
$newPrefs->set($v,$menuConfig->get($v));
}
else
{
$newPrefs->set($v, 0);
}
}
$menuConfig->remove($v);
}
$result = $newPrefs->save(false, true, false);
if ($result === TRUE)
{
$resultMessage = 'Historic member counts updated';
$result = $menuConfig->save(false, true, false); // Only re-save if successul.
}
elseif ($result === FALSE)
{
$resultMessage = 'moving historic member counts';
$status = E_MESSAGE_ERROR;
}
else
{ // No change
$resultMessage = 'Historic member counts already updated';
$status = E_MESSAGE_INFO;
}
// $result = $menuConfig->save(false, true, false); // Save updated menuprefs - without the counts - don't delete them if it fails.
//$updateMessages[] = $statusTexts[$status].': '.$resultMessage; // Admin log message
$log->logMessage($resultMessage,$status); // User message
}
// ++++++++ Modify Menu Paths +++++++.
if(varset($changeMenuPaths))
{
foreach($changeMenuPaths as $val)
{
$qry = "SELECT menu_path FROM `#menus` WHERE menu_name = '".$val['menu']."' AND (menu_path='".$val['oldpath']."' || menu_path='".$val['oldpath']."/' ) LIMIT 1";
if($sql->gen($qry))
{
if ($just_check) return update_needed('Menu path changed required: '.$val['menu'].' ');
$updqry = "menu_path='".$val['newpath']."/' WHERE menu_name = '".$val['menu']."' AND (menu_path='".$val['oldpath']."' || menu_path='".$val['oldpath']."/' ) ";
$status = $sql->update('menus', $updqry) ? E_MESSAGE_DEBUG : E_MESSAGE_ERROR;
$log->logMessage(LAN_UPDATE_23.'<b>'.$val['menu'].'</b> : '.$val['oldpath'].' => '.$val['newpath'], $status); // LAN_UPDATE_25;
// catch_error($sql);
}
}
}
// Leave this one here.. just in case..
//delete record for online_extended_menu (now only using one online menu)
if($sql->db_Select('menus', '*', "menu_path='online_extended_menu' || menu_path='online_extended_menu/'"))
{
if ($just_check) return update_needed("The Menu table needs to have some paths corrected in its data.");