xref: /webtrees/app/Services/ModuleService.php (revision 4d314e6b28a3e57668463e010244449523e91e5c)
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);
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                    $message = '<pre>' . e($ex->getMessage()) . "\n" . e($ex->getTraceAsString()) . '</pre>';
327                    FlashMessages::addMessage($message, 'danger');
328
329                    return null;
330                }
331            })
332            ->filter();
333    }
334
335    /**
336     * All modules.
337     *
338     * @param bool $include_disabled
339     *
340     * @return Collection
341     * @return ModuleInterface[]
342     */
343    public function all(bool $include_disabled = false): Collection
344    {
345        return app('cache.array')->rememberForever('all_modules', function (): Collection {
346            // Modules have a default status, order etc.
347            // We can override these from database settings.
348            $module_info = DB::table('module')
349                ->get()
350                ->mapWithKeys(function (stdClass $row): array {
351                    return [$row->module_name => $row];
352                });
353
354            return $this->coreModules()
355                ->merge($this->customModules())
356                ->map(function (ModuleInterface $module) use ($module_info): ModuleInterface {
357                    $info = $module_info->get($module->name());
358
359                    if ($info instanceof stdClass) {
360                        $module->setEnabled($info->status === 'enabled');
361
362                        if ($module instanceof ModuleFooterInterface && $info->footer_order !== null) {
363                            $module->setFooterOrder((int) $info->footer_order);
364                        }
365
366                        if ($module instanceof ModuleMenuInterface && $info->menu_order !== null) {
367                            $module->setMenuOrder((int) $info->menu_order);
368                        }
369
370                        if ($module instanceof ModuleSidebarInterface && $info->sidebar_order !== null) {
371                            $module->setSidebarOrder((int) $info->sidebar_order);
372                        }
373
374                        if ($module instanceof ModuleTabInterface && $info->tab_order !== null) {
375                            $module->setTabOrder((int) $info->tab_order);
376                        }
377                    } else {
378                        $module->setEnabled($module->isEnabledByDefault());
379
380                        DB::table('module')->insert([
381                            'module_name' => $module->name(),
382                            'status'      => $module->isEnabled() ? 'enabled' : 'disabled',
383                        ]);
384                    }
385
386                    return $module;
387                });
388        })->filter($this->enabledFilter($include_disabled));
389    }
390
391    /**
392     * Load a module in a static scope, to prevent it from modifying local or object variables.
393     *
394     * @param string $filename
395     *
396     * @return mixed
397     */
398    private static function load(string $filename)
399    {
400        return include $filename;
401    }
402
403    /**
404     * A function to sort modules by name
405     *
406     * @return Closure
407     */
408    private function moduleSorter(): Closure
409    {
410        return function (ModuleInterface $x, ModuleInterface $y): int {
411            return I18N::strcasecmp($x->title(), $y->title());
412        };
413    }
414
415    /**
416     * A function to sort footers
417     *
418     * @return Closure
419     */
420    private function footerSorter(): Closure
421    {
422        return function (ModuleFooterInterface $x, ModuleFooterInterface $y): int {
423            return $x->getFooterOrder() <=> $y->getFooterOrder();
424        };
425    }
426
427    /**
428     * A function to sort menus
429     *
430     * @return Closure
431     */
432    private function menuSorter(): Closure
433    {
434        return function (ModuleMenuInterface $x, ModuleMenuInterface $y): int {
435            return $x->getMenuOrder() <=> $y->getMenuOrder();
436        };
437    }
438
439    /**
440     * A function to sort menus
441     *
442     * @return Closure
443     */
444    private function sidebarSorter(): Closure
445    {
446        return function (ModuleSidebarInterface $x, ModuleSidebarInterface $y): int {
447            return $x->getSidebarOrder() <=> $y->getSidebarOrder();
448        };
449    }
450
451    /**
452     * A function to sort menus
453     *
454     * @return Closure
455     */
456    private function tabSorter(): Closure
457    {
458        return function (ModuleTabInterface $x, ModuleTabInterface $y): int {
459            return $x->getTabOrder() <=> $y->getTabOrder();
460        };
461    }
462
463    /**
464     * A function filter modules by type
465     *
466     * @param string $interface
467     *
468     * @return Closure
469     */
470    private function interfaceFilter(string $interface): Closure
471    {
472        return function (ModuleInterface $module) use ($interface): bool {
473            return $module instanceof $interface;
474        };
475    }
476
477    /**
478     * A function filter modules by enabled/disabled
479     *
480     * @param bool $include_disabled
481     *
482     * @return Closure
483     */
484    private function enabledFilter(bool $include_disabled): Closure
485    {
486        return function (ModuleInterface $module) use ($include_disabled): bool {
487            return $include_disabled || $module->isEnabled();
488        };
489    }
490
491    /**
492     * A function to convert modules into their titles - to create option lists, etc.
493     *
494     * @return Closure
495     */
496    public function titleMapper(): Closure
497    {
498        return function (ModuleInterface $module): string {
499            return $module->title();
500        };
501    }
502
503    /**
504     * Modules which (a) provide a specific function and (b) we have permission to see.
505     *
506     * @param string        $interface
507     * @param Tree          $tree
508     * @param UserInterface $user
509     *
510     * @return Collection
511     * @return ModuleInterface[]
512     */
513    public function findByComponent(string $interface, Tree $tree, UserInterface $user): Collection
514    {
515        return $this->findByInterface($interface, false, true)
516            ->filter(function (ModuleInterface $module) use ($interface, $tree, $user): bool {
517                return $module->accessLevel($tree, $interface) >= Auth::accessLevel($tree, $user);
518            });
519    }
520
521    /**
522     * All modules which provide a specific function.
523     *
524     * @param string $interface
525     * @param bool   $include_disabled
526     * @param bool   $sort
527     *
528     * @return Collection
529     * @return ModuleInterface[]
530     */
531    public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
532    {
533        $modules = $this->all($include_disabled)
534            ->filter($this->interfaceFilter($interface));
535
536        switch ($interface) {
537            case ModuleFooterInterface::class:
538                return $modules->sort($this->footerSorter());
539
540            case ModuleMenuInterface::class:
541                return $modules->sort($this->menuSorter());
542
543            case ModuleSidebarInterface::class:
544                return $modules->sort($this->sidebarSorter());
545
546            case ModuleTabInterface::class:
547                return $modules->sort($this->tabSorter());
548
549            default:
550                if ($sort) {
551                    return $modules->sort($this->moduleSorter());
552                }
553
554                return $modules;
555        }
556    }
557
558    /**
559     * Find a specified module, if it is currently active.
560     *
561     * @param string $module_name
562     * @param bool   $include_disabled
563     *
564     * @return ModuleInterface|null
565     */
566    public function findByName(string $module_name, bool $include_disabled = false): ?ModuleInterface
567    {
568        return $this->all($include_disabled)
569            ->filter(function (ModuleInterface $module) use ($module_name): bool {
570                return $module->name() === $module_name;
571            })
572            ->first();
573    }
574
575    /**
576     * Configuration settings are available through the various "module component" pages.
577     * For modules that do not provide a component, we need to list them separately.
578     *
579     * @param bool $include_disabled
580     *
581     * @return Collection
582     * @return ModuleConfigInterface[]
583     */
584    public function otherModules(bool $include_disabled = false): Collection
585    {
586        return $this->all($include_disabled)
587            ->filter(function (ModuleInterface $module): bool {
588                foreach (self::COMPONENTS as $interface) {
589                    if ($module instanceof $interface) {
590                        return false;
591                    }
592                }
593
594                return true;
595            });
596    }
597
598    /**
599     * Generate a list of module names which exist in the database but not on disk.
600     *
601     * @return Collection
602     * @return string[]
603     */
604    public function deletedModules(): Collection
605    {
606        $database_modules = DB::table('module')->pluck('module_name');
607
608        $disk_modules = $this->all(true)
609            ->map(function (ModuleInterface $module): string {
610                return $module->name();
611            });
612
613        return $database_modules->diff($disk_modules);
614    }
615}
616