xref: /webtrees/app/Http/RequestHandlers/ModuleDeleteSettings.php (revision 6f4ec3cadc983f0a7294108c634bef48846b4311)
19f667ff2SGreg Roach<?php
29f667ff2SGreg Roach
39f667ff2SGreg Roach/**
49f667ff2SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
69f667ff2SGreg Roach * This program is free software: you can redistribute it and/or modify
79f667ff2SGreg Roach * it under the terms of the GNU General Public License as published by
89f667ff2SGreg Roach * the Free Software Foundation, either version 3 of the License, or
99f667ff2SGreg Roach * (at your option) any later version.
109f667ff2SGreg Roach * This program is distributed in the hope that it will be useful,
119f667ff2SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
129f667ff2SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139f667ff2SGreg Roach * GNU General Public License for more details.
149f667ff2SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
169f667ff2SGreg Roach */
179f667ff2SGreg Roach
189f667ff2SGreg Roachdeclare(strict_types=1);
199f667ff2SGreg Roach
209f667ff2SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
219f667ff2SGreg Roach
22*6f4ec3caSGreg Roachuse Fisharebest\Webtrees\DB;
239f667ff2SGreg Roachuse Fisharebest\Webtrees\FlashMessages;
249f667ff2SGreg Roachuse Fisharebest\Webtrees\I18N;
25748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator;
269f667ff2SGreg Roachuse Psr\Http\Message\ResponseInterface;
279f667ff2SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
289f667ff2SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
299f667ff2SGreg Roach
309f667ff2SGreg Roachuse function redirect;
319f667ff2SGreg Roachuse function route;
329f667ff2SGreg Roach
339f667ff2SGreg Roach/**
349f667ff2SGreg Roach * Delete the database settings for a deleted module.
359f667ff2SGreg Roach */
369f667ff2SGreg Roachclass ModuleDeleteSettings implements RequestHandlerInterface
379f667ff2SGreg Roach{
389f667ff2SGreg Roach    /**
399f667ff2SGreg Roach     * Delete the database settings for a deleted module.
409f667ff2SGreg Roach     *
419f667ff2SGreg Roach     * @param ServerRequestInterface $request
429f667ff2SGreg Roach     *
439f667ff2SGreg Roach     * @return ResponseInterface
449f667ff2SGreg Roach     */
459f667ff2SGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
469f667ff2SGreg Roach    {
47748dbe15SGreg Roach        $module_name = Validator::parsedBody($request)->string('module_name');
489f667ff2SGreg Roach
499f667ff2SGreg Roach        DB::table('block_setting')
509f667ff2SGreg Roach            ->join('block', 'block_setting.block_id', '=', 'block.block_id')
519f667ff2SGreg Roach            ->join('module', 'block.module_name', '=', 'module.module_name')
529f667ff2SGreg Roach            ->where('module.module_name', '=', $module_name)
539f667ff2SGreg Roach            ->delete();
549f667ff2SGreg Roach
559f667ff2SGreg Roach        DB::table('block')
569f667ff2SGreg Roach            ->join('module', 'block.module_name', '=', 'module.module_name')
579f667ff2SGreg Roach            ->where('module.module_name', '=', $module_name)
589f667ff2SGreg Roach            ->delete();
599f667ff2SGreg Roach
609f667ff2SGreg Roach        DB::table('module_setting')
619f667ff2SGreg Roach            ->where('module_name', '=', $module_name)
629f667ff2SGreg Roach            ->delete();
639f667ff2SGreg Roach
649f667ff2SGreg Roach        DB::table('module_privacy')
659f667ff2SGreg Roach            ->where('module_name', '=', $module_name)
669f667ff2SGreg Roach            ->delete();
679f667ff2SGreg Roach
689f667ff2SGreg Roach        DB::table('module')
699f667ff2SGreg Roach            ->where('module_name', '=', $module_name)
709f667ff2SGreg Roach            ->delete();
719f667ff2SGreg Roach
729f667ff2SGreg Roach        FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been deleted.', $module_name), 'success');
739f667ff2SGreg Roach
743213013eSGreg Roach        return redirect(route(ModulesAllPage::class));
759f667ff2SGreg Roach    }
769f667ff2SGreg Roach}
77