"Fossies" - the Fresh Open Source Software Archive

Member "ampache-5.0.0/src/Module/Application/Admin/Catalog/AddCatalogAction.php" (31 Aug 2021, 3893 Bytes) of package /linux/www/ampache-5.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AddCatalogAction.php" see the Fossies "Dox" file reference documentation.

    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 
   23 declare(strict_types=0);
   24 
   25 namespace Ampache\Module\Application\Admin\Catalog;
   26 
   27 use Ampache\Config\ConfigContainerInterface;
   28 use Ampache\Config\ConfigurationKeyEnum;
   29 use Ampache\Repository\Model\Catalog;
   30 use Ampache\Module\Application\Exception\AccessDeniedException;
   31 use Ampache\Module\System\AmpError;
   32 use Ampache\Module\System\Core;
   33 use Ampache\Module\Util\Ui;
   34 use Ampache\Module\Util\UiInterface;
   35 use Ampache\Repository\UserRepositoryInterface;
   36 use Psr\Http\Message\ResponseInterface;
   37 use Psr\Http\Message\ServerRequestInterface;
   38 
   39 final class AddCatalogAction extends AbstractCatalogAction
   40 {
   41     public const REQUEST_KEY = 'add_catalog';
   42 
   43     private ConfigContainerInterface $configContainer;
   44 
   45     private UiInterface $ui;
   46 
   47     public function __construct(
   48         UiInterface $ui,
   49         ConfigContainerInterface $configContainer
   50     ) {
   51         parent::__construct($ui);
   52         $this->configContainer = $configContainer;
   53         $this->ui              = $ui;
   54     }
   55 
   56     /**
   57      * @param int[] $catalogIds
   58      * @throws AccessDeniedException
   59      */
   60     protected function handle(
   61         ServerRequestInterface $request,
   62         array $catalogIds
   63     ): ?ResponseInterface {
   64         if ($this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE) === true) {
   65             return null;
   66         }
   67 
   68         ob_end_flush();
   69 
   70         if (!strlen(filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) || filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES) == 'none') {
   71             AmpError::add('general', T_('Please select a Catalog type'));
   72         }
   73 
   74         if (!strlen(filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES))) {
   75             AmpError::add('general', T_('Please enter a Catalog name'));
   76         }
   77 
   78         if (!Core::form_verify('add_catalog')) {
   79             throw new AccessDeniedException();
   80         }
   81 
   82         // If an error hasn't occurred
   83         if (!AmpError::occurred()) {
   84             $catalog_id = Catalog::create($_POST);
   85             $users      = static::getUserRepository()->getValidArray();
   86 
   87             if (!$catalog_id) {
   88                 require Ui::find_template('show_add_catalog.inc.php');
   89 
   90                 return null;
   91             }
   92 
   93             $catalogIds[] = $catalog_id;
   94             catalog_worker('add_to_catalog', $catalogIds, $_POST);
   95 
   96             $this->ui->showConfirmation(T_('No Problem'),
   97                 T_('The Catalog creation process has started'),
   98                 sprintf('%s/admin/catalog.php', $this->configContainer->getWebPath()),
   99                 0,
  100                 'confirmation',
  101                 false
  102             );
  103         } else {
  104             require Ui::find_template('show_add_catalog.inc.php');
  105         }
  106 
  107         return null;
  108     }
  109 
  110     /**
  111      * @deprecated inject dependency
  112      */
  113     private static function getUserRepository(): UserRepositoryInterface
  114     {
  115         global $dic;
  116 
  117         return $dic->get(UserRepositoryInterface::class);
  118     }
  119 }