xref: /webtrees/app/Services/ModuleService.php (revision f397d0fdeebb0d5a9590d5ba2d4d2aae8df09df1)
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\I18N;
244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AhnentafelReportModule;
254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AlbumModule;
264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\AncestorsChartModule;
274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BatchUpdateModule;
284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BingWebmasterToolsModule;
294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthDeathMarriageReportModule;
304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\BirthReportModule;
3167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\BranchesListModule;
3209fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishMonarchs;
3309fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishPrimeMinisters;
3409fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\BritishSocialHistory;
354ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CalendarMenuModule;
364ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CemeteryReportModule;
374ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CensusAssistantModule;
384ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChangeReportModule;
394ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsBlockModule;
404ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ChartsMenuModule;
414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CkeditorModule;
424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ClippingsCartModule;
434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CloudsTheme;
444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ColorsTheme;
454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CompactTreeChartModule;
464ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ContactsFooterModule;
474ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\CookieWarningModule;
488d6560c4SGreg Roachuse Fisharebest\Webtrees\Module\CustomCssJsModule;
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;
7502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAfrikaans;
7602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageAlbanian;
7702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageArabic;
7802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBosnian;
7902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageBulgarian;
8002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCatalan;
8102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseSimplified;
8202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageChineseTraditional;
8302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCroatian;
8402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageCzech;
8502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDanish;
8602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDivehi;
8702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageDutch;
8802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishAustralia;
8902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishGreatBritain;
9002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEnglishUnitedStates;
9102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageEstonian;
9202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFaroese;
9302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFarsi;
9402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFinnish;
9502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrench;
9602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageFrenchCanada;
9702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGalician;
9802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGeorgian;
9902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGerman;
10002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageGreek;
10102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHebrew;
10202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageHungarian;
10302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageIcelandic;
10402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageIndonesian;
10502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageItalian;
10602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageJapanese;
10702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageJavanese;
10802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageKazhak;
10902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageKorean;
11002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLatvian;
11102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLingala;
11202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageLithuanian;
11302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMalay;
11402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMaori;
11502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageMarathi;
11602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNepalese;
11702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNorwegianBokmal;
11802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageNorwegianNynorsk;
11902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageOccitan;
12002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePolish;
12102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePortuguese;
12202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguagePortugueseBrazil;
12302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageRomanian;
12402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageRussian;
12502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSerbian;
12602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSerbianLatin;
12702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSlovakian;
12802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSlovenian;
12902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSpanish;
13002086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSundanese;
13102086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSwahili;
13202086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageSwedish;
13302086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTamil;
13402086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTatar;
13502086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageThai;
13602086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageTurkish;
13702086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageUkranian;
13802086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageVietnamese;
13902086832SGreg Roachuse Fisharebest\Webtrees\Module\LanguageYiddish;
1404ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LifespansChartModule;
1414ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ListsMenuModule;
1424ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoggedInUsersModule;
1434ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\LoginBlockModule;
1444ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MarriageReportModule;
1454ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MatomoAnalyticsModule;
14667992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\MediaListModule;
1474ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MediaTabModule;
1484ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MinimalTheme;
1494ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\MissingFactsReportModule;
150bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
1514ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface;
1524ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface;
153bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface;
1544ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleCustomInterface;
1554ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleFooterInterface;
156bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface;
1574ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface;
158bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface;
15967992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\ModuleListInterface;
1604ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface;
1614ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface;
1624ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface;
1634ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface;
164bf57b580SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface;
16567992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\NoteListModule;
1664ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\NotesTabModule;
1674ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OccupationReportModule;
1684ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\OnThisDayModule;
1694ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeChartModule;
1704ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeMapModule;
1714ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PedigreeReportModule;
17267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\PlaceHierarchyListModule;
1734ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PlacesModule;
1744ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\PoweredByWebtreesModule;
1754ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RecentChangesModule;
1764ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelatedIndividualsReportModule;
1774ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule;
1784ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\RelativesTabModule;
1794ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReportsMenuModule;
18067992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\RepositoryListModule;
1814ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ResearchTaskModule;
1824ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ReviewChangesModule;
1834ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SearchMenuModule;
1844ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SiteMapModule;
1854ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SlideShowModule;
18667992b6aSRichard Cisseeuse Fisharebest\Webtrees\Module\SourceListModule;
1874ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\SourcesTabModule;
1884ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatcounterModule;
1894ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StatisticsChartModule;
1904ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\StoriesModule;
1914ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ThemeSelectModule;
1924ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TimelineChartModule;
1934ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopGivenNamesModule;
1944ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopPageViewsModule;
1954ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TopSurnamesModule;
1964ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TreesMenuModule;
1974ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UpcomingAnniversariesModule;
1984ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserFavoritesModule;
1994ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserJournalModule;
2004ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserMessagesModule;
2014ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\UserWelcomeModule;
20209fbf3e5SGreg Roachuse Fisharebest\Webtrees\Module\USPresidents;
2034ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WebtreesTheme;
2044ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\WelcomeBlockModule;
2054ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\XeneaTheme;
2064ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\YahrzeitModule;
2074ca7e03cSGreg Roachuse Fisharebest\Webtrees\Tree;
2084ca7e03cSGreg Roachuse Fisharebest\Webtrees\Webtrees;
2094ca7e03cSGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
2104ca7e03cSGreg Roachuse Illuminate\Support\Collection;
2114ca7e03cSGreg Roachuse Illuminate\Support\Str;
2124ca7e03cSGreg Roachuse stdClass;
2134ca7e03cSGreg Roachuse Throwable;
2144ca7e03cSGreg Roach
2154ca7e03cSGreg Roach/**
2164ca7e03cSGreg Roach * Functions for managing and maintaining modules.
2174ca7e03cSGreg Roach */
2184ca7e03cSGreg Roachclass ModuleService
2194ca7e03cSGreg Roach{
220362b8464SGreg Roach    // Components are pieces of user-facing functionality, are managed together in the control panel.
2214ca7e03cSGreg Roach    private const COMPONENTS = [
22287cca37cSGreg Roach        ModuleAnalyticsInterface::class,
22387cca37cSGreg Roach        ModuleBlockInterface::class,
22487cca37cSGreg Roach        ModuleChartInterface::class,
22587cca37cSGreg Roach        ModuleFooterInterface::class,
22687cca37cSGreg Roach        ModuleHistoricEventsInterface::class,
22787cca37cSGreg Roach        ModuleLanguageInterface::class,
22887cca37cSGreg Roach        ModuleListInterface::class,
22987cca37cSGreg Roach        ModuleMenuInterface::class,
23087cca37cSGreg Roach        ModuleReportInterface::class,
23187cca37cSGreg Roach        ModuleSidebarInterface::class,
23287cca37cSGreg Roach        ModuleTabInterface::class,
23387cca37cSGreg Roach        ModuleThemeInterface::class,
2344ca7e03cSGreg Roach    ];
2354ca7e03cSGreg Roach
2364ca7e03cSGreg Roach    // Array keys are module names, and should match module names from earlier versions of webtrees.
2374ca7e03cSGreg Roach    private const CORE_MODULES = [
2384ca7e03cSGreg Roach        'GEDFact_assistant'       => CensusAssistantModule::class,
2394ca7e03cSGreg Roach        'ahnentafel_report'       => AhnentafelReportModule::class,
2404ca7e03cSGreg Roach        'ancestors_chart'         => AncestorsChartModule::class,
2414ca7e03cSGreg Roach        'batch_update'            => BatchUpdateModule::class,
2424ca7e03cSGreg Roach        'bdm_report'              => BirthDeathMarriageReportModule::class,
2434ca7e03cSGreg Roach        'bing-webmaster-tools'    => BingWebmasterToolsModule::class,
2444ca7e03cSGreg Roach        'birth_report'            => BirthReportModule::class,
24567992b6aSRichard Cissee        'branches_list'           => BranchesListModule::class,
24609fbf3e5SGreg Roach        'british-monarchs'        => BritishMonarchs::class,
24709fbf3e5SGreg Roach        'british-prime-ministers' => BritishPrimeMinisters::class,
24809fbf3e5SGreg Roach        'british-social-history'  => BritishSocialHistory::class,
2494ca7e03cSGreg Roach        'calendar-menu'           => CalendarMenuModule::class,
2504ca7e03cSGreg Roach        'cemetery_report'         => CemeteryReportModule::class,
2514ca7e03cSGreg Roach        'change_report'           => ChangeReportModule::class,
2524ca7e03cSGreg Roach        'charts'                  => ChartsBlockModule::class,
2534ca7e03cSGreg Roach        'charts-menu'             => ChartsMenuModule::class,
2544ca7e03cSGreg Roach        'ckeditor'                => CkeditorModule::class,
2554ca7e03cSGreg Roach        'clippings'               => ClippingsCartModule::class,
2564ca7e03cSGreg Roach        'clouds'                  => CloudsTheme::class,
2574ca7e03cSGreg Roach        'colors'                  => ColorsTheme::class,
2584ca7e03cSGreg Roach        'compact-chart'           => CompactTreeChartModule::class,
2594ca7e03cSGreg Roach        'contact-links'           => ContactsFooterModule::class,
2604ca7e03cSGreg Roach        'cookie-warning'          => CookieWarningModule::class,
2618d6560c4SGreg Roach        'custom-css-js'           => CustomCssJsModule::class,
2624ca7e03cSGreg Roach        'death_report'            => DeathReportModule::class,
2634ca7e03cSGreg Roach        'descendancy'             => DescendancyModule::class,
2644ca7e03cSGreg Roach        'descendancy_chart'       => DescendancyChartModule::class,
2654ca7e03cSGreg Roach        'descendancy_report'      => DescendancyReportModule::class,
2668eaf8709SGreg Roach        'extra_info'              => IndividualMetadataModule::class,
2674ca7e03cSGreg Roach        'fab'                     => FabTheme::class,
2684ca7e03cSGreg Roach        'fact_sources'            => FactSourcesReportModule::class,
2694ca7e03cSGreg Roach        'family_book_chart'       => FamilyBookChartModule::class,
2704ca7e03cSGreg Roach        'family_group_report'     => FamilyGroupReportModule::class,
27167992b6aSRichard Cissee        'family_list'             => FamilyListModule::class,
2724ca7e03cSGreg Roach        'family_nav'              => FamilyNavigatorModule::class,
2734ca7e03cSGreg Roach        'fan_chart'               => FanChartModule::class,
2744ca7e03cSGreg Roach        'faq'                     => FrequentlyAskedQuestionsModule::class,
2754ca7e03cSGreg Roach        'gedcom_block'            => WelcomeBlockModule::class,
2764ca7e03cSGreg Roach        'gedcom_favorites'        => FamilyTreeFavoritesModule::class,
2774ca7e03cSGreg Roach        'gedcom_news'             => FamilyTreeNewsModule::class,
2784ca7e03cSGreg Roach        'gedcom_stats'            => FamilyTreeStatisticsModule::class,
2794ca7e03cSGreg Roach        'google-analytics'        => GoogleAnalyticsModule::class,
2804ca7e03cSGreg Roach        'google-webmaster-tools'  => GoogleWebmasterToolsModule::class,
2814ca7e03cSGreg Roach        'hit-counter'             => HitCountFooterModule::class,
2824ca7e03cSGreg Roach        'hourglass_chart'         => HourglassChartModule::class,
2834ca7e03cSGreg Roach        'html'                    => HtmlBlockModule::class,
2844ca7e03cSGreg Roach        'individual_ext_report'   => IndividualFamiliesReportModule::class,
28567992b6aSRichard Cissee        'individual_list'         => IndividualListModule::class,
2864ca7e03cSGreg Roach        'individual_report'       => IndividualReportModule::class,
28702086832SGreg Roach        'language-af'             => LanguageAfrikaans::class,
28802086832SGreg Roach        'language-ar'             => LanguageArabic::class,
28902086832SGreg Roach        'language-bs'             => LanguageBosnian::class,
29002086832SGreg Roach        'language-bu'             => LanguageBulgarian::class,
29102086832SGreg Roach        'language-ca'             => LanguageCatalan::class,
29202086832SGreg Roach        'language-cs'             => LanguageCzech::class,
29302086832SGreg Roach        'language-da'             => LanguageDanish::class,
29402086832SGreg Roach        'language-de'             => LanguageGerman::class,
29502086832SGreg Roach        'language-dv'             => LanguageDivehi::class,
29602086832SGreg Roach        'language-el'             => LanguageGreek::class,
29702086832SGreg Roach        'language-en-AU'          => LanguageEnglishAustralia::class,
29802086832SGreg Roach        'language-en-GB'          => LanguageEnglishGreatBritain::class,
29902086832SGreg Roach        'language-en-US'          => LanguageEnglishUnitedStates::class,
30002086832SGreg Roach        'language-es'             => LanguageSpanish::class,
30102086832SGreg Roach        'language-et'             => LanguageEstonian::class,
30202086832SGreg Roach        'language-fa'             => LanguageFarsi::class,
30302086832SGreg Roach        'language-fi'             => LanguageFinnish::class,
30402086832SGreg Roach        'language-fo'             => LanguageFaroese::class,
30502086832SGreg Roach        'language-fr'             => LanguageFrench::class,
30602086832SGreg Roach        'language-fr-CA'          => LanguageFrenchCanada::class,
30702086832SGreg Roach        'language-gl'             => LanguageGalician::class,
30802086832SGreg Roach        'language-he'             => LanguageHebrew::class,
30902086832SGreg Roach        'language-hr'             => LanguageCroatian::class,
31002086832SGreg Roach        'language-hu'             => LanguageHungarian::class,
31102086832SGreg Roach        'language-id'             => LanguageIndonesian::class,
31202086832SGreg Roach        'language-is'             => LanguageIcelandic::class,
31302086832SGreg Roach        'language-it'             => LanguageItalian::class,
31402086832SGreg Roach        'language-ja'             => LanguageJapanese::class,
31502086832SGreg Roach        'language-jv'             => LanguageJavanese::class,
31602086832SGreg Roach        'language-ka'             => LanguageGeorgian::class,
31702086832SGreg Roach        'language-kk'             => LanguageKazhak::class,
31802086832SGreg Roach        'language-ko'             => LanguageKorean::class,
31902086832SGreg Roach        'language-ln'             => LanguageLingala::class,
32002086832SGreg Roach        'language-lt'             => LanguageLithuanian::class,
32102086832SGreg Roach        'language-lv'             => LanguageLatvian::class,
32202086832SGreg Roach        'language-mi'             => LanguageMaori::class,
32302086832SGreg Roach        'language-mr'             => LanguageMarathi::class,
32402086832SGreg Roach        'language-ms'             => LanguageMalay::class,
32502086832SGreg Roach        'language-nb'             => LanguageNorwegianBokmal::class,
32602086832SGreg Roach        'language-ne'             => LanguageNepalese::class,
32702086832SGreg Roach        'language-nl'             => LanguageDutch::class,
32802086832SGreg Roach        'language-nn'             => LanguageNorwegianNynorsk::class,
32902086832SGreg Roach        'language-oc'             => LanguageOccitan::class,
33002086832SGreg Roach        'language-pl'             => LanguagePolish::class,
33102086832SGreg Roach        'language-pt'             => LanguagePortuguese::class,
33202086832SGreg Roach        'language-pt-BR'          => LanguagePortugueseBrazil::class,
33302086832SGreg Roach        'language-ro'             => LanguageRomanian::class,
33402086832SGreg Roach        'language-ru'             => LanguageRussian::class,
33502086832SGreg Roach        'language-sk'             => LanguageSlovakian::class,
33602086832SGreg Roach        'language-sl'             => LanguageSlovenian::class,
33702086832SGreg Roach        'language-sq'             => LanguageAlbanian::class,
33802086832SGreg Roach        'language-sr'             => LanguageSerbian::class,
33902086832SGreg Roach        'language-sr-Latn'        => LanguageSerbianLatin::class,
34002086832SGreg Roach        'language-su'             => LanguageSundanese::class,
34102086832SGreg Roach        'language-sv'             => LanguageSwedish::class,
34202086832SGreg Roach        'language-sw'             => LanguageSwahili::class,
34302086832SGreg Roach        'language-ta'             => LanguageTamil::class,
34402086832SGreg Roach        'language-th'             => LanguageThai::class,
34502086832SGreg Roach        'language-tr'             => LanguageTurkish::class,
34602086832SGreg Roach        'language-tt'             => LanguageTatar::class,
34702086832SGreg Roach        'language-uk'             => LanguageUkranian::class,
34802086832SGreg Roach        'language-vi'             => LanguageVietnamese::class,
34902086832SGreg Roach        'language-yi'             => LanguageYiddish::class,
35002086832SGreg Roach        'language-zh-Hans'        => LanguageChineseSimplified::class,
35102086832SGreg Roach        'language-zh-Hant'        => LanguageChineseTraditional::class,
3524ca7e03cSGreg Roach        'lifespans_chart'         => LifespansChartModule::class,
3534ca7e03cSGreg Roach        'lightbox'                => AlbumModule::class,
3544ca7e03cSGreg Roach        'lists-menu'              => ListsMenuModule::class,
3554ca7e03cSGreg Roach        'logged_in'               => LoggedInUsersModule::class,
3564ca7e03cSGreg Roach        'login_block'             => LoginBlockModule::class,
3574ca7e03cSGreg Roach        'marriage_report'         => MarriageReportModule::class,
3584ca7e03cSGreg Roach        'matomo-analytics'        => MatomoAnalyticsModule::class,
3594ca7e03cSGreg Roach        'media'                   => MediaTabModule::class,
36067992b6aSRichard Cissee        'media_list'              => MediaListModule::class,
3614ca7e03cSGreg Roach        'minimal'                 => MinimalTheme::class,
3624ca7e03cSGreg Roach        'missing_facts_report'    => MissingFactsReportModule::class,
3634ca7e03cSGreg Roach        'notes'                   => NotesTabModule::class,
36467992b6aSRichard Cissee        'note_list'               => NoteListModule::class,
3654ca7e03cSGreg Roach        'occupation_report'       => OccupationReportModule::class,
3664ca7e03cSGreg Roach        'pedigree-map'            => PedigreeMapModule::class,
3674ca7e03cSGreg Roach        'pedigree_chart'          => PedigreeChartModule::class,
3684ca7e03cSGreg Roach        'pedigree_report'         => PedigreeReportModule::class,
3694ca7e03cSGreg Roach        'personal_facts'          => IndividualFactsTabModule::class,
3704ca7e03cSGreg Roach        'places'                  => PlacesModule::class,
37167992b6aSRichard Cissee        'places_list'             => PlaceHierarchyListModule::class,
3724ca7e03cSGreg Roach        'powered-by-webtrees'     => PoweredByWebtreesModule::class,
3734ca7e03cSGreg Roach        'random_media'            => SlideShowModule::class,
3744ca7e03cSGreg Roach        'recent_changes'          => RecentChangesModule::class,
3754ca7e03cSGreg Roach        'relationships_chart'     => RelationshipsChartModule::class,
3764ca7e03cSGreg Roach        'relative_ext_report'     => RelatedIndividualsReportModule::class,
3774ca7e03cSGreg Roach        'relatives'               => RelativesTabModule::class,
3784ca7e03cSGreg Roach        'reports-menu'            => ReportsMenuModule::class,
37967992b6aSRichard Cissee        'repository_list'         => RepositoryListModule::class,
3804ca7e03cSGreg Roach        'review_changes'          => ReviewChangesModule::class,
3814ca7e03cSGreg Roach        'search-menu'             => SearchMenuModule::class,
3824ca7e03cSGreg Roach        'sitemap'                 => SiteMapModule::class,
38367992b6aSRichard Cissee        'source_list'             => SourceListModule::class,
3844ca7e03cSGreg Roach        'sources_tab'             => SourcesTabModule::class,
3854ca7e03cSGreg Roach        'statcounter'             => StatcounterModule::class,
3864ca7e03cSGreg Roach        'statistics_chart'        => StatisticsChartModule::class,
3874ca7e03cSGreg Roach        'stories'                 => StoriesModule::class,
3884ca7e03cSGreg Roach        'theme_select'            => ThemeSelectModule::class,
3894ca7e03cSGreg Roach        'timeline_chart'          => TimelineChartModule::class,
3904ca7e03cSGreg Roach        'todays_events'           => OnThisDayModule::class,
3914ca7e03cSGreg Roach        'todo'                    => ResearchTaskModule::class,
3924ca7e03cSGreg Roach        'top10_givnnames'         => TopGivenNamesModule::class,
3934ca7e03cSGreg Roach        'top10_pageviews'         => TopPageViewsModule::class,
3944ca7e03cSGreg Roach        'top10_surnames'          => TopSurnamesModule::class,
3954ca7e03cSGreg Roach        'tree'                    => InteractiveTreeModule::class,
3964ca7e03cSGreg Roach        'trees-menu'              => TreesMenuModule::class,
3974ca7e03cSGreg Roach        'upcoming_events'         => UpcomingAnniversariesModule::class,
39809fbf3e5SGreg Roach        'us-presidents'           => USPresidents::class,
3994ca7e03cSGreg Roach        'user_blog'               => UserJournalModule::class,
4004ca7e03cSGreg Roach        'user_favorites'          => UserFavoritesModule::class,
4014ca7e03cSGreg Roach        'user_messages'           => UserMessagesModule::class,
4024ca7e03cSGreg Roach        'user_welcome'            => UserWelcomeModule::class,
4034ca7e03cSGreg Roach        'webtrees'                => WebtreesTheme::class,
4044ca7e03cSGreg Roach        'xenea'                   => XeneaTheme::class,
4054ca7e03cSGreg Roach        'yahrzeit'                => YahrzeitModule::class,
4064ca7e03cSGreg Roach    ];
4074ca7e03cSGreg Roach
4084ca7e03cSGreg Roach    /**
409dedcf571SGreg Roach     * A function to convert modules into their titles - to create option lists, etc.
410dedcf571SGreg Roach     *
411dedcf571SGreg Roach     * @return Closure
412dedcf571SGreg Roach     */
413dedcf571SGreg Roach    public function titleMapper(): Closure
414dedcf571SGreg Roach    {
415dedcf571SGreg Roach        return function (ModuleInterface $module): string {
416dedcf571SGreg Roach            return $module->title();
417dedcf571SGreg Roach        };
418dedcf571SGreg Roach    }
419dedcf571SGreg Roach
420dedcf571SGreg Roach    /**
4214ca7e03cSGreg Roach     * Modules which (a) provide a specific function and (b) we have permission to see.
4224ca7e03cSGreg Roach     *
42387cca37cSGreg Roach     * @param string        $interface
4244ca7e03cSGreg Roach     * @param Tree          $tree
425e5a6b4d4SGreg Roach     * @param UserInterface $user
4264ca7e03cSGreg Roach     *
42754c7f8dfSGreg Roach     * @return Collection
42854c7f8dfSGreg Roach     * @return ModuleInterface[]
4294ca7e03cSGreg Roach     */
43087cca37cSGreg Roach    public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection
4314ca7e03cSGreg Roach    {
432b5979037SGreg Roach        return $this->findByInterface($interface, false, true)
4330b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module) use ($interface, $tree, $user): bool {
43487cca37cSGreg Roach                return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user);
4354ca7e03cSGreg Roach            });
4364ca7e03cSGreg Roach    }
4374ca7e03cSGreg Roach
4384ca7e03cSGreg Roach    /**
4394ca7e03cSGreg Roach     * All modules which provide a specific function.
4404ca7e03cSGreg Roach     *
4414ca7e03cSGreg Roach     * @param string $interface
4424ca7e03cSGreg Roach     * @param bool   $include_disabled
443b5979037SGreg Roach     * @param bool   $sort
4444ca7e03cSGreg Roach     *
44554c7f8dfSGreg Roach     * @return Collection
44654c7f8dfSGreg Roach     * @return ModuleInterface[]
4474ca7e03cSGreg Roach     */
448b5979037SGreg Roach    public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
4494ca7e03cSGreg Roach    {
4509d627a9eSGreg Roach        $modules = $this->all($include_disabled)
4519d627a9eSGreg Roach            ->filter($this->interfaceFilter($interface));
4524ca7e03cSGreg Roach
4534ca7e03cSGreg Roach        switch ($interface) {
4544ca7e03cSGreg Roach            case ModuleFooterInterface::class:
455bf57b580SGreg Roach                return $modules->sort($this->footerSorter());
4564ca7e03cSGreg Roach
4574ca7e03cSGreg Roach            case ModuleMenuInterface::class:
458bf57b580SGreg Roach                return $modules->sort($this->menuSorter());
4594ca7e03cSGreg Roach
4604ca7e03cSGreg Roach            case ModuleSidebarInterface::class:
461bf57b580SGreg Roach                return $modules->sort($this->sidebarSorter());
4624ca7e03cSGreg Roach
4634ca7e03cSGreg Roach            case ModuleTabInterface::class:
464bf57b580SGreg Roach                return $modules->sort($this->tabSorter());
465b5979037SGreg Roach
466b5979037SGreg Roach            default:
467b5979037SGreg Roach                if ($sort) {
468b5979037SGreg Roach                    return $modules->sort($this->moduleSorter());
4694ca7e03cSGreg Roach                }
4704ca7e03cSGreg Roach
4714ca7e03cSGreg Roach                return $modules;
4724ca7e03cSGreg Roach        }
473b5979037SGreg Roach    }
4744ca7e03cSGreg Roach
4754ca7e03cSGreg Roach    /**
4768d6560c4SGreg Roach     * All modules.
4778d6560c4SGreg Roach     *
4788d6560c4SGreg Roach     * @param bool $include_disabled
4798d6560c4SGreg Roach     *
4808d6560c4SGreg Roach     * @return Collection
4818d6560c4SGreg Roach     * @return ModuleInterface[]
4828d6560c4SGreg Roach     */
4838d6560c4SGreg Roach    public function all(bool $include_disabled = false): Collection
4848d6560c4SGreg Roach    {
4858d6560c4SGreg Roach        return app('cache.array')->rememberForever('all_modules', function (): Collection {
4868d6560c4SGreg Roach            // Modules have a default status, order etc.
4878d6560c4SGreg Roach            // We can override these from database settings.
4888d6560c4SGreg Roach            $module_info = DB::table('module')
4898d6560c4SGreg Roach                ->get()
4900b5fd0a6SGreg Roach                ->mapWithKeys(static function (stdClass $row): array {
4918d6560c4SGreg Roach                    return [$row->module_name => $row];
4928d6560c4SGreg Roach                });
4938d6560c4SGreg Roach
4948d6560c4SGreg Roach            return $this->coreModules()
4958d6560c4SGreg Roach                ->merge($this->customModules())
4960b5fd0a6SGreg Roach                ->map(static function (ModuleInterface $module) use ($module_info): ModuleInterface {
4978d6560c4SGreg Roach                    $info = $module_info->get($module->name());
4988d6560c4SGreg Roach
4998d6560c4SGreg Roach                    if ($info instanceof stdClass) {
5008d6560c4SGreg Roach                        $module->setEnabled($info->status === 'enabled');
5018d6560c4SGreg Roach
5028d6560c4SGreg Roach                        if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) {
5038d6560c4SGreg Roach                            $module->setFooterOrder((int) $info->footer_order);
5048d6560c4SGreg Roach                        }
5058d6560c4SGreg Roach
5068d6560c4SGreg Roach                        if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) {
5078d6560c4SGreg Roach                            $module->setMenuOrder((int) $info->menu_order);
5088d6560c4SGreg Roach                        }
5098d6560c4SGreg Roach
5108d6560c4SGreg Roach                        if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) {
5118d6560c4SGreg Roach                            $module->setSidebarOrder((int) $info->sidebar_order);
5128d6560c4SGreg Roach                        }
5138d6560c4SGreg Roach
5148d6560c4SGreg Roach                        if ($module instanceof ModuleTabInterface && $info->tab_order !== null) {
5158d6560c4SGreg Roach                            $module->setTabOrder((int) $info->tab_order);
5168d6560c4SGreg Roach                        }
5178d6560c4SGreg Roach                    } else {
5188d6560c4SGreg Roach                        $module->setEnabled($module->isEnabledByDefault());
5198d6560c4SGreg Roach
5208d6560c4SGreg Roach                        DB::table('module')->insert([
5218d6560c4SGreg Roach                            'module_name' => $module->name(),
5228d6560c4SGreg Roach                            'status'      => $module->isEnabled() ? 'enabled' : 'disabled',
5238d6560c4SGreg Roach                        ]);
5248d6560c4SGreg Roach                    }
5258d6560c4SGreg Roach
5268d6560c4SGreg Roach                    return $module;
5278d6560c4SGreg Roach                });
5288d6560c4SGreg Roach        })->filter($this->enabledFilter($include_disabled));
5298d6560c4SGreg Roach    }
5308d6560c4SGreg Roach
5318d6560c4SGreg Roach    /**
5328d6560c4SGreg Roach     * All core modules in the system.
5338d6560c4SGreg Roach     *
5348d6560c4SGreg Roach     * @return Collection
5358d6560c4SGreg Roach     */
5368d6560c4SGreg Roach    private function coreModules(): Collection
5378d6560c4SGreg Roach    {
5388d6560c4SGreg Roach        return Collection::make(self::CORE_MODULES)
5390b5fd0a6SGreg Roach            ->map(static function (string $class, string $name): ModuleInterface {
5408d6560c4SGreg Roach                $module = app($class);
5418d6560c4SGreg Roach
5428d6560c4SGreg Roach                $module->setName($name);
5438d6560c4SGreg Roach
5448d6560c4SGreg Roach                return $module;
5458d6560c4SGreg Roach            });
5468d6560c4SGreg Roach    }
5478d6560c4SGreg Roach
5488d6560c4SGreg Roach    /**
5498d6560c4SGreg Roach     * All custom modules in the system.  Custom modules are defined in modules_v4/
5508d6560c4SGreg Roach     *
5518d6560c4SGreg Roach     * @return Collection
5528d6560c4SGreg Roach     */
5538d6560c4SGreg Roach    private function customModules(): Collection
5548d6560c4SGreg Roach    {
555*f397d0fdSGreg Roach        $pattern   = Webtrees::MODULES_DIR . '*/module.php';
5568d6560c4SGreg Roach        $filenames = glob($pattern, GLOB_NOSORT);
5578d6560c4SGreg Roach
5588d6560c4SGreg Roach        return Collection::make($filenames)
5590b5fd0a6SGreg Roach            ->filter(static function (string $filename): bool {
5608d6560c4SGreg Roach                // Special characters will break PHP variable names.
5618d6560c4SGreg Roach                // This also allows us to ignore modules called "foo.example" and "foo.disable"
5628d6560c4SGreg Roach                $module_name = basename(dirname($filename));
5638d6560c4SGreg Roach
5648d6560c4SGreg Roach                return !Str::contains($module_name, ['.', ' ', '[', ']']) && Str::length($module_name) <= 30;
5658d6560c4SGreg Roach            })
5660b5fd0a6SGreg Roach            ->map(static function (string $filename): ?ModuleCustomInterface {
5678d6560c4SGreg Roach                try {
5688d6560c4SGreg Roach                    $module = self::load($filename);
5698d6560c4SGreg Roach
5708d6560c4SGreg Roach                    if ($module instanceof ModuleCustomInterface) {
5718d6560c4SGreg Roach                        $module_name = '_' . basename(dirname($filename)) . '_';
5728d6560c4SGreg Roach
5738d6560c4SGreg Roach                        $module->setName($module_name);
5748d6560c4SGreg Roach                    } else {
5758d6560c4SGreg Roach                        return null;
5768d6560c4SGreg Roach                    }
5778d6560c4SGreg Roach
5788d6560c4SGreg Roach                    return $module;
5798d6560c4SGreg Roach                } catch (Throwable $ex) {
5808d6560c4SGreg Roach                    // It would be nice to show this error in a flash-message or similar, but the framework
5818d6560c4SGreg Roach                    // has not yet been initialised so we have no themes, languages, sessions, etc.
5828d6560c4SGreg Roach                    throw $ex;
5838d6560c4SGreg Roach                }
5848d6560c4SGreg Roach            })
5858d6560c4SGreg Roach            ->filter()
5860b5fd0a6SGreg Roach            ->mapWithKeys(static function (ModuleCustomInterface $module): array {
5878d6560c4SGreg Roach                return [$module->name() => $module];
5888d6560c4SGreg Roach            });
5898d6560c4SGreg Roach    }
5908d6560c4SGreg Roach
5918d6560c4SGreg Roach    /**
59202086832SGreg Roach     * During setup, we'll need access to some languages.
59302086832SGreg Roach     *
59402086832SGreg Roach     * @return Collection
59502086832SGreg Roach     */
59602086832SGreg Roach    public function setupLanguages(): Collection
59702086832SGreg Roach    {
59802086832SGreg Roach        return $this->coreModules()
5990b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module) {
60002086832SGreg Roach                return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault();
60102086832SGreg Roach            })
6020b5fd0a6SGreg Roach            ->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y) {
603c116a5ccSGreg Roach                return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable();
604c116a5ccSGreg Roach            });
60502086832SGreg Roach    }
60602086832SGreg Roach
60702086832SGreg Roach    /**
6088d6560c4SGreg Roach     * Load a module in a static scope, to prevent it from modifying local or object variables.
6098d6560c4SGreg Roach     *
6108d6560c4SGreg Roach     * @param string $filename
6118d6560c4SGreg Roach     *
6128d6560c4SGreg Roach     * @return mixed
6138d6560c4SGreg Roach     */
6148d6560c4SGreg Roach    private static function load(string $filename)
6158d6560c4SGreg Roach    {
6168d6560c4SGreg Roach        return include $filename;
6178d6560c4SGreg Roach    }
6188d6560c4SGreg Roach
6198d6560c4SGreg Roach    /**
6208d6560c4SGreg Roach     * A function filter modules by enabled/disabled
6218d6560c4SGreg Roach     *
6228d6560c4SGreg Roach     * @param bool $include_disabled
6238d6560c4SGreg Roach     *
6248d6560c4SGreg Roach     * @return Closure
6258d6560c4SGreg Roach     */
6268d6560c4SGreg Roach    private function enabledFilter(bool $include_disabled): Closure
6278d6560c4SGreg Roach    {
6288d6560c4SGreg Roach        return function (ModuleInterface $module) use ($include_disabled): bool {
6298d6560c4SGreg Roach            return $include_disabled || $module->isEnabled();
6308d6560c4SGreg Roach        };
6318d6560c4SGreg Roach    }
6328d6560c4SGreg Roach
6338d6560c4SGreg Roach    /**
6348d6560c4SGreg Roach     * A function filter modules by type
6358d6560c4SGreg Roach     *
6368d6560c4SGreg Roach     * @param string $interface
6378d6560c4SGreg Roach     *
6388d6560c4SGreg Roach     * @return Closure
6398d6560c4SGreg Roach     */
6408d6560c4SGreg Roach    private function interfaceFilter(string $interface): Closure
6418d6560c4SGreg Roach    {
6428d6560c4SGreg Roach        return function (ModuleInterface $module) use ($interface): bool {
6438d6560c4SGreg Roach            return $module instanceof $interface;
6448d6560c4SGreg Roach        };
6458d6560c4SGreg Roach    }
6468d6560c4SGreg Roach
6478d6560c4SGreg Roach    /**
6488d6560c4SGreg Roach     * A function to sort footers
6498d6560c4SGreg Roach     *
6508d6560c4SGreg Roach     * @return Closure
6518d6560c4SGreg Roach     */
6528d6560c4SGreg Roach    private function footerSorter(): Closure
6538d6560c4SGreg Roach    {
6548d6560c4SGreg Roach        return function (ModuleFooterInterface $x, ModuleFooterInterface $y): int {
6558d6560c4SGreg Roach            return $x->getFooterOrder() <=> $y->getFooterOrder();
6568d6560c4SGreg Roach        };
6578d6560c4SGreg Roach    }
6588d6560c4SGreg Roach
6598d6560c4SGreg Roach    /**
6608d6560c4SGreg Roach     * A function to sort menus
6618d6560c4SGreg Roach     *
6628d6560c4SGreg Roach     * @return Closure
6638d6560c4SGreg Roach     */
6648d6560c4SGreg Roach    private function menuSorter(): Closure
6658d6560c4SGreg Roach    {
6668d6560c4SGreg Roach        return function (ModuleMenuInterface $x, ModuleMenuInterface $y): int {
6678d6560c4SGreg Roach            return $x->getMenuOrder() <=> $y->getMenuOrder();
6688d6560c4SGreg Roach        };
6698d6560c4SGreg Roach    }
6708d6560c4SGreg Roach
6718d6560c4SGreg Roach    /**
6728d6560c4SGreg Roach     * A function to sort menus
6738d6560c4SGreg Roach     *
6748d6560c4SGreg Roach     * @return Closure
6758d6560c4SGreg Roach     */
6768d6560c4SGreg Roach    private function sidebarSorter(): Closure
6778d6560c4SGreg Roach    {
6788d6560c4SGreg Roach        return function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int {
6798d6560c4SGreg Roach            return $x->getSidebarOrder() <=> $y->getSidebarOrder();
6808d6560c4SGreg Roach        };
6818d6560c4SGreg Roach    }
6828d6560c4SGreg Roach
6838d6560c4SGreg Roach    /**
6848d6560c4SGreg Roach     * A function to sort menus
6858d6560c4SGreg Roach     *
6868d6560c4SGreg Roach     * @return Closure
6878d6560c4SGreg Roach     */
6888d6560c4SGreg Roach    private function tabSorter(): Closure
6898d6560c4SGreg Roach    {
6908d6560c4SGreg Roach        return function (ModuleTabInterface $x, ModuleTabInterface $y): int {
6918d6560c4SGreg Roach            return $x->getTabOrder() <=> $y->getTabOrder();
6928d6560c4SGreg Roach        };
6938d6560c4SGreg Roach    }
6948d6560c4SGreg Roach
6958d6560c4SGreg Roach    /**
69602086832SGreg Roach     * A function to sort modules by name.
69702086832SGreg Roach     *
69802086832SGreg Roach     * Languages have a "sortable" name, so that "British English" sorts as "English, British".
69902086832SGreg Roach     * This provides a more natural order in the language menu.
7008d6560c4SGreg Roach     *
7018d6560c4SGreg Roach     * @return Closure
7028d6560c4SGreg Roach     */
7038d6560c4SGreg Roach    private function moduleSorter(): Closure
7048d6560c4SGreg Roach    {
7058d6560c4SGreg Roach        return function (ModuleInterface $x, ModuleInterface $y): int {
70602086832SGreg Roach            $title1 = $x instanceof ModuleLanguageInterface ? $x->locale()->endonymSortable() : $x->title();
70702086832SGreg Roach            $title2 = $y instanceof ModuleLanguageInterface ? $y->locale()->endonymSortable() : $y->title();
70802086832SGreg Roach
70902086832SGreg Roach            return I18N::strcasecmp($title1, $title2);
7108d6560c4SGreg Roach        };
7118d6560c4SGreg Roach    }
7128d6560c4SGreg Roach
7138d6560c4SGreg Roach    /**
7144ca7e03cSGreg Roach     * Find a specified module, if it is currently active.
7154ca7e03cSGreg Roach     *
7164ca7e03cSGreg Roach     * @param string $module_name
717321a89daSGreg Roach     * @param bool   $include_disabled
7184ca7e03cSGreg Roach     *
7194ca7e03cSGreg Roach     * @return ModuleInterface|null
7204ca7e03cSGreg Roach     */
721321a89daSGreg Roach    public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface
7224ca7e03cSGreg Roach    {
7239d627a9eSGreg Roach        return $this->all($include_disabled)
7240b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module) use ($module_name): bool {
725321a89daSGreg Roach                return $module->name() === $module_name;
7264ca7e03cSGreg Roach            })
7274ca7e03cSGreg Roach            ->first();
7284ca7e03cSGreg Roach    }
729bf57b580SGreg Roach
730bf57b580SGreg Roach    /**
731bf57b580SGreg Roach     * Configuration settings are available through the various "module component" pages.
732bf57b580SGreg Roach     * For modules that do not provide a component, we need to list them separately.
733bf57b580SGreg Roach     *
73409fbf3e5SGreg Roach     * @param bool $include_disabled
73509fbf3e5SGreg Roach     *
73654c7f8dfSGreg Roach     * @return Collection
73754c7f8dfSGreg Roach     * @return ModuleConfigInterface[]
738bf57b580SGreg Roach     */
73909fbf3e5SGreg Roach    public function otherModules(bool $include_disabled = false): Collection
740bf57b580SGreg Roach    {
741abafa13cSGreg Roach        return $this->findByInterface(ModuleInterface::class, $include_disabled, true)
7420b5fd0a6SGreg Roach            ->filter(static function (ModuleInterface $module): bool {
743bf57b580SGreg Roach                foreach (self::COMPONENTS as $interface) {
744bf57b580SGreg Roach                    if ($module instanceof $interface) {
745bf57b580SGreg Roach                        return false;
746bf57b580SGreg Roach                    }
747bf57b580SGreg Roach                }
748bf57b580SGreg Roach
749bf57b580SGreg Roach                return true;
750bf57b580SGreg Roach            });
751bf57b580SGreg Roach    }
752bf57b580SGreg Roach
753bf57b580SGreg Roach    /**
754bf57b580SGreg Roach     * Generate a list of module names which exist in the database but not on disk.
755bf57b580SGreg Roach     *
75654c7f8dfSGreg Roach     * @return Collection
75754c7f8dfSGreg Roach     * @return string[]
758bf57b580SGreg Roach     */
759bf57b580SGreg Roach    public function deletedModules(): Collection
760bf57b580SGreg Roach    {
761bf57b580SGreg Roach        $database_modules = DB::table('module')->pluck('module_name');
762bf57b580SGreg Roach
763d5d58984SGreg Roach        $disk_modules = $this->all(true)
7640b5fd0a6SGreg Roach            ->map(static function (ModuleInterface $module): string {
765bf57b580SGreg Roach                return $module->name();
766bf57b580SGreg Roach            });
767bf57b580SGreg Roach
768bf57b580SGreg Roach        return $database_modules->diff($disk_modules);
769bf57b580SGreg Roach    }
7704ca7e03cSGreg Roach}
771