| Total Complexity | 53 |
| Total Lines | 634 |
| 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() |
||
| 22 | { |
||
| 23 | $lang = $this->lang; |
||
| 24 | |||
| 25 | $action = $this->action; |
||
| 26 | if ('tree' == $action) { |
||
| 27 | return $this->doTree(); |
||
| 28 | } |
||
| 29 | |||
| 30 | $this->printHeader($lang['strviews'] . ' - ' . $_REQUEST['matview']); |
||
| 31 | $this->printBody(); |
||
| 32 | |||
| 33 | switch ($action) { |
||
| 34 | case 'save_edit': |
||
| 35 | if (isset($_POST['cancel'])) { |
||
| 36 | $this->doDefinition(); |
||
| 37 | } else { |
||
| 38 | $this->doSaveEdit(); |
||
| 39 | } |
||
| 40 | |||
| 41 | break; |
||
| 42 | case 'edit': |
||
| 43 | $this->doEdit(); |
||
| 44 | |||
| 45 | break; |
||
| 46 | case 'export': |
||
| 47 | $this->doExport(); |
||
| 48 | |||
| 49 | break; |
||
| 50 | case 'definition': |
||
| 51 | $this->doDefinition(); |
||
| 52 | |||
| 53 | break; |
||
| 54 | case 'properties': |
||
| 55 | if (isset($_POST['cancel'])) { |
||
| 56 | $this->doDefault(); |
||
| 57 | } else { |
||
| 58 | $this->doProperties(); |
||
| 59 | } |
||
| 60 | |||
| 61 | break; |
||
| 62 | case 'alter': |
||
| 63 | if (isset($_POST['alter'])) { |
||
| 64 | $this->doAlter(false); |
||
| 65 | } else { |
||
| 66 | $this->doDefault(); |
||
| 67 | } |
||
| 68 | |||
| 69 | break; |
||
| 70 | case 'confirm_alter': |
||
| 71 | doAlter(true); |
||
| 72 | |||
| 73 | break; |
||
| 74 | case 'drop': |
||
| 75 | if (isset($_POST['drop'])) { |
||
| 76 | $this->doDrop(false); |
||
| 77 | } else { |
||
| 78 | $this->doDefault(); |
||
| 79 | } |
||
| 80 | |||
| 81 | break; |
||
| 82 | case 'confirm_drop': |
||
| 83 | $this->doDrop(true); |
||
| 84 | |||
| 85 | break; |
||
| 86 | default: |
||
| 87 | $this->doDefault(); |
||
| 88 | |||
| 89 | break; |
||
| 90 | } |
||
| 91 | |||
| 92 | $this->printFooter(); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Show view definition and virtual columns. |
||
| 97 | * |
||
| 98 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 99 | */ |
||
| 100 | public function doDefault($msg = '') |
||
| 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() |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Function to save after editing a view. |
||
| 276 | */ |
||
| 277 | public function doSaveEdit() |
||
| 278 | { |
||
| 279 | $lang = $this->lang; |
||
| 280 | $data = $this->misc->getDatabaseAccessor(); |
||
| 281 | |||
| 282 | $status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']); |
||
| 283 | if (0 == $status) { |
||
| 284 | $this->doDefinition($lang['strviewupdated']); |
||
| 285 | } else { |
||
| 286 | $this->doEdit($lang['strviewupdatedbad']); |
||
| 287 | } |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Function to allow editing of a view. |
||
| 292 | * |
||
| 293 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 294 | */ |
||
| 295 | public function doEdit($msg = '') |
||
| 329 | } |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Allow the dumping of the data "in" a view |
||
| 334 | * NOTE:: PostgreSQL doesn't currently support dumping the data in a view |
||
| 335 | * so I have disabled the data related parts for now. In the future |
||
| 336 | * we should allow it conditionally if it becomes supported. This is |
||
| 337 | * a SMOP since it is based on pg_dump version not backend version. |
||
| 338 | * |
||
| 339 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 340 | */ |
||
| 341 | public function doExport($msg = '') |
||
| 342 | { |
||
| 343 | $lang = $this->lang; |
||
| 344 | |||
| 345 | $this->printTrail('matview'); |
||
| 346 | $this->printTabs('matview', 'export'); |
||
| 347 | $this->printMsg($msg); |
||
| 348 | |||
| 349 | echo '<form action="' . \SUBFOLDER . "/src/views/dataexport.php\" method=\"post\">\n"; |
||
| 350 | echo "<table>\n"; |
||
| 351 | echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
||
| 352 | // Data only |
||
| 353 | echo "<!--\n"; |
||
| 354 | echo '<tr><th class="data left">'; |
||
| 355 | echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
||
| 356 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 357 | echo "<td><select name=\"d_format\" >\n"; |
||
| 358 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 359 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 360 | echo "<option value=\"csv\">CSV</option>\n"; |
||
| 361 | echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n"; |
||
| 362 | echo "<option value=\"html\">XHTML</option>\n"; |
||
| 363 | echo "<option value=\"xml\">XML</option>\n"; |
||
| 364 | echo "</select>\n</td>\n</tr>\n"; |
||
| 365 | echo "-->\n"; |
||
| 366 | |||
| 367 | // Structure only |
||
| 368 | 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"; |
||
| 369 | echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
||
| 370 | // Structure and data |
||
| 371 | echo "<!--\n"; |
||
| 372 | echo '<tr><th class="data left" rowspan="2">'; |
||
| 373 | echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
||
| 374 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 375 | echo "<td><select name=\"sd_format\">\n"; |
||
| 376 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 377 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 378 | echo "</select>\n</td>\n</tr>\n"; |
||
| 379 | echo "<td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n"; |
||
| 380 | echo "-->\n"; |
||
| 381 | echo "</table>\n"; |
||
| 382 | |||
| 383 | echo "<h3>{$lang['stroptions']}</h3>\n"; |
||
| 384 | echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
||
| 385 | echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n"; |
||
| 386 | |||
| 387 | echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
||
| 388 | echo $this->misc->form; |
||
| 389 | echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
||
| 390 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
||
| 391 | echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
||
| 392 | echo "</form>\n"; |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Show definition for a view. |
||
| 397 | * |
||
| 398 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 399 | */ |
||
| 400 | public function doDefinition($msg = '') |
||
| 401 | { |
||
| 402 | $lang = $this->lang; |
||
| 403 | $data = $this->misc->getDatabaseAccessor(); |
||
| 404 | |||
| 405 | // Get view |
||
| 406 | $vdata = $data->getView($_REQUEST['matview']); |
||
| 407 | |||
| 408 | $this->printTrail('matview'); |
||
| 409 | $this->printTabs('matview', 'definition'); |
||
| 410 | $this->printMsg($msg); |
||
| 411 | |||
| 412 | if ($vdata->recordCount() > 0) { |
||
| 413 | // Show comment if any |
||
| 414 | if (null !== $vdata->fields['relcomment']) { |
||
| 415 | echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
||
| 416 | } |
||
| 417 | |||
| 418 | echo "<table style=\"width: 100%\">\n"; |
||
| 419 | echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n"; |
||
| 420 | echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), "</td></tr>\n"; |
||
| 421 | echo "</table>\n"; |
||
| 422 | } else { |
||
| 423 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 424 | } |
||
| 425 | |||
| 426 | $this->printNavLinks(['alter' => [ |
||
|
1 ignored issue
–
show
|
|||
| 427 | 'attr' => [ |
||
| 428 | 'href' => [ |
||
| 429 | 'url' => 'materializedviewproperties.php', |
||
| 430 | 'urlvars' => [ |
||
| 431 | 'action' => 'edit', |
||
| 432 | 'server' => $_REQUEST['server'], |
||
| 433 | 'database' => $_REQUEST['database'], |
||
| 434 | 'schema' => $_REQUEST['schema'], |
||
| 435 | 'view' => $_REQUEST['matview'], |
||
| 436 | ], |
||
| 437 | ], |
||
| 438 | ], |
||
| 439 | 'content' => $lang['stralter'], |
||
| 440 | ]], 'materializedviewproperties-definition', get_defined_vars()); |
||
|
1 ignored issue
–
show
|
|||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Displays a screen where they can alter a column in a view. |
||
| 445 | * |
||
| 446 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 447 | */ |
||
| 448 | public function doProperties($msg = '') |
||
| 537 | } |
||
| 538 | } |
||
| 539 | |||
| 540 | public function doAlter($confirm = false, $msg = '') |
||
| 652 |