Skip to content

Commit 6e9d279

Browse files
committed
Add fix/checks for project config mismatches from Craft 3 > 3.1
1 parent cae2c92 commit 6e9d279

File tree

3 files changed

+41
-119
lines changed

3 files changed

+41
-119
lines changed

config.codekit3

-119
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@
126126
"oAP": "/build/src/fields",
127127
"oF": 0
128128
},
129-
"/src/icon.svg": {
130-
"ft": 2097152,
131-
"miP": 0,
132-
"oA": 2,
133-
"oAP": "/src/icon.svg",
134-
"oF": 0,
135-
"opt": 0,
136-
"plM": 3758088159,
137-
"prP": 0
138-
},
139129
"/src/integrations": {
140130
"ft": 65536,
141131
"oA": 1,
@@ -166,121 +156,12 @@
166156
"oAP": "/build/src/resources/dist",
167157
"oF": 0
168158
},
169-
"/src/resources/src/js/_configurator.js": {
170-
"ft": 64,
171-
"ma": 1,
172-
"mi": 1,
173-
"oA": 1,
174-
"oAP": "/src/resources/dist/js/_configurator.js",
175-
"oF": 0,
176-
"sC": 0,
177-
"tS": 0
178-
},
179-
"/src/resources/src/js/_input.js": {
180-
"ft": 64,
181-
"ma": 1,
182-
"mi": 1,
183-
"oA": 1,
184-
"oAP": "/src/resources/dist/js/_input.js",
185-
"oF": 0,
186-
"sC": 0,
187-
"tS": 0
188-
},
189-
"/src/resources/src/js/_matrix-configurator.js": {
190-
"ft": 64,
191-
"ma": 1,
192-
"mi": 1,
193-
"oA": 1,
194-
"oAP": "/src/resources/dist/js/_matrix-configurator.js",
195-
"oF": 0,
196-
"sC": 0,
197-
"tS": 0
198-
},
199-
"/src/resources/src/js/_matrix-input.js": {
200-
"ft": 64,
201-
"ma": 1,
202-
"mi": 1,
203-
"oA": 1,
204-
"oAP": "/src/resources/dist/js/_matrix-input.js",
205-
"oF": 0,
206-
"sC": 0,
207-
"tS": 0
208-
},
209-
"/src/resources/src/js/super-table.js": {
210-
"ft": 64,
211-
"ma": 1,
212-
"mi": 1,
213-
"oA": 0,
214-
"oAP": "/src/resources/dist/js/super-table.js",
215-
"oF": 0,
216-
"sC": 0,
217-
"tS": 0
218-
},
219-
"/src/resources/src/scss/_base.scss": {
220-
"aP": 1,
221-
"bl": 0,
222-
"dP": 10,
223-
"dS": 0,
224-
"ft": 4,
225-
"ma": 0,
226-
"oA": 1,
227-
"oAP": "/src/resources/dist/css/_base.css",
228-
"oF": 0,
229-
"oS": 3,
230-
"uL": 1
231-
},
232-
"/src/resources/src/scss/_configurator.scss": {
233-
"aP": 1,
234-
"bl": 0,
235-
"dP": 10,
236-
"dS": 0,
237-
"ft": 4,
238-
"ma": 0,
239-
"oA": 1,
240-
"oAP": "/src/resources/dist/css/_configurator.css",
241-
"oF": 0,
242-
"oS": 3,
243-
"uL": 1
244-
},
245-
"/src/resources/src/scss/_input.scss": {
246-
"aP": 1,
247-
"bl": 0,
248-
"dP": 10,
249-
"dS": 0,
250-
"ft": 4,
251-
"ma": 0,
252-
"oA": 1,
253-
"oAP": "/src/resources/dist/css/_input.css",
254-
"oF": 0,
255-
"oS": 3,
256-
"uL": 1
257-
},
258-
"/src/resources/src/scss/super-table.scss": {
259-
"aP": 1,
260-
"bl": 0,
261-
"dP": 10,
262-
"dS": 0,
263-
"ft": 4,
264-
"ma": 0,
265-
"oA": 0,
266-
"oAP": "/src/resources/dist/css/super-table.css",
267-
"oF": 0,
268-
"oS": 3,
269-
"uL": 1
270-
},
271159
"/src/services": {
272160
"ft": 65536,
273161
"oA": 1,
274162
"oAP": "/build/src/services",
275163
"oF": 0
276164
},
277-
"/src/SuperTable.php": {
278-
"cB": 0,
279-
"ft": 8192,
280-
"oA": 2,
281-
"oAP": "/src/SuperTable.php",
282-
"oF": 0
283-
},
284165
"/src/templates": {
285166
"ft": 65536,
286167
"oA": 1,

src/controllers/PluginController.php

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use craft\helpers\Json;
1515
use craft\helpers\MigrationHelper;
1616
use craft\helpers\UrlHelper;
17+
use craft\services\Fields;
1718
use craft\web\Controller;
1819

1920
class PluginController extends Controller
@@ -63,6 +64,7 @@ public function actionCheckContentTables()
6364
$fieldsService = Craft::$app->getFields();
6465
$superTableService = SuperTable::$plugin->getService();
6566
$matrixService = Craft::$app->getMatrix();
67+
$projectConfig = Craft::$app->getProjectConfig();
6668

6769
// Find all top-level Super Table fields and make sure their content table exists
6870
$superTableFields = (new Query())
@@ -207,6 +209,24 @@ public function actionCheckContentTables()
207209
}
208210
}
209211

212+
// Check for project config inconsistencies
213+
$superTableFields = (new Query())
214+
->select(['uid', 'settings'])
215+
->from([Table::FIELDS])
216+
->where(['type' => SuperTableField::class])
217+
->all();
218+
219+
foreach ($superTableFields as $superTableField) {
220+
$path = Fields::CONFIG_FIELDS_KEY . '.' . $superTableField['uid'] . '.settings';
221+
$settings = Json::decode($superTableField['settings']);
222+
$configSettings = $projectConfig->get($path);
223+
224+
if ($settings != $configSettings) {
225+
$errors = true;
226+
echo " > ERROR: #{$superTableField->id} has inconsistent field settings in its project config ...\n";
227+
}
228+
}
229+
210230
$output = ob_get_contents();
211231
ob_end_clean();
212232

src/migrations/m190120_000000_fix_supertablecontent_tables.php

+21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use craft\helpers\Db;
1313
use craft\helpers\Json;
1414
use craft\helpers\MigrationHelper;
15+
use craft\services\Fields;
1516

1617
class m190120_000000_fix_supertablecontent_tables extends Migration
1718
{
@@ -20,6 +21,7 @@ public function safeUp()
2021
$fieldsService = Craft::$app->getFields();
2122
$superTableService = SuperTable::$plugin->getService();
2223
$matrixService = Craft::$app->getMatrix();
24+
$projectConfig = Craft::$app->getProjectConfig();
2325

2426
// Find any `supertablecontents_*` tables, these should be `stc_*`. But we should check if these tables are completely empty
2527
foreach (Craft::$app->db->schema->getTableNames() as $tableName) {
@@ -218,6 +220,25 @@ public function safeUp()
218220
}
219221
}
220222
}
223+
224+
// Update Super Table settings in the project config to match the DB. This is because Craft 3.0 > 3.1 migration
225+
// has already fired, dumping potentially incorrect values into the project config. Because we've fixed above,
226+
// we should be good to update it again with correct values.
227+
$projectConfig->muteEvents = true;
228+
229+
$superTableFields = (new Query())
230+
->select(['uid', 'settings'])
231+
->from([Table::FIELDS])
232+
->where(['type' => SuperTableField::class])
233+
->all();
234+
235+
foreach ($superTableFields as $superTableField) {
236+
$path = Fields::CONFIG_FIELDS_KEY . '.' . $superTableField['uid'] . '.settings';
237+
$settings = Json::decode($superTableField['settings']);
238+
$projectConfig->set($path, $settings);
239+
}
240+
241+
$projectConfig->muteEvents = false;
221242
}
222243

223244
public function safeDown()

0 commit comments

Comments
 (0)