Skip to content

Commit

Permalink
[Bug]: Fix Inheritable Segment query (#460)
Browse files Browse the repository at this point in the history
* refactor query

* Apply php-cs-fixer changes

* fix changes were based on another vers

* Update SegmentAssignmentController.php

* task: also return empty when $`id` is not set

---------

Co-authored-by: kingjia90 <kingjia90@users.noreply.github.com>
  • Loading branch information
kingjia90 and kingjia90 committed May 16, 2023
1 parent d1d58c1 commit 76df151
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Controller/Admin/SegmentAssignmentController.php
Expand Up @@ -50,12 +50,17 @@ public static function getSubscribedServices()
*/
public function inheritableSegments(Request $request, SegmentManagerInterface $segmentManager)
{
$id = $request->get('id') ?? '';
$type = $request->get('type') ?? '';
$id = $request->get('id');
$type = $request->get('type');
if (!$type || !$id) {
return $this->adminJson(['data' => []]);
}

$db = \Pimcore\Db::get();
$parentIdStatement = sprintf('SELECT `%s` FROM `%s` WHERE `%s` = :value', $type === 'object' ? 'o_parentId' : 'parentId', $type.'s', $type === 'object' ? 'o_id' : 'id');
$parentIdStatement = sprintf('SELECT :parentIdField FROM %s WHERE :idField = :value', $db->quoteIdentifier($type . 's'));
$parentId = $db->fetchOne($parentIdStatement, [
'parentIdField' => $type === 'object' ? 'o_parentId' : 'parentId',
'idField' => $type === 'object' ? 'o_id' : 'id',
'value' => $id
]);

Expand Down

0 comments on commit 76df151

Please sign in to comment.