Skip to content

Commit 3176373

Browse files
authored
Merge pull request #8 from fredden/db-prefix
Respect db_prefix
2 parents c34f851 + a14b578 commit 3176373

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

Console/Command/CleanUpAttributesAndValuesWithoutParentCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function execute(InputInterface $input, OutputInterface $output)
7373
->getFirstItem();
7474
$output->writeln("<info>Cleaning values for $code</info>");
7575
foreach ($types as $type) {
76-
$eavTable = $db->getTableName('eav_attribute');
77-
$entityValueTable = $db->getTableName($code . '_entity_' . $type);
76+
$eavTable = $this->resourceConnection->getTableName('eav_attribute');
77+
$entityValueTable = $this->resourceConnection->getTableName($code . '_entity_' . $type);
7878
$query = "SELECT * FROM $entityValueTable WHERE `attribute_id` NOT IN(SELECT attribute_id"
7979
. " FROM `$eavTable` WHERE entity_type_id = " . $entityType->getEntityTypeId() . ")";
8080
$results = $db->fetchAll($query);

Console/Command/RemoveUnusedAttributesCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ public function execute(InputInterface $input, OutputInterface $output)
6868
$attributes = $this->attributeRepository
6969
->getList(ProductAttributeInterface::ENTITY_TYPE_CODE, $searchCriteria)
7070
->getItems();
71-
$eavAttributeTable = $db->getTableName('eav_attribute');
72-
$eavEntityAttributeTable = $db->getTableName('eav_entity_attribute');
71+
$eavAttributeTable = $this->resourceConnection->getTableName('eav_attribute');
72+
$eavEntityAttributeTable = $this->resourceConnection->getTableName('eav_entity_attribute');
7373
foreach ($attributes as $attribute) {
74-
$table = $db->getTableName('catalog_product_entity_' . $attribute->getBackendType());
74+
$table = $this->resourceConnection->getTableName('catalog_product_entity_' . $attribute->getBackendType());
7575
/* Look for attributes that have no values set in products */
7676
$attributeValues = (int)$db->fetchOne('SELECT COUNT(*) FROM ' . $table . ' WHERE attribute_id = ?',
7777
[$attribute->getAttributeId()]);

Console/Command/RemoveUnusedMediaCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function execute(InputInterface $input, OutputInterface $output): void
6060

6161
$imageDir = $this->getImageDir();
6262
$connection = $this->resourceConnection->getConnection('core_read');
63-
$mediaGalleryTable = $connection->getTableName('catalog_product_entity_media_gallery');
63+
$mediaGalleryTable = $this->resourceConnection->getTableName('catalog_product_entity_media_gallery');
6464

6565
$directoryIterator = new RecursiveDirectoryIterator($imageDir);
6666

Console/Command/RestoreUseDefaultConfigValueCommand.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,20 @@ public function execute(InputInterface $input, OutputInterface $output)
4646
$removedConfigValues = 0;
4747

4848
$db = $this->resourceConnection->getConnection();
49-
$configData = $db->fetchAll('SELECT DISTINCT path, value FROM ' . $db->getTableName('core_config_data')
49+
$tableName = $this->resourceConnection->getTableName('core_config_data');
50+
$configData = $db->fetchAll('SELECT DISTINCT path, value FROM ' . $tableName
5051
. ' WHERE scope_id = 0');
5152
foreach ($configData as $config) {
52-
$count = $db->fetchOne('SELECT COUNT(*) FROM ' . $db->getTableName('core_config_data')
53+
$count = $db->fetchOne('SELECT COUNT(*) FROM ' . $tableName
5354
. ' WHERE path = ? AND BINARY value = ?', [$config['path'], $config['value']]);
5455
if ($count > 1) {
5556
$output->writeln('Config path ' . $config['path'] . ' with value ' . $config['value'] . ' has ' . $count
5657
. ' values; deleting non-default values');
5758
if (!$isDryRun) {
58-
$db->query('DELETE FROM ' . $db->getTableName('core_config_data')
59-
. ' WHERE path = ? AND BINARY value = ? AND scope_id != ?',
60-
[$config['path'], $config['value'], 0]);
59+
$db->query(
60+
'DELETE FROM ' . $tableName . ' WHERE path = ? AND BINARY value = ? AND scope_id != ?',
61+
[$config['path'], $config['value'], 0]
62+
);
6163
}
6264
$removedConfigValues += ($count - 1);
6365
}

Console/Command/RestoreUseDefaultValueCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function execute(InputInterface $input, OutputInterface $output)
7575

7676
foreach ($tables as $table) {
7777
// Select all non-global values
78-
$fullTableName = $db->getTableName('catalog_' . $entity . '_entity_' . $table);
78+
$fullTableName = $this->resourceConnection->getTableName('catalog_' . $entity . '_entity_' . $table);
7979
$rows = $db->fetchAll('SELECT * FROM ' . $fullTableName . ' WHERE store_id != 0');
8080

8181
foreach ($rows as $row) {

0 commit comments

Comments
 (0)