Skip to content

Commit

Permalink
Replace Request::get with explicit input sources (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 authored Nov 28, 2024
1 parent 4416393 commit 4ec3748
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 109 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"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",
"symfony/config": "^6.2",
"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",
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Controller/Admin/ActivitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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',
Expand All @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions src/Controller/Admin/Customers/FilterDefinitionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -218,21 +218,21 @@ 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);
}

/**
* Prepare allowed user ids from request. This parameter consists of allowedUserIds and allowedRoleIds
*/
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);

Expand Down
33 changes: 17 additions & 16 deletions src/Controller/Admin/CustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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'),
]
);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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'),
]);
}

Expand All @@ -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')
);
Expand All @@ -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'),
]);
}

Expand All @@ -230,7 +230,7 @@ public function exportStepAction(Request $request): JsonResponse
$data['processIds'] = $processIds;

$this->exporterManager->saveExportTmpData(
$request->get('jobId'),
$request->query->getString('jobId'),
$data
);

Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Admin/DuplicatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
);

Expand All @@ -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]);
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/Admin/RulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions src/Controller/Admin/SegmentAssignmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => []]);
}
Expand Down Expand Up @@ -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]);

Expand All @@ -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);

Expand All @@ -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]);
Expand Down
Loading

0 comments on commit 4ec3748

Please sign in to comment.