Total Complexity | 53 |
Total Lines | 653 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like MaterializedviewpropertiesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MaterializedviewpropertiesController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class MaterializedviewpropertiesController extends BaseController |
||
15 | { |
||
16 | public $controller_name = 'MaterializedviewpropertiesController'; |
||
17 | |||
18 | /** |
||
19 | * Default method to render the controller according to the action parameter. |
||
20 | */ |
||
21 | public function render() |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Show view definition and virtual columns. |
||
99 | * |
||
100 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
101 | */ |
||
102 | public function doDefault($msg = '') |
||
103 | { |
||
104 | $conf = $this->conf; |
||
105 | |||
106 | $lang = $this->lang; |
||
107 | $data = $this->misc->getDatabaseAccessor(); |
||
108 | |||
109 | $attPre = function (&$rowdata) use ($data) { |
||
110 | $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
||
111 | }; |
||
112 | |||
113 | $this->printTrail('matview'); |
||
114 | $this->printTabs('matview', 'columns'); |
||
115 | $this->printMsg($msg); |
||
116 | |||
117 | // Get view |
||
118 | $vdata = $data->getView($_REQUEST['matview']); |
||
119 | // Get columns (using same method for getting a view) |
||
120 | $attrs = $data->getTableAttributes($_REQUEST['matview']); |
||
121 | |||
122 | // Show comment if any |
||
123 | if (null !== $vdata->fields['relcomment']) { |
||
124 | echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
||
125 | } |
||
126 | |||
127 | $columns = [ |
||
128 | 'column' => [ |
||
129 | 'title' => $lang['strcolumn'], |
||
130 | 'field' => Decorator::field('attname'), |
||
131 | 'url' => "colproperties.php?subject=column&{$this->misc->href}&view=".urlencode($_REQUEST['matview']).'&', |
||
132 | 'vars' => ['column' => 'attname'], |
||
133 | ], |
||
134 | 'type' => [ |
||
135 | 'title' => $lang['strtype'], |
||
136 | 'field' => Decorator::field('+type'), |
||
137 | ], |
||
138 | 'default' => [ |
||
139 | 'title' => $lang['strdefault'], |
||
140 | 'field' => Decorator::field('adsrc'), |
||
141 | ], |
||
142 | 'actions' => [ |
||
143 | 'title' => $lang['stractions'], |
||
144 | ], |
||
145 | 'comment' => [ |
||
146 | 'title' => $lang['strcomment'], |
||
147 | 'field' => Decorator::field('comment'), |
||
148 | ], |
||
149 | ]; |
||
150 | |||
151 | $actions = [ |
||
152 | 'alter' => [ |
||
153 | 'content' => $lang['stralter'], |
||
154 | 'attr' => [ |
||
155 | 'href' => [ |
||
156 | 'url' => 'materializedviewproperties.php', |
||
157 | 'urlvars' => [ |
||
158 | 'action' => 'properties', |
||
159 | 'view' => $_REQUEST['matview'], |
||
160 | 'column' => Decorator::field('attname'), |
||
161 | ], |
||
162 | ], |
||
163 | ], |
||
164 | ], |
||
165 | ]; |
||
166 | |||
167 | echo $this->printTable($attrs, $columns, $actions, 'materializedviewproperties-materializedviewproperties', null, $attPre); |
||
168 | |||
169 | echo "<br />\n"; |
||
170 | |||
171 | $navlinks = [ |
||
172 | 'browse' => [ |
||
173 | 'attr' => [ |
||
174 | 'href' => [ |
||
175 | 'url' => 'display.php', |
||
176 | 'urlvars' => [ |
||
177 | 'server' => $_REQUEST['server'], |
||
178 | 'database' => $_REQUEST['database'], |
||
179 | 'schema' => $_REQUEST['schema'], |
||
180 | 'matview' => $_REQUEST['matview'], |
||
181 | 'subject' => 'matview', |
||
182 | 'return' => 'matview', |
||
183 | ], |
||
184 | ], |
||
185 | ], |
||
186 | 'content' => $lang['strbrowse'], |
||
187 | ], |
||
188 | 'select' => [ |
||
189 | 'attr' => [ |
||
190 | 'href' => [ |
||
191 | 'url' => 'materializedviews.php', |
||
192 | 'urlvars' => [ |
||
193 | 'action' => 'confselectrows', |
||
194 | 'server' => $_REQUEST['server'], |
||
195 | 'database' => $_REQUEST['database'], |
||
196 | 'schema' => $_REQUEST['schema'], |
||
197 | 'matview' => $_REQUEST['matview'], |
||
198 | ], |
||
199 | ], |
||
200 | ], |
||
201 | 'content' => $lang['strselect'], |
||
202 | ], |
||
203 | 'drop' => [ |
||
204 | 'attr' => [ |
||
205 | 'href' => [ |
||
206 | 'url' => 'materializedviews.php', |
||
207 | 'urlvars' => [ |
||
208 | 'action' => 'confirm_drop', |
||
209 | 'server' => $_REQUEST['server'], |
||
210 | 'database' => $_REQUEST['database'], |
||
211 | 'schema' => $_REQUEST['schema'], |
||
212 | 'matview' => $_REQUEST['matview'], |
||
213 | ], |
||
214 | ], |
||
215 | ], |
||
216 | 'content' => $lang['strdrop'], |
||
217 | ], |
||
218 | 'alter' => [ |
||
219 | 'attr' => [ |
||
220 | 'href' => [ |
||
221 | 'url' => 'materializedviewproperties.php', |
||
222 | 'urlvars' => [ |
||
223 | 'action' => 'confirm_alter', |
||
224 | 'server' => $_REQUEST['server'], |
||
225 | 'database' => $_REQUEST['database'], |
||
226 | 'schema' => $_REQUEST['schema'], |
||
227 | 'matview' => $_REQUEST['matview'], |
||
228 | ], |
||
229 | ], |
||
230 | ], |
||
231 | 'content' => $lang['stralter'], |
||
232 | ], |
||
233 | ]; |
||
234 | |||
235 | $this->printNavLinks($navlinks, 'materializedviewproperties-materializedviewproperties', get_defined_vars()); |
||
236 | } |
||
237 | |||
238 | public function doTree() |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * Function to save after editing a view. |
||
282 | */ |
||
283 | public function doSaveEdit() |
||
284 | { |
||
285 | $conf = $this->conf; |
||
286 | |||
287 | $lang = $this->lang; |
||
288 | $data = $this->misc->getDatabaseAccessor(); |
||
289 | |||
290 | $status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']); |
||
291 | if (0 == $status) { |
||
292 | $this->doDefinition($lang['strviewupdated']); |
||
293 | } else { |
||
294 | $this->doEdit($lang['strviewupdatedbad']); |
||
295 | } |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Function to allow editing of a view. |
||
300 | * |
||
301 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
302 | */ |
||
303 | public function doEdit($msg = '') |
||
339 | } |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * Allow the dumping of the data "in" a view |
||
344 | * NOTE:: PostgreSQL doesn't currently support dumping the data in a view |
||
345 | * so I have disabled the data related parts for now. In the future |
||
346 | * we should allow it conditionally if it becomes supported. This is |
||
347 | * a SMOP since it is based on pg_dump version not backend version. |
||
348 | * |
||
349 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
350 | */ |
||
351 | public function doExport($msg = '') |
||
352 | { |
||
353 | $conf = $this->conf; |
||
354 | |||
355 | $lang = $this->lang; |
||
356 | $data = $this->misc->getDatabaseAccessor(); |
||
357 | |||
358 | $this->printTrail('view'); |
||
359 | $this->printTabs('view', 'export'); |
||
360 | $this->printMsg($msg); |
||
361 | |||
362 | echo '<form action="'.\SUBFOLDER."/src/views/dataexport.php\" method=\"post\">\n"; |
||
363 | echo "<table>\n"; |
||
364 | echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
||
365 | // Data only |
||
366 | echo "<!--\n"; |
||
367 | echo '<tr><th class="data left">'; |
||
368 | echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
||
369 | echo "<td>{$lang['strformat']}</td>\n"; |
||
370 | echo "<td><select name=\"d_format\" >\n"; |
||
371 | echo "<option value=\"copy\">COPY</option>\n"; |
||
372 | echo "<option value=\"sql\">SQL</option>\n"; |
||
373 | echo "<option value=\"csv\">CSV</option>\n"; |
||
374 | echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n"; |
||
375 | echo "<option value=\"html\">XHTML</option>\n"; |
||
376 | echo "<option value=\"xml\">XML</option>\n"; |
||
377 | echo "</select>\n</td>\n</tr>\n"; |
||
378 | echo "-->\n"; |
||
379 | |||
380 | // Structure only |
||
381 | echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" checked=\"checked\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n"; |
||
382 | echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
||
383 | // Structure and data |
||
384 | echo "<!--\n"; |
||
385 | echo '<tr><th class="data left" rowspan="2">'; |
||
386 | echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
||
387 | echo "<td>{$lang['strformat']}</td>\n"; |
||
388 | echo "<td><select name=\"sd_format\">\n"; |
||
389 | echo "<option value=\"copy\">COPY</option>\n"; |
||
390 | echo "<option value=\"sql\">SQL</option>\n"; |
||
391 | echo "</select>\n</td>\n</tr>\n"; |
||
392 | echo "<td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n"; |
||
393 | echo "-->\n"; |
||
394 | echo "</table>\n"; |
||
395 | |||
396 | echo "<h3>{$lang['stroptions']}</h3>\n"; |
||
397 | echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
||
398 | echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n"; |
||
399 | |||
400 | echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
||
401 | echo $this->misc->form; |
||
402 | echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
||
403 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
||
404 | echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
||
405 | echo "</form>\n"; |
||
406 | } |
||
407 | |||
408 | /** |
||
409 | * Show definition for a view. |
||
410 | * |
||
411 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
412 | */ |
||
413 | public function doDefinition($msg = '') |
||
414 | { |
||
415 | $conf = $this->conf; |
||
416 | |||
417 | $lang = $this->lang; |
||
418 | $data = $this->misc->getDatabaseAccessor(); |
||
419 | |||
420 | // Get view |
||
421 | $vdata = $data->getView($_REQUEST['matview']); |
||
422 | |||
423 | $this->printTrail('view'); |
||
424 | $this->printTabs('view', 'definition'); |
||
425 | $this->printMsg($msg); |
||
426 | |||
427 | if ($vdata->recordCount() > 0) { |
||
428 | // Show comment if any |
||
429 | if (null !== $vdata->fields['relcomment']) { |
||
430 | echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
||
431 | } |
||
432 | |||
433 | echo "<table style=\"width: 100%\">\n"; |
||
434 | echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n"; |
||
435 | echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), "</td></tr>\n"; |
||
436 | echo "</table>\n"; |
||
437 | } else { |
||
438 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
439 | } |
||
440 | |||
441 | $this->printNavLinks(['alter' => [ |
||
1 ignored issue
–
show
|
|||
442 | 'attr' => [ |
||
443 | 'href' => [ |
||
444 | 'url' => 'materializedviewproperties.php', |
||
445 | 'urlvars' => [ |
||
446 | 'action' => 'edit', |
||
447 | 'server' => $_REQUEST['server'], |
||
448 | 'database' => $_REQUEST['database'], |
||
449 | 'schema' => $_REQUEST['schema'], |
||
450 | 'view' => $_REQUEST['matview'], |
||
451 | ], |
||
452 | ], |
||
453 | ], |
||
454 | 'content' => $lang['stralter'], |
||
455 | ]], 'materializedviewproperties-definition', get_defined_vars()); |
||
1 ignored issue
–
show
|
|||
456 | } |
||
457 | |||
458 | /** |
||
459 | * Displays a screen where they can alter a column in a view. |
||
460 | * |
||
461 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
462 | */ |
||
463 | public function doProperties($msg = '') |
||
554 | } |
||
555 | } |
||
556 | |||
557 | public function doAlter($confirm = false, $msg = '') |
||
667 | } |
||
668 | } |
||
671 |