xref: /webtrees/app/Services/ModuleService.php (revision 8354ceb31bee4736b78590afb62d679c4f9389df)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Services;
19
20use Closure;
21use Fisharebest\Webtrees\Auth;
22use Fisharebest\Webtrees\Contracts\UserInterface;
23use Fisharebest\Webtrees\FlashMessages;
24use Fisharebest\Webtrees\I18N;
25use Fisharebest\Webtrees\Module\AhnentafelReportModule;
26use Fisharebest\Webtrees\Module\AlbumModule;
27use Fisharebest\Webtrees\Module\AncestorsChartModule;
28use Fisharebest\Webtrees\Module\BatchUpdateModule;
29use Fisharebest\Webtrees\Module\BingWebmasterToolsModule;
30use Fisharebest\Webtrees\Module\BirthDeathMarriageReportModule;
31use Fisharebest\Webtrees\Module\BirthReportModule;
32use Fisharebest\Webtrees\Module\BranchesListModule;
33use Fisharebest\Webtrees\Module\BritishMonarchs;
34use Fisharebest\Webtrees\Module\BritishPrimeMinisters;
35use Fisharebest\Webtrees\Module\BritishSocialHistory;
36use Fisharebest\Webtrees\Module\CalendarMenuModule;
37use Fisharebest\Webtrees\Module\CemeteryReportModule;
38use Fisharebest\Webtrees\Module\CensusAssistantModule;
39use Fisharebest\Webtrees\Module\ChangeReportModule;
40use Fisharebest\Webtrees\Module\ChartsBlockModule;
41use Fisharebest\Webtrees\Module\ChartsMenuModule;
42use Fisharebest\Webtrees\Module\CkeditorModule;
43use Fisharebest\Webtrees\Module\ClippingsCartModule;
44use Fisharebest\Webtrees\Module\CloudsTheme;
45use Fisharebest\Webtrees\Module\ColorsTheme;
46use Fisharebest\Webtrees\Module\CompactTreeChartModule;
47use Fisharebest\Webtrees\Module\ContactsFooterModule;
48use Fisharebest\Webtrees\Module\CookieWarningModule;
49use Fisharebest\Webtrees\Module\DeathReportModule;
50use Fisharebest\Webtrees\Module\DescendancyChartModule;
51use Fisharebest\Webtrees\Module\DescendancyModule;
52use Fisharebest\Webtrees\Module\DescendancyReportModule;
53use Fisharebest\Webtrees\Module\FabTheme;
54use Fisharebest\Webtrees\Module\FactSourcesReportModule;
55use Fisharebest\Webtrees\Module\FamilyBookChartModule;
56use Fisharebest\Webtrees\Module\FamilyGroupReportModule;
57use Fisharebest\Webtrees\Module\FamilyListModule;
58use Fisharebest\Webtrees\Module\FamilyNavigatorModule;
59use Fisharebest\Webtrees\Module\FamilyTreeFavoritesModule;
60use Fisharebest\Webtrees\Module\FamilyTreeNewsModule;
61use Fisharebest\Webtrees\Module\FamilyTreeStatisticsModule;
62use Fisharebest\Webtrees\Module\FanChartModule;
63use Fisharebest\Webtrees\Module\FrequentlyAskedQuestionsModule;
64use Fisharebest\Webtrees\Module\GoogleAnalyticsModule;
65use Fisharebest\Webtrees\Module\GoogleWebmasterToolsModule;
66use Fisharebest\Webtrees\Module\HitCountFooterModule;
67use Fisharebest\Webtrees\Module\HourglassChartModule;
68use Fisharebest\Webtrees\Module\HtmlBlockModule;
69use Fisharebest\Webtrees\Module\IndividualFactsTabModule;
70use Fisharebest\Webtrees\Module\IndividualFamiliesReportModule;
71use Fisharebest\Webtrees\Module\IndividualListModule;
72use Fisharebest\Webtrees\Module\IndividualMetadataModule;
73use Fisharebest\Webtrees\Module\IndividualReportModule;
74use Fisharebest\Webtrees\Module\InteractiveTreeModule;
75use Fisharebest\Webtrees\Module\LifespansChartModule;
76use Fisharebest\Webtrees\Module\ListsMenuModule;
77use Fisharebest\Webtrees\Module\LoggedInUsersModule;
78use Fisharebest\Webtrees\Module\LoginBlockModule;
79use Fisharebest\Webtrees\Module\MarriageReportModule;
80use Fisharebest\Webtrees\Module\MatomoAnalyticsModule;
81use Fisharebest\Webtrees\Module\MediaListModule;
82use Fisharebest\Webtrees\Module\MediaTabModule;
83use Fisharebest\Webtrees\Module\MinimalTheme;
84use Fisharebest\Webtrees\Module\MissingFactsReportModule;
85use Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
86use Fisharebest\Webtrees\Module\ModuleBlockInterface;
87use Fisharebest\Webtrees\Module\ModuleChartInterface;
88use Fisharebest\Webtrees\Module\ModuleConfigInterface;
89use Fisharebest\Webtrees\Module\ModuleCustomInterface;
90use Fisharebest\Webtrees\Module\ModuleFooterInterface;
91use Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface;
92use Fisharebest\Webtrees\Module\ModuleInterface;
93use Fisharebest\Webtrees\Module\ModuleLanguageInterface;
94use Fisharebest\Webtrees\Module\ModuleListInterface;
95use Fisharebest\Webtrees\Module\ModuleMenuInterface;
96use Fisharebest\Webtrees\Module\ModuleReportInterface;
97use Fisharebest\Webtrees\Module\ModuleSidebarInterface;
98use Fisharebest\Webtrees\Module\ModuleTabInterface;
99use Fisharebest\Webtrees\Module\ModuleThemeInterface;
100use Fisharebest\Webtrees\Module\NoteListModule;
101use Fisharebest\Webtrees\Module\NotesTabModule;
102use Fisharebest\Webtrees\Module\OccupationReportModule;
103use Fisharebest\Webtrees\Module\OnThisDayModule;
104use Fisharebest\Webtrees\Module\PedigreeChartModule;
105use Fisharebest\Webtrees\Module\PedigreeMapModule;
106use Fisharebest\Webtrees\Module\PedigreeReportModule;
107use Fisharebest\Webtrees\Module\PlaceHierarchyListModule;
108use Fisharebest\Webtrees\Module\PlacesModule;
109use Fisharebest\Webtrees\Module\PoweredByWebtreesModule;
110use Fisharebest\Webtrees\Module\RecentChangesModule;
111use Fisharebest\Webtrees\Module\RelatedIndividualsReportModule;
112use Fisharebest\Webtrees\Module\RelationshipsChartModule;
113use Fisharebest\Webtrees\Module\RelativesTabModule;
114use Fisharebest\Webtrees\Module\ReportsMenuModule;
115use Fisharebest\Webtrees\Module\RepositoryListModule;
116use Fisharebest\Webtrees\Module\ResearchTaskModule;
117use Fisharebest\Webtrees\Module\ReviewChangesModule;
118use Fisharebest\Webtrees\Module\SearchMenuModule;
119use Fisharebest\Webtrees\Module\SiteMapModule;
120use Fisharebest\Webtrees\Module\SlideShowModule;
121use Fisharebest\Webtrees\Module\SourceListModule;
122use Fisharebest\Webtrees\Module\SourcesTabModule;
123use Fisharebest\Webtrees\Module\StatcounterModule;
124use Fisharebest\Webtrees\Module\StatisticsChartModule;
125use Fisharebest\Webtrees\Module\StoriesModule;
126use Fisharebest\Webtrees\Module\ThemeSelectModule;
127use Fisharebest\Webtrees\Module\TimelineChartModule;
128use Fisharebest\Webtrees\Module\TopGivenNamesModule;
129use Fisharebest\Webtrees\Module\TopPageViewsModule;
130use Fisharebest\Webtrees\Module\TopSurnamesModule;
131use Fisharebest\Webtrees\Module\TreesMenuModule;
132use Fisharebest\Webtrees\Module\UpcomingAnniversariesModule;
133use Fisharebest\Webtrees\Module\UserFavoritesModule;
134use Fisharebest\Webtrees\Module\UserJournalModule;
135use Fisharebest\Webtrees\Module\UserMessagesModule;
136use Fisharebest\Webtrees\Module\UserWelcomeModule;
137use Fisharebest\Webtrees\Module\USPresidents;
138use Fisharebest\Webtrees\Module\WebtreesTheme;
139use Fisharebest\Webtrees\Module\WelcomeBlockModule;
140use Fisharebest\Webtrees\Module\XeneaTheme;
141use Fisharebest\Webtrees\Module\YahrzeitModule;
142use Fisharebest\Webtrees\Tree;
143use Fisharebest\Webtrees\Webtrees;
144use Illuminate\Database\Capsule\Manager as DB;
145use Illuminate\Support\Collection;
146use Illuminate\Support\Str;
147use stdClass;
148use Throwable;
149
150/**
151 * Functions for managing and maintaining modules.
152 */
153class ModuleService
154{
155    // Components are pieces of user-facing functionality, are managed together in the control panel.
156    private const COMPONENTS = [
157        ModuleAnalyticsInterface::class,
158        ModuleBlockInterface::class,
159        ModuleChartInterface::class,
160        ModuleFooterInterface::class,
161        ModuleHistoricEventsInterface::class,
162        ModuleLanguageInterface::class,
163        ModuleListInterface::class,
164        ModuleMenuInterface::class,
165        ModuleReportInterface::class,
166        ModuleSidebarInterface::class,
167        ModuleTabInterface::class,
168        ModuleThemeInterface::class,
169    ];
170
171    // Array keys are module names, and should match module names from earlier versions of webtrees.
172    private const CORE_MODULES = [
173        'GEDFact_assistant'       => CensusAssistantModule::class,
174        'ahnentafel_report'       => AhnentafelReportModule::class,
175        'ancestors_chart'         => AncestorsChartModule::class,
176        'batch_update'            => BatchUpdateModule::class,
177        'bdm_report'              => BirthDeathMarriageReportModule::class,
178        'bing-webmaster-tools'    => BingWebmasterToolsModule::class,
179        'birth_report'            => BirthReportModule::class,
180        'branches_list'           => BranchesListModule::class,
181        'british-monarchs'        => BritishMonarchs::class,
182        'british-prime-ministers' => BritishPrimeMinisters::class,
183        'british-social-history'  => BritishSocialHistory::class,
184        'calendar-menu'           => CalendarMenuModule::class,
185        'cemetery_report'         => CemeteryReportModule::class,
186        'change_report'           => ChangeReportModule::class,
187        'charts'                  => ChartsBlockModule::class,
188        'charts-menu'             => ChartsMenuModule::class,
189        'ckeditor'                => CkeditorModule::class,
190        'clippings'               => ClippingsCartModule::class,
191        'clouds'                  => CloudsTheme::class,
192        'colors'                  => ColorsTheme::class,
193        'compact-chart'           => CompactTreeChartModule::class,
194        'contact-links'           => ContactsFooterModule::class,
195        'cookie-warning'          => CookieWarningModule::class,
196        'death_report'            => DeathReportModule::class,
197        'descendancy'             => DescendancyModule::class,
198        'descendancy_chart'       => DescendancyChartModule::class,
199        'descendancy_report'      => DescendancyReportModule::class,
200        'extra_info'              => IndividualMetadataModule::class,
201        'fab'                     => FabTheme::class,
202        'fact_sources'            => FactSourcesReportModule::class,
203        'family_book_chart'       => FamilyBookChartModule::class,
204        'family_group_report'     => FamilyGroupReportModule::class,
205        'family_list'             => FamilyListModule::class,
206        'family_nav'              => FamilyNavigatorModule::class,
207        'fan_chart'               => FanChartModule::class,
208        'faq'                     => FrequentlyAskedQuestionsModule::class,
209        'gedcom_block'            => WelcomeBlockModule::class,
210        'gedcom_favorites'        => FamilyTreeFavoritesModule::class,
211        'gedcom_news'             => FamilyTreeNewsModule::class,
212        'gedcom_stats'            => FamilyTreeStatisticsModule::class,
213        'google-analytics'        => GoogleAnalyticsModule::class,
214        'google-webmaster-tools'  => GoogleWebmasterToolsModule::class,
215        'hit-counter'             => HitCountFooterModule::class,
216        'hourglass_chart'         => HourglassChartModule::class,
217        'html'                    => HtmlBlockModule::class,
218        'individual_ext_report'   => IndividualFamiliesReportModule::class,
219        'individual_list'         => IndividualListModule::class,
220        'individual_report'       => IndividualReportModule::class,
221        'lifespans_chart'         => LifespansChartModule::class,
222        'lightbox'                => AlbumModule::class,
223        'lists-menu'              => ListsMenuModule::class,
224        'logged_in'               => LoggedInUsersModule::class,
225        'login_block'             => LoginBlockModule::class,
226        'marriage_report'         => MarriageReportModule::class,
227        'matomo-analytics'        => MatomoAnalyticsModule::class,
228        'media'                   => MediaTabModule::class,
229        'media_list'              => MediaListModule::class,
230        'minimal'                 => MinimalTheme::class,
231        'missing_facts_report'    => MissingFactsReportModule::class,
232        'notes'                   => NotesTabModule::class,
233        'note_list'               => NoteListModule::class,
234        'occupation_report'       => OccupationReportModule::class,
235        'pedigree-map'            => PedigreeMapModule::class,
236        'pedigree_chart'          => PedigreeChartModule::class,
237        'pedigree_report'         => PedigreeReportModule::class,
238        'personal_facts'          => IndividualFactsTabModule::class,
239        'places'                  => PlacesModule::class,
240        'places_list'             => PlaceHierarchyListModule::class,
241        'powered-by-webtrees'     => PoweredByWebtreesModule::class,
242        'random_media'            => SlideShowModule::class,
243        'recent_changes'          => RecentChangesModule::class,
244        'relationships_chart'     => RelationshipsChartModule::class,
245        'relative_ext_report'     => RelatedIndividualsReportModule::class,
246        'relatives'               => RelativesTabModule::class,
247        'reports-menu'            => ReportsMenuModule::class,
248        'repository_list'         => RepositoryListModule::class,
249        'review_changes'          => ReviewChangesModule::class,
250        'search-menu'             => SearchMenuModule::class,
251        'sitemap'                 => SiteMapModule::class,
252        'source_list'             => SourceListModule::class,
253        'sources_tab'             => SourcesTabModule::class,
254        'statcounter'             => StatcounterModule::class,
255        'statistics_chart'        => StatisticsChartModule::class,
256        'stories'                 => StoriesModule::class,
257        'theme_select'            => ThemeSelectModule::class,
258        'timeline_chart'          => TimelineChartModule::class,
259        'todays_events'           => OnThisDayModule::class,
260        'todo'                    => ResearchTaskModule::class,
261        'top10_givnnames'         => TopGivenNamesModule::class,
262        'top10_pageviews'         => TopPageViewsModule::class,
263        'top10_surnames'          => TopSurnamesModule::class,
264        'tree'                    => InteractiveTreeModule::class,
265        'trees-menu'              => TreesMenuModule::class,
266        'upcoming_events'         => UpcomingAnniversariesModule::class,
267        'us-presidents'           => USPresidents::class,
268        'user_blog'               => UserJournalModule::class,
269        'user_favorites'          => UserFavoritesModule::class,
270        'user_messages'           => UserMessagesModule::class,
271        'user_welcome'            => UserWelcomeModule::class,
272        'webtrees'                => WebtreesTheme::class,
273        'xenea'                   => XeneaTheme::class,
274        'yahrzeit'                => YahrzeitModule::class,
275    ];
276
277    /**
278     * All core modules in the system.
279     *
280     * @return Collection
281     */
282    private function coreModules(): Collection
283    {
284        return Collection::make(self::CORE_MODULES)
285            ->map(function (string $class, string $name): ModuleInterface {
286                $module = app($class);
287
288                $module->setName($name);
289
290                return $module;
291            });
292    }
293
294    /**
295     * All custom modules in the system.  Custom modules are defined in modules_v4/
296     *
297     * @return Collection
298     */
299    private function customModules(): Collection
300    {
301        $pattern   = WT_ROOT . Webtrees::MODULES_PATH . '*/module.php';
302        $filenames = glob($pattern, GLOB_NOSORT);
303
304        return Collection::make($filenames)
305            ->filter(function (string $filename): bool {
306                // Special characters will break PHP variable names.
307                // This also allows us to ignore modules called "foo.example" and "foo.disable"
308                $module_name = basename(dirname($filename));
309
310                return !Str::contains($module_name, ['.', ' ', '[', ']']) && Str::length($module_name) <= 30;
311            })
312            ->map(function (string $filename): ?ModuleCustomInterface {
313                try {
314                    $module = self::load($filename);
315
316                    if ($module instanceof ModuleCustomInterface) {
317                        $module_name = '_' . basename(dirname($filename)) . '_';
318
319                        $module->setName($module_name);
320                    } else {
321                        return null;
322                    }
323
324                    return $module;
325                } catch (Throwable $ex) {
326                    // It would be nice to show this error in a flash-message or similar, but the framework
327                    // has not yet been initialised so we have no themes, languages, sessions, etc.
328                    throw $ex;
329                }
330            })
331            ->filter()
332            ->mapWithKeys(function (ModuleCustomInterface $module): array {
333                return [$module->name() => $module];
334            });
335    }
336
337    /**
338     * All modules.
339     *
340     * @param bool $include_disabled
341     *
342     * @return Collection
343     * @return ModuleInterface[]
344     */
345    public function all(bool $include_disabled = false): Collection
346    {
347        return app('cache.array')->rememberForever('all_modules', function (): Collection {
348            // Modules have a default status, order etc.
349            // We can override these from database settings.
350            $module_info = DB::table('module')
351                ->get()
352                ->mapWithKeys(function (stdClass $row): array {
353                    return [$row->module_name => $row];
354                });
355
356            return $this->coreModules()
357                ->merge($this->customModules())
358                ->map(function (ModuleInterface $module) use ($module_info): ModuleInterface {
359                    $info = $module_info->get($module->name());
360
361                    if ($info instanceof stdClass) {
362                        $module->setEnabled($info->status === 'enabled');
363
364                        if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) {
365                            $module->setFooterOrder((int) $info->footer_order);
366                        }
367
368                        if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) {
369                            $module->setMenuOrder((int) $info->menu_order);
370                        }
371
372                        if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) {
373                            $module->setSidebarOrder((int) $info->sidebar_order);
374                        }
375
376                        if ($module instanceof ModuleTabInterface && $info->tab_order !== null) {
377                            $module->setTabOrder((int) $info->tab_order);
378                        }
379                    } else {
380                        $module->setEnabled($module->isEnabledByDefault());
381
382                        DB::table('module')->insert([
383                            'module_name' => $module->name(),
384                            'status'      => $module->isEnabled() ? 'enabled' : 'disabled',
385                        ]);
386                    }
387
388                    return $module;
389                });
390        })->filter($this->enabledFilter($include_disabled));
391    }
392
393    /**
394     * Load a module in a static scope, to prevent it from modifying local or object variables.
395     *
396     * @param string $filename
397     *
398     * @return mixed
399     */
400    private static function load(string $filename)
401    {
402        return include $filename;
403    }
404
405    /**
406     * A function to sort modules by name
407     *
408     * @return Closure
409     */
410    private function moduleSorter(): Closure
411    {
412        return function (ModuleInterface $x, ModuleInterface $y): int {
413            return I18N::strcasecmp($x->title(), $y->title());
414        };
415    }
416
417    /**
418     * A function to sort footers
419     *
420     * @return Closure
421     */
422    private function footerSorter(): Closure
423    {
424        return function (ModuleFooterInterface $x, ModuleFooterInterface $y): int {
425            return $x->getFooterOrder() <=> $y->getFooterOrder();
426        };
427    }
428
429    /**
430     * A function to sort menus
431     *
432     * @return Closure
433     */
434    private function menuSorter(): Closure
435    {
436        return function (ModuleMenuInterface $x, ModuleMenuInterface $y): int {
437            return $x->getMenuOrder() <=> $y->getMenuOrder();
438        };
439    }
440
441    /**
442     * A function to sort menus
443     *
444     * @return Closure
445     */
446    private function sidebarSorter(): Closure
447    {
448        return function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int {
449            return $x->getSidebarOrder() <=> $y->getSidebarOrder();
450        };
451    }
452
453    /**
454     * A function to sort menus
455     *
456     * @return Closure
457     */
458    private function tabSorter(): Closure
459    {
460        return function (ModuleTabInterface $x, ModuleTabInterface $y): int {
461            return $x->getTabOrder() <=> $y->getTabOrder();
462        };
463    }
464
465    /**
466     * A function filter modules by type
467     *
468     * @param string $interface
469     *
470     * @return Closure
471     */
472    private function interfaceFilter(string $interface): Closure
473    {
474        return function (ModuleInterface $module) use ($interface): bool {
475            return $module instanceof $interface;
476        };
477    }
478
479    /**
480     * A function filter modules by enabled/disabled
481     *
482     * @param bool $include_disabled
483     *
484     * @return Closure
485     */
486    private function enabledFilter(bool $include_disabled): Closure
487    {
488        return function (ModuleInterface $module) use ($include_disabled): bool {
489            return $include_disabled || $module->isEnabled();
490        };
491    }
492
493    /**
494     * A function to convert modules into their titles - to create option lists, etc.
495     *
496     * @return Closure
497     */
498    public function titleMapper(): Closure
499    {
500        return function (ModuleInterface $module): string {
501            return $module->title();
502        };
503    }
504
505    /**
506     * Modules which (a) provide a specific function and (b) we have permission to see.
507     *
508     * @param string        $interface
509     * @param Tree          $tree
510     * @param UserInterface $user
511     *
512     * @return Collection
513     * @return ModuleInterface[]
514     */
515    public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection
516    {
517        return $this->findByInterface($interface, false, true)
518            ->filter(function (ModuleInterface $module) use ($interface, $tree, $user): bool {
519                return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user);
520            });
521    }
522
523    /**
524     * All modules which provide a specific function.
525     *
526     * @param string $interface
527     * @param bool   $include_disabled
528     * @param bool   $sort
529     *
530     * @return Collection
531     * @return ModuleInterface[]
532     */
533    public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
534    {
535        $modules = $this->all($include_disabled)
536            ->filter($this->interfaceFilter($interface));
537
538        switch ($interface) {
539            case ModuleFooterInterface::class:
540                return $modules->sort($this->footerSorter());
541
542            case ModuleMenuInterface::class:
543                return $modules->sort($this->menuSorter());
544
545            case ModuleSidebarInterface::class:
546                return $modules->sort($this->sidebarSorter());
547
548            case ModuleTabInterface::class:
549                return $modules->sort($this->tabSorter());
550
551            default:
552                if ($sort) {
553                    return $modules->sort($this->moduleSorter());
554                }
555
556                return $modules;
557        }
558    }
559
560    /**
561     * Find a specified module, if it is currently active.
562     *
563     * @param string $module_name
564     * @param bool   $include_disabled
565     *
566     * @return ModuleInterface|null
567     */
568    public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface
569    {
570        return $this->all($include_disabled)
571            ->filter(function (ModuleInterface $module) use ($module_name): bool {
572                return $module->name() === $module_name;
573            })
574            ->first();
575    }
576
577    /**
578     * Configuration settings are available through the various "module component" pages.
579     * For modules that do not provide a component, we need to list them separately.
580     *
581     * @param bool $include_disabled
582     *
583     * @return Collection
584     * @return ModuleConfigInterface[]
585     */
586    public function otherModules(bool $include_disabled = false): Collection
587    {
588        return $this->all($include_disabled)
589            ->filter(function (ModuleInterface $module): bool {
590                foreach (self::COMPONENTS as $interface) {
591                    if ($module instanceof $interface) {
592                        return false;
593                    }
594                }
595
596                return true;
597            });
598    }
599
600    /**
601     * Generate a list of module names which exist in the database but not on disk.
602     *
603     * @return Collection
604     * @return string[]
605     */
606    public function deletedModules(): Collection
607    {
608        $database_modules = DB::table('module')->pluck('module_name');
609
610        $disk_modules = $this->all(true)
611            ->map(function (ModuleInterface $module): string {
612                return $module->name();
613            });
614
615        return $database_modules->diff($disk_modules);
616    }
617}
618