From d4b5e464bc34b6d8cdbce32f69d53fd464c77fe4 Mon Sep 17 00:00:00 2001 From: Matthias Schuhmayer <38959016+mattamon@users.noreply.github.com> Date: Thu, 23 Jan 2025 12:54:26 +0100 Subject: [PATCH 01/16] [Bug]: Use parameters for joins in Customer Segment (#549) * Use parameters for joins * Use array_keys * Set param type * Use non deprecated version --- src/CustomerList/Filter/CustomerSegment.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 3bf9fcad..3718e09c 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -18,7 +18,12 @@ use CustomerManagementFrameworkBundle\Listing\Filter\AbstractFilter; use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface; use CustomerManagementFrameworkBundle\Service\MariaDb; +use Doctrine\DBAL\ArrayParameterType; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; +use Exception; +use InvalidArgumentException; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Listing as CoreListing; @@ -119,7 +124,7 @@ protected function addCustomerSegment(DataObject\CustomerSegment $segment) { if ($segment->getGroup() && null !== $this->segmentGroup) { if ($segment->getGroup()->getId() !== $this->segmentGroup->getId()) { - throw new \InvalidArgumentException('Segment does not belong to the defined segment group'); + throw new InvalidArgumentException('Segment does not belong to the defined segment group'); } } @@ -187,6 +192,7 @@ protected function applyAndQuery(CoreListing\Concrete $listing, QueryBuilder $qu * * @param string $joinName * @param int|array $conditionValue + * @throws Exception */ protected function addJoin( CoreListing\Concrete $listing, @@ -212,21 +218,25 @@ protected function addJoin( ); $condition = $baseCondition; - + $valuePlaceholder = $joinName . '_value'; + $parameterType = ParameterType::INTEGER; if ($this->type === self::OPERATOR_OR) { // must match any of the passed IDs $condition .= sprintf( ' AND %1$s.dest_id IN (%2$s)', $joinName, - implode(',', $conditionValue) + ':' . $valuePlaceholder ); + $value = array_keys($conditionValue); + $parameterType = ArrayParameterType::INTEGER; } else { // runs an extra join for every ID - all joins must match $condition .= sprintf( ' AND %1$s.dest_id = %2$s', $joinName, - $conditionValue + ':' . $valuePlaceholder ); + $value = $conditionValue; } $queryBuilder->join( @@ -235,5 +245,7 @@ protected function addJoin( $joinName, $condition ); + + $queryBuilder->setParameter($valuePlaceholder, $value, $parameterType); } } From a7d6b573390174f01ccbb06d7041b2e28023f68d Mon Sep 17 00:00:00 2001 From: kingjia90 <6014195+kingjia90@users.noreply.github.com> Date: Wed, 29 Jan 2025 10:46:14 +0000 Subject: [PATCH 02/16] Apply php-cs-fixer changes --- src/CustomerList/Filter/CustomerSegment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 3718e09c..1179cf35 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -19,7 +19,6 @@ use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface; use CustomerManagementFrameworkBundle\Service\MariaDb; use Doctrine\DBAL\ArrayParameterType; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Exception; @@ -192,6 +191,7 @@ protected function applyAndQuery(CoreListing\Concrete $listing, QueryBuilder $qu * * @param string $joinName * @param int|array $conditionValue + * * @throws Exception */ protected function addJoin( From 96b7173179e1dcbe8a4142d1bd6080b5154bc731 Mon Sep 17 00:00:00 2001 From: Ji Jia Jia Date: Wed, 29 Jan 2025 11:44:52 +0100 Subject: [PATCH 03/16] artifact bump --- .github/workflows/static-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index c0554d36..19011127 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -64,7 +64,7 @@ jobs: - name: "Upload baseline file" if: ${{ failure() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: phpstan-baseline.neon path: phpstan-baseline.neon From dcbfef18c98d40d3b2caa2eba7cf8ad4750e7535 Mon Sep 17 00:00:00 2001 From: Ji Jia Jia Date: Wed, 29 Jan 2025 11:54:19 +0100 Subject: [PATCH 04/16] fix stan --- .../DefaultObjectNamingScheme.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/CustomerProvider/ObjectNamingScheme/DefaultObjectNamingScheme.php b/src/CustomerProvider/ObjectNamingScheme/DefaultObjectNamingScheme.php index 0087451b..9084e179 100644 --- a/src/CustomerProvider/ObjectNamingScheme/DefaultObjectNamingScheme.php +++ b/src/CustomerProvider/ObjectNamingScheme/DefaultObjectNamingScheme.php @@ -152,15 +152,13 @@ private function extractNamingScheme(CustomerInterface $customer, $namingScheme) foreach ($namingScheme as $i => $namingSchemeItem) { preg_match_all('/{([a-zA-Z0-9]*)}/', $namingSchemeItem, $matchedPlaceholder); - if (sizeof($matchedPlaceholder)) { - foreach ($matchedPlaceholder[0] as $j => $placeholder) { - $field = $matchedPlaceholder[1][$j]; - - $getter = 'get'.ucfirst($field); - if (method_exists($customer, $getter)) { - $value = (string)$customer->$getter(); - $namingScheme[$i] = str_replace($placeholder, $value, $namingScheme[$i]); - } + foreach ($matchedPlaceholder[0] as $j => $placeholder) { + $field = $matchedPlaceholder[1][$j]; + + $getter = 'get'.ucfirst($field); + if (method_exists($customer, $getter)) { + $value = (string)$customer->$getter(); + $namingScheme[$i] = str_replace($placeholder, $value, $namingScheme[$i]); } } $namingScheme[$i] = trim($namingScheme[$i]) ?: '--'; From 86e36b8871a45970d12000ef57a5a63124dced37 Mon Sep 17 00:00:00 2001 From: Ji Jia Jia Date: Wed, 29 Jan 2025 11:57:17 +0100 Subject: [PATCH 05/16] fix --- src/CustomerList/Filter/CustomerSegment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 1179cf35..a885ab6a 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -19,6 +19,7 @@ use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface; use CustomerManagementFrameworkBundle\Service\MariaDb; use Doctrine\DBAL\ArrayParameterType; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Exception; @@ -228,7 +229,7 @@ protected function addJoin( ':' . $valuePlaceholder ); $value = array_keys($conditionValue); - $parameterType = ArrayParameterType::INTEGER; + $parameterType = Connection::PARAM_INT_ARRAY; } else { // runs an extra join for every ID - all joins must match $condition .= sprintf( From 7ed292423ae68d34227d3f8f6486a6153b0bea9a Mon Sep 17 00:00:00 2001 From: kingjia90 <6014195+kingjia90@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:17:20 +0000 Subject: [PATCH 06/16] Apply php-cs-fixer changes --- src/CustomerList/Filter/CustomerSegment.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index a885ab6a..c02facc0 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -18,7 +18,6 @@ use CustomerManagementFrameworkBundle\Listing\Filter\AbstractFilter; use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface; use CustomerManagementFrameworkBundle\Service\MariaDb; -use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; From 373d6275eeb4dea343f4856ce9664997b3d690ca Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Wed, 29 Jan 2025 12:24:58 +0100 Subject: [PATCH 07/16] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9bdd41c6..0f0b7f3b 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require": { "php": "~8.1.0 || ~8.2.0", - "doctrine/dbal": "^3.4.2", + "doctrine/dbal": "^3.4.4", "doctrine/migrations": "^3.0.2", "dragonmantank/cron-expression": "^3.0.2", "drewm/mailchimp-api": "^2.2", From 27cb5d3ca6a8ff5a77949a04c8d0a6decdc7c5c9 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Wed, 29 Jan 2025 12:26:33 +0100 Subject: [PATCH 08/16] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0f0b7f3b..5be4306b 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require": { "php": "~8.1.0 || ~8.2.0", - "doctrine/dbal": "^3.4.4", + "doctrine/dbal": "^3.4.6", "doctrine/migrations": "^3.0.2", "dragonmantank/cron-expression": "^3.0.2", "drewm/mailchimp-api": "^2.2", From 0fefcdc886585b9fb0f0209c68e925e06e93f629 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Wed, 29 Jan 2025 12:30:06 +0100 Subject: [PATCH 09/16] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5be4306b..cf6eaeb8 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require": { "php": "~8.1.0 || ~8.2.0", - "doctrine/dbal": "^3.4.6", + "doctrine/dbal": "^3.6.0", "doctrine/migrations": "^3.0.2", "dragonmantank/cron-expression": "^3.0.2", "drewm/mailchimp-api": "^2.2", From 85c548f91c81cfe3ef43c5fef39129b4eded4dc1 Mon Sep 17 00:00:00 2001 From: mattamon Date: Wed, 29 Jan 2025 15:16:34 +0100 Subject: [PATCH 10/16] Try different parameter type --- src/CustomerList/Filter/CustomerSegment.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index c02facc0..19b7f1dc 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -18,6 +18,7 @@ use CustomerManagementFrameworkBundle\Listing\Filter\AbstractFilter; use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface; use CustomerManagementFrameworkBundle\Service\MariaDb; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; @@ -228,7 +229,7 @@ protected function addJoin( ':' . $valuePlaceholder ); $value = array_keys($conditionValue); - $parameterType = Connection::PARAM_INT_ARRAY; + $parameterType = ArrayParameterType::INTEGER; } else { // runs an extra join for every ID - all joins must match $condition .= sprintf( From 538781586cd777337393ebda68846b25f5902a0d Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 10 Feb 2025 11:52:50 +0100 Subject: [PATCH 11/16] Update CustomerSegment.php --- src/CustomerList/Filter/CustomerSegment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 19b7f1dc..e209a8b8 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -74,7 +74,7 @@ public function __construct(array $segments, DataObject\CustomerSegmentGroup $se { $this->identifier = $this->buildIdentifier($segmentGroup); $this->segmentGroup = $segmentGroup; - $this->type = $type; + $this->type = $type === self::OPERATOR_AND ? self::OPERATOR_AND : self::OPERATOR_OR; foreach ($segments as $segment) { $this->addCustomerSegment($segment); From d492383681f658f3275dc39ec3319242dba3ae60 Mon Sep 17 00:00:00 2001 From: mattamon Date: Wed, 29 Jan 2025 15:25:29 +0100 Subject: [PATCH 12/16] fix --- src/CustomerList/Filter/CustomerSegment.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index e209a8b8..6c628988 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -219,25 +219,25 @@ protected function addJoin( ); $condition = $baseCondition; - $valuePlaceholder = $joinName . '_value'; - $parameterType = ParameterType::INTEGER; if ($this->type === self::OPERATOR_OR) { - // must match any of the passed IDs + $valueKeys = array_keys($conditionValue); + $isNumericArray = $valueKeys == array_filter($valueKeys, 'is_numeric'); + if (!$isNumericArray) { + throw new Exception('Invalid condition value'); + } + $condition .= sprintf( ' AND %1$s.dest_id IN (%2$s)', $joinName, - ':' . $valuePlaceholder + implode(',', $valueKeys) ); - $value = array_keys($conditionValue); - $parameterType = ArrayParameterType::INTEGER; } else { // runs an extra join for every ID - all joins must match $condition .= sprintf( - ' AND %1$s.dest_id = %2$s', + ' AND %1$s.dest_id = %2$d', $joinName, - ':' . $valuePlaceholder + is_numeric($conditionValue) ? $conditionValue : 0 ); - $value = $conditionValue; } $queryBuilder->join( @@ -246,7 +246,5 @@ protected function addJoin( $joinName, $condition ); - - $queryBuilder->setParameter($valuePlaceholder, $value, $parameterType); } } From d91d95114c24f45e5612cc74c9b2131b84f5f58f Mon Sep 17 00:00:00 2001 From: kingjia90 <6014195+kingjia90@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:57:35 +0000 Subject: [PATCH 13/16] Apply php-cs-fixer changes --- src/CustomerList/Filter/CustomerSegment.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 6c628988..ebbccb22 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -18,9 +18,6 @@ use CustomerManagementFrameworkBundle\Listing\Filter\AbstractFilter; use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface; use CustomerManagementFrameworkBundle\Service\MariaDb; -use Doctrine\DBAL\ArrayParameterType; -use Doctrine\DBAL\Connection; -use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Exception; use InvalidArgumentException; From b8c951717415dfc985b8c88f0c27fe350c352f60 Mon Sep 17 00:00:00 2001 From: Ji Jia Jia Date: Mon, 10 Feb 2025 14:59:27 +0100 Subject: [PATCH 14/16] fix --- src/CustomerList/Filter/CustomerSegment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 6c628988..9e5bbabf 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -223,7 +223,7 @@ protected function addJoin( $valueKeys = array_keys($conditionValue); $isNumericArray = $valueKeys == array_filter($valueKeys, 'is_numeric'); if (!$isNumericArray) { - throw new Exception('Invalid condition value'); + $valueKeys = [0]; } $condition .= sprintf( From 743139c1ec18a3f8e12c9ae4c981b0bc50e72e8f Mon Sep 17 00:00:00 2001 From: Ji Jia Jia Date: Mon, 10 Feb 2025 15:03:11 +0100 Subject: [PATCH 15/16] fix --- src/CustomerList/Filter/CustomerSegment.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 7b999de0..5a72fd67 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -190,7 +190,6 @@ protected function applyAndQuery(CoreListing\Concrete $listing, QueryBuilder $qu * @param string $joinName * @param int|array $conditionValue * - * @throws Exception */ protected function addJoin( CoreListing\Concrete $listing, From 1db756a02610ca3f44bc82cca59ff594e4f4f8d1 Mon Sep 17 00:00:00 2001 From: kingjia90 <6014195+kingjia90@users.noreply.github.com> Date: Mon, 10 Feb 2025 14:03:34 +0000 Subject: [PATCH 16/16] Apply php-cs-fixer changes --- src/CustomerList/Filter/CustomerSegment.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CustomerList/Filter/CustomerSegment.php b/src/CustomerList/Filter/CustomerSegment.php index 5a72fd67..a4642c88 100644 --- a/src/CustomerList/Filter/CustomerSegment.php +++ b/src/CustomerList/Filter/CustomerSegment.php @@ -19,7 +19,6 @@ use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface; use CustomerManagementFrameworkBundle\Service\MariaDb; use Doctrine\DBAL\Query\QueryBuilder; -use Exception; use InvalidArgumentException; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Listing as CoreListing;