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; 3309fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishMonarchs; 3409fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishPrimeMinisters; 3509fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishSocialHistory; 364ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CalendarMenuModule; 374ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CemeteryReportModule; 384ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CensusAssistantModule; 394ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChangeReportModule; 404ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsBlockModule; 414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsMenuModule; 424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CkeditorModule; 434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ClippingsCartModule; 444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CloudsTheme; 454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ColorsTheme; 464ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CompactTreeChartModule; 474ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ContactsFooterModule; 484ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CookieWarningModule; 494ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DeathReportModule; 504ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyChartModule; 514ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyModule; 524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\DescendancyReportModule; 534ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FabTheme; 544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FactSourcesReportModule; 554ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyBookChartModule; 564ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyGroupReportModule; 5767992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\FamilyListModule; 584ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyNavigatorModule; 594ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule; 604ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeNewsModule; 614ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FamilyTreeStatisticsModule; 624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FanChartModule; 634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\FrequentlyAskedQuestionsModule; 644ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleAnalyticsModule; 654ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule; 664ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HitCountFooterModule; 674ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HourglassChartModule; 684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\HtmlBlockModule; 694ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFactsTabModule; 704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualFamiliesReportModule; 7167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\IndividualListModule; 7209fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\IndividualMetadataModule; 734ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\IndividualReportModule; 744ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\InteractiveTreeModule; 754ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LifespansChartModule; 764ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ListsMenuModule; 774ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoggedInUsersModule; 784ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoginBlockModule; 794ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MarriageReportModule; 804ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MatomoAnalyticsModule; 8167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\MediaListModule; 824ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MediaTabModule; 834ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MinimalTheme; 844ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MissingFactsReportModule; 85bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 864ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface; 874ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 88bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface; 894ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleCustomInterface; 904ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleFooterInterface; 91bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface; 924ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface; 93bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface; 9467992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\ModuleListInterface; 954ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface; 964ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface; 974ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface; 984ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface; 99bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 10067992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\NoteListModule; 1014ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\NotesTabModule; 1024ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OccupationReportModule; 1034ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OnThisDayModule; 1044ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeChartModule; 1054ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeMapModule; 1064ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeReportModule; 10767992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\PlaceHierarchyListModule; 1084ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PlacesModule; 1094ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PoweredByWebtreesModule; 1104ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RecentChangesModule; 1114ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelatedIndividualsReportModule; 1124ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule; 1134ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelativesTabModule; 1144ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReportsMenuModule; 11567992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\RepositoryListModule; 1164ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ResearchTaskModule; 1174ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReviewChangesModule; 1184ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SearchMenuModule; 1194ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SiteMapModule; 1204ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SlideShowModule; 12167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\SourceListModule; 1224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SourcesTabModule; 1234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatcounterModule; 1244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatisticsChartModule; 1254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StoriesModule; 1264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ThemeSelectModule; 1274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TimelineChartModule; 1284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopGivenNamesModule; 1294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopPageViewsModule; 1304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopSurnamesModule; 1314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TreesMenuModule; 1324ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UpcomingAnniversariesModule; 1334ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserFavoritesModule; 1344ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserJournalModule; 1354ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserMessagesModule; 1364ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserWelcomeModule; 13709fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\USPresidents; 1384ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WebtreesTheme; 1394ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WelcomeBlockModule; 1404ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\XeneaTheme; 1414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\YahrzeitModule; 1424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Tree; 1434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Webtrees; 1444ca7e03cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 1454ca7e03cSGreg Roachuse Illuminate\Support\Collection; 1464ca7e03cSGreg Roachuse Illuminate\Support\Str; 1474ca7e03cSGreg Roachuse stdClass; 1484ca7e03cSGreg Roachuse Throwable; 1494ca7e03cSGreg Roach 1504ca7e03cSGreg Roach/** 1514ca7e03cSGreg Roach * Functions for managing and maintaining modules. 1524ca7e03cSGreg Roach */ 1534ca7e03cSGreg Roachclass ModuleService 1544ca7e03cSGreg Roach{ 155362b8464SGreg Roach // Components are pieces of user-facing functionality, are managed together in the control panel. 1564ca7e03cSGreg Roach private const COMPONENTS = [ 15787cca37cSGreg Roach ModuleAnalyticsInterface::class, 15887cca37cSGreg Roach ModuleBlockInterface::class, 15987cca37cSGreg Roach ModuleChartInterface::class, 16087cca37cSGreg Roach ModuleFooterInterface::class, 16187cca37cSGreg Roach ModuleHistoricEventsInterface::class, 16287cca37cSGreg Roach ModuleLanguageInterface::class, 16387cca37cSGreg Roach ModuleListInterface::class, 16487cca37cSGreg Roach ModuleMenuInterface::class, 16587cca37cSGreg Roach ModuleReportInterface::class, 16687cca37cSGreg Roach ModuleSidebarInterface::class, 16787cca37cSGreg Roach ModuleTabInterface::class, 16887cca37cSGreg Roach ModuleThemeInterface::class, 1694ca7e03cSGreg Roach ]; 1704ca7e03cSGreg Roach 1714ca7e03cSGreg Roach // Array keys are module names, and should match module names from earlier versions of webtrees. 1724ca7e03cSGreg Roach private const CORE_MODULES = [ 1734ca7e03cSGreg Roach 'GEDFact_assistant' => CensusAssistantModule::class, 1744ca7e03cSGreg Roach 'ahnentafel_report' => AhnentafelReportModule::class, 1754ca7e03cSGreg Roach 'ancestors_chart' => AncestorsChartModule::class, 1764ca7e03cSGreg Roach 'batch_update' => BatchUpdateModule::class, 1774ca7e03cSGreg Roach 'bdm_report' => BirthDeathMarriageReportModule::class, 1784ca7e03cSGreg Roach 'bing-webmaster-tools' => BingWebmasterToolsModule::class, 1794ca7e03cSGreg Roach 'birth_report' => BirthReportModule::class, 18067992b6aSRichard Cissee 'branches_list' => BranchesListModule::class, 18109fbf3e5SGreg Roach 'british-monarchs' => BritishMonarchs::class, 18209fbf3e5SGreg Roach 'british-prime-ministers' => BritishPrimeMinisters::class, 18309fbf3e5SGreg Roach 'british-social-history' => BritishSocialHistory::class, 1844ca7e03cSGreg Roach 'calendar-menu' => CalendarMenuModule::class, 1854ca7e03cSGreg Roach 'cemetery_report' => CemeteryReportModule::class, 1864ca7e03cSGreg Roach 'change_report' => ChangeReportModule::class, 1874ca7e03cSGreg Roach 'charts' => ChartsBlockModule::class, 1884ca7e03cSGreg Roach 'charts-menu' => ChartsMenuModule::class, 1894ca7e03cSGreg Roach 'ckeditor' => CkeditorModule::class, 1904ca7e03cSGreg Roach 'clippings' => ClippingsCartModule::class, 1914ca7e03cSGreg Roach 'clouds' => CloudsTheme::class, 1924ca7e03cSGreg Roach 'colors' => ColorsTheme::class, 1934ca7e03cSGreg Roach 'compact-chart' => CompactTreeChartModule::class, 1944ca7e03cSGreg Roach 'contact-links' => ContactsFooterModule::class, 1954ca7e03cSGreg Roach 'cookie-warning' => CookieWarningModule::class, 1964ca7e03cSGreg Roach 'death_report' => DeathReportModule::class, 1974ca7e03cSGreg Roach 'descendancy' => DescendancyModule::class, 1984ca7e03cSGreg Roach 'descendancy_chart' => DescendancyChartModule::class, 1994ca7e03cSGreg Roach 'descendancy_report' => DescendancyReportModule::class, 2008eaf8709SGreg Roach 'extra_info' => IndividualMetadataModule::class, 2014ca7e03cSGreg Roach 'fab' => FabTheme::class, 2024ca7e03cSGreg Roach 'fact_sources' => FactSourcesReportModule::class, 2034ca7e03cSGreg Roach 'family_book_chart' => FamilyBookChartModule::class, 2044ca7e03cSGreg Roach 'family_group_report' => FamilyGroupReportModule::class, 20567992b6aSRichard Cissee 'family_list' => FamilyListModule::class, 2064ca7e03cSGreg Roach 'family_nav' => FamilyNavigatorModule::class, 2074ca7e03cSGreg Roach 'fan_chart' => FanChartModule::class, 2084ca7e03cSGreg Roach 'faq' => FrequentlyAskedQuestionsModule::class, 2094ca7e03cSGreg Roach 'gedcom_block' => WelcomeBlockModule::class, 2104ca7e03cSGreg Roach 'gedcom_favorites' => FamilyTreeFavoritesModule::class, 2114ca7e03cSGreg Roach 'gedcom_news' => FamilyTreeNewsModule::class, 2124ca7e03cSGreg Roach 'gedcom_stats' => FamilyTreeStatisticsModule::class, 2134ca7e03cSGreg Roach 'google-analytics' => GoogleAnalyticsModule::class, 2144ca7e03cSGreg Roach 'google-webmaster-tools' => GoogleWebmasterToolsModule::class, 2154ca7e03cSGreg Roach 'hit-counter' => HitCountFooterModule::class, 2164ca7e03cSGreg Roach 'hourglass_chart' => HourglassChartModule::class, 2174ca7e03cSGreg Roach 'html' => HtmlBlockModule::class, 2184ca7e03cSGreg Roach 'individual_ext_report' => IndividualFamiliesReportModule::class, 21967992b6aSRichard Cissee 'individual_list' => IndividualListModule::class, 2204ca7e03cSGreg Roach 'individual_report' => IndividualReportModule::class, 2214ca7e03cSGreg Roach 'lifespans_chart' => LifespansChartModule::class, 2224ca7e03cSGreg Roach 'lightbox' => AlbumModule::class, 2234ca7e03cSGreg Roach 'lists-menu' => ListsMenuModule::class, 2244ca7e03cSGreg Roach 'logged_in' => LoggedInUsersModule::class, 2254ca7e03cSGreg Roach 'login_block' => LoginBlockModule::class, 2264ca7e03cSGreg Roach 'marriage_report' => MarriageReportModule::class, 2274ca7e03cSGreg Roach 'matomo-analytics' => MatomoAnalyticsModule::class, 2284ca7e03cSGreg Roach 'media' => MediaTabModule::class, 22967992b6aSRichard Cissee 'media_list' => MediaListModule::class, 2304ca7e03cSGreg Roach 'minimal' => MinimalTheme::class, 2314ca7e03cSGreg Roach 'missing_facts_report' => MissingFactsReportModule::class, 2324ca7e03cSGreg Roach 'notes' => NotesTabModule::class, 23367992b6aSRichard Cissee 'note_list' => NoteListModule::class, 2344ca7e03cSGreg Roach 'occupation_report' => OccupationReportModule::class, 2354ca7e03cSGreg Roach 'pedigree-map' => PedigreeMapModule::class, 2364ca7e03cSGreg Roach 'pedigree_chart' => PedigreeChartModule::class, 2374ca7e03cSGreg Roach 'pedigree_report' => PedigreeReportModule::class, 2384ca7e03cSGreg Roach 'personal_facts' => IndividualFactsTabModule::class, 2394ca7e03cSGreg Roach 'places' => PlacesModule::class, 24067992b6aSRichard Cissee 'places_list' => PlaceHierarchyListModule::class, 2414ca7e03cSGreg Roach 'powered-by-webtrees' => PoweredByWebtreesModule::class, 2424ca7e03cSGreg Roach 'random_media' => SlideShowModule::class, 2434ca7e03cSGreg Roach 'recent_changes' => RecentChangesModule::class, 2444ca7e03cSGreg Roach 'relationships_chart' => RelationshipsChartModule::class, 2454ca7e03cSGreg Roach 'relative_ext_report' => RelatedIndividualsReportModule::class, 2464ca7e03cSGreg Roach 'relatives' => RelativesTabModule::class, 2474ca7e03cSGreg Roach 'reports-menu' => ReportsMenuModule::class, 24867992b6aSRichard Cissee 'repository_list' => RepositoryListModule::class, 2494ca7e03cSGreg Roach 'review_changes' => ReviewChangesModule::class, 2504ca7e03cSGreg Roach 'search-menu' => SearchMenuModule::class, 2514ca7e03cSGreg Roach 'sitemap' => SiteMapModule::class, 25267992b6aSRichard Cissee 'source_list' => SourceListModule::class, 2534ca7e03cSGreg Roach 'sources_tab' => SourcesTabModule::class, 2544ca7e03cSGreg Roach 'statcounter' => StatcounterModule::class, 2554ca7e03cSGreg Roach 'statistics_chart' => StatisticsChartModule::class, 2564ca7e03cSGreg Roach 'stories' => StoriesModule::class, 2574ca7e03cSGreg Roach 'theme_select' => ThemeSelectModule::class, 2584ca7e03cSGreg Roach 'timeline_chart' => TimelineChartModule::class, 2594ca7e03cSGreg Roach 'todays_events' => OnThisDayModule::class, 2604ca7e03cSGreg Roach 'todo' => ResearchTaskModule::class, 2614ca7e03cSGreg Roach 'top10_givnnames' => TopGivenNamesModule::class, 2624ca7e03cSGreg Roach 'top10_pageviews' => TopPageViewsModule::class, 2634ca7e03cSGreg Roach 'top10_surnames' => TopSurnamesModule::class, 2644ca7e03cSGreg Roach 'tree' => InteractiveTreeModule::class, 2654ca7e03cSGreg Roach 'trees-menu' => TreesMenuModule::class, 2664ca7e03cSGreg Roach 'upcoming_events' => UpcomingAnniversariesModule::class, 26709fbf3e5SGreg Roach 'us-presidents' => USPresidents::class, 2684ca7e03cSGreg Roach 'user_blog' => UserJournalModule::class, 2694ca7e03cSGreg Roach 'user_favorites' => UserFavoritesModule::class, 2704ca7e03cSGreg Roach 'user_messages' => UserMessagesModule::class, 2714ca7e03cSGreg Roach 'user_welcome' => UserWelcomeModule::class, 2724ca7e03cSGreg Roach 'webtrees' => WebtreesTheme::class, 2734ca7e03cSGreg Roach 'xenea' => XeneaTheme::class, 2744ca7e03cSGreg Roach 'yahrzeit' => YahrzeitModule::class, 2754ca7e03cSGreg Roach ]; 2764ca7e03cSGreg Roach 2774ca7e03cSGreg Roach /** 2784ca7e03cSGreg Roach * All core modules in the system. 2794ca7e03cSGreg Roach * 2804ca7e03cSGreg Roach * @return Collection 2814ca7e03cSGreg Roach */ 2824ca7e03cSGreg Roach private function coreModules(): Collection 2834ca7e03cSGreg Roach { 284321a89daSGreg Roach return Collection::make(self::CORE_MODULES) 285321a89daSGreg Roach ->map(function (string $class, string $name): ModuleInterface { 286cab242e7SGreg Roach $module = app($class); 2874ca7e03cSGreg Roach 2884ca7e03cSGreg Roach $module->setName($name); 2894ca7e03cSGreg Roach 2904ca7e03cSGreg Roach return $module; 2914ca7e03cSGreg Roach }); 2924ca7e03cSGreg Roach } 2934ca7e03cSGreg Roach 2944ca7e03cSGreg Roach /** 2954ca7e03cSGreg Roach * All custom modules in the system. Custom modules are defined in modules_v4/ 2964ca7e03cSGreg Roach * 2974ca7e03cSGreg Roach * @return Collection 2984ca7e03cSGreg Roach */ 2994ca7e03cSGreg Roach private function customModules(): Collection 3004ca7e03cSGreg Roach { 3014ca7e03cSGreg Roach $pattern = WT_ROOT . Webtrees::MODULES_PATH . '*/module.php'; 3024ca7e03cSGreg Roach $filenames = glob($pattern); 3034ca7e03cSGreg Roach 304321a89daSGreg Roach return Collection::make($filenames) 3054ca7e03cSGreg Roach ->filter(function (string $filename): bool { 3064ca7e03cSGreg Roach // Special characters will break PHP variable names. 3074ca7e03cSGreg Roach // This also allows us to ignore modules called "foo.example" and "foo.disable" 3084ca7e03cSGreg Roach $module_name = basename(dirname($filename)); 3094ca7e03cSGreg Roach 3104ca7e03cSGreg Roach return !Str::contains($module_name, ['.', ' ', '[', ']']) && Str::length($module_name) <= 30; 3114ca7e03cSGreg Roach }) 3124ca7e03cSGreg Roach ->map(function (string $filename): ?ModuleCustomInterface { 3134ca7e03cSGreg Roach try { 3144ca7e03cSGreg Roach $module = self::load($filename); 3154ca7e03cSGreg Roach 3164ca7e03cSGreg Roach if ($module instanceof ModuleCustomInterface) { 3174ca7e03cSGreg Roach $module_name = '_' . basename(dirname($filename)) . '_'; 3184ca7e03cSGreg Roach 3194ca7e03cSGreg Roach $module->setName($module_name); 3204ca7e03cSGreg Roach } else { 3214ca7e03cSGreg Roach return null; 3224ca7e03cSGreg Roach } 3234ca7e03cSGreg Roach 3244ca7e03cSGreg Roach return $module; 3254ca7e03cSGreg Roach } catch (Throwable $ex) { 3264ca7e03cSGreg Roach $message = '<pre>' . e($ex->getMessage()) . "\n" . e($ex->getTraceAsString()) . '</pre>'; 3274ca7e03cSGreg Roach FlashMessages::addMessage($message, 'danger'); 3284ca7e03cSGreg Roach 3294ca7e03cSGreg Roach return null; 3304ca7e03cSGreg Roach } 3314ca7e03cSGreg Roach }) 3324ca7e03cSGreg Roach ->filter(); 3334ca7e03cSGreg Roach } 3344ca7e03cSGreg Roach 3354ca7e03cSGreg Roach /** 3364ca7e03cSGreg Roach * All modules. 3374ca7e03cSGreg Roach * 3389d627a9eSGreg Roach * @param bool $include_disabled 3399d627a9eSGreg Roach * 340*54c7f8dfSGreg Roach * @return Collection 341*54c7f8dfSGreg Roach * @return ModuleInterface[] 3424ca7e03cSGreg Roach */ 3439d627a9eSGreg Roach public function all(bool $include_disabled = false): Collection 3444ca7e03cSGreg Roach { 3454ca7e03cSGreg Roach return app('cache.array')->rememberForever('all_modules', function (): Collection { 3464ca7e03cSGreg Roach // Modules have a default status, order etc. 3474ca7e03cSGreg Roach // We can override these from database settings. 3484ca7e03cSGreg Roach $module_info = DB::table('module') 3494ca7e03cSGreg Roach ->get() 3504ca7e03cSGreg Roach ->mapWithKeys(function (stdClass $row): array { 3514ca7e03cSGreg Roach return [$row->module_name => $row]; 3524ca7e03cSGreg Roach }); 3534ca7e03cSGreg Roach 354bf57b580SGreg Roach return $this->coreModules() 355bf57b580SGreg Roach ->merge($this->customModules()) 3564ca7e03cSGreg Roach ->map(function (ModuleInterface $module) use ($module_info): ModuleInterface { 3574ca7e03cSGreg Roach $info = $module_info->get($module->name()); 3584ca7e03cSGreg Roach 3594ca7e03cSGreg Roach if ($info instanceof stdClass) { 3604ca7e03cSGreg Roach $module->setEnabled($info->status === 'enabled'); 3614ca7e03cSGreg Roach 3624ca7e03cSGreg Roach if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) { 3634ca7e03cSGreg Roach $module->setFooterOrder((int) $info->footer_order); 3644ca7e03cSGreg Roach } 3654ca7e03cSGreg Roach 3664ca7e03cSGreg Roach if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) { 3674ca7e03cSGreg Roach $module->setMenuOrder((int) $info->menu_order); 3684ca7e03cSGreg Roach } 3694ca7e03cSGreg Roach 3704ca7e03cSGreg Roach if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) { 3714ca7e03cSGreg Roach $module->setSidebarOrder((int) $info->sidebar_order); 3724ca7e03cSGreg Roach } 3734ca7e03cSGreg Roach 3744ca7e03cSGreg Roach if ($module instanceof ModuleTabInterface && $info->tab_order !== null) { 3754ca7e03cSGreg Roach $module->setTabOrder((int) $info->tab_order); 3764ca7e03cSGreg Roach } 3774ca7e03cSGreg Roach } else { 378888ddf4fSGreg Roach $module->setEnabled($module->isEnabledByDefault()); 379888ddf4fSGreg Roach 380888ddf4fSGreg Roach DB::table('module')->insert([ 381888ddf4fSGreg Roach 'module_name' => $module->name(), 382888ddf4fSGreg Roach 'status' => $module->isEnabled() ? 'enabled' : 'disabled', 383888ddf4fSGreg Roach ]); 3844ca7e03cSGreg Roach } 3854ca7e03cSGreg Roach 3864ca7e03cSGreg Roach return $module; 387b5979037SGreg Roach }); 3889d627a9eSGreg Roach })->filter($this->enabledFilter($include_disabled)); 3894ca7e03cSGreg Roach } 3904ca7e03cSGreg Roach 3914ca7e03cSGreg Roach /** 392a8fbc491SGreg Roach * Load a module in a static scope, to prevent it from modifying local or object variables. 3934ca7e03cSGreg Roach * 3944ca7e03cSGreg Roach * @param string $filename 3954ca7e03cSGreg Roach * 3964ca7e03cSGreg Roach * @return mixed 3974ca7e03cSGreg Roach */ 398a8fbc491SGreg Roach private static function load(string $filename) 3994ca7e03cSGreg Roach { 4004ca7e03cSGreg Roach return include $filename; 4014ca7e03cSGreg Roach } 4024ca7e03cSGreg Roach 4034ca7e03cSGreg Roach /** 4044ca7e03cSGreg Roach * A function to sort modules by name 4054ca7e03cSGreg Roach * 4064ca7e03cSGreg Roach * @return Closure 4074ca7e03cSGreg Roach */ 4084ca7e03cSGreg Roach private function moduleSorter(): Closure 4094ca7e03cSGreg Roach { 4104ca7e03cSGreg Roach return function (ModuleInterface $x, ModuleInterface $y): int { 4114ca7e03cSGreg Roach return I18N::strcasecmp($x->title(), $y->title()); 4124ca7e03cSGreg Roach }; 4134ca7e03cSGreg Roach } 4144ca7e03cSGreg Roach 4154ca7e03cSGreg Roach /** 4164ca7e03cSGreg Roach * A function to sort footers 4174ca7e03cSGreg Roach * 4184ca7e03cSGreg Roach * @return Closure 4194ca7e03cSGreg Roach */ 4204ca7e03cSGreg Roach private function footerSorter(): Closure 4214ca7e03cSGreg Roach { 4224ca7e03cSGreg Roach return function (ModuleFooterInterface $x, ModuleFooterInterface $y): int { 4234ca7e03cSGreg Roach return $x->getFooterOrder() <=> $y->getFooterOrder(); 4244ca7e03cSGreg Roach }; 4254ca7e03cSGreg Roach } 4264ca7e03cSGreg Roach 4274ca7e03cSGreg Roach /** 4284ca7e03cSGreg Roach * A function to sort menus 4294ca7e03cSGreg Roach * 4304ca7e03cSGreg Roach * @return Closure 4314ca7e03cSGreg Roach */ 4324ca7e03cSGreg Roach private function menuSorter(): Closure 4334ca7e03cSGreg Roach { 4344ca7e03cSGreg Roach return function (ModuleMenuInterface $x, ModuleMenuInterface $y): int { 4354ca7e03cSGreg Roach return $x->getMenuOrder() <=> $y->getMenuOrder(); 4364ca7e03cSGreg Roach }; 4374ca7e03cSGreg Roach } 4384ca7e03cSGreg Roach 4394ca7e03cSGreg Roach /** 4404ca7e03cSGreg Roach * A function to sort menus 4414ca7e03cSGreg Roach * 4424ca7e03cSGreg Roach * @return Closure 4434ca7e03cSGreg Roach */ 4444ca7e03cSGreg Roach private function sidebarSorter(): Closure 4454ca7e03cSGreg Roach { 4464ca7e03cSGreg Roach return function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int { 4474ca7e03cSGreg Roach return $x->getSidebarOrder() <=> $y->getSidebarOrder(); 4484ca7e03cSGreg Roach }; 4494ca7e03cSGreg Roach } 4504ca7e03cSGreg Roach 4514ca7e03cSGreg Roach /** 4524ca7e03cSGreg Roach * A function to sort menus 4534ca7e03cSGreg Roach * 4544ca7e03cSGreg Roach * @return Closure 4554ca7e03cSGreg Roach */ 4564ca7e03cSGreg Roach private function tabSorter(): Closure 4574ca7e03cSGreg Roach { 4584ca7e03cSGreg Roach return function (ModuleTabInterface $x, ModuleTabInterface $y): int { 4594ca7e03cSGreg Roach return $x->getTabOrder() <=> $y->getTabOrder(); 4604ca7e03cSGreg Roach }; 4614ca7e03cSGreg Roach } 4624ca7e03cSGreg Roach 4634ca7e03cSGreg Roach /** 464321a89daSGreg Roach * A function filter modules by type 465321a89daSGreg Roach * 466321a89daSGreg Roach * @param string $interface 467321a89daSGreg Roach * 468321a89daSGreg Roach * @return Closure 469321a89daSGreg Roach */ 470321a89daSGreg Roach private function interfaceFilter(string $interface): Closure 471321a89daSGreg Roach { 472321a89daSGreg Roach return function (ModuleInterface $module) use ($interface): bool { 473321a89daSGreg Roach return $module instanceof $interface; 474321a89daSGreg Roach }; 475321a89daSGreg Roach } 476321a89daSGreg Roach 477321a89daSGreg Roach /** 478321a89daSGreg Roach * A function filter modules by enabled/disabled 479321a89daSGreg Roach * 480321a89daSGreg Roach * @param bool $include_disabled 481321a89daSGreg Roach * 482321a89daSGreg Roach * @return Closure 483321a89daSGreg Roach */ 484321a89daSGreg Roach private function enabledFilter(bool $include_disabled): Closure 485321a89daSGreg Roach { 486321a89daSGreg Roach return function (ModuleInterface $module) use ($include_disabled): bool { 487321a89daSGreg Roach return $include_disabled || $module->isEnabled(); 488321a89daSGreg Roach }; 489321a89daSGreg Roach } 490321a89daSGreg Roach 491321a89daSGreg Roach /** 492dedcf571SGreg Roach * A function to convert modules into their titles - to create option lists, etc. 493dedcf571SGreg Roach * 494dedcf571SGreg Roach * @return Closure 495dedcf571SGreg Roach */ 496dedcf571SGreg Roach public function titleMapper(): Closure 497dedcf571SGreg Roach { 498dedcf571SGreg Roach return function (ModuleInterface $module): string { 499dedcf571SGreg Roach return $module->title(); 500dedcf571SGreg Roach }; 501dedcf571SGreg Roach } 502dedcf571SGreg Roach 503dedcf571SGreg Roach /** 5044ca7e03cSGreg Roach * Modules which (a) provide a specific function and (b) we have permission to see. 5054ca7e03cSGreg Roach * 50687cca37cSGreg Roach * @param string $interface 5074ca7e03cSGreg Roach * @param Tree $tree 508e5a6b4d4SGreg Roach * @param UserInterface $user 5094ca7e03cSGreg Roach * 510*54c7f8dfSGreg Roach * @return Collection 511*54c7f8dfSGreg Roach * @return ModuleInterface[] 5124ca7e03cSGreg Roach */ 51387cca37cSGreg Roach public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection 5144ca7e03cSGreg Roach { 515b5979037SGreg Roach return $this->findByInterface($interface, false, true) 51687cca37cSGreg Roach ->filter(function (ModuleInterface $module) use ($interface, $tree, $user): bool { 51787cca37cSGreg Roach return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user); 5184ca7e03cSGreg Roach }); 5194ca7e03cSGreg Roach } 5204ca7e03cSGreg Roach 5214ca7e03cSGreg Roach /** 5224ca7e03cSGreg Roach * All modules which provide a specific function. 5234ca7e03cSGreg Roach * 5244ca7e03cSGreg Roach * @param string $interface 5254ca7e03cSGreg Roach * @param bool $include_disabled 526b5979037SGreg Roach * @param bool $sort 5274ca7e03cSGreg Roach * 528*54c7f8dfSGreg Roach * @return Collection 529*54c7f8dfSGreg Roach * @return ModuleInterface[] 5304ca7e03cSGreg Roach */ 531b5979037SGreg Roach public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection 5324ca7e03cSGreg Roach { 5339d627a9eSGreg Roach $modules = $this->all($include_disabled) 5349d627a9eSGreg Roach ->filter($this->interfaceFilter($interface)); 5354ca7e03cSGreg Roach 5364ca7e03cSGreg Roach switch ($interface) { 5374ca7e03cSGreg Roach case ModuleFooterInterface::class: 538bf57b580SGreg Roach return $modules->sort($this->footerSorter()); 5394ca7e03cSGreg Roach 5404ca7e03cSGreg Roach case ModuleMenuInterface::class: 541bf57b580SGreg Roach return $modules->sort($this->menuSorter()); 5424ca7e03cSGreg Roach 5434ca7e03cSGreg Roach case ModuleSidebarInterface::class: 544bf57b580SGreg Roach return $modules->sort($this->sidebarSorter()); 5454ca7e03cSGreg Roach 5464ca7e03cSGreg Roach case ModuleTabInterface::class: 547bf57b580SGreg Roach return $modules->sort($this->tabSorter()); 548b5979037SGreg Roach 549b5979037SGreg Roach default: 550b5979037SGreg Roach if ($sort) { 551b5979037SGreg Roach return $modules->sort($this->moduleSorter()); 5524ca7e03cSGreg Roach } 5534ca7e03cSGreg Roach 5544ca7e03cSGreg Roach return $modules; 5554ca7e03cSGreg Roach } 556b5979037SGreg Roach } 5574ca7e03cSGreg Roach 5584ca7e03cSGreg Roach /** 5594ca7e03cSGreg Roach * Find a specified module, if it is currently active. 5604ca7e03cSGreg Roach * 5614ca7e03cSGreg Roach * @param string $module_name 562321a89daSGreg Roach * @param bool $include_disabled 5634ca7e03cSGreg Roach * 5644ca7e03cSGreg Roach * @return ModuleInterface|null 5654ca7e03cSGreg Roach */ 566321a89daSGreg Roach public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface 5674ca7e03cSGreg Roach { 5689d627a9eSGreg Roach return $this->all($include_disabled) 5694ca7e03cSGreg Roach ->filter(function (ModuleInterface $module) use ($module_name): bool { 570321a89daSGreg Roach return $module->name() === $module_name; 5714ca7e03cSGreg Roach }) 5724ca7e03cSGreg Roach ->first(); 5734ca7e03cSGreg Roach } 574bf57b580SGreg Roach 575bf57b580SGreg Roach /** 576bf57b580SGreg Roach * Configuration settings are available through the various "module component" pages. 577bf57b580SGreg Roach * For modules that do not provide a component, we need to list them separately. 578bf57b580SGreg Roach * 57909fbf3e5SGreg Roach * @param bool $include_disabled 58009fbf3e5SGreg Roach * 581*54c7f8dfSGreg Roach * @return Collection 582*54c7f8dfSGreg Roach * @return ModuleConfigInterface[] 583bf57b580SGreg Roach */ 58409fbf3e5SGreg Roach public function otherModules(bool $include_disabled = false): Collection 585bf57b580SGreg Roach { 58609fbf3e5SGreg Roach return $this->all($include_disabled) 58709fbf3e5SGreg Roach ->filter(function (ModuleInterface $module): bool { 588bf57b580SGreg Roach foreach (self::COMPONENTS as $interface) { 589bf57b580SGreg Roach if ($module instanceof $interface) { 590bf57b580SGreg Roach return false; 591bf57b580SGreg Roach } 592bf57b580SGreg Roach } 593bf57b580SGreg Roach 594bf57b580SGreg Roach return true; 595bf57b580SGreg Roach }); 596bf57b580SGreg Roach } 597bf57b580SGreg Roach 598bf57b580SGreg Roach /** 599bf57b580SGreg Roach * Generate a list of module names which exist in the database but not on disk. 600bf57b580SGreg Roach * 601*54c7f8dfSGreg Roach * @return Collection 602*54c7f8dfSGreg Roach * @return string[] 603bf57b580SGreg Roach */ 604bf57b580SGreg Roach public function deletedModules(): Collection 605bf57b580SGreg Roach { 606bf57b580SGreg Roach $database_modules = DB::table('module')->pluck('module_name'); 607bf57b580SGreg Roach 608d5d58984SGreg Roach $disk_modules = $this->all(true) 609bf57b580SGreg Roach ->map(function (ModuleInterface $module): string { 610bf57b580SGreg Roach return $module->name(); 611bf57b580SGreg Roach }); 612bf57b580SGreg Roach 613bf57b580SGreg Roach return $database_modules->diff($disk_modules); 614bf57b580SGreg Roach } 6154ca7e03cSGreg Roach} 616