Skip to content

Commit 4aabf34

Browse files
committed
Migration fixes
1 parent 542cc70 commit 4aabf34

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

src/controllers/PluginController.php

+12
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ public function actionCheckContentTables()
185185
$superTableField = $fieldsService->getFieldById($superTableBlockType['fieldId']);
186186
$fieldLayout = $fieldsService->getLayoutById($superTableBlockType['fieldLayoutId']);
187187

188+
if (!$superTableField) {
189+
$errors = true;
190+
echo " > ERROR: Blocktype field #{$superTableBlockType['fieldId']} not found ...\n";
191+
continue;
192+
}
193+
194+
if (get_class($superTableField) !== SuperTableField::class) {
195+
$errors = true;
196+
echo " > ERROR: Blocktype field #{$superTableBlockType['fieldId']} is not a Super Table field ...\n";
197+
continue;
198+
}
199+
188200
// Find what the columns should be according to the block type fields
189201
if ($fieldLayout) {
190202
foreach ($fieldLayout->getFields() as $field) {

src/migrations/m190120_000000_fix_supertablecontent_tables.php

+23-15
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ public function safeUp()
193193
$superTableField = $fieldsService->getFieldById($superTableBlockType['fieldId']);
194194
$fieldLayout = $fieldsService->getLayoutById($superTableBlockType['fieldLayoutId']);
195195

196+
if (!$superTableField) {
197+
echo " > ERROR: Blocktype field #{$superTableBlockType['fieldId']} not found ...\n";
198+
continue;
199+
}
200+
201+
if (get_class($superTableField) !== SuperTableField::class) {
202+
echo " > ERROR: Blocktype field #{$superTableBlockType['fieldId']} is not a Super Table field ...\n";
203+
continue;
204+
}
205+
196206
// Find what the columns should be according to the block type fields
197207
if ($fieldLayout) {
198208
foreach ($fieldLayout->getFields() as $field) {
@@ -216,27 +226,25 @@ public function safeUp()
216226
}
217227

218228
if ($superTableField) {
219-
if (get_class($superTableField) == SuperTableField::class) {
220-
$contentTable = $superTableField->contentTable;
229+
$contentTable = $superTableField->contentTable;
221230

222-
if ($contentTable) {
223-
$columns = $this->db->getTableSchema($contentTable)->columns;
231+
if ($contentTable) {
232+
$columns = $this->db->getTableSchema($contentTable)->columns;
224233

225-
foreach ($columns as $key => $column) {
226-
if (strstr($key, 'field_')) {
227-
$dbFieldColumns[] = $key;
228-
}
234+
foreach ($columns as $key => $column) {
235+
if (strstr($key, 'field_')) {
236+
$dbFieldColumns[] = $key;
229237
}
238+
}
230239

231-
// Sort items the same - just in case they're in a slightly different order, but all there
232-
sort($correctFieldColumns);
233-
sort($dbFieldColumns);
240+
// Sort items the same - just in case they're in a slightly different order, but all there
241+
sort($correctFieldColumns);
242+
sort($dbFieldColumns);
234243

235-
if ($correctFieldColumns != $dbFieldColumns) {
236-
$fieldsService->saveField($superTableField);
244+
if ($correctFieldColumns != $dbFieldColumns) {
245+
$fieldsService->saveField($superTableField);
237246

238-
echo " > Content table {$contentTable} field columns have been corrected ...\n";
239-
}
247+
echo " > Content table {$contentTable} field columns have been corrected ...\n";
240248
}
241249
}
242250
}

0 commit comments

Comments
 (0)