14ca7e03cSGreg Roach<?php 24ca7e03cSGreg Roach/** 34ca7e03cSGreg Roach * webtrees: online genealogy 44ca7e03cSGreg Roach * Copyright (C) 2019 webtrees development team 54ca7e03cSGreg Roach * This program is free software: you can redistribute it and/or modify 64ca7e03cSGreg Roach * it under the terms of the GNU General Public License as published by 74ca7e03cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 84ca7e03cSGreg Roach * (at your option) any later version. 94ca7e03cSGreg Roach * This program is distributed in the hope that it will be useful, 104ca7e03cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 114ca7e03cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 124ca7e03cSGreg Roach * GNU General Public License for more details. 134ca7e03cSGreg Roach * You should have received a copy of the GNU General Public License 144ca7e03cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 154ca7e03cSGreg Roach */ 164ca7e03cSGreg Roachdeclare(strict_types=1); 174ca7e03cSGreg Roach 184ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services; 194ca7e03cSGreg Roach 204ca7e03cSGreg Roachuse Closure; 214ca7e03cSGreg Roachuse Fisharebest\Webtrees\Auth; 22e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 234ca7e03cSGreg Roachuse Fisharebest\Webtrees\FlashMessages; 244ca7e03cSGreg Roachuse Fisharebest\Webtrees\I18N; 254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AhnentafelReportModule; 264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AlbumModule; 274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AncestorsChartModule; 284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BatchUpdateModule; 294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BingWebmasterToolsModule; 304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthDeathMarriageReportModule; 314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthReportModule; 3267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\BranchesListModule; 334ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CalendarMenuModule; 344ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CemeteryReportModule; 354ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CensusAssistantModule; 364ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChangeReportModule; 374ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsBlockModule; 384ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsMenuModule; 394ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CkeditorModule; 404ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ClippingsCartModule; 414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CloudsTheme; 424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ColorsTheme; 434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CompactTreeChartModule; 444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ContactsFooterModule; 454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CookieWarningModule; 464ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DeathReportModule; 474ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyChartModule; 484ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyModule; 494ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyReportModule; 508eaf8709SGreg Roachuse Fisharebest\Webtrees\Module\IndividualMetadataModule; 514ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FabTheme; 524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FactSourcesReportModule; 534ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyBookChartModule; 544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyGroupReportModule; 5567992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\FamilyListModule; 564ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyNavigatorModule; 574ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule; 584ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeNewsModule; 594ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeStatisticsModule; 604ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FanChartModule; 614ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FrequentlyAskedQuestionsModule; 624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleAnalyticsModule; 634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule; 644ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HitCountFooterModule; 654ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HourglassChartModule; 664ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HtmlBlockModule; 674ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFactsTabModule; 684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFamiliesReportModule; 6967992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\IndividualListModule; 704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualReportModule; 714ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\InteractiveTreeModule; 724ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LifespansChartModule; 734ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ListsMenuModule; 744ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoggedInUsersModule; 754ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoginBlockModule; 764ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MarriageReportModule; 774ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MatomoAnalyticsModule; 7867992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\MediaListModule; 794ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MediaTabModule; 804ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MinimalTheme; 814ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MissingFactsReportModule; 82bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 834ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface; 844ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 85bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface; 864ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleCustomInterface; 874ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleFooterInterface; 88bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface; 894ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface; 90bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface; 9167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\ModuleListInterface; 924ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface; 934ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface; 944ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface; 954ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface; 96bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 9767992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\NoteListModule; 984ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\NotesTabModule; 994ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OccupationReportModule; 1004ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OnThisDayModule; 1014ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeChartModule; 1024ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeMapModule; 1034ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeReportModule; 10467992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\PlaceHierarchyListModule; 1054ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PlacesModule; 1064ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PoweredByWebtreesModule; 1074ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RecentChangesModule; 1084ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelatedIndividualsReportModule; 1094ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule; 1104ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelativesTabModule; 1114ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReportsMenuModule; 11267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\RepositoryListModule; 1134ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ResearchTaskModule; 1144ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReviewChangesModule; 1154ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SearchMenuModule; 1164ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SiteMapModule; 1174ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SlideShowModule; 11867992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\SourceListModule; 1194ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SourcesTabModule; 1204ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatcounterModule; 1214ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatisticsChartModule; 1224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StoriesModule; 1234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ThemeSelectModule; 1244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TimelineChartModule; 1254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopGivenNamesModule; 1264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopPageViewsModule; 1274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopSurnamesModule; 1284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TreesMenuModule; 1294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UpcomingAnniversariesModule; 1304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserFavoritesModule; 1314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserJournalModule; 1324ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserMessagesModule; 1334ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserWelcomeModule; 1344ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WebtreesTheme; 1354ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WelcomeBlockModule; 1364ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\XeneaTheme; 1374ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\YahrzeitModule; 1384ca7e03cSGreg Roachuse Fisharebest\Webtrees\Tree; 1394ca7e03cSGreg Roachuse Fisharebest\Webtrees\Webtrees; 1404ca7e03cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 1414ca7e03cSGreg Roachuse Illuminate\Support\Collection; 1424ca7e03cSGreg Roachuse Illuminate\Support\Str; 1434ca7e03cSGreg Roachuse stdClass; 1444ca7e03cSGreg Roachuse Throwable; 1454ca7e03cSGreg Roach 1464ca7e03cSGreg Roach/** 1474ca7e03cSGreg Roach * Functions for managing and maintaining modules. 1484ca7e03cSGreg Roach */ 1494ca7e03cSGreg Roachclass ModuleService 1504ca7e03cSGreg Roach{ 151bf57b580SGreg Roach // Components are managed together in the control panel. 1524ca7e03cSGreg Roach private const COMPONENTS = [ 15387cca37cSGreg Roach ModuleAnalyticsInterface::class, 15487cca37cSGreg Roach ModuleBlockInterface::class, 15587cca37cSGreg Roach ModuleChartInterface::class, 15687cca37cSGreg Roach ModuleFooterInterface::class, 15787cca37cSGreg Roach ModuleHistoricEventsInterface::class, 15887cca37cSGreg Roach ModuleLanguageInterface::class, 15987cca37cSGreg Roach ModuleListInterface::class, 16087cca37cSGreg Roach ModuleMenuInterface::class, 16187cca37cSGreg Roach ModuleReportInterface::class, 16287cca37cSGreg Roach ModuleSidebarInterface::class, 16387cca37cSGreg Roach ModuleTabInterface::class, 16487cca37cSGreg Roach ModuleThemeInterface::class, 1654ca7e03cSGreg Roach ]; 1664ca7e03cSGreg Roach 1674ca7e03cSGreg Roach // Array keys are module names, and should match module names from earlier versions of webtrees. 1684ca7e03cSGreg Roach private const CORE_MODULES = [ 1694ca7e03cSGreg Roach 'GEDFact_assistant' => CensusAssistantModule::class, 1704ca7e03cSGreg Roach 'ahnentafel_report' => AhnentafelReportModule::class, 1714ca7e03cSGreg Roach 'ancestors_chart' => AncestorsChartModule::class, 1724ca7e03cSGreg Roach 'batch_update' => BatchUpdateModule::class, 1734ca7e03cSGreg Roach 'bdm_report' => BirthDeathMarriageReportModule::class, 1744ca7e03cSGreg Roach 'bing-webmaster-tools' => BingWebmasterToolsModule::class, 1754ca7e03cSGreg Roach 'birth_report' => BirthReportModule::class, 17667992b6aSRichard Cissee 'branches_list' => BranchesListModule::class, 1774ca7e03cSGreg Roach 'calendar-menu' => CalendarMenuModule::class, 1784ca7e03cSGreg Roach 'cemetery_report' => CemeteryReportModule::class, 1794ca7e03cSGreg Roach 'change_report' => ChangeReportModule::class, 1804ca7e03cSGreg Roach 'charts' => ChartsBlockModule::class, 1814ca7e03cSGreg Roach 'charts-menu' => ChartsMenuModule::class, 1824ca7e03cSGreg Roach 'ckeditor' => CkeditorModule::class, 1834ca7e03cSGreg Roach 'clippings' => ClippingsCartModule::class, 1844ca7e03cSGreg Roach 'clouds' => CloudsTheme::class, 1854ca7e03cSGreg Roach 'colors' => ColorsTheme::class, 1864ca7e03cSGreg Roach 'compact-chart' => CompactTreeChartModule::class, 1874ca7e03cSGreg Roach 'contact-links' => ContactsFooterModule::class, 1884ca7e03cSGreg Roach 'cookie-warning' => CookieWarningModule::class, 1894ca7e03cSGreg Roach 'death_report' => DeathReportModule::class, 1904ca7e03cSGreg Roach 'descendancy' => DescendancyModule::class, 1914ca7e03cSGreg Roach 'descendancy_chart' => DescendancyChartModule::class, 1924ca7e03cSGreg Roach 'descendancy_report' => DescendancyReportModule::class, 1938eaf8709SGreg Roach 'extra_info' => IndividualMetadataModule::class, 1944ca7e03cSGreg Roach 'fab' => FabTheme::class, 1954ca7e03cSGreg Roach 'fact_sources' => FactSourcesReportModule::class, 1964ca7e03cSGreg Roach 'family_book_chart' => FamilyBookChartModule::class, 1974ca7e03cSGreg Roach 'family_group_report' => FamilyGroupReportModule::class, 19867992b6aSRichard Cissee 'family_list' => FamilyListModule::class, 1994ca7e03cSGreg Roach 'family_nav' => FamilyNavigatorModule::class, 2004ca7e03cSGreg Roach 'fan_chart' => FanChartModule::class, 2014ca7e03cSGreg Roach 'faq' => FrequentlyAskedQuestionsModule::class, 2024ca7e03cSGreg Roach 'gedcom_block' => WelcomeBlockModule::class, 2034ca7e03cSGreg Roach 'gedcom_favorites' => FamilyTreeFavoritesModule::class, 2044ca7e03cSGreg Roach 'gedcom_news' => FamilyTreeNewsModule::class, 2054ca7e03cSGreg Roach 'gedcom_stats' => FamilyTreeStatisticsModule::class, 2064ca7e03cSGreg Roach 'google-analytics' => GoogleAnalyticsModule::class, 2074ca7e03cSGreg Roach 'google-webmaster-tools' => GoogleWebmasterToolsModule::class, 2084ca7e03cSGreg Roach 'hit-counter' => HitCountFooterModule::class, 2094ca7e03cSGreg Roach 'hourglass_chart' => HourglassChartModule::class, 2104ca7e03cSGreg Roach 'html' => HtmlBlockModule::class, 2114ca7e03cSGreg Roach 'individual_ext_report' => IndividualFamiliesReportModule::class, 21267992b6aSRichard Cissee 'individual_list' => IndividualListModule::class, 2134ca7e03cSGreg Roach 'individual_report' => IndividualReportModule::class, 2144ca7e03cSGreg Roach 'lifespans_chart' => LifespansChartModule::class, 2154ca7e03cSGreg Roach 'lightbox' => AlbumModule::class, 2164ca7e03cSGreg Roach 'lists-menu' => ListsMenuModule::class, 2174ca7e03cSGreg Roach 'logged_in' => LoggedInUsersModule::class, 2184ca7e03cSGreg Roach 'login_block' => LoginBlockModule::class, 2194ca7e03cSGreg Roach 'marriage_report' => MarriageReportModule::class, 2204ca7e03cSGreg Roach 'matomo-analytics' => MatomoAnalyticsModule::class, 2214ca7e03cSGreg Roach 'media' => MediaTabModule::class, 22267992b6aSRichard Cissee 'media_list' => MediaListModule::class, 2234ca7e03cSGreg Roach 'minimal' => MinimalTheme::class, 2244ca7e03cSGreg Roach 'missing_facts_report' => MissingFactsReportModule::class, 2254ca7e03cSGreg Roach 'notes' => NotesTabModule::class, 22667992b6aSRichard Cissee 'note_list' => NoteListModule::class, 2274ca7e03cSGreg Roach 'occupation_report' => OccupationReportModule::class, 2284ca7e03cSGreg Roach 'pedigree-map' => PedigreeMapModule::class, 2294ca7e03cSGreg Roach 'pedigree_chart' => PedigreeChartModule::class, 2304ca7e03cSGreg Roach 'pedigree_report' => PedigreeReportModule::class, 2314ca7e03cSGreg Roach 'personal_facts' => IndividualFactsTabModule::class, 2324ca7e03cSGreg Roach 'places' => PlacesModule::class, 23367992b6aSRichard Cissee 'places_list' => PlaceHierarchyListModule::class, 2344ca7e03cSGreg Roach 'powered-by-webtrees' => PoweredByWebtreesModule::class, 2354ca7e03cSGreg Roach 'random_media' => SlideShowModule::class, 2364ca7e03cSGreg Roach 'recent_changes' => RecentChangesModule::class, 2374ca7e03cSGreg Roach 'relationships_chart' => RelationshipsChartModule::class, 2384ca7e03cSGreg Roach 'relative_ext_report' => RelatedIndividualsReportModule::class, 2394ca7e03cSGreg Roach 'relatives' => RelativesTabModule::class, 2404ca7e03cSGreg Roach 'reports-menu' => ReportsMenuModule::class, 24167992b6aSRichard Cissee 'repository_list' => RepositoryListModule::class, 2424ca7e03cSGreg Roach 'review_changes' => ReviewChangesModule::class, 2434ca7e03cSGreg Roach 'search-menu' => SearchMenuModule::class, 2444ca7e03cSGreg Roach 'sitemap' => SiteMapModule::class, 24567992b6aSRichard Cissee 'source_list' => SourceListModule::class, 2464ca7e03cSGreg Roach 'sources_tab' => SourcesTabModule::class, 2474ca7e03cSGreg Roach 'statcounter' => StatcounterModule::class, 2484ca7e03cSGreg Roach 'statistics_chart' => StatisticsChartModule::class, 2494ca7e03cSGreg Roach 'stories' => StoriesModule::class, 2504ca7e03cSGreg Roach 'theme_select' => ThemeSelectModule::class, 2514ca7e03cSGreg Roach 'timeline_chart' => TimelineChartModule::class, 2524ca7e03cSGreg Roach 'todays_events' => OnThisDayModule::class, 2534ca7e03cSGreg Roach 'todo' => ResearchTaskModule::class, 2544ca7e03cSGreg Roach 'top10_givnnames' => TopGivenNamesModule::class, 2554ca7e03cSGreg Roach 'top10_pageviews' => TopPageViewsModule::class, 2564ca7e03cSGreg Roach 'top10_surnames' => TopSurnamesModule::class, 2574ca7e03cSGreg Roach 'tree' => InteractiveTreeModule::class, 2584ca7e03cSGreg Roach 'trees-menu' => TreesMenuModule::class, 2594ca7e03cSGreg Roach 'upcoming_events' => UpcomingAnniversariesModule::class, 2604ca7e03cSGreg Roach 'user_blog' => UserJournalModule::class, 2614ca7e03cSGreg Roach 'user_favorites' => UserFavoritesModule::class, 2624ca7e03cSGreg Roach 'user_messages' => UserMessagesModule::class, 2634ca7e03cSGreg Roach 'user_welcome' => UserWelcomeModule::class, 2644ca7e03cSGreg Roach 'webtrees' => WebtreesTheme::class, 2654ca7e03cSGreg Roach 'xenea' => XeneaTheme::class, 2664ca7e03cSGreg Roach 'yahrzeit' => YahrzeitModule::class, 2674ca7e03cSGreg Roach ]; 2684ca7e03cSGreg Roach 2694ca7e03cSGreg Roach /** 2704ca7e03cSGreg Roach * All core modules in the system. 2714ca7e03cSGreg Roach * 2724ca7e03cSGreg Roach * @return Collection 2734ca7e03cSGreg Roach */ 2744ca7e03cSGreg Roach private function coreModules(): Collection 2754ca7e03cSGreg Roach { 276321a89daSGreg Roach return Collection::make(self::CORE_MODULES) 277321a89daSGreg Roach ->map(function (string $class, string $name): ModuleInterface { 278cab242e7SGreg Roach $module = app($class); 2794ca7e03cSGreg Roach 2804ca7e03cSGreg Roach $module->setName($name); 2814ca7e03cSGreg Roach 2824ca7e03cSGreg Roach return $module; 2834ca7e03cSGreg Roach }); 2844ca7e03cSGreg Roach } 2854ca7e03cSGreg Roach 2864ca7e03cSGreg Roach /** 2874ca7e03cSGreg Roach * All custom modules in the system. Custom modules are defined in modules_v4/ 2884ca7e03cSGreg Roach * 2894ca7e03cSGreg Roach * @return Collection 2904ca7e03cSGreg Roach */ 2914ca7e03cSGreg Roach private function customModules(): Collection 2924ca7e03cSGreg Roach { 2934ca7e03cSGreg Roach $pattern = WT_ROOT . Webtrees::MODULES_PATH . '*/module.php'; 2944ca7e03cSGreg Roach $filenames = glob($pattern); 2954ca7e03cSGreg Roach 296321a89daSGreg Roach return Collection::make($filenames) 2974ca7e03cSGreg Roach ->filter(function (string $filename): bool { 2984ca7e03cSGreg Roach // Special characters will break PHP variable names. 2994ca7e03cSGreg Roach // This also allows us to ignore modules called "foo.example" and "foo.disable" 3004ca7e03cSGreg Roach $module_name = basename(dirname($filename)); 3014ca7e03cSGreg Roach 3024ca7e03cSGreg Roach return !Str::contains($module_name, ['.', ' ', '[', ']']) && Str::length($module_name) <= 30; 3034ca7e03cSGreg Roach }) 3044ca7e03cSGreg Roach ->map(function (string $filename): ?ModuleCustomInterface { 3054ca7e03cSGreg Roach try { 3064ca7e03cSGreg Roach $module = self::load($filename); 3074ca7e03cSGreg Roach 3084ca7e03cSGreg Roach if ($module instanceof ModuleCustomInterface) { 3094ca7e03cSGreg Roach $module_name = '_' . basename(dirname($filename)) . '_'; 3104ca7e03cSGreg Roach 3114ca7e03cSGreg Roach $module->setName($module_name); 3124ca7e03cSGreg Roach } else { 3134ca7e03cSGreg Roach return null; 3144ca7e03cSGreg Roach } 3154ca7e03cSGreg Roach 3164ca7e03cSGreg Roach return $module; 3174ca7e03cSGreg Roach } catch (Throwable $ex) { 3184ca7e03cSGreg Roach $message = '<pre>' . e($ex->getMessage()) . "\n" . e($ex->getTraceAsString()) . '</pre>'; 3194ca7e03cSGreg Roach FlashMessages::addMessage($message, 'danger'); 3204ca7e03cSGreg Roach 3214ca7e03cSGreg Roach return null; 3224ca7e03cSGreg Roach } 3234ca7e03cSGreg Roach }) 3244ca7e03cSGreg Roach ->filter(); 3254ca7e03cSGreg Roach } 3264ca7e03cSGreg Roach 3274ca7e03cSGreg Roach /** 3284ca7e03cSGreg Roach * All modules. 3294ca7e03cSGreg Roach * 330*9d627a9eSGreg Roach * @param bool $include_disabled 331*9d627a9eSGreg Roach * 3324ca7e03cSGreg Roach * @return Collection|ModuleInterface[] 3334ca7e03cSGreg Roach */ 334*9d627a9eSGreg Roach public function all(bool $include_disabled = false): Collection 3354ca7e03cSGreg Roach { 3364ca7e03cSGreg Roach return app('cache.array')->rememberForever('all_modules', function (): Collection { 3374ca7e03cSGreg Roach // Modules have a default status, order etc. 3384ca7e03cSGreg Roach // We can override these from database settings. 3394ca7e03cSGreg Roach $module_info = DB::table('module') 3404ca7e03cSGreg Roach ->get() 3414ca7e03cSGreg Roach ->mapWithKeys(function (stdClass $row): array { 3424ca7e03cSGreg Roach return [$row->module_name => $row]; 3434ca7e03cSGreg Roach }); 3444ca7e03cSGreg Roach 345bf57b580SGreg Roach return $this->coreModules() 346bf57b580SGreg Roach ->merge($this->customModules()) 3474ca7e03cSGreg Roach ->map(function (ModuleInterface $module) use ($module_info): ModuleInterface { 3484ca7e03cSGreg Roach $info = $module_info->get($module->name()); 3494ca7e03cSGreg Roach 3504ca7e03cSGreg Roach if ($info instanceof stdClass) { 3514ca7e03cSGreg Roach $module->setEnabled($info->status === 'enabled'); 3524ca7e03cSGreg Roach 3534ca7e03cSGreg Roach if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) { 3544ca7e03cSGreg Roach $module->setFooterOrder((int) $info->footer_order); 3554ca7e03cSGreg Roach } 3564ca7e03cSGreg Roach 3574ca7e03cSGreg Roach if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) { 3584ca7e03cSGreg Roach $module->setMenuOrder((int) $info->menu_order); 3594ca7e03cSGreg Roach } 3604ca7e03cSGreg Roach 3614ca7e03cSGreg Roach if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) { 3624ca7e03cSGreg Roach $module->setSidebarOrder((int) $info->sidebar_order); 3634ca7e03cSGreg Roach } 3644ca7e03cSGreg Roach 3654ca7e03cSGreg Roach if ($module instanceof ModuleTabInterface && $info->tab_order !== null) { 3664ca7e03cSGreg Roach $module->setTabOrder((int) $info->tab_order); 3674ca7e03cSGreg Roach } 3684ca7e03cSGreg Roach } else { 369888ddf4fSGreg Roach $module->setEnabled($module->isEnabledByDefault()); 370888ddf4fSGreg Roach 371888ddf4fSGreg Roach DB::table('module')->insert([ 372888ddf4fSGreg Roach 'module_name' => $module->name(), 373888ddf4fSGreg Roach 'status' => $module->isEnabled() ? 'enabled' : 'disabled', 374888ddf4fSGreg Roach ]); 3754ca7e03cSGreg Roach } 3764ca7e03cSGreg Roach 3774ca7e03cSGreg Roach return $module; 378b5979037SGreg Roach }); 379*9d627a9eSGreg Roach })->filter($this->enabledFilter($include_disabled)); 3804ca7e03cSGreg Roach } 3814ca7e03cSGreg Roach 3824ca7e03cSGreg Roach /** 383a8fbc491SGreg Roach * Load a module in a static scope, to prevent it from modifying local or object variables. 3844ca7e03cSGreg Roach * 3854ca7e03cSGreg Roach * @param string $filename 3864ca7e03cSGreg Roach * 3874ca7e03cSGreg Roach * @return mixed 3884ca7e03cSGreg Roach */ 389a8fbc491SGreg Roach private static function load(string $filename) 3904ca7e03cSGreg Roach { 3914ca7e03cSGreg Roach return include $filename; 3924ca7e03cSGreg Roach } 3934ca7e03cSGreg Roach 3944ca7e03cSGreg Roach /** 3954ca7e03cSGreg Roach * A function to sort modules by name 3964ca7e03cSGreg Roach * 3974ca7e03cSGreg Roach * @return Closure 3984ca7e03cSGreg Roach */ 3994ca7e03cSGreg Roach private function moduleSorter(): Closure 4004ca7e03cSGreg Roach { 4014ca7e03cSGreg Roach return function (ModuleInterface $x, ModuleInterface $y): int { 4024ca7e03cSGreg Roach return I18N::strcasecmp($x->title(), $y->title()); 4034ca7e03cSGreg Roach }; 4044ca7e03cSGreg Roach } 4054ca7e03cSGreg Roach 4064ca7e03cSGreg Roach /** 4074ca7e03cSGreg Roach * A function to sort footers 4084ca7e03cSGreg Roach * 4094ca7e03cSGreg Roach * @return Closure 4104ca7e03cSGreg Roach */ 4114ca7e03cSGreg Roach private function footerSorter(): Closure 4124ca7e03cSGreg Roach { 4134ca7e03cSGreg Roach return function (ModuleFooterInterface $x, ModuleFooterInterface $y): int { 4144ca7e03cSGreg Roach return $x->getFooterOrder() <=> $y->getFooterOrder(); 4154ca7e03cSGreg Roach }; 4164ca7e03cSGreg Roach } 4174ca7e03cSGreg Roach 4184ca7e03cSGreg Roach /** 4194ca7e03cSGreg Roach * A function to sort menus 4204ca7e03cSGreg Roach * 4214ca7e03cSGreg Roach * @return Closure 4224ca7e03cSGreg Roach */ 4234ca7e03cSGreg Roach private function menuSorter(): Closure 4244ca7e03cSGreg Roach { 4254ca7e03cSGreg Roach return function (ModuleMenuInterface $x, ModuleMenuInterface $y): int { 4264ca7e03cSGreg Roach return $x->getMenuOrder() <=> $y->getMenuOrder(); 4274ca7e03cSGreg Roach }; 4284ca7e03cSGreg Roach } 4294ca7e03cSGreg Roach 4304ca7e03cSGreg Roach /** 4314ca7e03cSGreg Roach * A function to sort menus 4324ca7e03cSGreg Roach * 4334ca7e03cSGreg Roach * @return Closure 4344ca7e03cSGreg Roach */ 4354ca7e03cSGreg Roach private function sidebarSorter(): Closure 4364ca7e03cSGreg Roach { 4374ca7e03cSGreg Roach return function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int { 4384ca7e03cSGreg Roach return $x->getSidebarOrder() <=> $y->getSidebarOrder(); 4394ca7e03cSGreg Roach }; 4404ca7e03cSGreg Roach } 4414ca7e03cSGreg Roach 4424ca7e03cSGreg Roach /** 4434ca7e03cSGreg Roach * A function to sort menus 4444ca7e03cSGreg Roach * 4454ca7e03cSGreg Roach * @return Closure 4464ca7e03cSGreg Roach */ 4474ca7e03cSGreg Roach private function tabSorter(): Closure 4484ca7e03cSGreg Roach { 4494ca7e03cSGreg Roach return function (ModuleTabInterface $x, ModuleTabInterface $y): int { 4504ca7e03cSGreg Roach return $x->getTabOrder() <=> $y->getTabOrder(); 4514ca7e03cSGreg Roach }; 4524ca7e03cSGreg Roach } 4534ca7e03cSGreg Roach 4544ca7e03cSGreg Roach /** 455321a89daSGreg Roach * A function filter modules by type 456321a89daSGreg Roach * 457321a89daSGreg Roach * @param string $interface 458321a89daSGreg Roach * 459321a89daSGreg Roach * @return Closure 460321a89daSGreg Roach */ 461321a89daSGreg Roach private function interfaceFilter(string $interface): Closure 462321a89daSGreg Roach { 463321a89daSGreg Roach return function (ModuleInterface $module) use ($interface): bool { 464321a89daSGreg Roach return $module instanceof $interface; 465321a89daSGreg Roach }; 466321a89daSGreg Roach } 467321a89daSGreg Roach 468321a89daSGreg Roach /** 469321a89daSGreg Roach * A function filter modules by enabled/disabled 470321a89daSGreg Roach * 471321a89daSGreg Roach * @param bool $include_disabled 472321a89daSGreg Roach * 473321a89daSGreg Roach * @return Closure 474321a89daSGreg Roach */ 475321a89daSGreg Roach private function enabledFilter(bool $include_disabled): Closure 476321a89daSGreg Roach { 477321a89daSGreg Roach return function (ModuleInterface $module) use ($include_disabled): bool { 478321a89daSGreg Roach return $include_disabled || $module->isEnabled(); 479321a89daSGreg Roach }; 480321a89daSGreg Roach } 481321a89daSGreg Roach 482321a89daSGreg Roach /** 483dedcf571SGreg Roach * A function to convert modules into their titles - to create option lists, etc. 484dedcf571SGreg Roach * 485dedcf571SGreg Roach * @return Closure 486dedcf571SGreg Roach */ 487dedcf571SGreg Roach public function titleMapper(): Closure 488dedcf571SGreg Roach { 489dedcf571SGreg Roach return function (ModuleInterface $module): string { 490dedcf571SGreg Roach return $module->title(); 491dedcf571SGreg Roach }; 492dedcf571SGreg Roach } 493dedcf571SGreg Roach 494dedcf571SGreg Roach /** 4954ca7e03cSGreg Roach * Modules which (a) provide a specific function and (b) we have permission to see. 4964ca7e03cSGreg Roach * 49787cca37cSGreg Roach * @param string $interface 4984ca7e03cSGreg Roach * @param Tree $tree 499e5a6b4d4SGreg Roach * @param UserInterface $user 5004ca7e03cSGreg Roach * 5014ca7e03cSGreg Roach * @return Collection|ModuleInterface[] 5024ca7e03cSGreg Roach */ 50387cca37cSGreg Roach public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection 5044ca7e03cSGreg Roach { 505b5979037SGreg Roach return $this->findByInterface($interface, false, true) 50687cca37cSGreg Roach ->filter(function (ModuleInterface $module) use ($interface, $tree, $user): bool { 50787cca37cSGreg Roach return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user); 5084ca7e03cSGreg Roach }); 5094ca7e03cSGreg Roach } 5104ca7e03cSGreg Roach 5114ca7e03cSGreg Roach /** 5124ca7e03cSGreg Roach * All modules which provide a specific function. 5134ca7e03cSGreg Roach * 5144ca7e03cSGreg Roach * @param string $interface 5154ca7e03cSGreg Roach * @param bool $include_disabled 516b5979037SGreg Roach * @param bool $sort 5174ca7e03cSGreg Roach * 5184ca7e03cSGreg Roach * @return Collection|ModuleInterface[] 5194ca7e03cSGreg Roach */ 520b5979037SGreg Roach public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection 5214ca7e03cSGreg Roach { 522*9d627a9eSGreg Roach $modules = $this->all($include_disabled) 523*9d627a9eSGreg Roach ->filter($this->interfaceFilter($interface)); 5244ca7e03cSGreg Roach 5254ca7e03cSGreg Roach switch ($interface) { 5264ca7e03cSGreg Roach case ModuleFooterInterface::class: 527bf57b580SGreg Roach return $modules->sort($this->footerSorter()); 5284ca7e03cSGreg Roach 5294ca7e03cSGreg Roach case ModuleMenuInterface::class: 530bf57b580SGreg Roach return $modules->sort($this->menuSorter()); 5314ca7e03cSGreg Roach 5324ca7e03cSGreg Roach case ModuleSidebarInterface::class: 533bf57b580SGreg Roach return $modules->sort($this->sidebarSorter()); 5344ca7e03cSGreg Roach 5354ca7e03cSGreg Roach case ModuleTabInterface::class: 536bf57b580SGreg Roach return $modules->sort($this->tabSorter()); 537b5979037SGreg Roach 538b5979037SGreg Roach default: 539b5979037SGreg Roach if ($sort) { 540b5979037SGreg Roach return $modules->sort($this->moduleSorter()); 5414ca7e03cSGreg Roach } 5424ca7e03cSGreg Roach 5434ca7e03cSGreg Roach return $modules; 5444ca7e03cSGreg Roach } 545b5979037SGreg Roach } 5464ca7e03cSGreg Roach 5474ca7e03cSGreg Roach /** 5484ca7e03cSGreg Roach * Find a specified module, if it is currently active. 5494ca7e03cSGreg Roach * 5504ca7e03cSGreg Roach * @param string $module_name 551321a89daSGreg Roach * @param bool $include_disabled 5524ca7e03cSGreg Roach * 5534ca7e03cSGreg Roach * @return ModuleInterface|null 5544ca7e03cSGreg Roach */ 555321a89daSGreg Roach public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface 5564ca7e03cSGreg Roach { 557*9d627a9eSGreg Roach return $this->all($include_disabled) 5584ca7e03cSGreg Roach ->filter(function (ModuleInterface $module) use ($module_name): bool { 559321a89daSGreg Roach return $module->name() === $module_name; 5604ca7e03cSGreg Roach }) 5614ca7e03cSGreg Roach ->first(); 5624ca7e03cSGreg Roach } 563bf57b580SGreg Roach 564bf57b580SGreg Roach /** 565bf57b580SGreg Roach * Configuration settings are available through the various "module component" pages. 566bf57b580SGreg Roach * For modules that do not provide a component, we need to list them separately. 567bf57b580SGreg Roach * 568bf57b580SGreg Roach * @return Collection|ModuleConfigInterface[] 569bf57b580SGreg Roach */ 570bf57b580SGreg Roach public function configOnlyModules(): Collection 571bf57b580SGreg Roach { 572bf57b580SGreg Roach return $this->findByInterface(ModuleConfigInterface::class) 573bf57b580SGreg Roach ->filter(function (ModuleConfigInterface $module): bool { 574bf57b580SGreg Roach foreach (self::COMPONENTS as $interface) { 575bf57b580SGreg Roach if ($module instanceof $interface) { 576bf57b580SGreg Roach return false; 577bf57b580SGreg Roach } 578bf57b580SGreg Roach } 579bf57b580SGreg Roach 580bf57b580SGreg Roach return true; 581bf57b580SGreg Roach }); 582bf57b580SGreg Roach } 583bf57b580SGreg Roach 584bf57b580SGreg Roach /** 585bf57b580SGreg Roach * Generate a list of module names which exist in the database but not on disk. 586bf57b580SGreg Roach * 587bf57b580SGreg Roach * @return Collection|string[] 588bf57b580SGreg Roach */ 589bf57b580SGreg Roach public function deletedModules(): Collection 590bf57b580SGreg Roach { 591bf57b580SGreg Roach $database_modules = DB::table('module')->pluck('module_name'); 592bf57b580SGreg Roach 593bf57b580SGreg Roach $disk_modules = $this->all() 594bf57b580SGreg Roach ->map(function (ModuleInterface $module): string { 595bf57b580SGreg Roach return $module->name(); 596bf57b580SGreg Roach }); 597bf57b580SGreg Roach 598bf57b580SGreg Roach return $database_modules->diff($disk_modules); 599bf57b580SGreg Roach } 6004ca7e03cSGreg Roach} 601