diff --git a/CHANGELOG.md b/CHANGELOG.md index 87b001d2..2f37a560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +#### v4.2.0 +- Bumped minimum requirement of `pimcore/pimcore` to `^11.2`. Replaced all `$request->get()` with their explicit input source. #### v4.1.2 Removed the package "rybakit/twig-deferred-extension". If you extend the twig layout from the Customer Data Framework, please check if custom CSS/JS code added by pimcore_head_script and pimcore_head_link is still working. diff --git a/composer.json b/composer.json index 0c24702d..57825c8c 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "pimcore/number-sequence-generator": "^2.0", "pimcore/admin-ui-classic-bundle": "^1.0", "pimcore/object-merger": "^4.0", - "pimcore/pimcore": "^11.0", + "pimcore/pimcore": "^11.2", "pimcore/search-query-parser": "^1.3", "pimcore/personalization-bundle": "^1.0", "symfony/asset": "^6.2", @@ -34,7 +34,7 @@ "symfony/console": "^6.2", "symfony/dependency-injection": "^6.2", "symfony/event-dispatcher": "^6.2", - "symfony/http-foundation": "^6.2", + "symfony/http-foundation": "^6.3", "symfony/http-kernel": "^6.2", "symfony/options-resolver": "^6.2", "symfony/routing": "^6.2", diff --git a/src/Controller/Admin.php b/src/Controller/Admin.php index 6da7233d..d3672e3a 100644 --- a/src/Controller/Admin.php +++ b/src/Controller/Admin.php @@ -104,8 +104,8 @@ protected function buildPaginator(Request $request, mixed $data, int $defaultPag $defaultPageSize = $this->defaultPageSize; } - $page = (int)$request->get('page', 1); - $pageSize = (int)$request->get('perPage', $defaultPageSize); + $page = $request->query->getInt('page', 1); + $pageSize = $request->query->getInt('perPage', $defaultPageSize); return $this->paginator->paginate($data, $page, $pageSize); } diff --git a/src/Controller/Admin/ActivitiesController.php b/src/Controller/Admin/ActivitiesController.php index 47ab299a..a8d0aed9 100644 --- a/src/Controller/Admin/ActivitiesController.php +++ b/src/Controller/Admin/ActivitiesController.php @@ -51,7 +51,7 @@ public function onKernelControllerEvent(ControllerEvent $event): void */ public function listAction(Request $request, CustomerProviderInterface $customerProvider): Response { - if ($customer = $customerProvider->getById($request->get('customerId'))) { + if ($customer = $customerProvider->getById($request->query->getInt('customerId'))) { $list = \Pimcore::getContainer()->get('cmf.activity_store')->getActivityList(); $list->setCondition('customerId = ' . $customer->getId()); $list->setOrderKey('activityDate'); @@ -65,13 +65,13 @@ public function listAction(Request $request, CustomerProviderInterface $customer $types = \Pimcore\Db::get()->fetchFirstColumn((string)$select); - if ($type = $request->get('type')) { + if ($type = $request->query->getString('type')) { $select = $list->getQueryBuilder(false); $select->andWhere('type = ' . $list->quote($type)); $list->setCondition((string) $select->getQueryPart('where')); } - $paginator = $this->paginator->paginate($list, $request->get('page', 1), 25); + $paginator = $this->paginator->paginate($list, $request->query->getInt('page', 1), 25); return $this->render( '@PimcoreCustomerManagementFramework/admin/activities/list.html.twig', @@ -94,7 +94,8 @@ public function listAction(Request $request, CustomerProviderInterface $customer */ public function detailAction(Request $request): Response { - $activity = \Pimcore::getContainer()->get('cmf.activity_store')->getEntryById($request->get('activityId')); + $activityId = $request->query->getInt('activityId'); + $activity = \Pimcore::getContainer()->get('cmf.activity_store')->getEntryById($activityId); return $this->render( '@PimcoreCustomerManagementFramework/admin/activities/detail.html.twig', diff --git a/src/Controller/Admin/Customers/FilterDefinitionController.php b/src/Controller/Admin/Customers/FilterDefinitionController.php index 74748791..7955bfb1 100644 --- a/src/Controller/Admin/Customers/FilterDefinitionController.php +++ b/src/Controller/Admin/Customers/FilterDefinitionController.php @@ -198,17 +198,17 @@ protected function getRedirectToFilter(int $filterDefinitionId = 0, array $error protected function getIdFromRequest(Request $request): int { - return intval($request->get('filterDefinition', [])['id'] ?? 0); + return intval($request->query->all('filterDefinition')['id'] ?? 0); } protected function getNameFromRequest(Request $request): string { - return strval($request->get('filterDefinition', [])['name'] ?? ''); + return strval($request->query->all('filterDefinition')['name'] ?? ''); } protected function getDefinitionFromRequest(Request $request): mixed { - return $request->get('filter', []); + return $request->query->all('filter'); } protected function getShowSegmentsFromRequest(Request $request): array @@ -218,12 +218,12 @@ protected function getShowSegmentsFromRequest(Request $request): array protected function getReadOnlyFromRequest(Request $request): bool { - return boolval($request->get('filterDefinition', [])['readOnly'] ?? false); + return boolval($request->query->all('filterDefinition')['readOnly'] ?? false); } protected function getShortcutAvailableFromRequest(Request $request): bool { - return boolval($request->get('filterDefinition', [])['shortcutAvailable'] ?? false); + return boolval($request->query->all('filterDefinition')['shortcutAvailable'] ?? false); } /** @@ -231,8 +231,8 @@ protected function getShortcutAvailableFromRequest(Request $request): bool */ protected function getAllowedUserIdsFromRequest(Request $request): array { - $allowedUserIds = $request->get('filterDefinition', [])['allowedUserIds'] ?? []; - $allowedRoleIds = $request->get('filterDefinition', [])['allowedRoleIds'] ?? []; + $allowedUserIds = $request->query->all('filterDefinition')['allowedUserIds'] ?? []; + $allowedRoleIds = $request->query->all('filterDefinition')['allowedRoleIds'] ?? []; $preparedAllowedUserIds = array_unique(array_merge($allowedUserIds, $allowedRoleIds)); sort($preparedAllowedUserIds); diff --git a/src/Controller/Admin/CustomersController.php b/src/Controller/Admin/CustomersController.php index 279a4bfb..e331d304 100644 --- a/src/Controller/Admin/CustomersController.php +++ b/src/Controller/Admin/CustomersController.php @@ -76,7 +76,7 @@ public function listAction(Request $request): Response { $filters = $this->fetchListFilters($request); $orders = $this->fetchListOrder($request); - $errors = $request->get('errors', []); + $errors = $request->query->all('errors'); $paginator = null; $customerView = \Pimcore::getContainer()->get('cmf.customer_view'); @@ -116,7 +116,7 @@ public function listAction(Request $request): Response 'filterDefinitions' => $this->getFilterDefinitions(), 'filterDefinition' => $this->getFilterDefinition($request), 'accessToTempCustomerFolder' => boolval($this->hasUserAccessToTempCustomerFolder()), - 'hideAdvancedFilterSettings' => boolval($request->get('segmentId')), + 'hideAdvancedFilterSettings' => $request->query->getBoolean('segmentId'), 'idField' => Service::getVersionDependentDatabaseColumnName('id'), ] ); @@ -128,7 +128,7 @@ public function listAction(Request $request): Response */ public function detailAction(Request $request): Response { - $customer = $this->getSearchHelper()->getCustomerProvider()->getById((int)$request->get('id')); + $customer = $this->getSearchHelper()->getCustomerProvider()->getById($request->query->getInt('id')); if ($customer instanceof CustomerInterface) { $customerView = \Pimcore::getContainer()->get('cmf.customer_view'); if (!$customerView->hasDetailView($customer)) { @@ -172,14 +172,14 @@ public function exportAction(Request $request): JsonResponse $jobId = uniqid(); $this->exporterManager->saveExportTmpData($jobId, [ 'processIds' => $ids, - 'exporter' => $request->get('exporter'), + 'exporter' => $request->query->getString('exporter'), ]); /** @noinspection PhpRouteMissingInspection */ return $this->jsonResponse([ 'url' => $this->generateUrl('customermanagementframework_admin_customers_exportstep', ['jobId' => $jobId]), 'jobId' => $jobId, - 'exporter' => $request->get('exporter'), + 'exporter' => $request->query->getString('exporter'), ]); } @@ -188,7 +188,7 @@ public function exportAction(Request $request): JsonResponse */ public function exportStepAction(Request $request): JsonResponse { - $perRequest = $request->get( + $perRequest = $request->query->getInt( 'perRequest', $this->getParameter('cmf.customer_export.items_per_request') ); @@ -208,8 +208,8 @@ public function exportStepAction(Request $request): JsonResponse return $this->jsonResponse([ 'finished' => true, 'url' => $this->generateUrl('customermanagementframework_admin_customers_downloadfinishedexport', - ['jobId' => $request->get('jobId')]), - 'jobId' => $request->get('jobId'), + ['jobId' => $request->query->getString('jobId')]), + 'jobId' => $request->query->getString('jobId'), ]); } @@ -230,7 +230,7 @@ public function exportStepAction(Request $request): JsonResponse $data['processIds'] = $processIds; $this->exporterManager->saveExportTmpData( - $request->get('jobId'), + $request->query->getString('jobId'), $data ); @@ -241,7 +241,7 @@ public function exportStepAction(Request $request): JsonResponse return $this->jsonResponse([ 'finished' => false, - 'jobId' => $request->get('jobId'), + 'jobId' => $request->query->getString('jobId'), 'notProcessedRecordsCount' => $notProcessedRecordsCount, 'totalRecordsCount' => $totalRecordsCount, 'percent' => $percent, @@ -298,7 +298,7 @@ public function downloadFinishedExportAction(Request $request): JsonResponse | R ] ); - $this->exporterManager->deleteExportTmpData($request->get('jobId')); + $this->exporterManager->deleteExportTmpData($request->query->getString('jobId')); return $response; } @@ -419,7 +419,7 @@ protected function buildListing(array $filters = [], array $orders = []): Listin */ protected function fetchListFilters(Request $request): array { - $filters = $request->get('filter', []); + $filters = $request->query->all('filter'); $filters = $this->addPrefilteredSegmentToFilters($request, $filters); $filters = $this->addFilterDefinitionCustomer($request, $filters); @@ -431,7 +431,7 @@ protected function fetchListFilters(Request $request): array */ protected function fetchListOrder(Request $request): array { - $orders = $request->get('order', []); + $orders = $request->query->all('order'); $ordersNullsLast = []; foreach ($orders as $key => $val) { @@ -472,7 +472,7 @@ protected function addPrefilteredSegmentToFilters(Request $request, array $filte protected function fetchPrefilteredSegment(Request $request): ?CustomerSegmentInterface { - $segmentId = $request->get('segmentId'); + $segmentId = $request->query->getInt('segmentId'); if ($segmentId) { $segment = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentById($segmentId); @@ -511,7 +511,7 @@ protected function getFilterDefinitions(): array protected function getFilterDefinition(Request $request): ?FilterDefinition { // fetch filter definition information - $filterDefinitionData = $request->get('filterDefinition', []); + $filterDefinitionData = $request->query->all('filterDefinition'); // build default FilterDefinition object if no selected $segmentGroups = $this->loadSegmentGroups(); $DefaultFilterDefinition = (new FilterDefinition())->setShowSegments(Objects::getIdsFromArray($segmentGroups)); @@ -605,7 +605,8 @@ protected function addFilterDefinitionSegments(Request $request, array $filters) } // set to filter which segments to show - $filters['showSegments'] = $request->get('apply-segment-selection') ? $filters['showSegments'] : $filterDefinition->getShowSegments(); + $segmentSelection = $request->query->getString('apply-segment-selection'); + $filters['showSegments'] = $segmentSelection ? $filters['showSegments'] : $filterDefinition->getShowSegments(); // return merged filters array return $filters; diff --git a/src/Controller/Admin/DuplicatesController.php b/src/Controller/Admin/DuplicatesController.php index 6aec9a9b..fa6c6146 100644 --- a/src/Controller/Admin/DuplicatesController.php +++ b/src/Controller/Admin/DuplicatesController.php @@ -51,7 +51,7 @@ public function onKernelControllerEvent(ControllerEvent $event): void public function listAction(Request $request, DuplicatesIndexInterface $duplicatesIndex): Response { // fetch all filters - $filters = $request->get('filter', []); + $filters = $request->query->all('filter'); // check if filters exist $customerList = null; if (!empty($filters)) { @@ -67,9 +67,9 @@ public function listAction(Request $request, DuplicatesIndexInterface $duplicate } $paginator = $duplicatesIndex->getPotentialDuplicates( - $request->get('page', 1), + $request->query->getInt('page', 1), 50, - $request->get('declined'), + $request->query->getBoolean('declined'), $customerList ); @@ -93,7 +93,7 @@ public function declineAction(Request $request): JsonResponse { try { \Pimcore::getContainer()->get('cmf.customer_duplicates_index')->declinePotentialDuplicate( - $request->get('id') + $request->request->getInt('id') ); return new JsonResponse(['success' => true]); diff --git a/src/Controller/Admin/RulesController.php b/src/Controller/Admin/RulesController.php index eb4022f7..97b5f8a9 100644 --- a/src/Controller/Admin/RulesController.php +++ b/src/Controller/Admin/RulesController.php @@ -83,7 +83,7 @@ public function listAction(Request $request): JsonResponse */ public function getAction(Request $request): JsonResponse { - $rule = Rule::getById((int)$request->get('id')); + $rule = Rule::getById($request->query->getInt('id')); if ($rule) { // create json config $json = [ @@ -144,8 +144,8 @@ public function saveAction(Request $request): JsonResponse // save rule config try { - $rule = Rule::getById((int)$request->get('id')); - $data = json_decode($request->get('data')); + $rule = Rule::getById($request->request->getInt('id')); + $data = json_decode($request->request->getString('data')); // apply basic settings $rule->setName($data->settings->name); @@ -224,7 +224,7 @@ public function addAction(Request $request): JsonResponse // save rule try { $rule = new Rule(); - $rule->setName($request->get('name')); + $rule->setName($request->request->getString('name')); if ($rule->save()) { $return['success'] = true; $return['id'] = $rule->getId(); @@ -253,7 +253,7 @@ public function deleteAction(Request $request): JsonResponse // delete rule try { - $rule = Rule::getById((int)$request->get('id')); + $rule = Rule::getById($request->request->getInt('id')); $rule->delete(); $return['success'] = true; } catch (\Exception $e) { diff --git a/src/Controller/Admin/SegmentAssignmentController.php b/src/Controller/Admin/SegmentAssignmentController.php index 83f73521..6f691f3a 100644 --- a/src/Controller/Admin/SegmentAssignmentController.php +++ b/src/Controller/Admin/SegmentAssignmentController.php @@ -48,8 +48,8 @@ public function __construct(protected SegmentAssignerInterface $segmentAssigner) */ public function inheritableSegments(Request $request, SegmentManagerInterface $segmentManager): JsonResponse { - $id = $request->get('id'); - $type = $request->get('type'); + $id = $request->query->getInt('id'); + $type = $request->query->getString('type'); if (!$type || !$id) { return $this->jsonResponse(['data' => []]); } @@ -80,8 +80,8 @@ public function inheritableSegments(Request $request, SegmentManagerInterface $s */ public function assignedSegments(Request $request): JsonResponse { - $id = $request->get('id') ?? ''; - $type = $request->get('type') ?? ''; + $id = $request->query->getInt('id'); + $type = $request->query->getString('type'); $assignmentTable = $this->getParameter('cmf.segmentAssignment.table.raw'); $segmentIds = \Pimcore\Db::get()->fetchOne("SELECT `segments` FROM $assignmentTable WHERE `elementId` = ? AND `elementType` = ?", [$id, $type]); @@ -101,10 +101,10 @@ public function assignedSegments(Request $request): JsonResponse */ public function assign(Request $request): JsonResponse { - $id = $request->get('id') ?? ''; - $type = $request->get('type') ?? ''; - $breaksInheritance = $request->get('breaksInheritance') === 'true'; - $segmentIds = json_decode($request->get('segmentIds'), true) ?? []; + $id = $request->request->getString('id'); + $type = $request->request->getString('type'); + $breaksInheritance = $request->request->getBoolean('breaksInheritance'); + $segmentIds = json_decode($request->request->getString('segmentIds'), true) ?? []; $success = $this->segmentAssigner->assignById($id, $type, $breaksInheritance, $segmentIds); @@ -116,8 +116,8 @@ public function assign(Request $request): JsonResponse */ public function breaksInheritance(Request $request): JsonResponse { - $id = $request->get('id') ?? ''; - $type = $request->get('type') ?? ''; + $id = $request->request->getString('id'); + $type = $request->request->getString('type'); $assignmentTable = $this->getParameter('cmf.segmentAssignment.table.raw'); $breaksInheritance = \Pimcore\Db::get()->fetchOne("SELECT `breaksInheritance` FROM $assignmentTable WHERE `elementId` = ? AND `elementType` = ?", [$id, $type]); diff --git a/src/Controller/Admin/SettingsController.php b/src/Controller/Admin/SettingsController.php index b22dd27c..7ca8b89a 100644 --- a/src/Controller/Admin/SettingsController.php +++ b/src/Controller/Admin/SettingsController.php @@ -40,10 +40,10 @@ public function userManagementAction(Request $request, CsrfProtectionHandler $cs $settingsStore = SettingsStore::get(WebserviceAuthenticator::SETTINGS_STORE_KEY, WebserviceAuthenticator::SETTINGS_STORE_SCOPE); $apiKeys = $settingsStore ? json_decode($settingsStore->getData(), true) : []; - if ($request->get('data')) { - if ($request->get('xaction') == 'update') { + if ($request->request->getString('data')) { + if ($request->query->getString('xaction') == 'update') { $csrfProtectionHandler->checkCsrfToken($request); - $data = $this->decodeJson($request->get('data')); + $data = $this->decodeJson($request->request->getString('data')); $apiKeys[$data['id']] = $data['apiKey']; SettingsStore::set(WebserviceAuthenticator::SETTINGS_STORE_KEY, json_encode($apiKeys), 'string', WebserviceAuthenticator::SETTINGS_STORE_SCOPE); @@ -52,16 +52,16 @@ public function userManagementAction(Request $request, CsrfProtectionHandler $cs } } else { $userListing = new \Pimcore\Model\User\Listing(); - $userListing->setLimit($request->get('limit')); - $userListing->setOffset($request->get('start')); + $userListing->setLimit($request->request->getInt('limit')); + $userListing->setOffset($request->request->getInt('start')); $sortingSettings = QueryParams::extractSortingSettings(array_merge($request->request->all(), $request->query->all())); if ($sortingSettings['orderKey']) { $userListing->setOrderKey($sortingSettings['orderKey']); $userListing->setOrder($sortingSettings['order']); } - if ($request->get('filter')) { - $filter = '%' . $request->get('filter') . '%'; + if ($request->request->getString('filter')) { + $filter = '%' . $request->request->getString('filter') . '%'; $userListing->addConditionParam('(`name` LIKE ? OR firstname LIKE ? OR lastname LIKE ? OR email LIKE ?)', [$filter, $filter, $filter, $filter] ); diff --git a/src/Controller/Admin/TemplatesController.php b/src/Controller/Admin/TemplatesController.php index d15bc73b..2f1b6b1c 100644 --- a/src/Controller/Admin/TemplatesController.php +++ b/src/Controller/Admin/TemplatesController.php @@ -37,14 +37,14 @@ class TemplatesController extends UserAwareController */ public function exportAction(Request $request, TemplateExporter $templateExporter): JsonResponse { - $document = PageSnippet::getById($request->get('document_id')); + $document = PageSnippet::getById($request->request->getInt('document_id')); if ($document) { $templateExporter->exportTemplate($document); return $this->jsonResponse(['success' => true]); } else { - throw new \Exception(sprintf('Document {%s} not found!', $request->get('document_id'))); + throw new \Exception(sprintf('Document {%s} not found!', $request->request->getInt('document_id'))); } } } diff --git a/src/Controller/Rest/AbstractRestController.php b/src/Controller/Rest/AbstractRestController.php index 3d72f92d..0a3ae99a 100644 --- a/src/Controller/Rest/AbstractRestController.php +++ b/src/Controller/Rest/AbstractRestController.php @@ -202,7 +202,7 @@ protected function resolveId(Request $request, $id = null) return $id; } - if ($id = $request->get('id')) { + if ($id = $request->attributes->getInt('id')) { return $id; } @@ -286,7 +286,7 @@ protected function checkCondition($condition) */ protected function buildCondition(Request $request) { - $q = trim($request->get('q')); + $q = trim($request->query->getString('q')); if (!$q) { return null; } diff --git a/src/CustomerList/ExporterManager.php b/src/CustomerList/ExporterManager.php index 9d35f76a..10a3c23f 100644 --- a/src/CustomerList/ExporterManager.php +++ b/src/CustomerList/ExporterManager.php @@ -78,7 +78,7 @@ public function buildExporter($key, Listing\Concrete $listing = null) */ public function getExportTmpData(Request $request) { - if (!$jobId = $request->get('jobId')) { + if (!$jobId = $request->query->getString('jobId')) { throw new \Exception('no jobId given'); } diff --git a/src/Event/Frontend/UrlActivityTracker.php b/src/Event/Frontend/UrlActivityTracker.php index 1955fe94..9c61e157 100644 --- a/src/Event/Frontend/UrlActivityTracker.php +++ b/src/Event/Frontend/UrlActivityTracker.php @@ -54,13 +54,13 @@ public function onKernelRequest(RequestEvent $event) $request = $event->getRequest(); - if (!$request->get('cmfa') || !$request->get('cmfc')) { + if (!$request->query->getString('cmfa') || !$request->query->getString('cmfc')) { return; } \Pimcore::getContainer()->get('cmf.activity_url_tracker')->trackActivity( - $request->get('cmfc'), - $request->get('cmfa'), + $request->query->getString('cmfc'), + $request->query->getString('cmfa'), $request->request->all() ); diff --git a/src/Filter/ExportActivitiesFilterParams.php b/src/Filter/ExportActivitiesFilterParams.php index d8f7a181..80026436 100644 --- a/src/Filter/ExportActivitiesFilterParams.php +++ b/src/Filter/ExportActivitiesFilterParams.php @@ -31,8 +31,8 @@ class ExportActivitiesFilterParams public static function fromRequest(Request $request) { $params = new static(); - $params->setType($request->get('type', false)); - $params->setModifiedSinceTimestamp($request->get('modifiedSinceTimestamp')); + $params->setType($request->query->has('type') ? $request->query->getString('type') : false); + $params->setModifiedSinceTimestamp($request->query->getInt('modifiedSinceTimestamp')); $params->setAllParams($request->request->all()); return $params; diff --git a/src/Filter/ExportCustomersFilterParams.php b/src/Filter/ExportCustomersFilterParams.php index 34a37e06..f728f923 100644 --- a/src/Filter/ExportCustomersFilterParams.php +++ b/src/Filter/ExportCustomersFilterParams.php @@ -46,9 +46,10 @@ class ExportCustomersFilterParams public static function fromRequest(Request $request) { $params = new static(); - $params->setIncludeActivities($request->get('includeActivities') == 'true' ? true : false); - $params->setSegments($request->get('segments')); - $params->setModificationTimestamp(intval($request->get('modificationTimestamp'))); + + $params->setIncludeActivities($request->query->getBoolean('includeActivities')); + $params->setSegments($request->query->all('segments') ?: $request->query->getInt('segments')); + $params->setModificationTimestamp($request->query->getInt('modificationTimestamp')); $params->setAllParams($request->request->all()); return $params; diff --git a/src/RESTApi/AbstractHandler.php b/src/RESTApi/AbstractHandler.php index 15fe0b0b..01c9c923 100644 --- a/src/RESTApi/AbstractHandler.php +++ b/src/RESTApi/AbstractHandler.php @@ -49,8 +49,8 @@ protected function handlePaginatorParams( $defaultPageSize = 100, $defaultPage = 1 ): PaginationInterface { - $pageSize = intval($request->get('pageSize', $defaultPageSize)); - $page = intval($request->get('page', $defaultPage)); + $pageSize = $request->query->getInt('pageSize', $defaultPageSize); + $page = $request->query->getInt('page', $defaultPage); return $this->paginator->paginate($listing, $page, $pageSize); } diff --git a/src/RESTApi/ActivitiesHandler.php b/src/RESTApi/ActivitiesHandler.php index cc5a4903..fff2e5f0 100644 --- a/src/RESTApi/ActivitiesHandler.php +++ b/src/RESTApi/ActivitiesHandler.php @@ -45,8 +45,8 @@ public function listRecords(Request $request) $timestamp = time(); - $pageSize = intval($request->get('pageSize', 100)); - $page = intval($request->get('page', 1)); + $pageSize = $request->query->getInt('pageSize', 100); + $page = $request->query->getInt('page', 1); $paginator = \Pimcore::getContainer()->get('cmf.activity_store')->getActivitiesDataForWebservice( $pageSize, @@ -80,7 +80,7 @@ public function listRecords(Request $request) */ public function readRecord(Request $request) { - $entry = $this->loadActivityStoreEntry($request->get('id')); + $entry = $this->loadActivityStoreEntry($request->attributes->getInt('id')); return $this->createActivityEntryResponse($entry); } @@ -163,7 +163,7 @@ public function createRecord(Request $request) */ public function updateRecord(Request $request) { - $entry = $this->loadActivityStoreEntry($request->get('id')); + $entry = $this->loadActivityStoreEntry($request->attributes->getInt('id')); $data = $this->getRequestData($request); if (isset($data['implementationClass']) && $data['implementationClass'] != $entry->getImplementationClass()) { @@ -180,7 +180,7 @@ public function updateRecord(Request $request) } \Pimcore::getContainer()->get('cmf.activity_store')->updateActivityInStore($activity, $entry); - $entry = $this->loadActivityStoreEntry($request->get('id')); + $entry = $this->loadActivityStoreEntry($request->attributes->getInt('id')); } else { return $this->createErrorResponse( sprintf( @@ -204,7 +204,7 @@ public function updateRecord(Request $request) */ public function deleteRecord(Request $request) { - $entry = $this->loadActivityStoreEntry($request->get('id')); + $entry = $this->loadActivityStoreEntry($request->attributes->getInt('id')); try { $activity = $entry->getRelatedItem(); diff --git a/src/RESTApi/CustomersHandler.php b/src/RESTApi/CustomersHandler.php index 642b54b2..17c17f7b 100644 --- a/src/RESTApi/CustomersHandler.php +++ b/src/RESTApi/CustomersHandler.php @@ -101,7 +101,7 @@ public function listRecords(Request $request) */ public function readRecord(Request $request) { - $customer = $this->loadCustomer($request->get('id')); + $customer = $this->loadCustomer($request->attributes->getInt('id')); return $this->createCustomerResponse($customer, $request); } @@ -139,7 +139,7 @@ public function createRecord(Request $request) */ public function updateRecord(Request $request) { - $customer = $this->loadCustomer($request->get('id')); + $customer = $this->loadCustomer($request->attributes->getInt('id')); $data = $this->getRequestData($request); try { @@ -160,7 +160,7 @@ public function updateRecord(Request $request) */ public function deleteRecord(Request $request) { - $customer = $this->loadCustomer($request->get('id')); + $customer = $this->loadCustomer($request->attributes->getInt('id')); try { $this->customerProvider->delete($customer); diff --git a/src/RESTApi/DeletionsHandler.php b/src/RESTApi/DeletionsHandler.php index 0cba57ae..3ac31776 100644 --- a/src/RESTApi/DeletionsHandler.php +++ b/src/RESTApi/DeletionsHandler.php @@ -28,8 +28,8 @@ class DeletionsHandler extends AbstractHandler */ public function listRecords(Request $request) { - $entityType = $request->get('entityType'); - $deletionsSinceTimestamp = $request->get('deletionsSinceTimestamp'); + $entityType = $request->query->getString('entityType'); + $deletionsSinceTimestamp = $request->query->getInt('deletionsSinceTimestamp'); $timestamp = time(); diff --git a/src/RESTApi/SegmentGroupsHandler.php b/src/RESTApi/SegmentGroupsHandler.php index bd3fe50d..350a659a 100644 --- a/src/RESTApi/SegmentGroupsHandler.php +++ b/src/RESTApi/SegmentGroupsHandler.php @@ -72,7 +72,7 @@ public function listRecords(Request $request) */ public function readRecord(Request $request) { - $segmentGroup = $this->loadSegmentGroup($request->get('id')); + $segmentGroup = $this->loadSegmentGroup($request->attributes->getInt('id')); return $this->createSegmentGroupResponse($segmentGroup); } @@ -139,7 +139,7 @@ public function updateRecord(Request $request) { $data = $this->getRequestData($request); - if (empty($request->get('id'))) { + if (!$request->attributes->has('id')) { return new Response( [ 'success' => false, @@ -149,14 +149,16 @@ public function updateRecord(Request $request) ); } + $id = $request->attributes->getInt('id'); + if (!$segmentGroup = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentGroupById( - $request->get('id') + $id ) ) { return new Response( [ 'success' => false, - 'msg' => sprintf('segment with id %s not found', $request->get('id')), + 'msg' => sprintf('segment with id %s not found', $id), ], Response::RESPONSE_CODE_NOT_FOUND ); @@ -178,7 +180,7 @@ public function updateRecord(Request $request) */ public function deleteRecord(Request $request) { - $segmentGroup = $this->loadSegmentGroup($request->get('id')); + $segmentGroup = $this->loadSegmentGroup($request->attributes->getInt('id')); try { $segmentGroup->delete(); diff --git a/src/RESTApi/SegmentsHandler.php b/src/RESTApi/SegmentsHandler.php index b10bc942..b3562277 100644 --- a/src/RESTApi/SegmentsHandler.php +++ b/src/RESTApi/SegmentsHandler.php @@ -74,7 +74,7 @@ public function listRecords(Request $request) */ public function readRecord(Request $request) { - $segment = $this->loadSegment($request->get('id')); + $segment = $this->loadSegment($request->attributes->getInt('id')); return $this->createSegmentResponse($segment); } @@ -163,7 +163,7 @@ public function updateRecord(Request $request) { $data = $this->getRequestData($request); - if (empty($request->get('id'))) { + if (!$request->attributes->has('id')) { return new Response( [ 'success' => false, @@ -172,12 +172,15 @@ public function updateRecord(Request $request) Response::RESPONSE_CODE_BAD_REQUEST ); } + $id = $request->attributes->getInt('id'); - if (!$segment = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentByid($request->get('id'))) { + $segment = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegmentByid($id); + + if (!$segment) { return new Response( [ 'success' => false, - 'msg' => sprintf('segment with id %s not found', $request->get('id')), + 'msg' => sprintf('segment with id %s not found', $id), ], Response::RESPONSE_CODE_NOT_FOUND ); @@ -199,7 +202,7 @@ public function updateRecord(Request $request) */ public function deleteRecord(Request $request) { - $segment = $this->loadSegment($request->get('id')); + $segment = $this->loadSegment($request->attributes->getInt('id')); try { $segment->delete(); diff --git a/src/Security/Authenticator/WebserviceAuthenticator.php b/src/Security/Authenticator/WebserviceAuthenticator.php index 1889bf29..8549f3f5 100644 --- a/src/Security/Authenticator/WebserviceAuthenticator.php +++ b/src/Security/Authenticator/WebserviceAuthenticator.php @@ -56,7 +56,7 @@ public function supports(Request $request): ?bool */ public function authenticate(Request $request): Passport { - if ($apiKey = $request->headers->get('x_api-key') ?? $request->get('apikey')) { + if ($apiKey = $request->headers->get('x_api-key') ?? $request->query->getString('apikey')) { $credentials['apiKey'] = $apiKey; } elseif (null !== $pimcoreUser = Authentication::authenticateSession()) { // check for existing session user $credentials['user'] = $pimcoreUser; diff --git a/src/Twig/Extension/CmfUrlUtilsExtension.php b/src/Twig/Extension/CmfUrlUtilsExtension.php index a1fcf5d3..6ef9dead 100644 --- a/src/Twig/Extension/CmfUrlUtilsExtension.php +++ b/src/Twig/Extension/CmfUrlUtilsExtension.php @@ -89,14 +89,14 @@ public function getFilterFormAction(PaginationInterface $paginator): string $request = $this->requestStack->getMainRequest(); - return $this->router->generate($request->get('_route'), $formActionParams); + return $this->router->generate($request->attributes->getString('_route'), $formActionParams); } public function getCurrentOrder($param): string { $request = $this->requestStack->getCurrentRequest(); - if ($request->get('order')) { - return $request->get('order')[$param] ?? ''; + if ($request->query->has('order')) { + return $request->query->all('order')[$param] ?? ''; } return ''; @@ -107,7 +107,7 @@ public function getNextFormOrderParams($param): array $request = $this->requestStack->getCurrentRequest(); $params = $request->query->all(); - $currentOrder = ($request->get('order') ? $request->get('order')[$param] ?? null : null); + $currentOrder = $params['order'][$param] ?? null; $nextOrder = ''; if (empty($currentOrder)) { $nextOrder = 'ASC'; @@ -124,11 +124,7 @@ public function getNextFormOrderParams($param): array protected function getCurrentFormOrderParams(Request $request): array { $result = []; - $order = $request->get('order'); - - if (!is_array($order)) { - return $result; - } + $order = $request->query->all('order'); $validDirections = ['ASC', 'DESC']; foreach ($order as $field => $direction) { @@ -143,11 +139,7 @@ protected function getCurrentFormOrderParams(Request $request): array protected function getFormFilterParams(Request $request): array { $result = []; - $filters = $request->get('filter'); - - if (!is_array($filters)) { - return $result; - } + $filters = $request->query->all('filter'); foreach ($filters as $key => $value) { if (!empty($value)) { @@ -171,7 +163,7 @@ protected function getQueryParams($includeOrder = true, $includeFilters = true): if ($includeFilters) { $params['filter'] = $this->getFormFilterParams($request); - if ($fd = $request->get('filterDefinition')) { + if ($fd = $request->query->all('filterDefinition')) { $params['filterDefinition'] = ['id' => $fd['id']]; } }