Total Complexity | 53 |
Total Lines | 645 |
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 | public function render() |
||
1 ignored issue
–
show
|
|||
19 | { |
||
20 | $conf = $this->conf; |
||
21 | |||
22 | $lang = $this->lang; |
||
23 | |||
24 | $action = $this->action; |
||
25 | if ('tree' == $action) { |
||
26 | return $this->doTree(); |
||
27 | } |
||
28 | |||
29 | $this->printHeader($lang['strviews'] . ' - ' . $_REQUEST['matview']); |
||
30 | $this->printBody(); |
||
31 | |||
32 | switch ($action) { |
||
33 | case 'save_edit': |
||
34 | if (isset($_POST['cancel'])) { |
||
35 | $this->doDefinition(); |
||
36 | } else { |
||
37 | $this->doSaveEdit(); |
||
38 | } |
||
39 | |||
40 | break; |
||
41 | case 'edit': |
||
42 | $this->doEdit(); |
||
43 | |||
44 | break; |
||
45 | case 'export': |
||
46 | $this->doExport(); |
||
47 | |||
48 | break; |
||
49 | case 'definition': |
||
50 | $this->doDefinition(); |
||
51 | |||
52 | break; |
||
53 | case 'properties': |
||
54 | if (isset($_POST['cancel'])) { |
||
55 | $this->doDefault(); |
||
56 | } else { |
||
57 | $this->doProperties(); |
||
58 | } |
||
59 | |||
60 | break; |
||
61 | case 'alter': |
||
62 | if (isset($_POST['alter'])) { |
||
63 | $this->doAlter(false); |
||
64 | } else { |
||
65 | $this->doDefault(); |
||
66 | } |
||
67 | |||
68 | break; |
||
69 | case 'confirm_alter': |
||
70 | doAlter(true); |
||
71 | |||
72 | break; |
||
73 | case 'drop': |
||
74 | if (isset($_POST['drop'])) { |
||
75 | $this->doDrop(false); |
||
76 | } else { |
||
77 | $this->doDefault(); |
||
78 | } |
||
79 | |||
80 | break; |
||
81 | case 'confirm_drop': |
||
82 | $this->doDrop(true); |
||
83 | |||
84 | break; |
||
85 | default: |
||
86 | $this->doDefault(); |
||
87 | |||
88 | break; |
||
89 | } |
||
90 | |||
91 | $this->printFooter(); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Show view definition and virtual columns |
||
96 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
97 | */ |
||
98 | public function doDefault($msg = '') |
||
99 | { |
||
100 | $conf = $this->conf; |
||
101 | |||
102 | $lang = $this->lang; |
||
103 | $data = $this->misc->getDatabaseAccessor(); |
||
104 | |||
105 | $attPre = function (&$rowdata) use ($data) { |
||
106 | $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
||
107 | }; |
||
108 | |||
109 | $this->printTrail('matview'); |
||
110 | $this->printTabs('matview', 'columns'); |
||
111 | $this->printMsg($msg); |
||
112 | |||
113 | // Get view |
||
114 | $vdata = $data->getView($_REQUEST['matview']); |
||
115 | // Get columns (using same method for getting a view) |
||
116 | $attrs = $data->getTableAttributes($_REQUEST['matview']); |
||
117 | |||
118 | // Show comment if any |
||
119 | if (null !== $vdata->fields['relcomment']) { |
||
120 | echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
||
121 | } |
||
122 | |||
123 | $columns = [ |
||
124 | 'column' => [ |
||
125 | 'title' => $lang['strcolumn'], |
||
126 | 'field' => Decorator::field('attname'), |
||
127 | 'url' => "colproperties.php?subject=column&{$this->misc->href}&view=" . urlencode($_REQUEST['matview']) . '&', |
||
128 | 'vars' => ['column' => 'attname'], |
||
129 | ], |
||
130 | 'type' => [ |
||
131 | 'title' => $lang['strtype'], |
||
132 | 'field' => Decorator::field('+type'), |
||
133 | ], |
||
134 | 'default' => [ |
||
135 | 'title' => $lang['strdefault'], |
||
136 | 'field' => Decorator::field('adsrc'), |
||
137 | ], |
||
138 | 'actions' => [ |
||
139 | 'title' => $lang['stractions'], |
||
140 | ], |
||
141 | 'comment' => [ |
||
142 | 'title' => $lang['strcomment'], |
||
143 | 'field' => Decorator::field('comment'), |
||
144 | ], |
||
145 | ]; |
||
146 | |||
147 | $actions = [ |
||
148 | 'alter' => [ |
||
149 | 'content' => $lang['stralter'], |
||
150 | 'attr' => [ |
||
151 | 'href' => [ |
||
152 | 'url' => 'materializedviewproperties.php', |
||
153 | 'urlvars' => [ |
||
154 | 'action' => 'properties', |
||
155 | 'view' => $_REQUEST['matview'], |
||
156 | 'column' => Decorator::field('attname'), |
||
157 | ], |
||
158 | ], |
||
159 | ], |
||
160 | ], |
||
161 | ]; |
||
162 | |||
163 | echo $this->printTable($attrs, $columns, $actions, 'materializedviewproperties-materializedviewproperties', null, $attPre); |
||
164 | |||
165 | echo "<br />\n"; |
||
166 | |||
167 | $navlinks = [ |
||
168 | 'browse' => [ |
||
169 | 'attr' => [ |
||
170 | 'href' => [ |
||
171 | 'url' => 'display.php', |
||
172 | 'urlvars' => [ |
||
173 | 'server' => $_REQUEST['server'], |
||
174 | 'database' => $_REQUEST['database'], |
||
175 | 'schema' => $_REQUEST['schema'], |
||
176 | 'matview' => $_REQUEST['matview'], |
||
177 | 'subject' => 'matview', |
||
178 | 'return' => 'matview', |
||
179 | ], |
||
180 | ], |
||
181 | ], |
||
182 | 'content' => $lang['strbrowse'], |
||
183 | ], |
||
184 | 'select' => [ |
||
185 | 'attr' => [ |
||
186 | 'href' => [ |
||
187 | 'url' => 'materializedviews.php', |
||
188 | 'urlvars' => [ |
||
189 | 'action' => 'confselectrows', |
||
190 | 'server' => $_REQUEST['server'], |
||
191 | 'database' => $_REQUEST['database'], |
||
192 | 'schema' => $_REQUEST['schema'], |
||
193 | 'matview' => $_REQUEST['matview'], |
||
194 | ], |
||
195 | ], |
||
196 | ], |
||
197 | 'content' => $lang['strselect'], |
||
198 | ], |
||
199 | 'drop' => [ |
||
200 | 'attr' => [ |
||
201 | 'href' => [ |
||
202 | 'url' => 'materializedviews.php', |
||
203 | 'urlvars' => [ |
||
204 | 'action' => 'confirm_drop', |
||
205 | 'server' => $_REQUEST['server'], |
||
206 | 'database' => $_REQUEST['database'], |
||
207 | 'schema' => $_REQUEST['schema'], |
||
208 | 'matview' => $_REQUEST['matview'], |
||
209 | ], |
||
210 | ], |
||
211 | ], |
||
212 | 'content' => $lang['strdrop'], |
||
213 | ], |
||
214 | 'alter' => [ |
||
215 | 'attr' => [ |
||
216 | 'href' => [ |
||
217 | 'url' => 'materializedviewproperties.php', |
||
218 | 'urlvars' => [ |
||
219 | 'action' => 'confirm_alter', |
||
220 | 'server' => $_REQUEST['server'], |
||
221 | 'database' => $_REQUEST['database'], |
||
222 | 'schema' => $_REQUEST['schema'], |
||
223 | 'matview' => $_REQUEST['matview'], |
||
224 | ], |
||
225 | ], |
||
226 | ], |
||
227 | 'content' => $lang['stralter'], |
||
228 | ], |
||
229 | ]; |
||
230 | |||
231 | $this->printNavLinks($navlinks, 'materializedviewproperties-materializedviewproperties', get_defined_vars()); |
||
232 | } |
||
233 | |||
234 | public function doTree() |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * Function to save after editing a view |
||
278 | */ |
||
279 | public function doSaveEdit() |
||
280 | { |
||
281 | $conf = $this->conf; |
||
282 | |||
283 | $lang = $this->lang; |
||
284 | $data = $this->misc->getDatabaseAccessor(); |
||
285 | |||
286 | $status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']); |
||
287 | if (0 == $status) { |
||
288 | $this->doDefinition($lang['strviewupdated']); |
||
289 | } else { |
||
290 | $this->doEdit($lang['strviewupdatedbad']); |
||
291 | } |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Function to allow editing of a view |
||
296 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
297 | */ |
||
298 | public function doEdit($msg = '') |
||
334 | } |
||
335 | } |
||
336 | |||
337 | /** |
||
338 | * Allow the dumping of the data "in" a view |
||
339 | * NOTE:: PostgreSQL doesn't currently support dumping the data in a view |
||
340 | * so I have disabled the data related parts for now. In the future |
||
341 | * we should allow it conditionally if it becomes supported. This is |
||
342 | * a SMOP since it is based on pg_dump version not backend version. |
||
343 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
344 | */ |
||
345 | public function doExport($msg = '') |
||
346 | { |
||
347 | $conf = $this->conf; |
||
348 | |||
349 | $lang = $this->lang; |
||
350 | $data = $this->misc->getDatabaseAccessor(); |
||
351 | |||
352 | $this->printTrail('view'); |
||
353 | $this->printTabs('view', 'export'); |
||
354 | $this->printMsg($msg); |
||
355 | |||
356 | echo '<form action="' . SUBFOLDER . "/src/views/dataexport.php\" method=\"post\">\n"; |
||
357 | echo "<table>\n"; |
||
358 | echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
||
359 | // Data only |
||
360 | echo "<!--\n"; |
||
361 | echo '<tr><th class="data left">'; |
||
362 | echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
||
363 | echo "<td>{$lang['strformat']}</td>\n"; |
||
364 | echo "<td><select name=\"d_format\" >\n"; |
||
365 | echo "<option value=\"copy\">COPY</option>\n"; |
||
366 | echo "<option value=\"sql\">SQL</option>\n"; |
||
367 | echo "<option value=\"csv\">CSV</option>\n"; |
||
368 | echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n"; |
||
369 | echo "<option value=\"html\">XHTML</option>\n"; |
||
370 | echo "<option value=\"xml\">XML</option>\n"; |
||
371 | echo "</select>\n</td>\n</tr>\n"; |
||
372 | echo "-->\n"; |
||
373 | |||
374 | // Structure only |
||
375 | 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"; |
||
376 | echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
||
377 | // Structure and data |
||
378 | echo "<!--\n"; |
||
379 | echo '<tr><th class="data left" rowspan="2">'; |
||
380 | echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
||
381 | echo "<td>{$lang['strformat']}</td>\n"; |
||
382 | echo "<td><select name=\"sd_format\">\n"; |
||
383 | echo "<option value=\"copy\">COPY</option>\n"; |
||
384 | echo "<option value=\"sql\">SQL</option>\n"; |
||
385 | echo "</select>\n</td>\n</tr>\n"; |
||
386 | echo "<td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n"; |
||
387 | echo "-->\n"; |
||
388 | echo "</table>\n"; |
||
389 | |||
390 | echo "<h3>{$lang['stroptions']}</h3>\n"; |
||
391 | echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
||
392 | echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n"; |
||
393 | |||
394 | echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
||
395 | echo $this->misc->form; |
||
396 | echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
||
397 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
||
398 | echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
||
399 | echo "</form>\n"; |
||
400 | } |
||
401 | |||
402 | /** |
||
403 | * Show definition for a view |
||
404 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
405 | */ |
||
406 | public function doDefinition($msg = '') |
||
407 | { |
||
408 | $conf = $this->conf; |
||
409 | |||
410 | $lang = $this->lang; |
||
411 | $data = $this->misc->getDatabaseAccessor(); |
||
412 | |||
413 | // Get view |
||
414 | $vdata = $data->getView($_REQUEST['matview']); |
||
415 | |||
416 | $this->printTrail('view'); |
||
417 | $this->printTabs('view', 'definition'); |
||
418 | $this->printMsg($msg); |
||
419 | |||
420 | if ($vdata->recordCount() > 0) { |
||
421 | // Show comment if any |
||
422 | if (null !== $vdata->fields['relcomment']) { |
||
423 | echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
||
424 | } |
||
425 | |||
426 | echo "<table style=\"width: 100%\">\n"; |
||
427 | echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n"; |
||
428 | echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), "</td></tr>\n"; |
||
429 | echo "</table>\n"; |
||
430 | } else { |
||
431 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
432 | } |
||
433 | |||
434 | $this->printNavLinks(['alter' => [ |
||
1 ignored issue
–
show
|
|||
435 | 'attr' => [ |
||
436 | 'href' => [ |
||
437 | 'url' => 'materializedviewproperties.php', |
||
438 | 'urlvars' => [ |
||
439 | 'action' => 'edit', |
||
440 | 'server' => $_REQUEST['server'], |
||
441 | 'database' => $_REQUEST['database'], |
||
442 | 'schema' => $_REQUEST['schema'], |
||
443 | 'view' => $_REQUEST['matview'], |
||
444 | ], |
||
445 | ], |
||
446 | ], |
||
447 | 'content' => $lang['stralter'], |
||
448 | ]], 'materializedviewproperties-definition', get_defined_vars()); |
||
1 ignored issue
–
show
|
|||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Displays a screen where they can alter a column in a view |
||
453 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
454 | */ |
||
455 | public function doProperties($msg = '') |
||
546 | } |
||
547 | } |
||
548 | |||
549 | public function doAlter($confirm = false, $msg = '') |
||
1 ignored issue
–
show
|
|||
550 | { |
||
659 | } |
||
660 | } |
||
663 |