17
17
use Magento \Framework \Setup \Declaration \Schema \Declaration \TableElement \ElementNameResolver ;
18
18
use Magento \Framework \Setup \Declaration \Schema \Diff \Diff ;
19
19
use Magento \Framework \Setup \Declaration \Schema \Dto \Schema ;
20
- use Magento \Framework \Setup \Declaration \Schema \Dto \Table ;
21
20
use Magento \Framework \Setup \Declaration \Schema \SchemaConfig ;
22
21
use Magento \Framework \Setup \JsonPersistor ;
23
22
@@ -137,7 +136,9 @@ private function persistModule(Schema $schema, string $moduleName)
137
136
. Diff::GENERATED_WHITELIST_FILE_NAME ;
138
137
139
138
//We need to load whitelist file and update it with new revision of code.
139
+ // phpcs:disable Magento2.Functions.DiscouragedFunction
140
140
if (file_exists ($ whiteListFileName )) {
141
+ // phpcs:disable Magento2.Functions.DiscouragedFunction
141
142
$ content = json_decode (file_get_contents ($ whiteListFileName ), true );
142
143
}
143
144
@@ -193,19 +194,16 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
193
194
$ elementType = 'index ' ;
194
195
if (!empty ($ tableData [$ elementType ])) {
195
196
foreach ($ tableData [$ elementType ] as $ tableElementData ) {
196
- if (!isset ($ tableElementData ['column ' ])) {
197
- continue ;
198
- }
199
197
$ indexName = $ this ->elementNameResolver ->getFullIndexName (
200
198
$ table ,
201
- $ tableElementData ['column ' ],
199
+ $ tableElementData ['column ' ] ?? [] ,
202
200
$ tableElementData ['indexType ' ] ?? null
203
201
);
204
202
$ declaredStructure [$ elementType ][$ indexName ] = true ;
205
203
}
206
204
}
207
205
208
- $ constraintName = $ this ->getConstraintName ($ schema , $ table , $ tableData );
206
+ $ constraintName = $ this ->getConstraintName ($ schema , $ tableName , $ tableData );
209
207
if ($ constraintName ) {
210
208
$ declaredStructure += $ constraintName ;
211
209
}
@@ -214,22 +212,22 @@ private function getElementsWithAutogeneratedName(Schema $schema, string $tableN
214
212
}
215
213
216
214
/**
215
+ * Provide autogenerated names of the table constraint.
216
+ *
217
217
* @param Schema $schema
218
- * @param Table $table
218
+ * @param string $tableName
219
219
* @param array $tableData
220
220
* @return array
221
221
*/
222
- private function getConstraintName (Schema $ schema , Table $ table , array $ tableData ): array
222
+ private function getConstraintName (Schema $ schema , string $ tableName , array $ tableData ): array
223
223
{
224
224
$ declaredStructure = [];
225
+ $ table = $ schema ->getTableByName ($ tableName );
225
226
226
227
$ elementType = 'constraint ' ;
227
228
if (!empty ($ tableData [$ elementType ])) {
228
229
foreach ($ tableData [$ elementType ] as $ tableElementData ) {
229
- if (!isset ($ tableElementData ['referenceTable ' ])) {
230
- continue ;
231
- }
232
- if ($ tableElementData ['type ' ] === 'foreign ' ) {
230
+ if ($ tableElementData ['type ' ] === 'foreign ' && isset ($ tableElementData ['referenceTable ' ])) {
233
231
$ referenceTable = $ schema ->getTableByName ($ tableElementData ['referenceTable ' ]);
234
232
$ column = $ table ->getColumnByName ($ tableElementData ['column ' ]);
235
233
$ referenceColumn = $ referenceTable ->getColumnByName ($ tableElementData ['referenceColumn ' ]);
@@ -241,12 +239,9 @@ private function getConstraintName(Schema $schema, Table $table, array $tableDat
241
239
$ referenceColumn
242
240
) : null ;
243
241
} else {
244
- if (!isset ($ tableElementData ['column ' ])) {
245
- continue ;
246
- }
247
242
$ constraintName = $ this ->elementNameResolver ->getFullIndexName (
248
243
$ table ,
249
- $ tableElementData ['column ' ],
244
+ $ tableElementData ['column ' ] ?? [] ,
250
245
$ tableElementData ['type ' ]
251
246
);
252
247
}
0 commit comments