From 917681d98fcefce4fef2dc813447b8f38d685c8d Mon Sep 17 00:00:00 2001 From: Matthias Schuhmayer <38959016+mattamon@users.noreply.github.com> Date: Fri, 22 Nov 2024 07:29:01 +0100 Subject: [PATCH] [Task] request explicit input source (#88) * request explicit input source * Added admin-ui as dependency and added upgrade notes * managed by the core Co-authored-by: JiaJia Ji * Letting composer decide which version to install Co-authored-by: JiaJia Ji --------- Co-authored-by: JiaJia Ji --- .github/workflows/static-analysis.yml | 2 +- composer.json | 9 +- doc/01_Upgrade/README.md | 5 ++ src/Controller/AdminController.php | 125 +++++++++++++------------- 4 files changed, 74 insertions(+), 67 deletions(-) create mode 100644 doc/01_Upgrade/README.md diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index e4cef1e..405bc4c 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -19,7 +19,7 @@ jobs: include: - { php-version: "8.1", dependencies: "lowest", require_admin_bundle: false } - { php-version: "8.2", dependencies: "highest", require_admin_bundle: true } - - { php-version: "8.3", dependencies: "highest", pimcore_version: "11.x-dev as 11.0.0", require_admin_bundle: true } + - { php-version: "8.3", dependencies: "highest", pimcore_version: "11.x-dev", require_admin_bundle: true } steps: - name: "Checkout code" uses: "actions/checkout@v2" diff --git a/composer.json b/composer.json index e5855d0..90dfd09 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,10 @@ "minimum-stability": "dev", "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "pimcore/pimcore": "^11.0", - "pimcore/output-data-config-toolkit-bundle": "^4.1 || ^5.0" + "pimcore/admin-ui-classic-bundle": "^1.0", + "pimcore/pimcore": "^11.2", + "pimcore/output-data-config-toolkit-bundle": "^4.1 || ^5.0", + "symfony/http-foundation": "^6.3" }, "require-dev": { "phpstan/phpstan": "^1.9" @@ -20,9 +22,6 @@ "Web2PrintToolsBundle\\": "src/" } }, - "suggest": { - "pimcore/admin-ui-classic-bundle": "Required for Pimcore 11" - }, "extra": { "pimcore": { "bundles": [ diff --git a/doc/01_Upgrade/README.md b/doc/01_Upgrade/README.md new file mode 100644 index 0000000..32dcacb --- /dev/null +++ b/doc/01_Upgrade/README.md @@ -0,0 +1,5 @@ +# Update Notes + +## Update to Version 5.2 +### General +- Dropped support of Pimcore 10, bumped minimum requirement of `pimcore/pimcore` to `^11.2`. Replaced all `$request->get()` with their explicit input source. \ No newline at end of file diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 4b974ec..bffe4a5 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -15,6 +15,7 @@ namespace Web2PrintToolsBundle\Controller; +use Exception; use Pimcore\Controller\Traits\JsonHelperTrait; use Pimcore\Controller\UserAwareController; use Pimcore\Db; @@ -37,10 +38,10 @@ class AdminController extends UserAwareController */ public function favoriteOutputDefinitionsTableProxyAction(Request $request) { - if ($request->get('data')) { - if ($request->get('xaction') == 'destroy') { - $id = json_decode($request->get('data'), true); - $idValue = $id['id'] ?? ''; + if ($request->request->getString('data')) { + $data = json_decode($request->request->getString('data'), true); + if ($request->query->getString('xaction') === 'destroy') { + $idValue = $data['id'] ?? ''; if (!empty($idValue)) { $def = FavoriteOutputDefinition::getById($idValue); if (!empty($def)) { @@ -50,20 +51,18 @@ public function favoriteOutputDefinitionsTableProxyAction(Request $request) } } - throw new \Exception('OutputDefinition with id ' . $idValue . ' not found.'); - } elseif ($request->get('xaction') == 'update') { - $data = json_decode($request->get('data'), true); + throw new Exception('OutputDefinition with id ' . $idValue . ' not found.'); + } elseif ($request->query->getString('xaction') === 'update') { $def = FavoriteOutputDefinition::getById($data['id']); if (!empty($def)) { $def->setValues($data); $def->save(); return $this->jsonResponse(['data' => get_object_vars($def), 'success' => true]); - } else { - throw new \Exception('Definition with id ' . $data['id'] . ' not found.'); } - } elseif ($request->get('xaction') == 'create') { - $data = json_decode($request->get('data'), true); + + throw new Exception('Definition with id ' . $data['id'] . ' not found.'); + } elseif ($request->query->getString('xaction') === 'create') { unset($data['id']); $def = new FavoriteOutputDefinition(); $def->setValues($data); @@ -71,47 +70,48 @@ public function favoriteOutputDefinitionsTableProxyAction(Request $request) return $this->jsonResponse(['data' => get_object_vars($def), 'success' => true]); } - } else { - $list = new FavoriteOutputDefinition\Listing(); - $list->setOrder('asc'); - $list->setOrderKey('description'); - - if ($request->get('sort')) { - $sortConfig = json_decode($request->get('sort'), true); - $sortConfig = $sortConfig[0]; - if ($sortConfig['property']) { - $list->setOrderKey($sortConfig['property']); - } - if ($sortConfig['direction']) { - $list->setOrder($sortConfig['direction']); - } + } + + $list = new FavoriteOutputDefinition\Listing(); + $list->setOrder('asc'); + $list->setOrderKey('description'); + + if ($request->request->getString('sort')) { + $sortConfig = json_decode($request->request->getString('sort'), true); + $sortConfig = $sortConfig[0]; + if ($sortConfig['property']) { + $list->setOrderKey($sortConfig['property']); } + if ($sortConfig['direction']) { + $list->setOrder($sortConfig['direction']); + } + } - $list->setLimit($request->get('limit')); - $list->setOffset($request->get('start')); + $list->setLimit($request->request->getInt('limit')); + $list->setOffset($request->request->getInt('start')); - $condition = '1 = 1'; - if ($request->get('filter')) { - $filterString = $request->get('filter'); - $filters = json_decode($filterString, true); + $condition = '1 = 1'; + if ($request->request->getString('filter')) { + $filterString = $request->request->getString('filter'); + $filters = json_decode($filterString, true); - $db = \Pimcore\Db::get(); - foreach ($filters as $f) { - if ($f->type == 'string') { - $condition .= ' AND ' . $db->quoteIdentifier($f->property) . ' LIKE ' . $db->quote('%' . $f->value . '%'); - } - } - $list->setCondition($condition); - } - $list->load(); + $db = Db::get(); - $definitions = []; - foreach ($list->getOutputDefinitions() as $u) { - $definitions[] = get_object_vars($u); + foreach ($filters as $f) { + if ($f['type'] === 'string') { + $condition .= ' AND ' . $db->quoteIdentifier($f['property']) . ' LIKE ' . $db->quote('%' . $f['value'] . '%'); + } } + $list->setCondition($condition); + } - return $this->jsonResponse(['data' => $definitions, 'success' => true, 'total' => $list->getTotalCount()]); + $definitions = []; + foreach ($list->getOutputDefinitions() as $u) { + $definitions[] = get_object_vars($u); } + + return $this->jsonResponse(['data' => $definitions, 'success' => true, 'total' => $list->getTotalCount()]); + } /** @@ -122,7 +122,7 @@ public function favoriteOutputDefinitionsAction(Request $request) $list = new FavoriteOutputDefinition\Listing(); $list->setOrder('asc'); $list->setOrderKey('description'); - $condition = (DataObject\Service::getVersionDependentDatabaseColumnName('classId') .' = ' . $list->quote($request->get('classId'))); + $condition = (DataObject\Service::getVersionDependentDatabaseColumnName('classId') .' = ' . $list->quote($request->query->getString('classId'))); $list->setCondition($condition); $definitions = []; @@ -138,9 +138,10 @@ public function favoriteOutputDefinitionsAction(Request $request) */ public function saveOrUpdateFavoriteOutputDefinitionAction(Request $request) { - $configuration = $request->get('configuration'); - $id = $request->get('existing'); - $newName = strip_tags($request->get('text')); + + $configuration = $request->request->getString('configuration'); + $id = $request->request->getInt('existing'); + $newName = strip_tags($request->request->getString('text')); $savedConfig = FavoriteOutputDefinition::getById($id); if ($id && $savedConfig) { @@ -148,25 +149,27 @@ public function saveOrUpdateFavoriteOutputDefinitionAction(Request $request) $savedConfig->save(); return $this->jsonResponse(['success' => true]); - } elseif ($newName) { + } + + if ($newName) { $db = Db::get(); $list = new FavoriteOutputDefinition\Listing(); - $classId = $request->get('classId'); + $classId = $request->request->getString('classId'); $list->setCondition(DataObject\Service::getVersionDependentDatabaseColumnName('classId') .' = ' . $list->quote($classId) . ' AND ' . $db->quoteIdentifier('description') . ' = ' . $list->quote($newName)); $existingOnes = $list->load(); - if (!empty($existingOnes) && !$request->get('force')) { + if (!empty($existingOnes) && !$request->request->getBoolean('force')) { return $this->jsonResponse(['success' => false, 'nameexists' => true, 'id' => $existingOnes[0]->getId()]); - } else { - $newConfiguration = new FavoriteOutputDefinition(); - $newConfiguration->setClassId($request->get('classId')); - $newConfiguration->setDescription($newName); - $newConfiguration->setConfiguration($configuration); - $newConfiguration->save(); - - return $this->jsonResponse(['success' => true]); } - } else { - return $this->jsonResponse(['success' => false]); + + $newConfiguration = new FavoriteOutputDefinition(); + $newConfiguration->setClassId($request->request->getString('classId')); + $newConfiguration->setDescription($newName); + $newConfiguration->setConfiguration($configuration); + $newConfiguration->save(); + + return $this->jsonResponse(['success' => true]); } + + return $this->jsonResponse(['success' => false]); } }