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\LocalPlay; 26 27use Ampache\Config\ConfigContainerInterface; 28use Ampache\Config\ConfigurationKeyEnum; 29use Ampache\Module\Application\Exception\AccessDeniedException; 30use Ampache\Module\Authorization\AccessLevelEnum; 31use Ampache\Module\Authorization\GuiGatekeeperInterface; 32use Ampache\Module\Playback\Localplay\LocalPlay; 33use Ampache\Module\Util\UiInterface; 34use Psr\Http\Message\ResponseFactoryInterface; 35use Psr\Http\Message\ResponseInterface; 36use Psr\Http\Message\ServerRequestInterface; 37use Teapot\StatusCode; 38 39final class UpdateInstanceAction extends AbstractLocalPlayAction 40{ 41 public const REQUEST_KEY = 'update_instance'; 42 43 private ConfigContainerInterface $configContainer; 44 45 private ResponseFactoryInterface $responseFactory; 46 47 private UiInterface $ui; 48 49 public function __construct( 50 ConfigContainerInterface $configContainer, 51 ResponseFactoryInterface $responseFactory, 52 UiInterface $ui 53 ) { 54 parent::__construct($configContainer, $ui); 55 $this->configContainer = $configContainer; 56 $this->responseFactory = $responseFactory; 57 $this->ui = $ui; 58 } 59 60 protected function handle( 61 ServerRequestInterface $request, 62 GuiGatekeeperInterface $gatekeeper 63 ): ?ResponseInterface { 64 // This requires 75 or better! 65 if ($gatekeeper->mayAccess(AccessLevelEnum::TYPE_LOCALPLAY, AccessLevelEnum::LEVEL_MANAGER) === false) { 66 throw new AccessDeniedException(); 67 } 68 69 // Setup the object 70 $localplay = new LocalPlay($this->configContainer->get(ConfigurationKeyEnum::LOCALPLAY_CONTROLLER)); 71 $localplay->update_instance($_REQUEST['instance'], $_POST); 72 73 return $this->responseFactory 74 ->createResponse(StatusCode::FOUND) 75 ->withHeader( 76 'Location', 77 sprintf('%s/localplay.php?action=show_instances', $this->configContainer->getWebPath()) 78 ); 79 } 80} 81