@@ -21,6 +21,13 @@ class PluginController extends Controller
21
21
// Public Methods
22
22
// =========================================================================
23
23
24
+ public function actionSettings ()
25
+ {
26
+ return $ this ->renderTemplate ('super-table/plugin-settings ' , [
27
+ 'settings ' => true ,
28
+ ]);
29
+ }
30
+
24
31
public function actionFixContentTables ()
25
32
{
26
33
// Backup!
@@ -36,11 +43,14 @@ public function actionFixContentTables()
36
43
37
44
ob_end_clean ();
38
45
39
- echo nl2br ($ output );
46
+ $ output = nl2br ($ output );
40
47
41
- echo '<br>Fixes complete. ' ;
48
+ $ output .= '<br>Fixes complete. ' ;
42
49
43
- exit ;
50
+ return $ this ->renderTemplate ('super-table/plugin-settings ' , [
51
+ 'fixed ' => true ,
52
+ 'output ' => $ output ,
53
+ ]);
44
54
}
45
55
46
56
public function actionCheckContentTables ()
@@ -154,18 +164,62 @@ public function actionCheckContentTables()
154
164
}
155
165
}
156
166
167
+ // Check each table for missing field columns in their content tables
168
+ $ superTableBlockTypes = (new Query ())
169
+ ->select (['* ' ])
170
+ ->from (['{{%supertableblocktypes}} ' ])
171
+ ->all ();
172
+
173
+ foreach ($ superTableBlockTypes as $ superTableBlockType ) {
174
+ $ correctFieldColumns = [];
175
+ $ dbFieldColumns = [];
176
+
177
+ $ fieldLayout = $ fieldsService ->getLayoutById ($ superTableBlockType ['fieldLayoutId ' ]);
178
+
179
+ // Find what the columns should be according to the block type fields
180
+ if ($ fieldLayout ) {
181
+ foreach ($ fieldLayout ->getFields () as $ field ) {
182
+ if ($ field ::hasContentColumn ()) {
183
+ $ correctFieldColumns [] = 'field_ ' . $ field ->handle ;
184
+ }
185
+ }
186
+ }
187
+
188
+ $ field = $ fieldsService ->getFieldById ($ superTableBlockType ['fieldId ' ]);
189
+
190
+ if ($ field ) {
191
+ $ contentTable = $ field ->contentTable ;
192
+
193
+ if ($ contentTable ) {
194
+ $ columns = Craft::$ app ->getDb ()->getTableSchema ($ contentTable )->columns ;
195
+
196
+ foreach ($ columns as $ key => $ column ) {
197
+ if (strstr ($ key , 'field_ ' )) {
198
+ $ dbFieldColumns [] = $ key ;
199
+ }
200
+ }
201
+
202
+ if ($ correctFieldColumns != $ dbFieldColumns ) {
203
+ $ errors = true ;
204
+ echo " > ERROR: {$ contentTable } has missing field columns ... \n" ;
205
+ }
206
+ }
207
+ }
208
+ }
209
+
157
210
$ output = ob_get_contents ();
158
211
ob_end_clean ();
159
212
160
- echo nl2br ($ output );
213
+ $ output = nl2br ($ output );
161
214
162
- if ($ errors ) {
163
- echo '<br>Fix the above errors by running the <a href=" ' . UrlHelper::actionUrl ('super-table/plugin/fix-content-tables ' ) . '">Super Table content table fixer. ' ;
164
- } else {
165
- echo 'No errors found. ' ;
215
+ if (!$ errors ) {
216
+ $ output .= 'No errors found. ' ;
166
217
}
167
218
168
- exit ;
219
+ return $ this ->renderTemplate ('super-table/plugin-settings ' , [
220
+ 'checkErrors ' => $ errors ,
221
+ 'output ' => $ output ,
222
+ ]);
169
223
}
170
224
171
225
}
0 commit comments