Skip to content

Commit

Permalink
[Task] request explicit input source (#88)
Browse files Browse the repository at this point in the history
* request explicit input source

* Added admin-ui as dependency and added upgrade notes

* managed by the core

Co-authored-by: JiaJia Ji <[email protected]>

* Letting composer decide which version to install

Co-authored-by: JiaJia Ji <[email protected]>

---------

Co-authored-by: JiaJia Ji <[email protected]>
  • Loading branch information
mattamon and kingjia90 authored Nov 22, 2024
1 parent d77170e commit 917681d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,9 +22,6 @@
"Web2PrintToolsBundle\\": "src/"
}
},
"suggest": {
"pimcore/admin-ui-classic-bundle": "Required for Pimcore 11"
},
"extra": {
"pimcore": {
"bundles": [
Expand Down
5 changes: 5 additions & 0 deletions doc/01_Upgrade/README.md
Original file line number Diff line number Diff line change
@@ -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.
125 changes: 64 additions & 61 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Web2PrintToolsBundle\Controller;

use Exception;
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Pimcore\Db;
Expand All @@ -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)) {
Expand All @@ -50,68 +51,67 @@ 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);
$def->save();

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()]);

}

/**
Expand All @@ -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 = [];
Expand All @@ -138,35 +138,38 @@ 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) {
$savedConfig->setConfiguration($configuration);
$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]);
}
}

0 comments on commit 917681d

Please sign in to comment.