Skip to content

Commit 37b4c2f

Browse files
kingjia90mattamon
andauthored
[Bug]: Use parameters for joins in Customer Segment (#556)
* [Bug]: Use parameters for joins in Customer Segment (#549) * Use parameters for joins * Use array_keys * Set param type * Use non deprecated version * Apply php-cs-fixer changes * artifact bump * fix stan * fix * Apply php-cs-fixer changes * Try different parameter type * Apply php-cs-fixer changes * Revert different array type * try with different approach * fix * Update CustomerSegment.php * fix * Apply php-cs-fixer changes --------- Co-authored-by: Matthias Schuhmayer <[email protected]> Co-authored-by: kingjia90 <[email protected]> Co-authored-by: mattamon <[email protected]> Co-authored-by: mattamon <[email protected]>
1 parent f21abe0 commit 37b4c2f

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
- name: "Upload baseline file"
5151
if: ${{ failure() }}
52-
uses: actions/upload-artifact@v2
52+
uses: actions/upload-artifact@v4
5353
with:
5454
name: phpstan-baseline.neon
5555
path: phpstan-baseline.neon

src/CustomerList/Filter/CustomerSegment.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface;
2020
use CustomerManagementFrameworkBundle\Service\MariaDb;
2121
use Doctrine\DBAL\Query\QueryBuilder;
22+
use InvalidArgumentException;
2223
use Pimcore\Model\DataObject;
2324
use Pimcore\Model\DataObject\Listing as CoreListing;
2425

@@ -70,7 +71,7 @@ public function __construct(array $segments, DataObject\CustomerSegmentGroup $se
7071
{
7172
$this->identifier = $this->buildIdentifier($segmentGroup);
7273
$this->segmentGroup = $segmentGroup;
73-
$this->type = $type;
74+
$this->type = $type === self::OPERATOR_AND ? self::OPERATOR_AND : self::OPERATOR_OR;
7475

7576
foreach ($segments as $segment) {
7677
$this->addCustomerSegment($segment);
@@ -123,7 +124,7 @@ protected function addCustomerSegment(DataObject\CustomerSegment $segment)
123124
{
124125
if ($segment->getGroup() && null !== $this->segmentGroup) {
125126
if ($segment->getGroup()->getId() !== $this->segmentGroup->getId()) {
126-
throw new \InvalidArgumentException('Segment does not belong to the defined segment group');
127+
throw new InvalidArgumentException('Segment does not belong to the defined segment group');
127128
}
128129
}
129130

@@ -221,20 +222,26 @@ protected function addJoin(
221222
);
222223

223224
$condition = $baseCondition;
224-
225225
if ($this->type === self::OPERATOR_OR) {
226226
// must match any of the passed IDs
227+
228+
$valueKeys = array_keys($conditionValue);
229+
$isNumericArray = $valueKeys == array_filter($valueKeys, 'is_numeric');
230+
if (!$isNumericArray) {
231+
$valueKeys = [0];
232+
}
233+
227234
$condition .= sprintf(
228235
' AND %1$s.dest_id IN (%2$s)',
229236
$joinName,
230-
implode(',', $conditionValue)
237+
implode(',', $valueKeys)
231238
);
232239
} else {
233240
// runs an extra join for every ID - all joins must match
234241
$condition .= sprintf(
235-
' AND %1$s.dest_id = %2$s',
242+
' AND %1$s.dest_id = %2$d',
236243
$joinName,
237-
$conditionValue
244+
is_numeric($conditionValue) ? $conditionValue : 0
238245
);
239246
}
240247

src/CustomerProvider/ObjectNamingScheme/DefaultObjectNamingScheme.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,13 @@ private function extractNamingScheme(CustomerInterface $customer, $namingScheme)
146146
foreach ($namingScheme as $i => $namingSchemeItem) {
147147
preg_match_all('/{([a-zA-Z0-9]*)}/', $namingSchemeItem, $matchedPlaceholder);
148148

149-
if (sizeof($matchedPlaceholder)) {
150-
foreach ($matchedPlaceholder[0] as $j => $placeholder) {
151-
$field = $matchedPlaceholder[1][$j];
152-
153-
$getter = 'get'.ucfirst($field);
154-
if (method_exists($customer, $getter)) {
155-
$value = (string)$customer->$getter();
156-
$namingScheme[$i] = str_replace($placeholder, $value, $namingScheme[$i]);
157-
}
149+
foreach ($matchedPlaceholder[0] as $j => $placeholder) {
150+
$field = $matchedPlaceholder[1][$j];
151+
152+
$getter = 'get'.ucfirst($field);
153+
if (method_exists($customer, $getter)) {
154+
$value = (string)$customer->$getter();
155+
$namingScheme[$i] = str_replace($placeholder, $value, $namingScheme[$i]);
158156
}
159157
}
160158
$namingScheme[$i] = trim($namingScheme[$i]) ?: '--';

0 commit comments

Comments
 (0)