Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AjaxPluginCategoryUpdateLogic
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateImpl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 executeImpl
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page\Ajax;
6
7use PeServer\App\Models\AppDatabaseCache;
8use PeServer\App\Models\Dao\Entities\PluginCategoriesEntityDao;
9use PeServer\App\Models\Domain\Page\PageLogicBase;
10use PeServer\App\Models\ResponseJson;
11use PeServer\App\Models\SessionKey;
12use PeServer\Core\Database\IDatabaseContext;
13use PeServer\Core\Mvc\LogicCallMode;
14use PeServer\Core\Mvc\LogicParameter;
15use PeServer\Core\Text;
16use PeServer\Core\TypeUtility;
17
18class AjaxPluginCategoryUpdateLogic extends PageLogicBase
19{
20    public function __construct(LogicParameter $parameter, private AppDatabaseCache $dbCache)
21    {
22        parent::__construct($parameter);
23    }
24
25    #region PageLogicBase
26
27    protected function validateImpl(LogicCallMode $callMode): void
28    {
29        //NOP
30    }
31
32    protected function executeImpl(LogicCallMode $callMode): void
33    {
34        $json = $this->getRequestJson();
35
36        $params = [
37            'plugin_category_id' => $this->getRequest('plugin_category_id'),
38            'category_display_name' => Text::trim(TypeUtility::toString($json['category_display_name'])),
39            'category_description' => Text::trim(TypeUtility::toString($json['category_description'])),
40        ];
41
42        $database = $this->openDatabase();
43        $database->transaction(function (IDatabaseContext $context) use ($params) {
44            $pluginCategoriesEntityDao = new PluginCategoriesEntityDao($context);
45
46            $pluginCategoryId = TypeUtility::toString($params['plugin_category_id']);
47            $categoryDisplayName = TypeUtility::toString($params['category_display_name']);
48            $categoryDescription = TypeUtility::toString($params['category_description']);
49            $pluginCategoriesEntityDao->updatePluginCategory($pluginCategoryId, $categoryDisplayName, $categoryDescription);
50
51            return true;
52        });
53
54        $this->setResponseJson(ResponseJson::success($params));
55
56        $this->dbCache->exportPluginInformation();
57    }
58
59    #endregion
60}