Skip to content

Commit fa2ce25

Browse files
kingjia90mattamon
andauthored
[Bug]: Use parameters for joins in Customer Segment (#549) (#557)
* [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 * Update composer.json * Update composer.json * Update composer.json * Try different parameter type * Update CustomerSegment.php * fix * Apply php-cs-fixer changes * fix * 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]>
1 parent be8498f commit fa2ce25

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

.github/workflows/static-analysis.yml

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

6565
- name: "Upload baseline file"
6666
if: ${{ failure() }}
67-
uses: actions/upload-artifact@v2
67+
uses: actions/upload-artifact@v4
6868
with:
6969
name: phpstan-baseline.neon
7070
path: phpstan-baseline.neon

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"require": {
1616
"php": "~8.1.0 || ~8.2.0",
17-
"doctrine/dbal": "^3.4.2",
17+
"doctrine/dbal": "^3.6.0",
1818
"doctrine/migrations": "^3.0.2",
1919
"dragonmantank/cron-expression": "^3.0.2",
2020
"drewm/mailchimp-api": "^2.2",

src/CustomerList/Filter/CustomerSegment.php

Lines changed: 13 additions & 7 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

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

7475
foreach ($segments as $segment) {
7576
$this->addCustomerSegment($segment);
@@ -119,7 +120,7 @@ protected function addCustomerSegment(DataObject\CustomerSegment $segment)
119120
{
120121
if ($segment->getGroup() && null !== $this->segmentGroup) {
121122
if ($segment->getGroup()->getId() !== $this->segmentGroup->getId()) {
122-
throw new \InvalidArgumentException('Segment does not belong to the defined segment group');
123+
throw new InvalidArgumentException('Segment does not belong to the defined segment group');
123124
}
124125
}
125126

@@ -187,6 +188,7 @@ protected function applyAndQuery(CoreListing\Concrete $listing, QueryBuilder $qu
187188
*
188189
* @param string $joinName
189190
* @param int|array $conditionValue
191+
*
190192
*/
191193
protected function addJoin(
192194
CoreListing\Concrete $listing,
@@ -212,20 +214,24 @@ protected function addJoin(
212214
);
213215

214216
$condition = $baseCondition;
215-
216217
if ($this->type === self::OPERATOR_OR) {
217-
// must match any of the passed IDs
218+
$valueKeys = array_keys($conditionValue);
219+
$isNumericArray = $valueKeys == array_filter($valueKeys, 'is_numeric');
220+
if (!$isNumericArray) {
221+
$valueKeys = [0];
222+
}
223+
218224
$condition .= sprintf(
219225
' AND %1$s.dest_id IN (%2$s)',
220226
$joinName,
221-
implode(',', $conditionValue)
227+
implode(',', $valueKeys)
222228
);
223229
} else {
224230
// runs an extra join for every ID - all joins must match
225231
$condition .= sprintf(
226-
' AND %1$s.dest_id = %2$s',
232+
' AND %1$s.dest_id = %2$d',
227233
$joinName,
228-
$conditionValue
234+
is_numeric($conditionValue) ? $conditionValue : 0
229235
);
230236
}
231237

src/CustomerProvider/ObjectNamingScheme/DefaultObjectNamingScheme.php

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

155-
if (sizeof($matchedPlaceholder)) {
156-
foreach ($matchedPlaceholder[0] as $j => $placeholder) {
157-
$field = $matchedPlaceholder[1][$j];
158-
159-
$getter = 'get'.ucfirst($field);
160-
if (method_exists($customer, $getter)) {
161-
$value = (string)$customer->$getter();
162-
$namingScheme[$i] = str_replace($placeholder, $value, $namingScheme[$i]);
163-
}
155+
foreach ($matchedPlaceholder[0] as $j => $placeholder) {
156+
$field = $matchedPlaceholder[1][$j];
157+
158+
$getter = 'get'.ucfirst($field);
159+
if (method_exists($customer, $getter)) {
160+
$value = (string)$customer->$getter();
161+
$namingScheme[$i] = str_replace($placeholder, $value, $namingScheme[$i]);
164162
}
165163
}
166164
$namingScheme[$i] = trim($namingScheme[$i]) ?: '--';

0 commit comments

Comments
 (0)