1<?php 2/* 3 * vim:set softtabstop=4 shiftwidth=4 expandtab: 4 * 5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later) 6 * Copyright 2001 - 2020 Ampache.org 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 * 21 */ 22 23declare(strict_types=0); 24 25namespace Ampache\Module\Application\Video; 26 27use Ampache\Config\ConfigContainerInterface; 28use Ampache\Config\ConfigurationKeyEnum; 29use Ampache\Repository\Model\Catalog; 30use Ampache\Repository\Model\Video; 31use Ampache\Module\Application\ApplicationActionInterface; 32use Ampache\Module\Application\Exception\AccessDeniedException; 33use Ampache\Module\Authorization\GuiGatekeeperInterface; 34use Ampache\Module\Util\UiInterface; 35use Psr\Http\Message\ResponseInterface; 36use Psr\Http\Message\ServerRequestInterface; 37 38final class ConfirmDeleteAction implements ApplicationActionInterface 39{ 40 public const REQUEST_KEY = 'confirm_delete'; 41 42 private ConfigContainerInterface $configContainer; 43 44 private UiInterface $ui; 45 46 public function __construct( 47 ConfigContainerInterface $configContainer, 48 UiInterface $ui 49 ) { 50 $this->configContainer = $configContainer; 51 $this->ui = $ui; 52 } 53 54 public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gatekeeper): ?ResponseInterface 55 { 56 if ($this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE)) { 57 return null; 58 } 59 60 $video = Video::create_from_id( 61 filter_input(INPUT_GET, 'video_id', FILTER_SANITIZE_SPECIAL_CHARS) 62 ); 63 if (!Catalog::can_remove($video)) { 64 throw new AccessDeniedException( 65 sprintf('Unauthorized to remove the video `%s`', $video->id), 66 ); 67 } 68 69 $this->ui->showHeader(); 70 71 if ($video->remove()) { 72 $this->ui->showConfirmation( 73 T_('No Problem'), 74 T_('Video has been deleted'), 75 $this->configContainer->getWebPath() 76 ); 77 } else { 78 $this->ui->showConfirmation( 79 T_('There Was a Problem'), 80 T_('Couldn\'t delete this Video.'), 81 $this->configContainer->getWebPath() 82 ); 83 } 84 85 $this->ui->showQueryStats(); 86 $this->ui->showFooter(); 87 88 return null; 89 } 90} 91