18ce3bd73SGreg Roach<?php 28ce3bd73SGreg Roach 38ce3bd73SGreg Roach/** 48ce3bd73SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 68ce3bd73SGreg Roach * This program is free software: you can redistribute it and/or modify 78ce3bd73SGreg Roach * it under the terms of the GNU General Public License as published by 88ce3bd73SGreg Roach * the Free Software Foundation, either version 3 of the License, or 98ce3bd73SGreg Roach * (at your option) any later version. 108ce3bd73SGreg Roach * This program is distributed in the hope that it will be useful, 118ce3bd73SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 128ce3bd73SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 138ce3bd73SGreg Roach * GNU General Public License for more details. 148ce3bd73SGreg 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/>. 168ce3bd73SGreg Roach */ 178ce3bd73SGreg Roach 188ce3bd73SGreg Roachdeclare(strict_types=1); 198ce3bd73SGreg Roach 208ce3bd73SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 218ce3bd73SGreg Roach 22*a1bd562dSGreg Roachuse Fisharebest\Webtrees\Registry; 23*a1bd562dSGreg Roachuse Fisharebest\Webtrees\Services\MediaFileService; 24748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator; 258ce3bd73SGreg Roachuse Psr\Http\Message\ResponseInterface; 268ce3bd73SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 278ce3bd73SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 288ce3bd73SGreg Roach 298ce3bd73SGreg Roachuse function redirect; 308ce3bd73SGreg Roachuse function route; 318ce3bd73SGreg Roach 328ce3bd73SGreg Roach/** 338ce3bd73SGreg Roach * Manage media from the control panel. 348ce3bd73SGreg Roach */ 358ce3bd73SGreg Roachclass ManageMediaAction implements RequestHandlerInterface 368ce3bd73SGreg Roach{ 37*a1bd562dSGreg Roach private MediaFileService $media_file_service; 38*a1bd562dSGreg Roach 39*a1bd562dSGreg Roach /** 40*a1bd562dSGreg Roach * @param MediaFileService $media_file_service 41*a1bd562dSGreg Roach */ 42*a1bd562dSGreg Roach public function __construct(MediaFileService $media_file_service) 43*a1bd562dSGreg Roach { 44*a1bd562dSGreg Roach $this->media_file_service = $media_file_service; 45*a1bd562dSGreg Roach } 46*a1bd562dSGreg Roach 478ce3bd73SGreg Roach /** 488ce3bd73SGreg Roach * @param ServerRequestInterface $request 498ce3bd73SGreg Roach * 508ce3bd73SGreg Roach * @return ResponseInterface 518ce3bd73SGreg Roach */ 528ce3bd73SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 538ce3bd73SGreg Roach { 54*a1bd562dSGreg Roach $data_filesystem = Registry::filesystem()->data(); 55*a1bd562dSGreg Roach $media_folders = $this->media_file_service->allMediaFolders($data_filesystem)->all(); 56*a1bd562dSGreg Roach 578ce3bd73SGreg Roach return redirect(route(ManageMediaPage::class, [ 58748dbe15SGreg Roach 'files' => Validator::parsedBody($request)->string('files'), 59*a1bd562dSGreg Roach 'media_folder' => Validator::parsedBody($request)->isInArray($media_folders)->string('media_folder'), 60748dbe15SGreg Roach 'subfolders' => Validator::parsedBody($request)->string('subfolders'), 618ce3bd73SGreg Roach ])); 628ce3bd73SGreg Roach } 638ce3bd73SGreg Roach} 64