1<?php 2 3/* 4 * vim:set softtabstop=4 shiftwidth=4 expandtab: 5 * 6 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later) 7 * Copyright 2001 - 2020 Ampache.org 8 * 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Affero General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Affero General Public License for more details. 18 * 19 * You should have received a copy of the GNU Affero General Public License 20 * along with this program. If not, see <https://www.gnu.org/licenses/>. 21 * 22 */ 23 24declare(strict_types=0); 25 26namespace Ampache\Module\Application\Share; 27 28use Ampache\Config\ConfigContainerInterface; 29use Ampache\Config\ConfigurationKeyEnum; 30use Ampache\Repository\Model\Share; 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 CleanAction implements ApplicationActionInterface 39{ 40 public const REQUEST_KEY = 'clean'; 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::SHARE)) { 57 throw new AccessDeniedException('Access Denied: sharing features are not enabled.'); 58 } 59 60 if ($this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE)) { 61 throw new AccessDeniedException(); 62 } 63 64 $this->ui->showHeader(); 65 66 Share::garbage_collection(); 67 $next_url = sprintf( 68 '%s/stats.php?action=share', 69 $this->configContainer->getWebPath() 70 ); 71 $this->ui->showConfirmation( 72 T_('No Problem'), 73 T_('Expired shares have been cleaned'), 74 $next_url 75 ); 76 $this->ui->showFooter(); 77 78 return null; 79 } 80} 81