1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 JLoader::import('joomla.filesystem.folder');
12 JLoader::import('joomla.filesystem.file');
13 JLoader::import('joomla.installer.installer');
14 JLoader::import('joomla.utilities.date');
15
16 17 18
19 abstract class FOFUtilsInstallscript
20 {
21 22 23 24 25
26 protected $componentName = 'com_foobar';
27
28 29 30 31 32
33 protected $componentTitle = 'Foobar Component';
34
35 36 37 38 39 40
41 protected $installation_queue = array(
42
43 'modules' => array(
44 'admin' => array(),
45 'site' => array()
46 ),
47
48 'plugins' => array(
49 'system' => array(),
50 )
51 );
52
53 54 55 56 57
58 protected $uninstallation_queue = array(
59
60 'modules' => array(
61 'admin' => array(),
62 'site' => array()
63 ),
64
65 'plugins' => array(
66 'system' => array(),
67 )
68 );
69
70 71 72 73 74 75
76 protected $removeFilesFree = array(
77 'files' => array(
78
79
80 ),
81 'folders' => array(
82
83
84 )
85 );
86
87 88 89 90 91 92
93 protected $removeFilesAllVersions = array(
94 'files' => array(
95
96
97 ),
98 'folders' => array(
99
100
101 )
102 );
103
104 105 106 107 108
109 protected $cliScriptFiles = array(
110
111
112 );
113
114 115 116 117 118
119 protected $cliSourcePath = 'cli';
120
121 122 123 124 125
126 protected $fofSourcePath = 'fof';
127
128 129 130 131 132
133 protected $strapperSourcePath = 'strapper';
134
135 136 137 138 139
140 protected $modulesSourcePath = 'modules';
141
142 143 144 145 146
147 protected $pluginsSourcePath = 'plugins';
148
149 150 151 152 153 154 155
156 protected $schemaXmlPathRelative = true;
157
158 159 160 161 162 163 164
165 protected $schemaXmlPath = 'sql/xml';
166
167 168 169 170 171
172 protected $minimumPHPVersion = '5.3.3';
173
174 175 176 177 178
179 protected $minimumJoomlaVersion = '2.5.6';
180
181 182 183 184 185
186 protected $maximumJoomlaVersion = '3.9.99';
187
188 189 190 191 192
193 protected $isPaid = false;
194
195 196 197 198 199 200 201 202 203
204 protected $postInstallationMessages = array();
205
206 207 208 209 210 211 212 213 214
215 public function preflight($type, $parent)
216 {
217
218 if (!empty($this->minimumPHPVersion))
219 {
220 if (defined('PHP_VERSION'))
221 {
222 $version = PHP_VERSION;
223 }
224 elseif (function_exists('phpversion'))
225 {
226 $version = phpversion();
227 }
228 else
229 {
230 $version = '5.0.0';
231 }
232
233 if (!version_compare($version, $this->minimumPHPVersion, 'ge'))
234 {
235 $msg = "<p>You need PHP $this->minimumPHPVersion or later to install this component</p>";
236
237 if (version_compare(JVERSION, '3.0', 'gt'))
238 {
239 JLog::add($msg, JLog::WARNING, 'jerror');
240 }
241 else
242 {
243 JError::raiseWarning(100, $msg);
244 }
245
246 return false;
247 }
248 }
249
250
251 if (!empty($this->minimumJoomlaVersion) && !version_compare(JVERSION, $this->minimumJoomlaVersion, 'ge'))
252 {
253 $msg = "<p>You need Joomla! $this->minimumJoomlaVersion or later to install this component</p>";
254
255 if (version_compare(JVERSION, '3.0', 'gt'))
256 {
257 JLog::add($msg, JLog::WARNING, 'jerror');
258 }
259 else
260 {
261 JError::raiseWarning(100, $msg);
262 }
263
264 return false;
265 }
266
267
268 if (!empty($this->maximumJoomlaVersion) && !version_compare(JVERSION, $this->maximumJoomlaVersion, 'le'))
269 {
270 $msg = "<p>You need Joomla! $this->maximumJoomlaVersion or earlier to install this component</p>";
271
272 if (version_compare(JVERSION, '3.0', 'gt'))
273 {
274 JLog::add($msg, JLog::WARNING, 'jerror');
275 }
276 else
277 {
278 JError::raiseWarning(100, $msg);
279 }
280
281 return false;
282 }
283
284
285
286 if (function_exists('opcache_reset'))
287 {
288 opcache_reset();
289 }
290
291
292 if (in_array($type, array('install', 'discover_install')))
293 {
294
295 $this->bugfixDBFunctionReturnedNoError();
296 }
297 else
298 {
299
300 $this->bugfixCantBuildAdminMenus();
301 }
302
303 return true;
304 }
305
306 307 308 309 310 311 312 313
314 public function postflight($type, $parent)
315 {
316
317 $dbInstaller = new FOFDatabaseInstaller(array(
318 'dbinstaller_directory' =>
319 ($this->schemaXmlPathRelative ? JPATH_ADMINISTRATOR . '/components/' . $this->componentName : '') . '/' .
320 $this->schemaXmlPath
321 ));
322 $dbInstaller->updateSchema();
323
324
325 $status = $this->installSubextensions($parent);
326
327
328 $fofInstallationStatus = $this->installFOF($parent);
329
330
331 $strapperInstallationStatus = $this->installStrapper($parent);
332
333
334 $this->_createAdminMenus($parent);
335
336
337
338 $this->_reallyPublishAdminMenuItems($parent);
339
340
341 if ($this->isPaid)
342 {
343
344 $removeFiles = $this->removeFilesAllVersions;
345 }
346 else
347 {
348
349 $removeFiles = array('files' => array(), 'folders' => array());
350
351 if (isset($this->removeFilesAllVersions['files']))
352 {
353 if (isset($this->removeFilesFree['files']))
354 {
355 $removeFiles['files'] = array_merge($this->removeFilesAllVersions['files'], $this->removeFilesFree['files']);
356 }
357 else
358 {
359 $removeFiles['files'] = $this->removeFilesAllVersions['files'];
360 }
361 }
362 elseif (isset($this->removeFilesFree['files']))
363 {
364 $removeFiles['files'] = $this->removeFilesFree['files'];
365 }
366
367 if (isset($this->removeFilesAllVersions['folders']))
368 {
369 if (isset($this->removeFilesFree['folders']))
370 {
371 $removeFiles['folders'] = array_merge($this->removeFilesAllVersions['folders'], $this->removeFilesFree['folders']);
372 }
373 else
374 {
375 $removeFiles['folders'] = $this->removeFilesAllVersions['folders'];
376 }
377 }
378 elseif (isset($this->removeFilesFree['folders']))
379 {
380 $removeFiles['folders'] = $this->removeFilesFree['folders'];
381 }
382 }
383
384
385 $this->removeFilesAndFolders($removeFiles);
386
387
388 $this->copyCliFiles($parent);
389
390
391 $this->renderPostInstallation($status, $fofInstallationStatus, $strapperInstallationStatus, $parent);
392
393
394 $uninstall_status = $this->uninstallObsoleteSubextensions($parent);
395
396
397 $platform = FOFPlatform::getInstance();
398
399 if (method_exists($platform, 'clearCache'))
400 {
401 FOFPlatform::getInstance()->clearCache();
402 }
403
404
405 $this->_rebuildMenu();
406
407
408 $this->_applyPostInstallationMessages();
409 }
410
411 412 413 414 415
416 public function uninstall($parent)
417 {
418
419 $dbInstaller = new FOFDatabaseInstaller(array(
420 'dbinstaller_directory' =>
421 ($this->schemaXmlPathRelative ? JPATH_ADMINISTRATOR . '/components/' . $this->componentName : '') . '/' .
422 $this->schemaXmlPath
423 ));
424 $dbInstaller->removeSchema();
425
426
427 $status = $this->uninstallSubextensions($parent);
428
429
430 $this->uninstallPostInstallationMessages();
431
432
433 $this->renderPostUninstallation($status, $parent);
434 }
435
436 437 438 439 440
441 protected function copyCliFiles($parent)
442 {
443 $src = $parent->getParent()->getPath('source');
444
445 $cliPath = JPATH_ROOT . '/cli';
446
447 if (!JFolder::exists($cliPath))
448 {
449 JFolder::create($cliPath);
450 }
451
452 foreach ($this->cliScriptFiles as $script)
453 {
454 if (JFile::exists($cliPath . '/' . $script))
455 {
456 JFile::delete($cliPath . '/' . $script);
457 }
458
459 if (JFile::exists($src . '/' . $this->cliSourcePath . '/' . $script))
460 {
461 JFile::copy($src . '/' . $this->cliSourcePath . '/' . $script, $cliPath . '/' . $script);
462 }
463 }
464 }
465
466 467 468
469 protected function renderPostInstallation($status, $fofInstallationStatus, $strapperInstallationStatus, $parent)
470 {
471 $rows = 0;
472 ?>
473 <table class="adminlist table table-striped" width="100%">
474 <thead>
475 <tr>
476 <th class="title" colspan="2">Extension</th>
477 <th width="30%">Status</th>
478 </tr>
479 </thead>
480 <tfoot>
481 <tr>
482 <td colspan="3"></td>
483 </tr>
484 </tfoot>
485 <tbody>
486 <tr class="row<?php echo($rows++ % 2); ?>">
487 <td class="key" colspan="2"><?php echo $this->componentTitle ?></td>
488 <td><strong style="color: green">Installed</strong></td>
489 </tr>
490 <?php if ($fofInstallationStatus['required']): ?>
491 <tr class="row<?php echo($rows++ % 2); ?>">
492 <td class="key" colspan="2">
493 <strong>Framework on Framework (FOF) <?php echo $fofInstallationStatus['version'] ?></strong>
494 [<?php echo $fofInstallationStatus['date'] ?>]
495 </td>
496 <td><strong>
497 <span
498 style="color: <?php echo $fofInstallationStatus['required'] ? ($fofInstallationStatus['installed'] ? 'green' : 'red') : '#660' ?>; font-weight: bold;">
499 <?php echo $fofInstallationStatus['required'] ? ($fofInstallationStatus['installed'] ? 'Installed' : 'Not Installed') : 'Already up-to-date'; ?>
500 </span>
501 </strong></td>
502 </tr>
503 <?php endif; ?>
504 <?php if ($strapperInstallationStatus['required']): ?>
505 <tr class="row<?php echo($rows++ % 2); ?>">
506 <td class="key" colspan="2">
507 <strong>Akeeba Strapper <?php echo $strapperInstallationStatus['version'] ?></strong>
508 [<?php echo $strapperInstallationStatus['date'] ?>]
509 </td>
510 <td><strong>
511 <span
512 style="color: <?php echo $strapperInstallationStatus['required'] ? ($strapperInstallationStatus['installed'] ? 'green' : 'red') : '#660' ?>; font-weight: bold;">
513 <?php echo $strapperInstallationStatus['required'] ? ($strapperInstallationStatus['installed'] ? 'Installed' : 'Not Installed') : 'Already up-to-date'; ?>
514 </span>
515 </strong></td>
516 </tr>
517 <?php endif; ?>
518 <?php if (count($status->modules)) : ?>
519 <tr>
520 <th>Module</th>
521 <th>Client</th>
522 <th></th>
523 </tr>
524 <?php foreach ($status->modules as $module) : ?>
525 <tr class="row<?php echo($rows++ % 2); ?>">
526 <td class="key"><?php echo $module['name']; ?></td>
527 <td class="key"><?php echo ucfirst($module['client']); ?></td>
528 <td><strong
529 style="color: <?php echo ($module['result']) ? "green" : "red" ?>"><?php echo ($module['result']) ? 'Installed' : 'Not installed'; ?></strong>
530 </td>
531 </tr>
532 <?php endforeach; ?>
533 <?php endif; ?>
534 <?php if (count($status->plugins)) : ?>
535 <tr>
536 <th>Plugin</th>
537 <th>Group</th>
538 <th></th>
539 </tr>
540 <?php foreach ($status->plugins as $plugin) : ?>
541 <tr class="row<?php echo($rows++ % 2); ?>">
542 <td class="key"><?php echo ucfirst($plugin['name']); ?></td>
543 <td class="key"><?php echo ucfirst($plugin['group']); ?></td>
544 <td><strong
545 style="color: <?php echo ($plugin['result']) ? "green" : "red" ?>"><?php echo ($plugin['result']) ? 'Installed' : 'Not installed'; ?></strong>
546 </td>
547 </tr>
548 <?php endforeach; ?>
549 <?php endif; ?>
550 </tbody>
551 </table>
552 <?php
553 }
554
555 556 557
558 protected function renderPostUninstallation($status, $parent)
559 {
560 $rows = 1;
561 ?>
562 <table class="adminlist table table-striped" width="100%">
563 <thead>
564 <tr>
565 <th class="title" colspan="2"><?php echo JText::_('Extension'); ?></th>
566 <th width="30%"><?php echo JText::_('Status'); ?></th>
567 </tr>
568 </thead>
569 <tfoot>
570 <tr>
571 <td colspan="3"></td>
572 </tr>
573 </tfoot>
574 <tbody>
575 <tr class="row<?php echo($rows++ % 2); ?>">
576 <td class="key" colspan="2"><?php echo $this->componentTitle; ?></td>
577 <td><strong style="color: green">Removed</strong></td>
578 </tr>
579 <?php if (count($status->modules)) : ?>
580 <tr>
581 <th>Module</th>
582 <th>Client</th>
583 <th></th>
584 </tr>
585 <?php foreach ($status->modules as $module) : ?>
586 <tr class="row<?php echo($rows++ % 2); ?>">
587 <td class="key"><?php echo $module['name']; ?></td>
588 <td class="key"><?php echo ucfirst($module['client']); ?></td>
589 <td><strong
590 style="color: <?php echo ($module['result']) ? "green" : "red" ?>"><?php echo ($module['result']) ? 'Removed' : 'Not removed'; ?></strong>
591 </td>
592 </tr>
593 <?php endforeach; ?>
594 <?php endif; ?>
595 <?php if (count($status->plugins)) : ?>
596 <tr>
597 <th>Plugin</th>
598 <th>Group</th>
599 <th></th>
600 </tr>
601 <?php foreach ($status->plugins as $plugin) : ?>
602 <tr class="row<?php echo($rows++ % 2); ?>">
603 <td class="key"><?php echo ucfirst($plugin['name']); ?></td>
604 <td class="key"><?php echo ucfirst($plugin['group']); ?></td>
605 <td><strong
606 style="color: <?php echo ($plugin['result']) ? "green" : "red" ?>"><?php echo ($plugin['result']) ? 'Removed' : 'Not removed'; ?></strong>
607 </td>
608 </tr>
609 <?php endforeach; ?>
610 <?php endif; ?>
611 </tbody>
612 </table>
613 <?php
614 }
615
616 617 618
619 protected function bugfixDBFunctionReturnedNoError()
620 {
621 $db = FOFPlatform::getInstance()->getDbo();
622
623
624 $query = $db->getQuery(true);
625 $query->select('id')
626 ->from('#__assets')
627 ->where($db->qn('name') . ' = ' . $db->q($this->componentName));
628 $db->setQuery($query);
629
630 try
631 {
632 $ids = $db->loadColumn();
633 }
634 catch (Exception $exc)
635 {
636 return;
637 }
638
639 if (!empty($ids))
640 {
641 foreach ($ids as $id)
642 {
643 $query = $db->getQuery(true);
644 $query->delete('#__assets')
645 ->where($db->qn('id') . ' = ' . $db->q($id));
646 $db->setQuery($query);
647
648 try
649 {
650 $db->execute();
651 }
652 catch (Exception $exc)
653 {
654
655 }
656 }
657 }
658
659
660 $query = $db->getQuery(true);
661 $query->select('extension_id')
662 ->from('#__extensions')
663 ->where($db->qn('type') . ' = ' . $db->q('component'))
664 ->where($db->qn('element') . ' = ' . $db->q($this->componentName));
665 $db->setQuery($query);
666 $ids = $db->loadColumn();
667
668 if (!empty($ids))
669 {
670 foreach ($ids as $id)
671 {
672 $query = $db->getQuery(true);
673 $query->delete('#__extensions')
674 ->where($db->qn('extension_id') . ' = ' . $db->q($id));
675 $db->setQuery($query);
676
677 try
678 {
679 $db->execute();
680 }
681 catch (Exception $exc)
682 {
683
684 }
685 }
686 }
687
688
689 $query = $db->getQuery(true);
690 $query->select('id')
691 ->from('#__menu')
692 ->where($db->qn('type') . ' = ' . $db->q('component'))
693 ->where($db->qn('menutype') . ' = ' . $db->q('main'))
694 ->where($db->qn('link') . ' LIKE ' . $db->q('index.php?option=' . $this->componentName));
695 $db->setQuery($query);
696 $ids = $db->loadColumn();
697
698 if (!empty($ids))
699 {
700 foreach ($ids as $id)
701 {
702 $query = $db->getQuery(true);
703 $query->delete('#__menu')
704 ->where($db->qn('id') . ' = ' . $db->q($id));
705 $db->setQuery($query);
706
707 try
708 {
709 $db->execute();
710 }
711 catch (Exception $exc)
712 {
713
714 }
715 }
716 }
717 }
718
719 720 721
722 protected function ()
723 {
724 $db = FOFPlatform::getInstance()->getDbo();
725
726
727 $query = $db->getQuery(true);
728 $query->select('extension_id')
729 ->from('#__extensions')
730 ->where($db->qn('type') . ' = ' . $db->q('component'))
731 ->where($db->qn('element') . ' = ' . $db->q($this->componentName));
732 $db->setQuery($query);
733
734 try
735 {
736 $ids = $db->loadColumn();
737 }
738 catch (Exception $exc)
739 {
740 return;
741 }
742
743
744 if (count($ids) > 1)
745 {
746 asort($ids);
747 $extension_id = array_shift($ids);
748
749 foreach ($ids as $id)
750 {
751 $query = $db->getQuery(true);
752 $query->delete('#__extensions')
753 ->where($db->qn('extension_id') . ' = ' . $db->q($id));
754 $db->setQuery($query);
755
756 try
757 {
758 $db->execute();
759 }
760 catch (Exception $exc)
761 {
762
763 }
764 }
765 }
766
767
768 $query = $db->getQuery(true);
769 $query->select('id')
770 ->from('#__assets')
771 ->where($db->qn('name') . ' = ' . $db->q($this->componentName));
772 $db->setQuery($query);
773 $ids = $db->loadObjectList();
774
775 if (count($ids) > 1)
776 {
777 asort($ids);
778 $asset_id = array_shift($ids);
779
780 foreach ($ids as $id)
781 {
782 $query = $db->getQuery(true);
783 $query->delete('#__assets')
784 ->where($db->qn('id') . ' = ' . $db->q($id));
785 $db->setQuery($query);
786
787 try
788 {
789 $db->execute();
790 }
791 catch (Exception $exc)
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 protected function installSubextensions($parent)
877 {
878 $src = $parent->getParent()->getPath('source');
879
880 $db = FOFPlatform::getInstance()->getDbo();;
881
882 $status = new JObject();
883 $status->modules = array();
884 $status->plugins = array();
885
886
887 if (isset($this->installation_queue['modules']) && count($this->installation_queue['modules']))
888 {
889 foreach ($this->installation_queue['modules'] as $folder => $modules)
890 {
891 if (count($modules))
892 {
893 foreach ($modules as $module => $modulePreferences)
894 {
895
896 if (empty($folder))
897 {
898 $folder = 'site';
899 }
900
901 $path = "$src/" . $this->modulesSourcePath . "/$folder/$module";
902
903 if (!is_dir($path))
904 {
905 $path = "$src/" . $this->modulesSourcePath . "/$folder/mod_$module";
906 }
907
908 if (!is_dir($path))
909 {
910 $path = "$src/" . $this->modulesSourcePath . "/$module";
911 }
912
913 if (!is_dir($path))
914 {
915 $path = "$src/" . $this->modulesSourcePath . "/mod_$module";
916 }
917
918 if (!is_dir($path))
919 {
920 continue;
921 }
922
923
924 $sql = $db->getQuery(true)
925 ->select('COUNT(*)')
926 ->from('#__modules')
927 ->where($db->qn('module') . ' = ' . $db->q('mod_' . $module));
928 $db->setQuery($sql);
929
930 try
931 {
932 $count = $db->loadResult();
933 }
934 catch (Exception $exc)
935 {
936 $count = 0;
937 }
938
939 $installer = new JInstaller;
940 $result = $installer->install($path);
941 $status->modules[] = array(
942 'name' => 'mod_' . $module,
943 'client' => $folder,
944 'result' => $result
945 );
946
947
948 if (!$count)
949 {
950
951 list($modulePosition, $modulePublished) = $modulePreferences;
952
953 $sql = $db->getQuery(true)
954 ->update($db->qn('#__modules'))
955 ->set($db->qn('position') . ' = ' . $db->q($modulePosition))
956 ->where($db->qn('module') . ' = ' . $db->q('mod_' . $module));
957
958 if ($modulePublished)
959 {
960 $sql->set($db->qn('published') . ' = ' . $db->q('1'));
961 }
962
963 $db->setQuery($sql);
964
965 try
966 {
967 $db->execute();
968 }
969 catch (Exception $exc)
970 {
971
972 }
973
974
975 if ($folder == 'admin')
976 {
977 try
978 {
979 $query = $db->getQuery(true);
980 $query->select('MAX(' . $db->qn('ordering') . ')')
981 ->from($db->qn('#__modules'))
982 ->where($db->qn('position') . '=' . $db->q($modulePosition));
983 $db->setQuery($query);
984 $position = $db->loadResult();
985 $position++;
986
987 $query = $db->getQuery(true);
988 $query->update($db->qn('#__modules'))
989 ->set($db->qn('ordering') . ' = ' . $db->q($position))
990 ->where($db->qn('module') . ' = ' . $db->q('mod_' . $module));
991 $db->setQuery($query);
992 $db->execute();
993 }
994 catch (Exception $exc)
995 {
996
997 }
998 }
999
1000
1001 try
1002 {
1003 $query = $db->getQuery(true);
1004 $query->select('id')->from($db->qn('#__modules'))
1005 ->where($db->qn('module') . ' = ' . $db->q('mod_' . $module));
1006 $db->setQuery($query);
1007 $moduleid = $db->loadResult();
1008
1009 $query = $db->getQuery(true);
1010 $query->select('*')->from($db->qn('#__modules_menu'))
1011 ->where($db->qn('moduleid') . ' = ' . $db->q($moduleid));
1012 $db->setQuery($query);
1013 $assignments = $db->loadObjectList();
1014 $isAssigned = !empty($assignments);
1015
1016 if (!$isAssigned)
1017 {
1018 $o = (object)array(
1019 'moduleid' => $moduleid,
1020 'menuid' => 0
1021 );
1022 $db->insertObject('#__modules_menu', $o);
1023 }
1024 }
1025 catch (Exception $exc)
1026 {
1027
1028 }
1029 }
1030 }
1031 }
1032 }
1033 }
1034
1035
1036 if (isset($this->installation_queue['plugins']) && count($this->installation_queue['plugins']))
1037 {
1038 foreach ($this->installation_queue['plugins'] as $folder => $plugins)
1039 {
1040 if (count($plugins))
1041 {
1042 foreach ($plugins as $plugin => $published)
1043 {
1044 $path = "$src/" . $this->pluginsSourcePath . "/$folder/$plugin";
1045
1046 if (!is_dir($path))
1047 {
1048 $path = "$src/" . $this->pluginsSourcePath . "/$folder/plg_$plugin";
1049 }
1050
1051 if (!is_dir($path))
1052 {
1053 $path = "$src/" . $this->pluginsSourcePath . "/$plugin";
1054 }
1055
1056 if (!is_dir($path))
1057 {
1058 $path = "$src/" . $this->pluginsSourcePath . "/plg_$plugin";
1059 }
1060
1061 if (!is_dir($path))
1062 {
1063 continue;
1064 }
1065
1066
1067 $query = $db->getQuery(true)
1068 ->select('COUNT(*)')
1069 ->from($db->qn('#__extensions'))
1070 ->where($db->qn('element') . ' = ' . $db->q($plugin))
1071 ->where($db->qn('folder') . ' = ' . $db->q($folder));
1072 $db->setQuery($query);
1073
1074 try
1075 {
1076 $count = $db->loadResult();
1077 }
1078 catch (Exception $exc)
1079 {
1080 $count = 0;
1081 }
1082
1083 $installer = new JInstaller;
1084 $result = $installer->install($path);
1085
1086 $status->plugins[] = array('name' => 'plg_' . $plugin, 'group' => $folder, 'result' => $result);
1087
1088 if ($published && !$count)
1089 {
1090 $query = $db->getQuery(true)
1091 ->update($db->qn('#__extensions'))
1092 ->set($db->qn('enabled') . ' = ' . $db->q('1'))
1093 ->where($db->qn('element') . ' = ' . $db->q($plugin))
1094 ->where($db->qn('folder') . ' = ' . $db->q($folder));
1095 $db->setQuery($query);
1096
1097 try
1098 {
1099 $db->execute();
1100 }
1101 catch (Exception $exc)
1102 {
1103
1104 }
1105 }
1106 }
1107 }
1108 }
1109 }
1110
1111
1112 FOFUtilsCacheCleaner::clearPluginsAndModulesCache();
1113
1114 return $status;
1115 }
1116
1117 1118 1119 1120 1121 1122 1123
1124 protected function uninstallSubextensions($parent)
1125 {
1126 $db = FOFPlatform::getInstance()->getDbo();
1127
1128 $status = new stdClass();
1129 $status->modules = array();
1130 $status->plugins = array();
1131
1132 $src = $parent->getParent()->getPath('source');
1133
1134
1135 if (isset($this->installation_queue['modules']) && count($this->installation_queue['modules']))
1136 {
1137 foreach ($this->installation_queue['modules'] as $folder => $modules)
1138 {
1139 if (count($modules))
1140 {
1141 foreach ($modules as $module => $modulePreferences)
1142 {
1143
1144 $sql = $db->getQuery(true)
1145 ->select($db->qn('extension_id'))
1146 ->from($db->qn('#__extensions'))
1147 ->where($db->qn('element') . ' = ' . $db->q('mod_' . $module))
1148 ->where($db->qn('type') . ' = ' . $db->q('module'));
1149 $db->setQuery($sql);
1150
1151 try
1152 {
1153 $id = $db->loadResult();
1154 }
1155 catch (Exception $exc)
1156 {
1157 $id = 0;
1158 }
1159
1160
1161 if ($id)
1162 {
1163 $installer = new JInstaller;
1164 $result = $installer->uninstall('module', $id, 1);
1165 $status->modules[] = array(
1166 'name' => 'mod_' . $module,
1167 'client' => $folder,
1168 'result' => $result
1169 );
1170 }
1171 }
1172 }
1173 }
1174 }
1175
1176
1177 if (isset($this->installation_queue['plugins']) && count($this->installation_queue['plugins']))
1178 {
1179 foreach ($this->installation_queue['plugins'] as $folder => $plugins)
1180 {
1181 if (count($plugins))
1182 {
1183 foreach ($plugins as $plugin => $published)
1184 {
1185 $sql = $db->getQuery(true)
1186 ->select($db->qn('extension_id'))
1187 ->from($db->qn('#__extensions'))
1188 ->where($db->qn('type') . ' = ' . $db->q('plugin'))
1189 ->where($db->qn('element') . ' = ' . $db->q($plugin))
1190 ->where($db->qn('folder') . ' = ' . $db->q($folder));
1191 $db->setQuery($sql);
1192
1193 try
1194 {
1195 $id = $db->loadResult();
1196 }
1197 catch (Exception $exc)
1198 {
1199 $id = 0;
1200 }
1201
1202 if ($id)
1203 {
1204 $installer = new JInstaller;
1205 $result = $installer->uninstall('plugin', $id, 1);
1206 $status->plugins[] = array(
1207 'name' => 'plg_' . $plugin,
1208 'group' => $folder,
1209 'result' => $result
1210 );
1211 }
1212 }
1213 }
1214 }
1215 }
1216
1217
1218 FOFUtilsCacheCleaner::clearPluginsAndModulesCache();
1219
1220 return $status;
1221 }
1222
1223 1224 1225 1226 1227
1228 protected function removeFilesAndFolders($removeList)
1229 {
1230
1231 if (isset($removeList['files']) && !empty($removeList['files']))
1232 {
1233 foreach ($removeList['files'] as $file)
1234 {
1235 $f = JPATH_ROOT . '/' . $file;
1236
1237 if (!JFile::exists($f))
1238 {
1239 continue;
1240 }
1241
1242 JFile::delete($f);
1243 }
1244 }
1245
1246
1247 if (isset($removeList['folders']) && !empty($removeList['folders']))
1248 {
1249 foreach ($removeList['folders'] as $folder)
1250 {
1251 $f = JPATH_ROOT . '/' . $folder;
1252
1253 if (!JFolder::exists($f))
1254 {
1255 continue;
1256 }
1257
1258 JFolder::delete($f);
1259 }
1260 }
1261 }
1262
1263 1264 1265 1266 1267 1268 1269
1270 protected function installFOF($parent)
1271 {
1272
1273 $src = $parent->getParent()->getPath('source');
1274 $source = $src . '/' . $this->fofSourcePath;
1275
1276 if (!JFolder::exists($source))
1277 {
1278 return array(
1279 'required' => false,
1280 'installed' => false,
1281 'version' => '0.0.0',
1282 'date' => '2011-01-01',
1283 );
1284 }
1285
1286
1287 if (!defined('JPATH_LIBRARIES'))
1288 {
1289 $target = JPATH_ROOT . '/libraries/f0f';
1290 }
1291 else
1292 {
1293 $target = JPATH_LIBRARIES . '/f0f';
1294 }
1295
1296
1297 $haveToInstallFOF = false;
1298
1299 if (!JFolder::exists($target))
1300 {
1301
1302 $haveToInstallFOF = true;
1303 }
1304 else
1305 {
1306
1307 $fofVersion = array();
1308
1309 if (JFile::exists($target . '/version.txt'))
1310 {
1311 $rawData = JFile::read($target . '/version.txt');
1312 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1313 $info = explode("\n", $rawData);
1314 $fofVersion['installed'] = array(
1315 'version' => trim($info[0]),
1316 'date' => new JDate(trim($info[1]))
1317 );
1318 }
1319 else
1320 {
1321 $fofVersion['installed'] = array(
1322 'version' => '0.0',
1323 'date' => new JDate('2011-01-01')
1324 );
1325 }
1326
1327 $rawData = @file_get_contents($source . '/version.txt');
1328 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1329 $info = explode("\n", $rawData);
1330
1331 $fofVersion['package'] = array(
1332 'version' => trim($info[0]),
1333 'date' => new JDate(trim($info[1]))
1334 );
1335
1336 $haveToInstallFOF = $fofVersion['package']['date']->toUNIX() > $fofVersion['installed']['date']->toUNIX();
1337 }
1338
1339 $installedFOF = false;
1340
1341 if ($haveToInstallFOF)
1342 {
1343 $versionSource = 'package';
1344 $installer = new JInstaller;
1345 $installedFOF = $installer->install($source);
1346 }
1347 else
1348 {
1349 $versionSource = 'installed';
1350 }
1351
1352 if (!isset($fofVersion))
1353 {
1354 $fofVersion = array();
1355
1356 if (JFile::exists($target . '/version.txt'))
1357 {
1358 $rawData = @file_get_contents($source . '/version.txt');
1359 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1360 $info = explode("\n", $rawData);
1361 $fofVersion['installed'] = array(
1362 'version' => trim($info[0]),
1363 'date' => new JDate(trim($info[1]))
1364 );
1365 }
1366 else
1367 {
1368 $fofVersion['installed'] = array(
1369 'version' => '0.0',
1370 'date' => new JDate('2011-01-01')
1371 );
1372 }
1373
1374 $rawData = @file_get_contents($source . '/version.txt');
1375 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1376 $info = explode("\n", $rawData);
1377
1378 $fofVersion['package'] = array(
1379 'version' => trim($info[0]),
1380 'date' => new JDate(trim($info[1]))
1381 );
1382
1383 $versionSource = 'installed';
1384 }
1385
1386 if (!($fofVersion[$versionSource]['date'] instanceof JDate))
1387 {
1388 $fofVersion[$versionSource]['date'] = new JDate();
1389 }
1390
1391 return array(
1392 'required' => $haveToInstallFOF,
1393 'installed' => $installedFOF,
1394 'version' => $fofVersion[$versionSource]['version'],
1395 'date' => $fofVersion[$versionSource]['date']->format('Y-m-d'),
1396 );
1397 }
1398
1399 1400 1401 1402 1403 1404 1405
1406 protected function installStrapper($parent)
1407 {
1408 $src = $parent->getParent()->getPath('source');
1409 $source = $src . '/' . $this->strapperSourcePath;
1410
1411 $target = JPATH_ROOT . '/media/akeeba_strapper';
1412
1413 if (!JFolder::exists($source))
1414 {
1415 return array(
1416 'required' => false,
1417 'installed' => false,
1418 'version' => '0.0.0',
1419 'date' => '2011-01-01',
1420 );
1421 }
1422
1423 $haveToInstallStrapper = false;
1424
1425 if (!JFolder::exists($target))
1426 {
1427 $haveToInstallStrapper = true;
1428 }
1429 else
1430 {
1431 $strapperVersion = array();
1432
1433 if (JFile::exists($target . '/version.txt'))
1434 {
1435 $rawData = JFile::read($target . '/version.txt');
1436 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1437 $info = explode("\n", $rawData);
1438 $strapperVersion['installed'] = array(
1439 'version' => trim($info[0]),
1440 'date' => new JDate(trim($info[1]))
1441 );
1442 }
1443 else
1444 {
1445 $strapperVersion['installed'] = array(
1446 'version' => '0.0',
1447 'date' => new JDate('2011-01-01')
1448 );
1449 }
1450
1451 $rawData = JFile::read($source . '/version.txt');
1452 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1453 $info = explode("\n", $rawData);
1454 $strapperVersion['package'] = array(
1455 'version' => trim($info[0]),
1456 'date' => new JDate(trim($info[1]))
1457 );
1458
1459 $haveToInstallStrapper = $strapperVersion['package']['date']->toUNIX() > $strapperVersion['installed']['date']->toUNIX();
1460 }
1461
1462 $installedStraper = false;
1463
1464 if ($haveToInstallStrapper)
1465 {
1466 $versionSource = 'package';
1467 $installer = new JInstaller;
1468 $installedStraper = $installer->install($source);
1469 }
1470 else
1471 {
1472 $versionSource = 'installed';
1473 }
1474
1475 if (!isset($strapperVersion))
1476 {
1477 $strapperVersion = array();
1478
1479 if (JFile::exists($target . '/version.txt'))
1480 {
1481 $rawData = JFile::read($target . '/version.txt');
1482 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1483 $info = explode("\n", $rawData);
1484 $strapperVersion['installed'] = array(
1485 'version' => trim($info[0]),
1486 'date' => new JDate(trim($info[1]))
1487 );
1488 }
1489 else
1490 {
1491 $strapperVersion['installed'] = array(
1492 'version' => '0.0',
1493 'date' => new JDate('2011-01-01')
1494 );
1495 }
1496
1497 $rawData = JFile::read($source . '/version.txt');
1498 $rawData = ($rawData === false) ? "0.0.0\n2011-01-01\n" : $rawData;
1499 $info = explode("\n", $rawData);
1500
1501 $strapperVersion['package'] = array(
1502 'version' => trim($info[0]),
1503 'date' => new JDate(trim($info[1]))
1504 );
1505
1506 $versionSource = 'installed';
1507 }
1508
1509 if (!($strapperVersion[$versionSource]['date'] instanceof JDate))
1510 {
1511 $strapperVersion[$versionSource]['date'] = new JDate();
1512 }
1513
1514 return array(
1515 'required' => $haveToInstallStrapper,
1516 'installed' => $installedStraper,
1517 'version' => $strapperVersion[$versionSource]['version'],
1518 'date' => $strapperVersion[$versionSource]['date']->format('Y-m-d'),
1519 );
1520 }
1521
1522 1523 1524 1525 1526 1527 1528
1529 protected function uninstallObsoleteSubextensions($parent)
1530 {
1531 JLoader::import('joomla.installer.installer');
1532
1533 $db = FOFPlatform::getInstance()->getDbo();
1534
1535 $status = new stdClass();
1536 $status->modules = array();
1537 $status->plugins = array();
1538
1539 $src = $parent->getParent()->getPath('source');
1540
1541
1542 if (isset($this->uninstallation_queue['modules']) && count($this->uninstallation_queue['modules']))
1543 {
1544 foreach ($this->uninstallation_queue['modules'] as $folder => $modules)
1545 {
1546 if (count($modules))
1547 {
1548 foreach ($modules as $module)
1549 {
1550
1551 $sql = $db->getQuery(true)
1552 ->select($db->qn('extension_id'))
1553 ->from($db->qn('#__extensions'))
1554 ->where($db->qn('element') . ' = ' . $db->q('mod_' . $module))
1555 ->where($db->qn('type') . ' = ' . $db->q('module'));
1556 $db->setQuery($sql);
1557 $id = $db->loadResult();
1558
1559 if ($id)
1560 {
1561 $installer = new JInstaller;
1562 $result = $installer->uninstall('module', $id, 1);
1563 $status->modules[] = array(
1564 'name' => 'mod_' . $module,
1565 'client' => $folder,
1566 'result' => $result
1567 );
1568 }
1569 }
1570 }
1571 }
1572 }
1573
1574
1575 if (isset($this->uninstallation_queue['plugins']) && count($this->uninstallation_queue['plugins']))
1576 {
1577 foreach ($this->uninstallation_queue['plugins'] as $folder => $plugins)
1578 {
1579 if (count($plugins))
1580 {
1581 foreach ($plugins as $plugin)
1582 {
1583 $sql = $db->getQuery(true)
1584 ->select($db->qn('extension_id'))
1585 ->from($db->qn('#__extensions'))
1586 ->where($db->qn('type') . ' = ' . $db->q('plugin'))
1587 ->where($db->qn('element') . ' = ' . $db->q($plugin))
1588 ->where($db->qn('folder') . ' = ' . $db->q($folder));
1589 $db->setQuery($sql);
1590
1591 $id = $db->loadResult();
1592 if ($id)
1593 {
1594 $installer = new JInstaller;
1595 $result = $installer->uninstall('plugin', $id, 1);
1596 $status->plugins[] = array(
1597 'name' => 'plg_' . $plugin,
1598 'group' => $folder,
1599 'result' => $result
1600 );
1601 }
1602 }
1603 }
1604 }
1605 }
1606
1607 return $status;
1608 }
1609
1610 1611 1612 1613 1614 1615 1616
1617 private function ($parent)
1618 {
1619 $db = $db = FOFPlatform::getInstance()->getDbo();
1620
1621
1622 $table = JTable::getInstance('menu');
1623 $option = $parent->get('element');
1624
1625
1626 $query = $db->getQuery(true)
1627 ->select('m.id, e.extension_id')
1628 ->from('#__menu AS m')
1629 ->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')
1630 ->where('m.parent_id = 1')
1631 ->where('m.client_id = 1')
1632 ->where('m.menutype = ' . $db->q('main'))
1633 ->where($db->qn('e') . '.' . $db->qn('type') . ' = ' . $db->q('component'))
1634 ->where('e.element = ' . $db->quote($option));
1635
1636 $db->setQuery($query);
1637
1638 $componentrow = $db->loadObject();
1639
1640
1641 if ($componentrow)
1642 {
1643
1644
1645 }
1646
1647
1648 $query->clear()
1649 ->select('e.extension_id')
1650 ->from('#__extensions AS e')
1651 ->where('e.type = ' . $db->quote('component'))
1652 ->where('e.element = ' . $db->quote($option));
1653 $db->setQuery($query);
1654 $component_id = $db->loadResult();
1655
1656
1657 $menuElement = $parent->get('manifest')->administration->menu;
1658
1659
1660
1661
1662 $query = $db->getQuery(true)
1663 ->select($db->qn('id'))
1664 ->from($db->qn('#__menu'))
1665 ->where($db->qn('id') . ' = ' . $db->q(1));
1666 $rootItemId = $db->setQuery($query)->loadResult();
1667
1668 if (is_null($rootItemId))
1669 {
1670
1671 $rootItemId = null;
1672 $query = $db->getQuery(true)
1673 ->select($db->qn('id'))
1674 ->from($db->qn('#__menu'))
1675 ->where($db->qn('title') . ' = ' . $db->q('Menu_Item_Root'));
1676 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
1677 }
1678
1679 if (is_null($rootItemId))
1680 {
1681
1682 $rootItemId = null;
1683 $query = $db->getQuery(true)
1684 ->select($db->qn('id'))
1685 ->from($db->qn('#__menu'))
1686 ->where($db->qn('alias') . ' = ' . $db->q('root'));
1687 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
1688 }
1689
1690 if (is_null($rootItemId))
1691 {
1692
1693 $rootItemId = null;
1694 $query = $db->getQuery(true)
1695 ->select($db->qn('id'))
1696 ->from($db->qn('#__menu'))
1697 ->where($db->qn('component_id') . ' = ' . $db->q('0'));
1698 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
1699 }
1700
1701 if (is_null($rootItemId))
1702 {
1703
1704 $rootItemId = null;
1705 $query = $db->getQuery(true)
1706 ->select($db->qn('id'))
1707 ->from($db->qn('#__menu'))
1708 ->order($db->qn('lft') . ' ASC');
1709 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
1710 }
1711
1712 if (is_null($rootItemId))
1713 {
1714
1715 throw new Exception("Your site is broken. There is no root menu item. As a result it is impossible to create menu items. The installation of this component has failed. Please fix your database and retry!", 500);
1716 }
1717
1718 if ($menuElement)
1719 {
1720 $data = array();
1721 $data['menutype'] = 'main';
1722 $data['client_id'] = 1;
1723 $data['title'] = (string)trim($menuElement);
1724 $data['alias'] = (string)$menuElement;
1725 $data['link'] = 'index.php?option=' . $option;
1726 $data['type'] = 'component';
1727 $data['published'] = 0;
1728 $data['parent_id'] = 1;
1729 $data['component_id'] = $component_id;
1730 $data['img'] = ((string)$menuElement->attributes()->img) ? (string)$menuElement->attributes()->img : 'class:component';
1731 $data['home'] = 0;
1732 $data['path'] = '';
1733 $data['params'] = '';
1734 }
1735
1736 else
1737 {
1738 $data = array();
1739 $data['menutype'] = 'main';
1740 $data['client_id'] = 1;
1741 $data['title'] = $option;
1742 $data['alias'] = $option;
1743 $data['link'] = 'index.php?option=' . $option;
1744 $data['type'] = 'component';
1745 $data['published'] = 0;
1746 $data['parent_id'] = 1;
1747 $data['component_id'] = $component_id;
1748 $data['img'] = 'class:component';
1749 $data['home'] = 0;
1750 $data['path'] = '';
1751 $data['params'] = '';
1752 }
1753
1754 try
1755 {
1756 $table->setLocation($rootItemId, 'last-child');
1757 }
1758 catch (InvalidArgumentException $e)
1759 {
1760 if (class_exists('JLog'))
1761 {
1762 JLog::add($e->getMessage(), JLog::WARNING, 'jerror');
1763 }
1764
1765 return false;
1766 }
1767
1768 if (!$table->bind($data) || !$table->check() || !$table->store())
1769 {
1770
1771 $query->clear()
1772 ->select('id')
1773 ->from('#__menu')
1774 ->where('menutype = ' . $db->quote('main'))
1775 ->where('client_id = 1')
1776 ->where('link = ' . $db->quote('index.php?option=' . $option))
1777 ->where('type = ' . $db->quote('component'))
1778 ->where('parent_id = 1')
1779 ->where('home = 0');
1780
1781 $db->setQuery($query);
1782 $menu_ids_level1 = $db->loadColumn();
1783
1784 if (empty($menu_ids_level1))
1785 {
1786
1787 JError::raiseWarning(1, $table->getError());
1788
1789 return false;
1790 }
1791 else
1792 {
1793 $ids = implode(',', $menu_ids_level1);
1794
1795 $query->clear()
1796 ->select('id')
1797 ->from('#__menu')
1798 ->where('menutype = ' . $db->quote('main'))
1799 ->where('client_id = 1')
1800 ->where('type = ' . $db->quote('component'))
1801 ->where('parent_id in (' . $ids . ')')
1802 ->where('level = 2')
1803 ->where('home = 0');
1804
1805 $db->setQuery($query);
1806 $menu_ids_level2 = $db->loadColumn();
1807
1808 $ids = implode(',', array_merge($menu_ids_level1, $menu_ids_level2));
1809
1810
1811 $query->clear()
1812 ->delete('#__menu')
1813 ->where('id in (' . $ids . ')');
1814
1815 $db->setQuery($query);
1816 $db->query();
1817
1818
1819 $table->setLocation($rootItemId, 'last-child');
1820
1821 if (!$table->bind($data) || !$table->check() || !$table->store())
1822 {
1823
1824 JError::raiseWarning(1, $table->getError());
1825
1826 return false;
1827 }
1828 }
1829 }
1830
1831 1832 1833 1834
1835 $parent->getParent()->pushStep(array('type' => 'menu', 'id' => $component_id));
1836
1837 1838 1839
1840
1841 if (!$parent->get('manifest')->administration->submenu)
1842 {
1843 return true;
1844 }
1845
1846 $parent_id = $table->id;
1847
1848 foreach ($parent->get('manifest')->administration->submenu->menu as $child)
1849 {
1850 $data = array();
1851 $data['menutype'] = 'main';
1852 $data['client_id'] = 1;
1853 $data['title'] = (string)trim($child);
1854 $data['alias'] = (string)$child;
1855 $data['type'] = 'component';
1856 $data['published'] = 0;
1857 $data['parent_id'] = $parent_id;
1858 $data['component_id'] = $component_id;
1859 $data['img'] = ((string)$child->attributes()->img) ? (string)$child->attributes()->img : 'class:component';
1860 $data['home'] = 0;
1861
1862
1863 if ((string)$child->attributes()->link)
1864 {
1865 $data['link'] = 'index.php?' . $child->attributes()->link;
1866 }
1867 else
1868 {
1869 $request = array();
1870
1871 if ((string)$child->attributes()->act)
1872 {
1873 $request[] = 'act=' . $child->attributes()->act;
1874 }
1875
1876 if ((string)$child->attributes()->task)
1877 {
1878 $request[] = 'task=' . $child->attributes()->task;
1879 }
1880
1881 if ((string)$child->attributes()->controller)
1882 {
1883 $request[] = 'controller=' . $child->attributes()->controller;
1884 }
1885
1886 if ((string)$child->attributes()->view)
1887 {
1888 $request[] = 'view=' . $child->attributes()->view;
1889 }
1890
1891 if ((string)$child->attributes()->layout)
1892 {
1893 $request[] = 'layout=' . $child->attributes()->layout;
1894 }
1895
1896 if ((string)$child->attributes()->sub)
1897 {
1898 $request[] = 'sub=' . $child->attributes()->sub;
1899 }
1900
1901 $qstring = (count($request)) ? '&' . implode('&', $request) : '';
1902 $data['link'] = 'index.php?option=' . $option . $qstring;
1903 }
1904
1905 $table = JTable::getInstance('menu');
1906
1907 try
1908 {
1909 $table->setLocation($parent_id, 'last-child');
1910 }
1911 catch (InvalidArgumentException $e)
1912 {
1913 return false;
1914 }
1915
1916 if (!$table->bind($data) || !$table->check() || !$table->store())
1917 {
1918
1919 return false;
1920 }
1921
1922 1923 1924 1925
1926 $parent->getParent()->pushStep(array('type' => 'menu', 'id' => $component_id));
1927 }
1928
1929 return true;
1930 }
1931
1932 1933 1934 1935 1936 1937 1938
1939 private function ($parent)
1940 {
1941 $db = FOFPlatform::getInstance()->getDbo();
1942
1943 $option = $parent->get('element');
1944
1945 $query = $db->getQuery(true)
1946 ->update('#__menu AS m')
1947 ->join('LEFT', '#__extensions AS e ON m.component_id = e.extension_id')
1948 ->set($db->qn('published') . ' = ' . $db->q(1))
1949 ->where('m.parent_id = 1')
1950 ->where('m.client_id = 1')
1951 ->where('m.menutype = ' . $db->quote('main'))
1952 ->where('e.type = ' . $db->quote('component'))
1953 ->where('e.element = ' . $db->quote($option));
1954
1955 $db->setQuery($query);
1956
1957 try
1958 {
1959 $db->execute();
1960 }
1961 catch (Exception $e)
1962 {
1963
1964 }
1965 }
1966
1967 1968 1969 1970
1971 private function ()
1972 {
1973
1974 $table = JTable::getInstance('menu');
1975 $db = FOFPlatform::getInstance()->getDbo();
1976
1977
1978
1979 $query = $db->getQuery(true)
1980 ->select($db->qn('id'))
1981 ->from($db->qn('#__menu'))
1982 ->where($db->qn('id') . ' = ' . $db->q(1));
1983 $rootItemId = $db->setQuery($query)->loadResult();
1984
1985 if (is_null($rootItemId))
1986 {
1987
1988 $rootItemId = null;
1989 $query = $db->getQuery(true)
1990 ->select($db->qn('id'))
1991 ->from($db->qn('#__menu'))
1992 ->where($db->qn('title') . ' = ' . $db->q('Menu_Item_Root'));
1993 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
1994 }
1995
1996 if (is_null($rootItemId))
1997 {
1998
1999 $rootItemId = null;
2000 $query = $db->getQuery(true)
2001 ->select($db->qn('id'))
2002 ->from($db->qn('#__menu'))
2003 ->where($db->qn('alias') . ' = ' . $db->q('root'));
2004 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
2005 }
2006
2007 if (is_null($rootItemId))
2008 {
2009
2010 $rootItemId = null;
2011 $query = $db->getQuery(true)
2012 ->select($db->qn('id'))
2013 ->from($db->qn('#__menu'))
2014 ->where($db->qn('component_id') . ' = ' . $db->q('0'));
2015 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
2016 }
2017
2018 if (is_null($rootItemId))
2019 {
2020
2021 $rootItemId = null;
2022 $query = $db->getQuery(true)
2023 ->select($db->qn('id'))
2024 ->from($db->qn('#__menu'))
2025 ->order($db->qn('lft') . ' ASC');
2026 $rootItemId = $db->setQuery($query, 0, 1)->loadResult();
2027 }
2028
2029 if (is_null($rootItemId))
2030 {
2031
2032 return false;
2033 }
2034
2035 $table->rebuild($rootItemId);
2036 }
2037
2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107
2108 protected function addPostInstallationMessage(array $options)
2109 {
2110
2111 if (!is_array($options))
2112 {
2113 throw new Exception('Post-installation message definitions must be of type array', 500);
2114 }
2115
2116
2117 $defaultOptions = array(
2118 'extension_id' => '',
2119 'type' => '',
2120 'title_key' => '',
2121 'description_key' => '',
2122 'action_key' => '',
2123 'language_extension' => '',
2124 'language_client_id' => '',
2125 'action_file' => '',
2126 'action' => '',
2127 'condition_file' => '',
2128 'condition_method' => '',
2129 'version_introduced' => '',
2130 'enabled' => '1',
2131 );
2132
2133 $options = array_merge($defaultOptions, $options);
2134
2135
2136 $defaultKeys = array_keys($defaultOptions);
2137 $allKeys = array_keys($options);
2138 $extraKeys = array_diff($allKeys, $defaultKeys);
2139
2140 if (!empty($extraKeys))
2141 {
2142 foreach ($extraKeys as $key)
2143 {
2144 unset($options[$key]);
2145 }
2146 }
2147
2148
2149 $options['extension_id'] = (int)$options['extension_id'];
2150 $options['language_client_id'] = (int)$options['language_client_id'];
2151 $options['enabled'] = (int)$options['enabled'];
2152
2153
2154 foreach (array('language_client_id', 'enabled') as $key)
2155 {
2156 $options[$key] = $options[$key] ? 1 : 0;
2157 }
2158
2159
2160 if (!(int)$options['extension_id'])
2161 {
2162 throw new Exception('Post-installation message definitions need an extension_id', 500);
2163 }
2164
2165
2166 if (!in_array($options['type'], array('message', 'link', 'action')))
2167 {
2168 throw new Exception('Post-installation message definitions need to declare a type of message, link or action', 500);
2169 }
2170
2171
2172 if (empty($options['title_key']))
2173 {
2174 throw new Exception('Post-installation message definitions need a title key', 500);
2175 }
2176
2177
2178 if (empty($options['description_key']))
2179 {
2180 throw new Exception('Post-installation message definitions need a description key', 500);
2181 }
2182
2183
2184 if (($options['type'] != 'message') && empty($options['action_key']))
2185 {
2186 throw new Exception('Post-installation message definitions need an action key when they are of type "' . $options['type'] . '"', 500);
2187 }
2188
2189
2190 if (empty($options['language_extension']))
2191 {
2192 throw new Exception('Post-installation message definitions need to specify which extension contains their language keys', 500);
2193 }
2194
2195
2196 if ($options['type'] == 'action')
2197 {
2198 if (empty($options['action_file']))
2199 {
2200 throw new Exception('Post-installation message definitions need an action file when they are of type "action"', 500);
2201 }
2202
2203 $file_path = FOFTemplateUtils::parsePath($options['action_file'], true);
2204
2205 if (!@is_file($file_path))
2206 {
2207 throw new Exception('The action file ' . $options['action_file'] . ' of your post-installation message definition does not exist', 500);
2208 }
2209
2210 if (empty($options['action']))
2211 {
2212 throw new Exception('Post-installation message definitions need an action (function name) when they are of type "action"', 500);
2213 }
2214 }
2215
2216 if ($options['type'] == 'link')
2217 {
2218 if (empty($options['link']))
2219 {
2220 throw new Exception('Post-installation message definitions need an action (URL) when they are of type "link"', 500);
2221 }
2222 }
2223
2224
2225 if ($options['type'] != 'message')
2226 {
2227 if (empty($options['condition_file']))
2228 {
2229 throw new Exception('Post-installation message definitions need a condition file when they are of type "' . $options['type'] . '"', 500);
2230 }
2231
2232 $file_path = FOFTemplateUtils::parsePath($options['condition_file'], true);
2233
2234 if (!@is_file($file_path))
2235 {
2236 throw new Exception('The condition file ' . $options['condition_file'] . ' of your post-installation message definition does not exist', 500);
2237 }
2238
2239 if (empty($options['condition_method']))
2240 {
2241 throw new Exception('Post-installation message definitions need a condition method (function name) when they are of type "' . $options['type'] . '"', 500);
2242 }
2243 }
2244
2245
2246 $tableName = '#__postinstall_messages';
2247
2248 $db = FOFPlatform::getInstance()->getDbo();
2249 $query = $db->getQuery(true)
2250 ->select('*')
2251 ->from($db->qn($tableName))
2252 ->where($db->qn('extension_id') . ' = ' . $db->q($options['extension_id']))
2253 ->where($db->qn('type') . ' = ' . $db->q($options['type']))
2254 ->where($db->qn('title_key') . ' = ' . $db->q($options['title_key']));
2255 $existingRow = $db->setQuery($query)->loadAssoc();
2256
2257
2258 if (!empty($existingRow))
2259 {
2260 $same = true;
2261
2262 foreach ($options as $k => $v)
2263 {
2264 if ($k == 'enabled')
2265 {
2266 continue;
2267 }
2268
2269 if ($existingRow[$k] != $v)
2270 {
2271 $same = false;
2272 break;
2273 }
2274 }
2275
2276
2277 if ($same)
2278 {
2279 return;
2280 }
2281
2282
2283 $query = $db->getQuery(true)
2284 ->delete($db->qn($tableName))
2285 ->where($db->q('extension_id') . ' = ' . $db->q($options['extension_id']))
2286 ->where($db->q('type') . ' = ' . $db->q($options['type']))
2287 ->where($db->q('title_key') . ' = ' . $db->q($options['title_key']));
2288 $db->setQuery($query)->execute();
2289 }
2290
2291
2292 $options = (object)$options;
2293 $db->insertObject($tableName, $options);
2294 }
2295
2296 2297 2298 2299 2300
2301 protected function _applyPostInstallationMessages()
2302 {
2303
2304 if (!version_compare(JVERSION, '3.2.0', 'ge'))
2305 {
2306 return;
2307 }
2308
2309
2310 if (empty($this->postInstallationMessages))
2311 {
2312 return;
2313 }
2314
2315
2316 $db = FOFPlatform::getInstance()->getDbo();
2317 $query = $db->getQuery(true);
2318 $query->select('extension_id')
2319 ->from('#__extensions')
2320 ->where($db->qn('type') . ' = ' . $db->q('component'))
2321 ->where($db->qn('element') . ' = ' . $db->q($this->componentName));
2322 $db->setQuery($query);
2323
2324 try
2325 {
2326 $ids = $db->loadColumn();
2327 }
2328 catch (Exception $exc)
2329 {
2330 return;
2331 }
2332
2333 if (empty($ids))
2334 {
2335 return;
2336 }
2337
2338 $extension_id = array_shift($ids);
2339
2340 foreach ($this->postInstallationMessages as $message)
2341 {
2342 $message['extension_id'] = $extension_id;
2343 $this->addPostInstallationMessage($message);
2344 }
2345 }
2346
2347 protected function uninstallPostInstallationMessages()
2348 {
2349
2350 if (!version_compare(JVERSION, '3.2.0', 'ge'))
2351 {
2352 return;
2353 }
2354
2355
2356 if (empty($this->postInstallationMessages))
2357 {
2358 return;
2359 }
2360
2361
2362 $db = FOFPlatform::getInstance()->getDbo();
2363 $query = $db->getQuery(true);
2364 $query->select('extension_id')
2365 ->from('#__extensions')
2366 ->where($db->qn('type') . ' = ' . $db->q('component'))
2367 ->where($db->qn('element') . ' = ' . $db->q($this->componentName));
2368 $db->setQuery($query);
2369
2370 try
2371 {
2372 $ids = $db->loadColumn();
2373 }
2374 catch (Exception $exc)
2375 {
2376 return;
2377 }
2378
2379 if (empty($ids))
2380 {
2381 return;
2382 }
2383
2384 $extension_id = array_shift($ids);
2385
2386 $query = $db->getQuery(true)
2387 ->delete($db->qn('#__postinstall_messages'))
2388 ->where($db->qn('extension_id') . ' = ' . $db->q($extension_id));
2389
2390 try
2391 {
2392 $db->setQuery($query)->execute();
2393 }
2394 catch (Exception $e)
2395 {
2396 return;
2397 }
2398 }
2399 }
2400