Skip to content

Commit a3df993

Browse files
authored
Remove instances of hard-coded table names (#720)
1 parent 01227c8 commit a3df993

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

app/code/Meta/BusinessExtension/Model/ResourceModel/FacebookInstalledFeature.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ public function _construct()
3939
/**
4040
* Check if feature exists
4141
*
42-
* @param string $featureType
43-
* @param int $storeId
42+
* @param string $featureType
43+
* @param int $storeId
4444
* @return bool
4545
*/
4646
public function doesFeatureTypeExist($featureType, $storeId)
4747
{
4848
$connection = $this->getConnection();
49+
50+
$facebookInstalledFeaturesTable = $connection->getTableName(self::TABLE_NAME);
4951
$select = $connection->select()
50-
->from(self::TABLE_NAME)
52+
->from($facebookInstalledFeaturesTable)
5153
->where('feature_type = ?', $featureType)
5254
->where('store_id = ?', $storeId);
5355
return $connection->fetchRow($select) !== false;
@@ -56,20 +58,22 @@ public function doesFeatureTypeExist($featureType, $storeId)
5658
/**
5759
* Delete all features matching storeId
5860
*
59-
* @param int $storeId
61+
* @param int $storeId
6062
* @return int
6163
*/
6264
public function deleteAll($storeId)
6365
{
6466
$connection = $this->getConnection();
65-
return $connection->delete(self::TABLE_NAME, ['store_id = ?' => $storeId]);
67+
68+
$facebookInstalledFeaturesTable = $connection->getTableName(self::TABLE_NAME);
69+
return $connection->delete($facebookInstalledFeaturesTable, ['store_id = ?' => $storeId]);
6670
}
67-
71+
6872
/**
6973
* Save response data from 'installed_features' to table
7074
*
71-
* @param array $features
72-
* @param int $storeId
75+
* @param array $features
76+
* @param int $storeId
7377
* @return void
7478
*/
7579
public function saveResponseData($features, $storeId)
@@ -84,16 +88,18 @@ function ($value) use ($storeId) {
8488
},
8589
array_values($features)
8690
);
87-
91+
8892
$connection = $this->getConnection();
89-
$connection->insertOnDuplicate(self::TABLE_NAME, $finalFeatures);
93+
94+
$facebookInstalledFeaturesTable = $connection->getTableName(self::TABLE_NAME);
95+
$connection->insertOnDuplicate($facebookInstalledFeaturesTable, $finalFeatures);
9096
}
9197

9298
/**
9399
* Format array data for insertion in DB
94100
*
95-
* @param array|string $feature
96-
* @param string $key
101+
* @param array|string $feature
102+
* @param string $key
97103
* @return string|null
98104
*/
99105
private function formatArrayData($feature, $key)

app/code/Meta/BusinessExtension/Model/ResourceModel/MetaIssueNotification.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ public function _construct()
4141
/**
4242
* Delete all notifications matching notification id
4343
*
44-
* @param string $notificationId
44+
* @param string $notificationId
4545
* @return int
4646
*/
4747
public function deleteByNotificationId(string $notificationId): int
4848
{
4949
$connection = $this->getConnection();
50-
return $connection->delete(self::TABLE_NAME, ['notification_id = ?' => $notificationId]);
50+
51+
$metaIssueNotificationTable = $connection->getTableName(self::TABLE_NAME);
52+
return $connection->delete($metaIssueNotificationTable, ['notification_id = ?' => $notificationId]);
5153
}
5254

5355
/**
@@ -63,7 +65,9 @@ public function saveVersionNotification(MetaIssueNotificationInterface $notifica
6365
'message' => $notification->getMessage(),
6466
'severity' => $notification->getSeverity(),
6567
];
66-
$connection->insertOnDuplicate(self::TABLE_NAME, $version_notification);
68+
69+
$metaIssueNotificationTable = $connection->getTableName(self::TABLE_NAME);
70+
$connection->insertOnDuplicate($metaIssueNotificationTable, $version_notification);
6771
}
6872

6973
/**
@@ -72,8 +76,10 @@ public function saveVersionNotification(MetaIssueNotificationInterface $notifica
7276
public function loadVersionNotification()
7377
{
7478
$connection = $this->getConnection();
79+
80+
$metaIssueNotificationTable = $connection->getTableName(self::TABLE_NAME);
7581
$select = $connection->select()
76-
->from(self::TABLE_NAME)
82+
->from($metaIssueNotificationTable)
7783
->where('notification_id = ?', MetaIssueNotification::VERSION_NOTIFICATION_ID);
7884
return $connection->fetchRow($select);
7985
}

app/code/Meta/Catalog/Model/ResourceModel/FacebookCatalogUpdate.php

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ class FacebookCatalogUpdate extends AbstractDb
6565
* @param string $connectionName
6666
*/
6767
public function __construct(
68-
Context $context,
68+
Context $context,
6969
CollectionFactory $collectionFactory,
70-
Random $random,
71-
OptionProvider $optionProvider,
72-
DateTime $dateTime,
70+
Random $random,
71+
OptionProvider $optionProvider,
72+
DateTime $dateTime,
7373
$connectionName = null
7474
) {
7575
parent::__construct($context, $connectionName);
@@ -106,7 +106,10 @@ public function addProductIds(array $ids, string $method): int
106106
}
107107
}
108108
if (!empty($dataToInsert)) {
109-
return $this->getConnection()->insertMultiple(self::TABLE_NAME, $dataToInsert);
109+
$connection = $this->getConnection();
110+
111+
$facebookCatalogUpdateTable = $connection->getTableName(self::TABLE_NAME);
112+
return $connection->insertMultiple($facebookCatalogUpdateTable, $dataToInsert);
110113
}
111114
return 0;
112115
}
@@ -146,7 +149,9 @@ public function reserveProductsForBatchId(string $method, string $batchId): int
146149

147150
$connection = $this->getConnection();
148151
$updateWhere = $connection->quoteInto('row_id IN (?)', $data);
149-
return $connection->update(self::TABLE_NAME, ['batch_id' => $batchId], $updateWhere);
152+
153+
$facebookCatalogUpdateTable = $connection->getTableName(self::TABLE_NAME);
154+
return $connection->update($facebookCatalogUpdateTable, ['batch_id' => $batchId], $updateWhere);
150155
}
151156

152157
/**
@@ -158,7 +163,9 @@ public function reserveProductsForBatchId(string $method, string $batchId): int
158163
public function deleteBatch(string $batchId): int
159164
{
160165
$connection = $this->getConnection();
161-
return $connection->delete(self::TABLE_NAME, ['batch_id = ?' => $batchId]);
166+
167+
$facebookCatalogUpdateTable = $connection->getTableName(self::TABLE_NAME);
168+
return $connection->delete($facebookCatalogUpdateTable, ['batch_id = ?' => $batchId]);
162169
}
163170

164171
/**
@@ -170,7 +177,9 @@ public function deleteBatch(string $batchId): int
170177
public function clearBatchId(string $batchId): int
171178
{
172179
$connection = $this->getConnection();
173-
return $connection->update(self::TABLE_NAME, ['batch_id' => null], ['batch_id = ?' => $batchId]);
180+
181+
$facebookCatalogUpdateTable = $connection->getTableName(self::TABLE_NAME);
182+
return $connection->update($facebookCatalogUpdateTable, ['batch_id' => null], ['batch_id = ?' => $batchId]);
174183
}
175184

176185
/**
@@ -206,11 +215,16 @@ public function getReservedProducts(string $batchId): Collection
206215
private function getChildProductLinks(array $parentIds)
207216
{
208217
$parentLinkField = $this->optionProvider->getProductEntityLinkField();
209-
$select = $this->getConnection()->select()
210-
->from($this->getTable('catalog_product_super_link'), ['parent_id', 'product_id'])
211-
->joinLeft(['e' => $this->getTable('catalog_product_entity')], "e.{$parentLinkField} = parent_id")
218+
$connection = $this->getConnection();
219+
220+
$catalogProductSuperLinkTable = $connection->getTableName('catalog_product_super_link');
221+
$catalogProductEntityTable = $connection->getTableName('catalog_product_entity');
222+
223+
$select = $connection->select()
224+
->from($catalogProductSuperLinkTable, ['parent_id', 'product_id'])
225+
->joinLeft(['e' => $catalogProductEntityTable], "e.{$parentLinkField} = parent_id")
212226
->where('e.entity_id IN (?)', $parentIds);
213-
return $this->getConnection()->fetchAll($select);
227+
return $connection->fetchAll($select);
214228
}
215229

216230
/**
@@ -225,7 +239,9 @@ public function deleteUpdateProductEntries($sku): void
225239
return;
226240
}
227241
$connection = $this->getConnection();
228-
$connection->delete(self::TABLE_NAME, ['sku = ?' => $sku, 'method = ?' => 'update']);
242+
243+
$facebookCatalogUpdateTable = $connection->getTableName(self::TABLE_NAME);
244+
$connection->delete($facebookCatalogUpdateTable, ['sku = ?' => $sku, 'method = ?' => 'update']);
229245
}
230246

231247
/**
@@ -259,8 +275,10 @@ public function cleanupTable()
259275
{
260276
$dateLimit = $this->dateTime->date(null, '-7 days');
261277
$connection = $this->getConnection();
278+
279+
$facebookCatalogUpdateTable = $connection->getTableName(self::TABLE_NAME);
262280
return $connection->delete(
263-
self::TABLE_NAME,
281+
$facebookCatalogUpdateTable,
264282
[
265283
"batch_id IS NOT NULL",
266284
"created_at < '{$dateLimit}'"

0 commit comments

Comments
 (0)