-
Notifications
You must be signed in to change notification settings - Fork 9
/
proclaim.script.php
executable file
·920 lines (832 loc) · 35.2 KB
/
proclaim.script.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
<?php
/**
* Proclaim Script install
*
* @package Proclaim
* @subpackage com_proclaim
* @copyright (C) 2007 CWM Team All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @link https://www.christianwebministries.org
* */
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\Session\Session;
use Joomla\CMS\Uri\Uri;
use Joomla\Database\DatabaseDriver;
use Joomla\Database\DatabaseInterface;
use Joomla\Filesystem\File;
// 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 = [
// -- modules => { (folder) => { (module) => { (position), (published) } }* }*
'modules' => [
'administrator' => [],
'site' => [
'proclaim' => 0,
'proclaim_podcast' => 0,
],
],
// -- plugins => { (folder) => { (element) => (published) }* }*
'plugins' => [
'finder' => ['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.0.0-alpha.240321';
/**
* @var DatabaseDriver|DatabaseInterface|null
*
* @since 7.2.0
*/
protected DatabaseDriver|null|DatabaseInterface $dbo;
/**
* Minimum PHP version required to install the extension
*
* @var string
* @since 3.6
*/
protected $minimumPhp = '8.1.0';
/**
* Minimum Joomla! Version required to install the extension
*
* @var string
* @since 3.6
*/
protected $minimumJoomla = '4.2.0';
/**
* @var string The component's name
* @since 1.5
*/
protected $extension = 'com_proclaim';
/**
* @var string
* @since 1.5
*/
protected $xml;
/**
* @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;
/**
* Function called before 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);
/**
* Find a partial string in the array
* @param array $array
*
* @return array
*
* @since 10.0
*/
function array_partial_search(array $array): array
{
$found = [];
// Loop through each item and check for a match.
foreach ($array as $string) {
// If found somewhere inside the string, add.
if (str_contains($string, 'bsms_podcast')) {
$found[] = $string;
}
}
return $found;
}
$results = $this->dbo->setQuery('SHOW TABLES')->loadColumn();
if (!empty(array_partial_search($results))) {
// Add field if missing Subtitle to series
$query = "SHOW COLUMNS FROM " . $this->dbo->quoteName('#__bsms_podcast') . " LIKE " . $this->dbo->quote('subtitle');
$this->dbo->setQuery($query);
$db = $this->dbo->loadResult();
if (empty($db)) {
$alter = "ALTER TABLE #__bsms_podcast ADD subtitle TEXT";
$this->dbo->setquery($alter);
$this->dbo->execute();
}
}
return parent::preflight($type, $parent);
}
/**
* 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('DatabaseDriver');
}
/**
* 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 = [];
// Modules uninstalling
if (count(self::$installActionQueue['modules'])) {
foreach (self::$installActionQueue['modules'] as $folder => $modules) {
if (count($modules)) {
foreach ($modules as $module => $modulePreferences) {
// Find the module ID
$sql = $this->dbo->getQuery(true)
->select($this->dbo->qn('extension_id'))
->from($this->dbo->qn('#__extensions'))
->where($this->dbo->qn('element') . ' = ' . $this->dbo->q('mod_' . $module))
->where($this->dbo->qn('type') . ' = ' . $this->dbo->q('module'));
$this->dbo->setQuery($sql);
$id = $this->dbo->loadResult();
// Uninstall the module
if ($id !== null) {
$installer = new Installer();
$result = $installer->uninstall('module', $id, 1);
$this->status->modules[] = [
'name' => 'mod_' . $module,
'client' => $folder,
'result' => $result,
];
}
}//end foreach
}//end if
}//end foreach
}//end if
// Plugins uninstalling
if (count(self::$installActionQueue['plugins'])) {
foreach (self::$installActionQueue['plugins'] as $folder => $plugins) {
if (count($plugins)) {
foreach ($plugins as $plugin => $published) {
$sql = $this->dbo->getQuery(true)
->select($this->dbo->qn('extension_id'))
->from($this->dbo->qn('#__extensions'))
->where($this->dbo->qn('type') . ' = ' . $this->dbo->q('plugin'))
->where($this->dbo->qn('element') . ' = ' . $this->dbo->q($plugin))
->where($this->dbo->qn('folder') . ' = ' . $this->dbo->q($folder));
$this->dbo->setQuery($sql);
$id = $this->dbo->loadResult();
if ($id !== null) {
$installer = new Installer();
$result = $installer->uninstall('plugin', $id, 1);
$this->status->plugins[] = [
'name' => 'plg_' . $plugin,
'group' => $folder,
'result' => $result,
];
}
}//end foreach
}//end if
}//end foreach
}//end if
}
/**
* 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 (count($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 (count($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
{
// Install subExtensions
$this->installSubextensions($parent);
// Show the post-installation page
$this->renderPostInstallation($this->status, $parent);
//Remove old com_biblestudy menu items on admin side
$this->removeBibleStudyVersion();
if ($type === 'install') {
// A redirect to a new location after the installation is completed.
$parent->getParent()->setRedirectURL(
Uri::base() .
'index.php?option=com_proclaim&view=cwminstall&task=cwminstall.browse&scanstate=start&' .
Session::getFormToken() . '=1'
);
}
}
/**
* Installs extensions (modules, plugins) bundled with the main extension
*
* @param InstallerAdapter $parent The class calling this method
*
* @return void
*
* @since 1.7.0
*/
private function installSubextensions($parent): void
{
$src = $parent->getParent()->getPath('source');
$this->status = new stdClass();
$this->status->modules = [];
$this->status->plugins = [];
// Clean up old installed language filesl
$languages = [
"en-GB.com_proclaim.ini",
"en-GB.com_proclaim.sys.ini",
"en-GB.mod_proclaim.ini",
"en-GB.mod_proclaim.sys.ini",
"en-GB.mod_proclaim_podcast.ini",
"en-GB.mod_proclaim_podcast.sys.ini",
"en-GB.plg_proclaim.ini",
"en-GB.plg_proclaim.sys.ini",
"en-GB.plg_finder_proclaim.ini",
"en-GB.plg_finder_proclaim.sys.ini"
];
foreach ($languages as $language) {
if (file_exists(JPATH_ADMINISTRATOR . "/language/en-GB/$language")) {
File::delete(JPATH_ADMINISTRATOR . "/language/en-GB/$language");
}
if (file_exists(JPATH_ROOT . "/language/en-GB/$language")) {
File::delete(JPATH_ROOT . "/language/en-GB/$language");
}
}
// Modules installation
if (count(self::$installActionQueue['modules'])) {
foreach (self::$installActionQueue['modules'] as $folder => $modules) {
if (count($modules)) {
foreach ($modules as $module => $modulePreferences) {
// Install the module
if (empty($folder)) {
$folder = 'site';
}
$path = "$src/modules/$folder/$module";
if (!is_dir($path)) {
$path = "$src/modules/$folder/mod_$module";
}
if (!is_dir($path)) {
$path = "$src/modules/$module";
}
if (!is_dir($path)) {
$path = "$src/modules/mod_$module";
}
if (!is_dir($path)) {
continue;
}
// Was the module already installed?
$sql = $this->dbo->getQuery(true)
->select('COUNT(*)')
->from('#__modules')
->where($this->dbo->qn('module') . ' = ' . $this->dbo->q('mod_' . $module));
$this->dbo->setQuery($sql);
$count = $this->dbo->loadResult();
$installer = new Installer();
$result = $installer->install($path);
$this->status->modules[] = [
'name' => 'mod_' . $module,
'client' => $folder,
'result' => $result,
];
// Modify where it's published and its published state
if (!$count) {
// A. Position and state
list($modulePosition, $modulePublished) = $modulePreferences;
if ($modulePosition === 'cwmcpanel') {
$modulePosition = 'icon';
}
$sql = $this->dbo->getQuery(true)
->update($this->dbo->qn('#__modules'))
->set($this->dbo->qn('position') . ' = ' . $this->dbo->q($modulePosition))
->where($this->dbo->qn('module') . ' = ' . $this->dbo->q('mod_' . $module));
if ($modulePublished) {
$sql->set($this->dbo->qn('published') . ' = ' . $this->dbo->q('1'));
}
$this->dbo->setQuery($sql);
$this->dbo->execute();
// B. Change the ordering of back-end modules to 1 + max ordering
if ($folder === 'administrator') {
$query = $this->dbo->getQuery(true);
$query->select('MAX(' . $this->dbo->qn('ordering') . ')')
->from($this->dbo->qn('#__modules'))
->where($this->dbo->qn('position') . '=' . $this->dbo->q($modulePosition));
$this->dbo->setQuery($query);
$position = $this->dbo->loadResult();
$position++;
$query = $this->dbo->getQuery(true);
$query->update($this->dbo->qn('#__modules'))
->set($this->dbo->qn('ordering') . ' = ' . $this->dbo->q($position))
->where($this->dbo->qn('module') . ' = ' . $this->dbo->q('mod_' . $module));
$this->dbo->setQuery($query);
$this->dbo->execute();
}
// C. Link to all pages
$query = $this->dbo->getQuery(true);
$query->select('id')
->from($this->dbo->qn('#__modules'))
->where($this->dbo->qn('module') . ' = ' . $this->dbo->q('mod_' . $module));
$this->dbo->setQuery($query);
$moduleid = $this->dbo->loadResult();
$query = $this->dbo->getQuery(true);
$query->select('*')
->from($this->dbo->qn('#__modules_menu'))
->where($this->dbo->qn('moduleid') . ' = ' . $this->dbo->q($moduleid));
$this->dbo->setQuery($query);
$assignments = $this->dbo->loadObjectList();
$isAssigned = !empty($assignments);
if (!$isAssigned) {
$o = (object)[
'moduleid' => $moduleid,
'menuid' => 0,
];
$this->dbo->insertObject('#__modules_menu', $o);
}
}//end if
}//end foreach
}//end if
}//end foreach
}//end if
// Plugin's installation
if (count(self::$installActionQueue['plugins'])) {
foreach (self::$installActionQueue['plugins'] as $folder => $plugins) {
if (count($plugins) !== 0) {
foreach ($plugins as $plugin => $published) {
$path = "$src/plugins/$folder/$plugin";
if (!is_dir($path)) {
$path = "$src/plugins/$folder/plg_$plugin";
}
if (!is_dir($path)) {
$path = "$src/plugins/$plugin";
}
if (!is_dir($path)) {
$path = "$src/plugins/plg_$plugin";
}
if (!is_dir($path)) {
continue;
}
// Was the plugin already installed?
$query = $this->dbo->getQuery(true)
->select('COUNT(*)')
->from($this->dbo->qn('#__extensions'))
->where($this->dbo->qn('element') . ' = ' . $this->dbo->q($plugin))
->where($this->dbo->qn('folder') . ' = ' . $this->dbo->q($folder));
$this->dbo->setQuery($query);
$count = $this->dbo->loadResult();
$installer = new JInstaller();
$result = $installer->install($path);
$this->status->plugins[] = [
'name' => 'plg_' . $plugin,
'group' => $folder,
'result' => $result,
];
if ($published && !$count) {
$query = $this->dbo->getQuery(true)
->update($this->dbo->qn('#__extensions'))
->set($this->dbo->qn('enabled') . ' = ' . $this->dbo->q('1'))
->where($this->dbo->qn('element') . ' = ' . $this->dbo->q($plugin))
->where($this->dbo->qn('folder') . ' = ' . $this->dbo->q($folder));
$this->dbo->setQuery($query);
$this->dbo->execute();
}
}//end foreach
}//end if
}//end foreach
}//end if
}
/**
* Renders the post-installation message
*
* @param object $status Object of things to install
* @param InstallerAdapter $parent The class calling this method
*
* @return void
* @since 1.7.0
*/
private function renderPostInstallation($status, $parent): void
{
try {
$language = Factory::getApplication()->getLanguage();
$language->load('com_proclaim', JPATH_ADMINISTRATOR . '/components/com_proclaim', 'en-GB', true);
$language->load('com_proclaim', JPATH_ADMINISTRATOR . '/components/com_proclaim', null, true);
} catch (Exception $e) {
return;
}
echo '<img src="../media/com_proclaim/images/proclaim.jpg" width="48" height="48"
alt="Proclaim"/>
<h2>Welcome to CWM Proclaim System</h2>
<table class="adminlist table" style="width: 300px;">
<thead>
<tr>
<th class="title">Extension</th>
<th class="title">Client</th>
<th class="title">' . Text::_('JBS_INS_STATUS') . '</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<tr>
<td class="key">' . Text::_('JBS_CMN_com_proclaim') . '</td>
<td class="key">Site</td>
<td><strong style="color: green;">' . Text::_('JBS_INS_INSTALLED') . '</strong></td>
</tr>';
if (count($status->modules)) {
echo "<tr>
<th>Module</th>
<th>Client</th>
<th><?php echo Text::_('JBS_INS_STATUS'); ?></th>
</tr>";
foreach ($status->modules as $module) {
echo '<tr>';
echo '<td class="key">' . $module['name'] . '</td>';
echo '<td class="key">' . ucfirst($module['client']) . '</td>';
echo '<td class="key">';
echo '<strong style="color: ' . ($module['result'] ? 'green' : 'red') . ';">';
echo ' ' . ($module['result'] ? Text::_('JBS_INS_INSTALLED') : Text::_(
'JBS_INS_NOT_INSTALLED'
)) . ' ';
echo '</strong>';
echo '</td>';
echo '</tr>';
}
}
if (count($status->plugins)) {
?>
<tr>
<th>Plugin</th>
<th>Group</th>
<th><?php
echo Text::_('JBS_INS_STATUS'); ?></th>
</tr>
<?php
foreach ($status->plugins as $plugin) {
echo '<tr>';
echo '<td class="key">' . ucfirst($plugin['name']) . '</td>';
echo '<td class="key">' . ucfirst($plugin['group']) . '</td>';
echo '<td>';
echo '<strong style="color: ' . ($plugin['result'] ? 'green' : 'red') . ';">';
echo ' ' . ($plugin['result'] ? Text::_('JBS_INS_INSTALLED') : Text::_(
'JBS_INS_NOT_INSTALLED'
)) . '';
echo '</strong>';
echo '</td>';
echo '</tr>';
}
}//end if
echo '</tbody></table>';
}
/**
* Remove left overs do to upgrade from an older Proclaim version.
*
* @return void
* @throws Exception
* @since 10.0.0
*/
private function removeBibleStudyVersion(): void
{
$menuBibleStudyStatus = false;
$comBibleStudyStatus = false;
// Get BibleStudy extension ID
$query = $this->dbo->getQuery(true);
$query->select('extension_id');
$query->from('#__extensions');
$query->where($this->dbo->quoteName('element') . ' = ' . $this->dbo->q('com_biblestudy'));
$this->dbo->setQuery($query);
$biblestudyID = (int) $this->dbo->loadResult();
if ($biblestudyID !== 0) {
// Get Proclaim extension ID
$query = $this->dbo->getQuery(true);
$query->select('extension_id');
$query->from('#__extensions');
$query->where($this->dbo->quoteName('element') . ' = ' . $this->dbo->q('com_proclaim'));
$this->dbo->setQuery($query);
$proclaimID = (int) $this->dbo->loadResult();
// Remove old com_biblestudy folders and files as we can't uninstall them
$this->deleteFolders = ['/components/com_biblestudy', '/administrator/components/com_biblestudy'];
$this->deleteFiles = ['/language/en-GB/en-GB.com_biblestudy.ini'];
$this->removefiles();
// Clean up Admin Menus form old install
$query = $this->dbo->getQuery(true);
$query->delete($this->dbo->quoteName('#__menu'));
$query->where($this->dbo->quoteName('link') . 'LIKE "%com_biblestudy%"');
// This check to make sure the menu items is from the Admin Main menu only
$query->where($this->dbo->quoteName('client_id') . ' = 1');
$query->where($this->dbo->quoteName('menutype') . ' = ' . $this->dbo->quote('main'));
$this->dbo->setQuery($query);
try {
$menuBibleStudyStatus = $this->dbo->execute();
} catch (RuntimeException $e) {
Factory::getApplication()->enqueueMessage("Failed to execute Admin Menu removal", "error");
}
// Update Site Menus for BibleStudy to Proclaim
$query = $this->dbo->getQuery(true);
$query->select('id, component_id, link');
$query->from($this->dbo->quoteName('#__menu'));
$query->where($this->dbo->quoteName('link') . 'LIKE "%com_biblestudy%"');
$query->where($this->dbo->quoteName('client_id') . ' = 0');
$this->dbo->setQuery($query);
$results = $this->dbo->loadObjectList();
foreach ($results as $result) {
$query = $this->dbo->getQuery(true);
// Fields to update.
$fields = array(
$this->dbo->quoteName('link') . ' = ' . $this->dbo->quote(str_replace("com_biblestudy&view=", "com_proclaim&view=cwm", $result->link)),
$this->dbo->quoteName('component_id') . ' = ' . $proclaimID,
);
// Conditions for which records should be updated.
$conditions = array(
$this->dbo->quoteName('id') . ' = ' . $result->id,
);
$query->update($this->dbo->quoteName('#__menu'))->set($fields)->where($conditions);
$this->dbo->setQuery($query);
$menuBibleStudyStatus = $this->dbo->execute();
}
// Update Site Modules for BibleStudy to Proclaim
$query = $this->dbo->getQuery(true);
$query->select('id, module');
$query->from($this->dbo->quoteName('#__modules'));
$query->where($this->dbo->quoteName('module') . 'LIKE "%mod_biblestudy%"');
$this->dbo->setQuery($query);
$results = $this->dbo->loadObjectList();
foreach ($results as $result) {
$query = $this->dbo->getQuery(true);
// Fields to update.
$fields = array(
$this->dbo->quoteName('module') . ' = ' . $this->dbo->quote(str_replace("mod_biblestudy", "mod_proclaim", $result->module)),
);
// Conditions for which records should be updated.
$conditions = array(
$this->dbo->quoteName('id') . ' = ' . $result->id,
);
$query->update($this->dbo->quoteName('#__modules'))->set($fields)->where($conditions);
$this->dbo->setQuery($query);
$menuBibleStudyStatus = $this->dbo->execute();
}
// Migrate Plugin Podcast to Tasks
$message = new \stdClass();
$message->title_key = 'New Scheduled Task for Podcast RSS Rile Creation'; // Language string
$message->description_key = 'You may now what to setup Podcast RSS Task to replace your old system. We could not migrate your old podcast plugin schedule'; // Language string
$message->type = 'message'; // message | action
$message->version_introduced = '10.0.0';
(new CWM\Component\Proclaim\Administrator\Model\CwminstallModel())->postInstallMessages($message);
// Migrate Plugin Backup to Tasks
$message = new \stdClass();
$message->title_key = 'New Scheduled Task for Backups'; // Language string
$message->description_key = 'You may now what to setup backups to replace your old system. We could not migrate your old backup plugin schedule'; // Language string
$message->type = 'message'; // message | action
$message->version_introduced = '10.0.0';
(new CWM\Component\Proclaim\Administrator\Model\CwminstallModel())->postInstallMessages($message);
// Delete Old stale com_biblestudy extension.
$query = $this->dbo->getQuery(true);
$query->delete($this->dbo->quoteName('#__extensions'));
$query->where($this->dbo->quoteName('element') . ' = ' . $this->dbo->q('com_biblestudy'));
$this->dbo->setQuery($query);
try {
$comBibleStudyStatus = $this->dbo->execute();
} catch (RuntimeException $e) {
Factory::getApplication()->enqueueMessage("Failed to execute com_biblestudy removal", "error");
}
// Delete Old stale pkg_biblestudy_package extension.
$query = $this->dbo->getQuery(true);
$query->delete($this->dbo->quoteName('#__extensions'));
$query->where($this->dbo->quoteName('element') . ' = ' . $this->dbo->q('pkg_biblestudy_package'));
$this->dbo->setQuery($query);
try {
$comBibleStudyStatus = $this->dbo->execute();
} catch (RuntimeException $e) {
Factory::getApplication()->enqueueMessage("Failed to execute pkg_biblestudy_package removal", "error");
}
// Reset Status info
$this->status = new stdClass();
$this->status->modules = [];
$this->status->plugins = [];
// Update Install Actions to uninstall the BibleStudy components
self::$installActionQueue = [
// -- modules => { (folder) => { (module) => { (position), (published) } }* }*
'modules' => [
'administrator' => [],
'site' => [
'biblestudy' => 0,
'biblestudy_podcast' => 0,
],
],
// -- plugins => { (folder) => { (element) => (published) }* }*
'plugins' => [
'finder' => ['biblestudy' => 0],
'search' => ['biblestudysearch' => 0,],
'system' => [
'jbspodcast' => 0,
'jbsbackup' => 0,
],
],
];
// Remove old Components
$this->uninstallSubextensions();
if (
$menuBibleStudyStatus ||
$comBibleStudyStatus ||
count($this->status->modules) ||
count($this->status->plugins)
) {
Factory::getApplication()->enqueueMessage("We have removed leftovers from Proclaim old version", "notice");
}
}
}
}