-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathproclaim.script.php
More file actions
executable file
·2220 lines (1965 loc) · 83.3 KB
/
proclaim.script.php
File metadata and controls
executable file
·2220 lines (1965 loc) · 83.3 KB
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
/**
* Proclaim Script install
*
* @package Proclaim
* @subpackage com_proclaim
* @copyright (C) 2026 CWM Team All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @link https://www.christianwebministries.org
* */
use CWM\Component\Proclaim\Administrator\Helper\CwmguidedtourHelper;
use CWM\Component\Proclaim\Administrator\Helper\CwmmigrationHelper;
use CWM\Component\Proclaim\Administrator\Lib\CwmscriptureMigration;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Adapter\ComponentAdapter;
use Joomla\CMS\Installer\Adapter\FileAdapter;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScript;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Session\Session;
use Joomla\Database\DatabaseInterface;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Proclaim Install Script
*
* @package Proclaim.Admin
* @since 7.0.0
*/
class com_proclaimInstallerScript extends InstallerScript
{
/**
* @var array $extensions test
*
* @since 9.0.18
*/
protected static array $extensions = [
'dom',
'gd',
'json',
'pcre',
'SimpleXML',
];
/**
* The list of extra modules and plugins to install
*
* @var array $Installation_Queue Array of Items to install
* @author CWM Team
* @since 9.0.18
*/
private static array $installActionQueue = [
// Libraries and plg_content_scripturelinks are now installed by pkg_proclaim (Joomla package).
// Only plugins/modules still bundled inside com_proclaim.zip are listed here.
// -- modules => { (folder) => { (module) => { (position), (published) } }* }*
'modules' => [
'admin' => [
'proclaimicon' => ['icon', 1],
],
'site' => [
'proclaim' => ['', 0],
'proclaim_podcast' => ['', 0],
'proclaim_youtube' => ['', 0],
],
],
// -- plugins => { (folder) => { (element) => (published) }* }*
'plugins' => [
'finder' => ['proclaim' => 1],
'schemaorg' => ['proclaim' => 1],
'system' => ['proclaim' => 1],
'task' => [
'proclaim' => 1,
],
],
];
/**
* @var string Path to MySQL files
* @since 1.5
*/
public string $filePath = '/components/com_proclaim/install/sql/updates/mysql';
/**
* The version number of the extension. Max 20 characters
*
* @var string
* @since 3.6
*/
protected $release = '10.1.0';
/**
* @var DatabaseInterface|null
*
* @since 7.2.0
*/
protected DatabaseInterface|null $dbo;
/**
* Minimum PHP version required to install the extension
*
* @var string
* @since 3.6
*/
protected $minimumPhp = '8.3.0';
/**
* Minimum Joomla! Version required to install the extension
*
* @var string
* @since 3.6
*/
protected $minimumJoomla = '5.0.0';
/**
* @var string The component's name
* @since 1.5
*/
protected $extension = 'com_proclaim';
/**
* @var object
* @since 1.5
*/
protected object $status;
/**
* Allow downgrades of your extension
*
* Use at your own risk, as if there is a change in functionality, people may wish to downgrade.
*
* @var bool
* @since 3.6
*/
protected $allowDowngrades = true;
/**
* A list of files to be deleted since version 10.0.1
*
* @var array
* @since 3.6
*/
protected $deleteFiles = [
// Media CSS files removed
'/media/com_proclaim/css/icons.css',
'/media/com_proclaim/css/icons.min.css',
'/media/com_proclaim/css/bsmImport.css',
'/media/com_proclaim/css/bsmImport.min.css',
'/media/com_proclaim/css/general.min.min.css',
'/media/com_proclaim/css/biblestudy.css.map',
// Media CSS files removed in 10.1.0
'/media/com_proclaim/css/bsms.fancybox.css',
'/media/com_proclaim/css/bsms.fancybox.min.css',
'/media/com_proclaim/css/biblestudy-debug.css',
// Media JS files removed
'/media/com_proclaim/js/bsmImport.js',
'/media/com_proclaim/js/bsmImport.min.js',
'/media/com_proclaim/js/noconflict.js',
'/media/com_proclaim/js/noconflict.min.js',
'/media/com_proclaim/js/videoswitch.js',
'/media/com_proclaim/js/videoswitch.min.js',
'/media/com_proclaim/js/jquery.mousewheel.pack.js',
'/media/com_proclaim/js/jquery.mousewheel.pack.min.js',
'/media/com_proclaim/js/cwmadmin-mediafiles-default-fileconvert-footer.js',
'/media/com_proclaim/js/cwmadmin-mediafiles-default-fileconvert-footer.min.js',
'/media/com_proclaim/js/assat.js',
'/media/com_proclaim/js/assat.min.js',
'/media/com_proclaim/js/assat.min.min.js',
'/media/com_proclaim/js/biblestudy-ui.js',
'/media/com_proclaim/js/biblestudy-ui.min.js',
'/media/com_proclaim/js/biblestudy.min.js',
'/media/com_proclaim/js/grunt-config.json',
'/media/com_proclaim/js/modernizr-config.json',
'/media/com_proclaim/js/modernizr.old.js',
'/media/com_proclaim/js/modernizr.old.min.js',
'/media/com_proclaim/js/modernizr.old.min.min.js',
// Media JS files removed in 10.1.0
'/media/com_proclaim/js/popper.min.js',
'/media/com_proclaim/js/modernizr.min.js',
// Fancybox old files (jQuery version)
'/media/com_proclaim/fancybox/jquery.fancybox.min.css',
'/media/com_proclaim/fancybox/jquery.fancybox.min.js',
// Fancybox files removed in 10.1.0 (ESM replaced with UMD)
'/media/com_proclaim/fancybox/fancybox.esm.js',
'/media/com_proclaim/fancybox/fancybox.esm.min.js',
// Legacy site files
'/components/com_proclaim/controller.php',
'/components/com_proclaim/proclaim.php',
'/components/com_proclaim/proclaim.xml',
'/components/com_proclaim/proclaimbak.php',
'/components/com_proclaim/src/Model/CwmpodcastdisplayModel.php',
'/components/com_proclaim/router.php',
// German language files for the finder plugin
'/plugins/finder/proclaim/language/de-DE/de-DE.plg_finder_biblestudy.ini',
'/plugins/finder/proclaim/language/de-DE/de-DE.plg_finder_biblestudy.sys.ini',
// Module files removed in 10.1.0
'/modules/mod_proclaim_youtube/helper.php',
// Dead helper classes removed in 10.1.0
'/administrator/components/com_proclaim/src/Helper/Cwmsearchfilters.php',
// Dead site server picker removed in 10.1.0
'/components/com_proclaim/src/Model/CwmserverslistModel.php',
'/components/com_proclaim/forms/filter_serverslist.xml',
// Dead site form XMLs (no frontend models use them) removed in 10.1.0
'/components/com_proclaim/forms/mediafile.xml',
'/components/com_proclaim/forms/message.xml',
// Bible provider files moved to lib_cwmscripture in 10.3.0
'/components/com_proclaim/src/Bible/BibleProviderInterface.php',
'/components/com_proclaim/src/Bible/AbstractBibleProvider.php',
'/components/com_proclaim/src/Bible/BiblePassageResult.php',
'/components/com_proclaim/src/Bible/BibleProviderFactory.php',
'/components/com_proclaim/src/Bible/Provider/ApiBibleProvider.php',
'/components/com_proclaim/src/Bible/Provider/GetBibleProvider.php',
'/components/com_proclaim/src/Bible/Provider/LocalProvider.php',
'/administrator/components/com_proclaim/src/Bible/BibleImporter.php',
'/administrator/components/com_proclaim/src/Helper/ScriptureReference.php',
// Scripture JS/CSS moved to lib_cwmscripture in 10.3.0
// (cwm-fetch and scripture-autocomplete stay in com_proclaim)
'/media/com_proclaim/js/bible-translations.js',
'/media/com_proclaim/js/bible-translations.min.js',
'/media/com_proclaim/js/bible-translations.min.js.gz',
'/media/com_proclaim/js/bible-translations.min.js.map',
'/media/com_proclaim/js/scripture-switcher.js',
'/media/com_proclaim/js/scripture-switcher.min.js',
'/media/com_proclaim/js/scripture-switcher.min.js.gz',
'/media/com_proclaim/js/scripture-switcher.min.js.map',
'/media/com_proclaim/js/scripture-tooltip.js',
'/media/com_proclaim/js/scripture-tooltip.min.js',
'/media/com_proclaim/js/scripture-tooltip.min.js.gz',
'/media/com_proclaim/js/scripture-tooltip.min.js.map',
'/media/com_proclaim/css/scripture-text.css',
'/media/com_proclaim/css/scripture-text.min.css',
'/media/com_proclaim/css/scripture-text.min.css.map',
'/media/com_proclaim/css/scripture-switcher.css',
'/media/com_proclaim/css/scripture-switcher.min.css',
'/media/com_proclaim/css/scripture-switcher.min.css.map',
'/media/com_proclaim/css/scripture-tooltip.css',
'/media/com_proclaim/css/scripture-tooltip.min.css',
'/media/com_proclaim/css/scripture-tooltip.min.css.map',
];
/**
* A list of folders to be deleted since version 10.0.1
*
* @var array
* @since 3.6
*/
protected $deleteFolders = [
// Media folders
'/media/com_proclaim/player',
'/media/com_proclaim/less',
'/media/com_proclaim/backup',
'/media/com_proclaim/js/plugins',
'/media/com_proclaim/js/views',
'/media/com_proclaim/js/mediafile',
// Media folders removed in 10.1.0
'/media/com_proclaim/carousel',
'/media/com_proclaim/panzoom',
// Legacy site folders
'/components/com_proclaim/views',
'/components/com_proclaim/models',
'/components/com_proclaim/helpers',
'/components/com_proclaim/lib',
'/components/com_proclaim/old info',
'/components/com_proclaim/sef_ext',
// Old CWM prefixed View folders (renamed to Cwm prefix)
'/components/com_proclaim/src/View/CWMCommentList',
'/components/com_proclaim/src/View/CWMLandingPage',
'/components/com_proclaim/src/View/CWMLatest',
'/components/com_proclaim/src/View/CWMMediaFileForm',
'/components/com_proclaim/src/View/CWMMediaFileList',
'/components/com_proclaim/src/View/CWMMessageForm',
'/components/com_proclaim/src/View/CWMMessageList',
'/components/com_proclaim/src/View/Cwmpodcastdisplay',
'/components/com_proclaim/src/View/CWMPodcastList',
'/components/com_proclaim/src/View/CWMPopUp',
'/components/com_proclaim/src/View/CWMSeriesDisplay',
'/components/com_proclaim/src/View/CWMSeriesDisplays',
'/components/com_proclaim/src/View/CWMSermon',
'/components/com_proclaim/src/View/CWMSermons',
'/components/com_proclaim/src/View/CWMServersList',
'/components/com_proclaim/src/View/Cwmserverslist',
'/components/com_proclaim/tmpl/cwmserverslist',
'/components/com_proclaim/src/View/CWMSqueezeBox',
'/components/com_proclaim/src/View/CWMTeacher',
'/components/com_proclaim/src/View/CWMTeachers',
'/components/com_proclaim/src/View/CWMTerms',
'/components/com_proclaim/src/View/CWMcommentform',
'/components/com_proclaim/src/View/Teacher',
// Old CWM prefixed tmpl folders
'/components/com_proclaim/tmpl/CWMCommentForm',
'/components/com_proclaim/tmpl/CWMCommentList',
'/components/com_proclaim/tmpl/CWMMediaFileForm',
'/components/com_proclaim/tmpl/CWMMediaFileList',
'/components/com_proclaim/tmpl/Cwmpodcastdisplay',
'/components/com_proclaim/tmpl/CWMMessageForm',
'/components/com_proclaim/tmpl/CWMMessageList',
'/components/com_proclaim/tmpl/Teacher',
// Removed plugins
'/plugins/search/biblestudysearch',
'/plugins/system/proclaimbackup',
'/plugins/system/proclaimpodcast',
// Bible provider folders moved to lib_cwmscripture in 10.3.0
'/components/com_proclaim/src/Bible/Provider',
'/components/com_proclaim/src/Bible',
'/administrator/components/com_proclaim/src/Bible',
];
/**
* A list of folders to be renamed since version 10.0.1
* Format: ['old_path' => 'new_path']
*
* @var array
* @since 10.0.2
*/
protected array $renameFolders = [
// Site View folders - CWM prefix renamed to Cwm
'/components/com_proclaim/src/View/CWMCommentList' => '/components/com_proclaim/src/View/Cwmcommentlist',
'/components/com_proclaim/src/View/CWMLandingPage' => '/components/com_proclaim/src/View/Cwmlandingpage',
'/components/com_proclaim/src/View/CWMLatest' => '/components/com_proclaim/src/View/Cwmlatest',
'/components/com_proclaim/src/View/CWMMediaFileForm' => '/components/com_proclaim/src/View/Cwmmediafileform',
'/components/com_proclaim/src/View/CWMMediaFileList' => '/components/com_proclaim/src/View/Cwmmediafilelist',
'/components/com_proclaim/src/View/CWMMessageForm' => '/components/com_proclaim/src/View/Cwmmessageform',
'/components/com_proclaim/src/View/CWMMessageList' => '/components/com_proclaim/src/View/Cwmmessagelist',
'/components/com_proclaim/src/View/CWMPodcastList' => '/components/com_proclaim/src/View/Cwmpodcastlist',
'/components/com_proclaim/src/View/CWMPopUp' => '/components/com_proclaim/src/View/Cwmpopup',
'/components/com_proclaim/src/View/CWMSeriesDisplay' => '/components/com_proclaim/src/View/Cwmseriesdisplay',
'/components/com_proclaim/src/View/CWMSeriesDisplays' => '/components/com_proclaim/src/View/Cwmseriesdisplays',
'/components/com_proclaim/src/View/CWMSermon' => '/components/com_proclaim/src/View/Cwmsermon',
'/components/com_proclaim/src/View/CWMSermons' => '/components/com_proclaim/src/View/Cwmsermons',
// CWMServersList removed — dead legacy modal picker (no frontend usage)
'/components/com_proclaim/src/View/CWMSqueezeBox' => '/components/com_proclaim/src/View/Cwmsqueezebox',
'/components/com_proclaim/src/View/CWMTeacher' => '/components/com_proclaim/src/View/Cwmteacher',
'/components/com_proclaim/src/View/CWMTeachers' => '/components/com_proclaim/src/View/Cwmteachers',
'/components/com_proclaim/src/View/CWMTerms' => '/components/com_proclaim/src/View/Cwmterms',
'/components/com_proclaim/src/View/CWMcommentform' => '/components/com_proclaim/src/View/Cwmcommentform',
'/components/com_proclaim/src/View/Teacher' => '/components/com_proclaim/src/View/Cwmteacher',
// Site tmpl folders - CWM prefix renamed to Cwm
'/components/com_proclaim/tmpl/CWMCommentForm' => '/components/com_proclaim/tmpl/Cwmcommentform',
'/components/com_proclaim/tmpl/CWMCommentList' => '/components/com_proclaim/tmpl/Cwmcommentlist',
'/components/com_proclaim/tmpl/CWMMediaFileForm' => '/components/com_proclaim/tmpl/Cwmmediafileform',
'/components/com_proclaim/tmpl/CWMMediaFileList' => '/components/com_proclaim/tmpl/Cwmmediafilelist',
'/components/com_proclaim/tmpl/CWMMessageForm' => '/components/com_proclaim/tmpl/Cwmmessageform',
'/components/com_proclaim/tmpl/CWMMessageList' => '/components/com_proclaim/tmpl/Cwmmessagelist',
'/components/com_proclaim/tmpl/Teacher' => '/components/com_proclaim/tmpl/Cwmteacher',
];
/**
* Function called before the extension installation/update/removal procedure commences
*
* @param string $type The type of change (install, update, or discover_install, not uninstall)
* @param ComponentAdapter $parent The class calling this method
*
* @return bool True on success
*
* @throws Exception
* @since 1.5
*/
public function preflight($type, $parent): bool
{
$this->setDboFromAdapter($parent);
if ($type === 'update') {
$this->ensureSchemaReady();
}
return parent::preflight($type, $parent);
}
/**
* Ensure database schema matches the currently installed version.
*
* Reads the OLD install.mysql.utf8.sql (still on disk from the
* installed version) and parses the expected columns per table.
* Compares against the live database and drops any columns that
* exist in the DB but NOT in the install SQL — these are leftovers
* from a failed partial upgrade that would cause "Duplicate column"
* errors when Joomla re-runs the migration SQL files.
*
* This restores the DB to the clean state of the installed version
* so Joomla's migration path can run without errors.
*
* @return void
*
* @since 10.2.1
*/
private function ensureSchemaReady(): void
{
// Read the CURRENTLY INSTALLED install SQL (old version, not the new package)
$installSqlPath = JPATH_ADMINISTRATOR . '/components/com_proclaim/sql/install.mysql.utf8.sql';
if (!file_exists($installSqlPath)) {
return;
}
$sql = @file_get_contents($installSqlPath);
if ($sql === false || $sql === '') {
return;
}
// Parse the install SQL to get expected columns per table
$expectedSchema = $this->parseInstallSql($sql);
if (empty($expectedSchema)) {
return;
}
$db = $this->dbo;
foreach ($expectedSchema as $table => $expectedColumns) {
if (!$this->tableExists($table)) {
continue;
}
$liveColumns = $this->getTableColumns($table);
// Find columns in the live DB that are NOT in the install SQL.
// These are leftovers from a failed partial upgrade — drop them
// so the migration SQL's ADD COLUMN won't hit "Duplicate column".
$extraColumns = array_diff($liveColumns, $expectedColumns);
foreach ($extraColumns as $column) {
try {
$db->setQuery(
'ALTER TABLE ' . $db->quoteName($table)
. ' DROP COLUMN ' . $db->quoteName($column)
);
$db->execute();
} catch (\Exception $e) {
// Ignore — column may have been dropped by concurrent request
}
}
}
// Second pass: fix columns that SHOULD exist but are missing.
// This catches bugs where a migration's schema version advanced
// but the column was never added (e.g., missing from install SQL).
$requiredFixes = [
'#__bsms_podcast' => [
'platform_links' => 'TEXT DEFAULT NULL',
],
];
foreach ($requiredFixes as $table => $columns) {
if (!$this->tableExists($table)) {
continue;
}
$liveColumns = $this->getTableColumns($table);
foreach ($columns as $column => $definition) {
if (!\in_array($column, $liveColumns, true)) {
try {
$db->setQuery(
'ALTER TABLE ' . $db->quoteName($table)
. ' ADD COLUMN ' . $db->quoteName($column) . ' ' . $definition
);
$db->execute();
} catch (\Exception $e) {
// Ignore
}
}
}
}
}
/**
* Parse install.mysql.utf8.sql to extract expected columns per table.
*
* Reads CREATE TABLE statements and extracts column names (not keys,
* constraints, or other non-column definitions).
*
* @param string $sql The full install SQL content
*
* @return array<string, array<string>> Map of table name => [column names]
*
* @since 10.2.1
*/
private function parseInstallSql(string $sql): array
{
$schema = [];
// Match CREATE TABLE blocks: table name and body inside parentheses
if (!preg_match_all(
'/CREATE\s+TABLE\s+IF\s+NOT\s+EXISTS\s+`([^`]+)`\s*\((.*?)\)\s*ENGINE/si',
$sql,
$matches,
PREG_SET_ORDER
)) {
return [];
}
foreach ($matches as $match) {
$table = $match[1];
// Ensure #__ prefix for consistency
if (!str_starts_with($table, '#__')) {
$table = '#__' . $table;
}
$body = $match[2];
// Extract column names: lines starting with `column_name` followed by a type
// Skip PRIMARY KEY, KEY, INDEX, UNIQUE, CONSTRAINT lines
$columns = [];
foreach (explode("\n", $body) as $line) {
$line = trim($line);
if ($line === '' || str_starts_with($line, '--')) {
continue;
}
// Column definitions start with `column_name` then a space and type keyword
if (preg_match('/^`([^`]+)`\s+\w/', $line)) {
$columns[] = preg_replace('/^`([^`]+)`.*/', '$1', $line);
}
}
if (!empty($columns)) {
$schema[$table] = $columns;
}
}
return $schema;
}
/**
* Get column names for a table.
*
* @param string $table Table name with #__ prefix
*
* @return array List of column names
*
* @since 10.2.1
*/
private function getTableColumns(string $table): array
{
try {
$columns = $this->dbo->getTableColumns($table);
return array_keys($columns);
} catch (\Exception $e) {
return [];
}
}
/**
* Check if a database table exists
*
* @param string $table The table name (with #__ prefix)
*
* @return bool True if table exists
*
* @since 10.0.0
*/
private function tableExists(string $table): bool
{
$table = str_replace('#__', $this->dbo->getPrefix(), $table);
try {
$tables = $this->dbo->getTableList();
return \in_array($table, $tables, true);
} catch (Exception $e) {
return false;
}
}
/**
* Find the installation path for an extension
*
* @param string $src The source directory
* @param string $type The extension type ('module' or 'plugin')
* @param string $folder The folder (client for modules, group for plugins)
* @param string $element The extension element name
*
* @return string|null The path if found, null otherwise
*
* @since 10.0.0
*/
private function findExtensionPath(string $src, string $type, string $folder, string $element): ?string
{
$prefix = $type === 'module' ? 'mod_' : 'plg_';
$subdir = $type === 'module' ? 'modules' : 'plugins';
$paths = [
"$src/$subdir/$folder/$element",
"$src/$subdir/$folder/{$prefix}$element",
"$src/$subdir/$element",
"$src/$subdir/{$prefix}$element",
];
foreach ($paths as $path) {
if (is_dir($path)) {
return $path;
}
}
return null;
}
/**
* Set the database object from the installation adapter, if possible
*
* @param InstallerAdapter|mixed $adapter The class calling this method
*
* @return void
* @since 7.2.0
*/
private function setDboFromAdapter(mixed $adapter): void
{
$this->dbo = null;
if (class_exists(InstallerAdapter::class) && ($adapter instanceof InstallerAdapter)) {
/**
* If this is Joomla 4.2+ the adapter has a protected getDatabase() method which we can access with the
* magic property $adapter->db. On Joomla 4.1 and lower, this is not available. So, we have to first figure
* out if we can actually use the magic property...
*/
try {
$refObj = new ReflectionObject($adapter);
if ($refObj->hasMethod('getDatabase')) {
$this->dbo = $adapter->db;
return;
}
} catch (Throwable $e) {
// If something breaks, we will fall through
}
}
$this->dbo = Factory::getContainer()->get(DatabaseInterface::class);
}
/**
* Uninstall rout
*
* @param FileAdapter $parent The class calling this method
*
* @return bool
*
* @throws Exception
* @since 1.5
*/
public function uninstall($parent): bool
{
// Uninstall sub-extensions
$this->uninstallSubExtensions();
// Show the post-uninstalling page
$this->renderPostUninstallation($this->status, $parent);
return true;
}
/**
* Uninstalls extensions (modules, plugins) bundled with the main extension
*
* @return void
*
* @since 9.0.18
*/
private function uninstallSubExtensions(): void
{
$this->status = new stdClass();
$this->status->modules = [];
$this->status->plugins = [];
// Libraries and plg_content_scripturelinks are managed by pkg_proclaim (Joomla package).
// Joomla's package uninstaller handles their cleanup.
// Modules uninstalling
if (!empty(self::$installActionQueue['modules'])) {
foreach (self::$installActionQueue['modules'] as $client => $modules) {
if (!empty($modules)) {
$this->uninstallModules($client, $modules);
}
}
}
// Plugins uninstalling
if (!empty(self::$installActionQueue['plugins'])) {
foreach (self::$installActionQueue['plugins'] as $group => $plugins) {
if (!empty($plugins)) {
$this->uninstallPlugins($group, $plugins);
}
}
}
}
/**
* Uninstall modules for a specific client
*
* @param string $client Client (site/admin)
* @param array $modules List of modules
*
* @return void
* @since 10.1.0
*/
private function uninstallModules(string $client, array $modules): void
{
foreach ($modules as $module => $modulePreferences) {
$element = 'mod_' . $module;
$id = $this->getExtensionId('module', $element);
if ($id) {
$installer = new Installer();
$installer->setDatabase($this->dbo);
$result = $installer->uninstall('module', $id, 1);
$this->status->modules[] = [
'name' => $element,
'client' => $client,
'result' => $result,
];
}
}
}
/**
* Uninstall plugins for a specific group
*
* @param string $group Plugin group
* @param array $plugins List of plugins
*
* @return void
* @since 10.1.0
*/
private function uninstallPlugins(string $group, array $plugins): void
{
foreach ($plugins as $plugin => $published) {
$id = $this->getExtensionId('plugin', $plugin, $group);
if ($id) {
$installer = new Installer();
$installer->setDatabase($this->dbo);
$result = $installer->uninstall('plugin', $id, 1);
$this->status->plugins[] = [
'name' => 'plg_' . $plugin,
'group' => $group,
'result' => $result,
];
}
}
}
/**
* Get extension ID
*
* @param string $type Extension type
* @param string $element Extension element
* @param string|null $folder Extension folder (optional)
*
* @return int|null
* @since 10.1.0
*/
private function getExtensionId(string $type, string $element, ?string $folder = null): ?int
{
$query = $this->dbo->getQuery(true)
->select($this->dbo->qn('extension_id'))
->from($this->dbo->qn('#__extensions'))
->where($this->dbo->qn('element') . ' = ' . $this->dbo->q($element))
->where($this->dbo->qn('type') . ' = ' . $this->dbo->q($type));
if ($folder) {
$query->where($this->dbo->qn('folder') . ' = ' . $this->dbo->q($folder));
}
$this->dbo->setQuery($query);
$result = $this->dbo->loadResult();
return $result ? (int) $result : null;
}
/**
* Render Post Uninstalling
*
* @param object $status Object of things to uninstall
* @param InstallerAdapter $parent The class calling this method
*
* @return void
*
* @since 1.7.0
*/
private function renderPostUninstallation($status, $parent): void
{
$rows = 0;
echo '<h2>' . Text::_('JBS_INS_UNINSTALL') . '</h2>
<table class="adminlist">
<thead>
<tr>
<th class="title" colspan="2">' . Text::_('JBS_INS_EXTENSION') . '</th>
<th >' . Text::_('JBS_INS_STATUS') . '</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<tr class="row0">
<td class="key" colspan="2">' . Text::_('JBS_CMN_COM_PROCLAIM') . '</td>
<td><strong style="color: green;">' . Text::_('JBS_INS_REMOVED') . '</strong></td>
</tr>';
if (!empty($status->modules)) {
?>
<tr>
<th><?php
echo Text::_('JBS_INS_MODULE'); ?></th>
<th><?php
echo Text::_('JBS_INS_CLIENT'); ?></th>
<th></th>
</tr>
<?php
foreach ($status->modules as $module) {
?>
<tr class="row<?php
echo $rows++; ?>">
<td class="key"><?php
echo $module['name']; ?></td>
<td class="key"><?php
echo ucfirst($module['client']); ?></td>
<td>
<strong style="color: <?php
echo '' . ($module['result'] ? 'green' : 'red'); ?>">
<?php
echo ' ' . ($module['result'] ? Text::_('JBS_INS_REMOVED') : Text::_(
'JBS_INS_NOT_REMOVED'
));
?>
</strong>
</td>
</tr>
<?php
}
}//end if
?>
<?php
if (!empty($status->plugins)) {
?>
<tr>
<th><?php
echo Text::_('Plugin'); ?></th>
<th><?php
echo Text::_('Group'); ?></th>
<th></th>
</tr>
<?php
foreach ($status->plugins as $plugin) {
?>
<tr class="row<?php
echo $rows++; ?>">
<td class="key"><?php
echo ucfirst($plugin['name']); ?></td>
<td class="key"><?php
echo ucfirst($plugin['group']); ?></td>
<td><strong style="color: <?php
echo '' . ($plugin['result'] ? 'green' : 'red'); ?>;">
<?php
echo '' . ($plugin['result'] ? Text::_('JBS_INS_REMOVED') : Text::_(
'JBS_INS_NOT_REMOVED'
));
?>
</strong>
</td>
</tr>
<?php
}
}//end if
echo '</tbody></table>';
}
/**
* Post Flight
*
* @param string $type The type of change (install, update, or discover_install, not uninstall)
* @param ComponentAdapter $parent The class calling this method
*
* @return void
*
* @throws Exception
* @since 1.5
*/
public function postflight(string $type, ComponentAdapter $parent): void
{
// Rename old folders before deletion (must happen before removeFiles is called)
if ($type === 'update') {
$this->renameLegacyFolders();
}
// Install subExtensions
$this->installSubExtensions($parent);
// Copy language files to the system folder
$this->copyLanguageFiles();
// Show the post-installation page
$this->renderPostInstallation($this->status, $parent);
//Remove old com_biblestudy menu items on the admin side
$this->removeBibleStudyVersion($parent);
if ($type === 'install' || $type === 'update') {
// This is a fresh install. Register for the guided tour directly.
try {
$helperPath = JPATH_ADMINISTRATOR . '/components/com_proclaim/src/Helper/CwmguidedtourHelper.php';
if (file_exists($helperPath)) {
require_once $helperPath;
$tourHelper = new CwmguidedtourHelper();
$tours = $tourHelper->registerGuidedTours();
$messages = $tourHelper->registerPostInstallMessages();
if ($tours > 0) {
Factory::getApplication()->enqueueMessage($tours . ' guided tour(s) have been installed.', 'message');
} else {
Factory::getApplication()->enqueueMessage('No new guided tours were installed.', 'notice');
}
if ($messages > 0) {
Factory::getApplication()->enqueueMessage($messages . ' post-installation message(s) have been installed.', 'message');
}
} else {
Factory::getApplication()->enqueueMessage('Guided tour helper file not found.', 'warning');
}
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage('Failed to register guided tour: ' . $e->getMessage(), 'error');
}
// Migrate legacy scripture columns to junction table
try {
$migrationPath = JPATH_ADMINISTRATOR . '/components/com_proclaim/src/Lib/CwmscriptureMigration.php';
if (file_exists($migrationPath)) {
require_once $migrationPath;
// Also require the helper dependencies
$helperDir = JPATH_ADMINISTRATOR . '/components/com_proclaim/src/Helper/';
require_once $helperDir . 'ScriptureReference.php';
require_once $helperDir . 'CwmscriptureHelper.php';
$migrated = CwmscriptureMigration::migrate();
if ($migrated > 0) {
Factory::getApplication()->enqueueMessage(
$migrated . ' study scripture reference(s) migrated to new format.',
'message'
);
}
}
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage(
'Scripture migration notice: ' . $e->getMessage(),
'warning'
);
}
// Fix legacy image paths in mediafile params (images/biblestudy/ -> media/com_proclaim/images/)
try {
CwmmigrationHelper::fixMediafileLegacyPaths();
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage(
'Mediafile path migration notice: ' . $e->getMessage(),
'warning'
);
}
// Migrate studyimage param values to thumbnailm column
try {
$this->migrateStudyImageParams();
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage(
'StudyImage migration notice: ' . $e->getMessage(),
'warning'
);
}
// Drop vestigial text/pdf columns from templates table.
// Done in PHP because ALTER TABLE DROP COLUMN is not idempotent.
$this->dropLegacyTemplateColumns();
// Migrate existing alternate link data to platform_links JSON
$this->migratePodcastAlternateLinks();