Skip to content

Commit 647542f

Browse files
committed
ACP2E-1709: error during declarative schema whitelsit generation
1 parent c1f1cf5 commit 647542f

File tree

1 file changed

+30
-33
lines changed

1 file changed

+30
-33
lines changed

app/code/Magento/Developer/Model/Setup/Declaration/Schema/WhitelistGenerator.php

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ private function persistModule(Schema $schema, string $moduleName)
138138
//We need to load whitelist file and update it with new revision of code.
139139
// phpcs:disable Magento2.Functions.DiscouragedFunction
140140
if (file_exists($whiteListFileName)) {
141-
// phpcs:disable Magento2.Functions.DiscouragedFunction
142141
$content = json_decode(file_get_contents($whiteListFileName), true);
143142
}
144143

@@ -203,46 +202,16 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
203202
}
204203
}
205204

206-
$constraintName = $this->getConstraintName($schema, $tableName, $tableData);
207-
if ($constraintName) {
208-
$declaredStructure += $constraintName;
209-
}
210-
211-
return $declaredStructure;
212-
}
213-
214-
/**
215-
* Provide autogenerated names of the table constraint.
216-
*
217-
* @param Schema $schema
218-
* @param string $tableName
219-
* @param array $tableData
220-
* @return array
221-
*/
222-
private function getConstraintName(Schema $schema, string $tableName, array $tableData): array
223-
{
224-
$declaredStructure = [];
225-
$table = $schema->getTableByName($tableName);
226-
227205
$elementType = 'constraint';
228206
if (!empty($tableData[$elementType])) {
229207
foreach ($tableData[$elementType] as $tableElementData) {
230208
if ($tableElementData['type'] === 'foreign' && isset($tableElementData['referenceTable'])) {
231-
$referenceTable = $schema->getTableByName($tableElementData['referenceTable']);
232-
$column = $table->getColumnByName($tableElementData['column']);
233-
$referenceColumn = $referenceTable->getColumnByName($tableElementData['referenceColumn']);
234-
$constraintName = ($column !== false && $referenceColumn !== false) ?
235-
$this->elementNameResolver->getFullFKName(
236-
$table,
237-
$column,
238-
$referenceTable,
239-
$referenceColumn
240-
) : null;
209+
$constraintName = $this->getConstraintName($schema, $tableName, $tableElementData);
241210
} else {
242211
$constraintName = $this->elementNameResolver->getFullIndexName(
243212
$table,
244213
$tableElementData['column'] ?? [],
245-
$tableElementData['type']
214+
$tableElementData['type'] ?? null
246215
);
247216
}
248217
if ($constraintName) {
@@ -254,6 +223,34 @@ private function getConstraintName(Schema $schema, string $tableName, array $tab
254223
return $declaredStructure;
255224
}
256225

226+
/**
227+
* Provide autogenerated names of the table constraint.
228+
*
229+
* @param Schema $schema
230+
* @param string $tableName
231+
* @param array $tableElementData
232+
* @return string|null
233+
*/
234+
private function getConstraintName(Schema $schema, string $tableName, array $tableElementData): ?string
235+
{
236+
$table = $schema->getTableByName($tableName);
237+
238+
$referenceTable = isset($tableElementData['referenceTable'])
239+
? $schema->getTableByName($tableElementData['referenceTable']) : false;
240+
$column = isset($tableElementData['column'])
241+
? $table->getColumnByName($tableElementData['column']) : false;
242+
$referenceColumn = isset($tableElementData['referenceColumn'])
243+
? $referenceTable->getColumnByName($tableElementData['referenceColumn']) : false;
244+
245+
return ($column !== false && $referenceColumn !== false && $referenceTable !== false) ?
246+
$this->elementNameResolver->getFullFKName(
247+
$table,
248+
$column,
249+
$referenceTable,
250+
$referenceColumn
251+
) : null;
252+
}
253+
257254
/**
258255
* Load db_schema content from the primary scope app/etc/db_schema.xml.
259256
*

0 commit comments

Comments
 (0)