@@ -138,7 +138,6 @@ private function persistModule(Schema $schema, string $moduleName)
138
138
//We need to load whitelist file and update it with new revision of code.
139
139
// phpcs:disable Magento2.Functions.DiscouragedFunction
140
140
if (file_exists ($ whiteListFileName )) {
141
- // phpcs:disable Magento2.Functions.DiscouragedFunction
142
141
$ content = json_decode (file_get_contents ($ whiteListFileName ), true );
143
142
}
144
143
@@ -203,46 +202,16 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
203
202
}
204
203
}
205
204
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
-
227
205
$ elementType = 'constraint ' ;
228
206
if (!empty ($ tableData [$ elementType ])) {
229
207
foreach ($ tableData [$ elementType ] as $ tableElementData ) {
230
208
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 );
241
210
} else {
242
211
$ constraintName = $ this ->elementNameResolver ->getFullIndexName (
243
212
$ table ,
244
213
$ tableElementData ['column ' ] ?? [],
245
- $ tableElementData ['type ' ]
214
+ $ tableElementData ['type ' ] ?? null
246
215
);
247
216
}
248
217
if ($ constraintName ) {
@@ -254,6 +223,34 @@ private function getConstraintName(Schema $schema, string $tableName, array $tab
254
223
return $ declaredStructure ;
255
224
}
256
225
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
+
257
254
/**
258
255
* Load db_schema content from the primary scope app/etc/db_schema.xml.
259
256
*
0 commit comments