Skip to content

Commit b054047

Browse files
authored
[Task] Remove BC Layer for DataObject Service (getVersionDependentDatabaseColumnName) (#567)
* Replaced method with fixed columns * Apply php-cs-fixer changes
1 parent 2fad00f commit b054047

File tree

25 files changed

+48
-103
lines changed

25 files changed

+48
-103
lines changed

src/ActionTrigger/Condition/CountActivities.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use CustomerManagementFrameworkBundle\ActionTrigger\RuleEnvironmentInterface;
1919
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
2020
use Pimcore;
21-
use Pimcore\Model\DataObject\Service;
2221

2322
class CountActivities extends AbstractMatchCondition
2423
{
@@ -72,8 +71,7 @@ public function getDbCondition(ConditionDefinitionInterface $conditionDefinition
7271
if (!sizeof($ids)) {
7372
return '-1';
7473
}
75-
$idField = Service::getVersionDependentDatabaseColumnName('id');
7674

77-
return $idField . ' in ('.implode(',', $ids).')';
75+
return 'id in ('.implode(',', $ids).')';
7876
}
7977
}

src/ActionTrigger/Condition/Customer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use CustomerManagementFrameworkBundle\ActionTrigger\RuleEnvironmentInterface;
1919
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
2020
use Pimcore\Model\DataObject\AbstractObject;
21-
use Pimcore\Model\DataObject\Service;
2221

2322
class Customer extends AbstractCondition
2423
{
@@ -60,8 +59,7 @@ public function getDbCondition(ConditionDefinitionInterface $conditionDefinition
6059

6160
$customerId = intval($options[self::OPTION_CUSTOMER_ID]);
6261

63-
$idField = Service::getVersionDependentDatabaseColumnName('id');
64-
$condition = sprintf($idField . ' = %s', $customerId);
62+
$condition = sprintf('id = %s', $customerId);
6563

6664
$not = $options[self::OPTION_NOT];
6765

src/ActionTrigger/EventHandler/DefaultEventHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
3030
use Knp\Component\Pager\PaginatorInterface;
3131
use Pimcore;
32-
use Pimcore\Model\DataObject\Service;
3332

3433
class DefaultEventHandler implements EventHandlerInterface
3534
{
@@ -105,8 +104,7 @@ public function handleCustomerListEvent(CustomerListEventInterface $event, RuleE
105104

106105
$listing = Pimcore::getContainer()->get('cmf.customer_provider')->getList();
107106
$listing->setCondition($where);
108-
$idField = Service::getVersionDependentDatabaseColumnName('id');
109-
$listing->setOrderKey($idField);
107+
$listing->setOrderKey('id');
110108
$listing->setOrder('asc');
111109

112110
$paginator = $this->paginator->paginate($listing, 1, 100);

src/Controller/Admin/CustomersController.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function listAction(Request $request): Response
9999
'paginator' => $paginator,
100100
'paginationVariables' => $paginator instanceof SlidingPaginationInterface ? $paginator->getPaginationData() : [],
101101
'customerView' => $customerView,
102-
'idField' => Service::getVersionDependentDatabaseColumnName('id'),
102+
'idField' => 'id',
103103
]);
104104
} else {
105105
return $this->render(
@@ -117,7 +117,7 @@ public function listAction(Request $request): Response
117117
'filterDefinition' => $this->getFilterDefinition($request),
118118
'accessToTempCustomerFolder' => boolval($this->hasUserAccessToTempCustomerFolder()),
119119
'hideAdvancedFilterSettings' => $request->query->getBoolean('segmentId'),
120-
'idField' => Service::getVersionDependentDatabaseColumnName('id'),
120+
'idField' => 'id',
121121
]
122122
);
123123
}
@@ -163,11 +163,10 @@ public function exportAction(Request $request): JsonResponse
163163
$filters = $this->fetchListFilters($request);
164164
$listing = $this->buildListing($filters);
165165

166-
$idField = Service::getVersionDependentDatabaseColumnName('id');
167166
$fromTable = $listing->getQueryBuilder()->getQueryPart('from')[0]['table'];
168167
$query = $listing->getQueryBuilder()
169168
->resetQueryPart('select')
170-
->select($fromTable . '.' . $idField);
169+
->select($fromTable . '.id');
171170
$ids = Db::get()->fetchFirstColumn((string)$query);
172171

173172
$jobId = uniqid();
@@ -217,11 +216,10 @@ public function exportStepAction(Request $request): JsonResponse
217216
$ids = array_slice($data['processIds'], 0, $perRequest);
218217
$processIds = array_slice($data['processIds'], $perRequest);
219218

220-
$idField = Service::getVersionDependentDatabaseColumnName('id');
221219
$listing = $this->buildListing();
222220

223221
$fromTable = $listing->getQueryBuilder()->getQueryPart('from')[0]['table'];
224-
$listing->addConditionParam($fromTable . '.' . $idField . ' in ('.implode(', ', $ids).')');
222+
$listing->addConditionParam($fromTable . '.id in ('.implode(', ', $ids).')');
225223

226224
$exporter = $this->getExporter($listing, $data['exporter']);
227225
$exportData = $exporter->getExportData();
@@ -394,7 +392,7 @@ public function loadSegmentGroups(): array
394392
protected function buildListing(array $filters = [], array $orders = []): Listing\Concrete
395393
{
396394
$listing = $this->getSearchHelper()->getCustomerProvider()->getList();
397-
$idField = Service::getVersionDependentDatabaseColumnName('id');
395+
$idField = 'id';
398396

399397
if (array_key_exists('operator-segments', $filters)) {
400398
if ($filters['operator-segments'] == 'ANY') {

src/Controller/Admin/DuplicatesController.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use CustomerManagementFrameworkBundle\DuplicatesIndex\DuplicatesIndexInterface;
2121
use Knp\Bundle\PaginatorBundle\Pagination\SlidingPaginationInterface;
2222
use Pimcore\Model\DataObject\AbstractObject;
23-
use Pimcore\Model\DataObject\Service;
2423
use Symfony\Component\HttpFoundation\JsonResponse;
2524
use Symfony\Component\HttpFoundation\Request;
2625
use Symfony\Component\HttpFoundation\Response;
@@ -57,9 +56,8 @@ public function listAction(Request $request, DuplicatesIndexInterface $duplicate
5756
if (!empty($filters)) {
5857
// build customer listing
5958
$customerList = $this->getSearchHelper()->getCustomerProvider()->getList();
60-
$idField = Service::getVersionDependentDatabaseColumnName('id');
6159
$customerList
62-
->setOrderKey($idField)
60+
->setOrderKey('id')
6361
->setOrder('ASC');
6462

6563
/** @noinspection PhpUnhandledExceptionInspection */

src/Controller/Admin/SegmentAssignmentController.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Pimcore\Controller\Traits\JsonHelperTrait;
2222
use Pimcore\Controller\UserAwareController;
2323
use Pimcore\Model\DataObject\CustomerSegment;
24-
use Pimcore\Model\DataObject\Service;
2524
use Symfony\Component\HttpFoundation\JsonResponse;
2625
use Symfony\Component\HttpFoundation\Request;
2726
use Symfony\Component\Routing\Annotation\Route;
@@ -55,13 +54,11 @@ public function inheritableSegments(Request $request, SegmentManagerInterface $s
5554
}
5655

5756
$db = \Pimcore\Db::get();
58-
$idField = Service::getVersionDependentDatabaseColumnName('id');
59-
$parentIdField = Service::getVersionDependentDatabaseColumnName('parentId');
6057

6158
$parentIdStatement = sprintf('SELECT :parentIdField FROM %s WHERE :idField = :value', $db->quoteIdentifier($type . 's'));
6259
$parentId = $db->fetchOne($parentIdStatement, [
63-
'parentIdField' => $parentIdField,
64-
'idField' => $idField,
60+
'parentIdField' => 'parentId',
61+
'idField' => 'id',
6562
'value' => $id,
6663
]);
6764

src/CustomerDuplicatesService/DefaultCustomerDuplicatesService.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use CustomerManagementFrameworkBundle\Model\CustomerInterface;
2020
use Pimcore\Model\DataObject\ClassDefinition;
2121
use Pimcore\Model\DataObject\Listing\Concrete;
22-
use Pimcore\Model\DataObject\Service;
2322
use Pimcore\Model\Element\ElementInterface;
2423

2524
class DefaultCustomerDuplicatesService implements CustomerDuplicatesServiceInterface
@@ -92,9 +91,8 @@ public function getDuplicatesByData(array $data, $limit = 0)
9291
$list = $customerProvider->getList();
9392
$customerProvider->addActiveCondition($list);
9493

95-
$publishedKey = Service::getVersionDependentDatabaseColumnName('published');
9694
$list
97-
->addConditionParam($publishedKey . ' = ?', 1);
95+
->addConditionParam('published = ?', 1);
9896

9997
foreach ($data as $field => $value) {
10098
if (is_null($value) || $value === '') {
@@ -139,8 +137,7 @@ public function getDuplicatesOfCustomerByFields(CustomerInterface $customer, arr
139137
$duplicates = $this->getDuplicatesByData($data, $limit);
140138

141139
if ($customer->getId()) {
142-
$idField = Service::getVersionDependentDatabaseColumnName('id');
143-
$duplicates->addConditionParam($idField . ' != ?', $customer->getId());
140+
$duplicates->addConditionParam('id != ?', $customer->getId());
144141
}
145142

146143
if (!is_null($duplicates) && $duplicates->getCount()) {

src/CustomerList/Exporter/AbstractExporter.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,8 @@ protected function getHeaderTitles(array $exportData)
191191
if ($this->getExportSegmentsAsColumns() && sizeof($exportData[self::SEGMENT_IDS])) {
192192
$list = \Pimcore::getContainer()->get('cmf.segment_manager')->getSegments();
193193
array_walk($exportData[self::SEGMENT_IDS], 'intval');
194-
$idField = Service::getVersionDependentDatabaseColumnName('id');
195-
$pathField = Service::getVersionDependentDatabaseColumnName('path');
196-
$keyField = Service::getVersionDependentDatabaseColumnName('key');
197-
$list->addConditionParam($idField . ' in(' . implode(', ', $exportData[self::SEGMENT_IDS]) .')');
198-
$list->setOrderKey('concat(' . $list->quoteIdentifier($pathField) .', '. $list->quoteIdentifier($keyField) . ')', false);
194+
$list->addConditionParam('id in(' . implode(', ', $exportData[self::SEGMENT_IDS]) .')');
195+
$list->setOrderKey('concat(' . $list->quoteIdentifier('path') .', '. $list->quoteIdentifier('key') . ')', false);
199196

200197
$i = sizeof($titles);
201198
foreach ($list as $item) {

src/CustomerList/Filter/CustomerSegment.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,8 @@ protected function addJoin(
210210
$relationNames = implode(',', MariaDb::quoteArray($this->relationNames));
211211

212212
// relation matches one of our field names and relates to our current object
213-
$idField = DataObject\Service::getVersionDependentDatabaseColumnName('id');
214213
$baseCondition = sprintf(
215-
'`%1$s`.fieldname IN (%2$s) AND `%1$s`.src_id = ' . "`$tableName`." . $idField,
214+
'`%1$s`.fieldname IN (%2$s) AND `%1$s`.src_id = ' . "`$tableName`.id",
216215
$joinName,
217216
$relationNames
218217
);

src/CustomerProvider/ObjectNamingScheme/DefaultObjectNamingScheme.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,13 @@ public function cleanupEmptyFolders()
101101

102102
$archiveDir = $this->archiveDir ?: $this->parentPath;
103103

104-
$idField = Service::getVersionDependentDatabaseColumnName('id');
105-
$pathField = Service::getVersionDependentDatabaseColumnName('path');
106-
$keyField = Service::getVersionDependentDatabaseColumnName('key');
107-
$typeField = Service::getVersionDependentDatabaseColumnName('type');
108-
$parentIdField = Service::getVersionDependentDatabaseColumnName('parentId');
109-
$creationDateField = Service::getVersionDependentDatabaseColumnName('creationDate');
104+
$idField = 'id';
105+
$pathField = 'path';
110106

111107
$folders->setCondition(
112108
$idField . ' in (
113109
select '. $idField .' from (
114-
select `'. $idField .'`, `'. $pathField .'`, `'. $keyField .'`, `'. $typeField .'`, (select count(*) from objects where `' . $parentIdField . '` = `o`. `'. $idField ."`) as counter from objects o) as temp where counter=0 and type = 'folder' and (". $pathField .' like ? or '. $pathField .' like ?) and '. $creationDateField .' < ?)',
110+
select `'. $idField .'`, `' . $pathField .'`, `key`, `type`, (select count(*) from objects where `parentId` = `o`. `'. $idField ."`) as counter from objects o) as temp where counter=0 and type = 'folder' and (". $pathField .' like ? or '. $pathField .' like ?) and creationDate < ?)',
115111
[
116112
str_replace('//', '/', $this->parentPath.'/%'),
117113
str_replace('//', '/', $archiveDir .'/%'),

src/DependencyInjection/Configuration.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace CustomerManagementFrameworkBundle\DependencyInjection;
1919

2020
use Pimcore\Model\DataObject\AbstractObject;
21-
use Pimcore\Model\DataObject\Service;
2221
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
2322
use Symfony\Component\Config\Definition\ConfigurationInterface;
2423

@@ -269,7 +268,7 @@ private function buildCustomerListNode()
269268
];
270269

271270
$defaultFilterPropertiesEquals = [
272-
'id' => Service::getVersionDependentDatabaseColumnName('id'),
271+
'id' => 'id',
273272
'active' => 'active',
274273
];
275274

@@ -284,7 +283,7 @@ private function buildCustomerListNode()
284283
'lastname',
285284
],
286285
'search' => [
287-
Service::getVersionDependentDatabaseColumnName('id'),
286+
'id',
288287
'idEncoded',
289288
'firstname',
290289
'lastname',

src/DuplicatesIndex/DefaultMariaDbDuplicatesIndex.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Pimcore\Db;
2727
use Pimcore\Logger;
2828
use Pimcore\Model\DataObject\Listing\Concrete;
29-
use Pimcore\Model\DataObject\Service;
3029
use Symfony\Component\Console\Helper\ProgressBar;
3130
use Symfony\Component\Console\Output\OutputInterface;
3231

@@ -103,7 +102,7 @@ public function recreateIndex()
103102
$customerList = $customerProvider->getList();
104103

105104
$customerProvider->addActiveCondition($customerList);
106-
$customerList->setOrderKey(Service::getVersionDependentDatabaseColumnName('id'));
105+
$customerList->setOrderKey('id');
107106

108107
$paginator = $this->paginator->paginate($customerList);
109108
$paginator->setItemNumberPerPage(200);

src/Helper/Objects.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Pimcore\File;
1919
use Pimcore\Model\DataObject\Concrete;
2020
use Pimcore\Model\DataObject\Data\ObjectMetadata;
21-
use Pimcore\Model\DataObject\Service as DataObjectService;
2221
use Pimcore\Model\Element\ElementInterface;
2322
use Pimcore\Model\Element\Service;
2423

@@ -43,15 +42,13 @@ public static function checkObjectKey(Concrete $object)
4342
private static function checkObjectKeyHelper(Concrete $object, $origKey = null, $keyCounter = 1)
4443
{
4544
$origKey = is_null($origKey) ? self::getValidKey($object->getKey()) : $origKey;
46-
$pathField = DataObjectService::getVersionDependentDatabaseColumnName('path');
47-
$keyField = DataObjectService::getVersionDependentDatabaseColumnName('key');
48-
$idField = DataObjectService::getVersionDependentDatabaseColumnName('id');
45+
$idField = 'id';
4946
$notUnique = true;
5047
while ($notUnique) {
5148
$list = new \Pimcore\Model\DataObject\Listing;
5249
$list->setUnpublished(true);
5350
$list->addConditionParam(
54-
$pathField . ' = ? and `' . $keyField . '` = ?',
51+
'`path` = ? and `key` = ?',
5552
[(string)$object->getParent() . '/', $object->getKey()]
5653
);
5754
$objectId = $object->getId();

src/Listing/Filter/Permission.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Doctrine\DBAL\Query\QueryBuilder;
1919
use Pimcore\Db;
2020
use Pimcore\Model\DataObject\Listing as CoreListing;
21-
use Pimcore\Model\DataObject\Service;
2221
use Pimcore\Model\User;
2322
use Pimcore\Model\User\Workspace\DataObject;
2423

@@ -82,8 +81,8 @@ protected function addPermissionFilters(QueryBuilder $queryBuilder)
8281
// initialize deny conditions array
8382
$denyConditions = [];
8483
$db = Db::get();
85-
$pathField = $db->quoteIdentifier(Service::getVersionDependentDatabaseColumnName('path'));
86-
$keyField = $db->quoteIdentifier(Service::getVersionDependentDatabaseColumnName('key'));
84+
$pathField = $db->quoteIdentifier('path');
85+
$keyField = $db->quoteIdentifier('key');
8786
foreach ($workspaces as $workspace) {
8887
// if user is allowed to list content -> add to allow conditions
8988
if ($workspace->getList()) {

src/Model/AbstractObjectActivity.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Exception;
2222
use Pimcore;
2323
use Pimcore\Model\DataObject\Concrete;
24-
use Pimcore\Model\DataObject\Service;
2524

2625
abstract class AbstractObjectActivity extends Concrete implements PersistentActivityInterface
2726
{
@@ -53,12 +52,9 @@ public function cmfToArray()
5352
$result = ObjectToArray::getInstance()->toArray($this);
5453
unset($result['customer']);
5554

56-
$idField = Service::getVersionDependentDatabaseColumnName('id');
57-
$pathField = Service::getVersionDependentDatabaseColumnName('path');
58-
$keyField = Service::getVersionDependentDatabaseColumnName('key');
59-
$result[$idField] = $this->getId();
60-
$result[$pathField] = $this->getKey();
61-
$result[$keyField] = $this->getRealFullPath();
55+
$result['id'] = $this->getId();
56+
$result['key'] = $this->getKey();
57+
$result['path'] = $this->getRealFullPath();
6258

6359
return $result;
6460
}
@@ -76,7 +72,7 @@ public function cmfUpdateData(array $data)
7672
public static function cmfCreate(array $data, $fromWebservice = false)
7773
{
7874
$object = null;
79-
$idField = Service::getVersionDependentDatabaseColumnName('id');
75+
$idField = 'id';
8076
if (!empty($data[$idField])) {
8177
$object = self::getById($data[$idField]);
8278
}

src/Newsletter/ProviderHandler/Mailchimp.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use CustomerManagementFrameworkBundle\Traits\LoggerAware;
3838
use Pimcore\File;
3939
use Pimcore\Model\DataObject\CustomerSegment;
40-
use Pimcore\Model\DataObject\Service;
4140
use Psr\Log\LoggerInterface;
4241

4342
class Mailchimp implements NewsletterProviderHandlerInterface
@@ -490,10 +489,9 @@ protected function getExportableSegmentGroups()
490489
protected function getAllExportableSegments()
491490
{
492491
$groups = $this->getExportableSegmentGroups();
493-
$idField = Service::getVersionDependentDatabaseColumnName('id');
494492
$select = $groups->getQueryBuilder()
495493
->resetQueryPart('select')
496-
->select($idField);
494+
->select('id');
497495

498496
$segments = $this->segmentManager->getSegments();
499497
$segments->addConditionParam('group__id in (' . $select . ')');
@@ -858,9 +856,9 @@ public function doesOtherSubscribedCustomerWithEmailExist($email, $customerId =
858856

859857
$list = $customerProvider->getList();
860858
$customerProvider->addActiveCondition($list);
861-
$idField = Service::getVersionDependentDatabaseColumnName('id');
859+
862860
if ($customerId) {
863-
$list->setCondition('trim(lower(email)) = ? and ' . $idField .' != ?', [trim(strtolower($email)), $customerId]);
861+
$list->setCondition('trim(lower(email)) = ? and id != ?', [trim(strtolower($email)), $customerId]);
864862
} else {
865863
$list->setCondition('trim(lower(email)) = ?', [trim(strtolower($email))]);
866864
}

0 commit comments

Comments
 (0)