| Conditions | 13 |
| Paths | 10 |
| Total Lines | 95 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 266 | public function doAlter($confirm = false, $msg = '') |
||
| 267 | { |
||
| 268 | $data = $this->misc->getDatabaseAccessor(); |
||
| 269 | |||
| 270 | if ($confirm) { |
||
| 271 | $this->printTrail($this->subject); |
||
| 272 | $this->printTitle($this->lang['stralter'], 'pg.matview.alter'); |
||
| 273 | $this->printMsg($msg); |
||
| 274 | |||
| 275 | // Fetch matview info |
||
| 276 | $matview = $data->getView($_REQUEST[$this->subject]); |
||
| 277 | |||
| 278 | if ($matview->recordCount() > 0) { |
||
| 279 | $this->coalesceArr($_POST, 'name', $matview->fields['relname']); |
||
| 280 | |||
| 281 | $this->coalesceArr($_POST, 'owner', $matview->fields['relowner']); |
||
| 282 | |||
| 283 | $this->coalesceArr($_POST, 'newschema', $matview->fields['nspname']); |
||
| 284 | |||
| 285 | $this->coalesceArr($_POST, 'comment', $matview->fields['relcomment']); |
||
| 286 | |||
| 287 | echo '<form action="'.\SUBFOLDER."/src/views/materializedviewproperties\" method=\"post\">\n"; |
||
| 288 | echo "<table>\n"; |
||
| 289 | echo "<tr><th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 290 | echo '<td class="data1">'; |
||
| 291 | echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 292 | htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; |
||
| 293 | |||
| 294 | if ($data->isSuperUser()) { |
||
| 295 | // Fetch all users |
||
| 296 | $users = $data->getUsers(); |
||
| 297 | |||
| 298 | echo "<tr><th class=\"data left required\">{$this->lang['strowner']}</th>\n"; |
||
| 299 | echo '<td class="data1"><select name="owner">'; |
||
| 300 | while (!$users->EOF) { |
||
| 301 | $uname = $users->fields['usename']; |
||
| 302 | echo '<option value="', htmlspecialchars($uname), '"', |
||
| 303 | ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
||
| 304 | $users->moveNext(); |
||
| 305 | } |
||
| 306 | echo "</select></td></tr>\n"; |
||
| 307 | } |
||
| 308 | |||
| 309 | if ($data->hasAlterTableSchema()) { |
||
| 310 | $schemas = $data->getSchemas(); |
||
| 311 | echo "<tr><th class=\"data left required\">{$this->lang['strschema']}</th>\n"; |
||
| 312 | echo '<td class="data1"><select name="newschema">'; |
||
| 313 | while (!$schemas->EOF) { |
||
| 314 | $schema = $schemas->fields['nspname']; |
||
| 315 | echo '<option value="', htmlspecialchars($schema), '"', |
||
| 316 | ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
||
| 317 | $schemas->moveNext(); |
||
| 318 | } |
||
| 319 | echo "</select></td></tr>\n"; |
||
| 320 | } |
||
| 321 | |||
| 322 | echo "<tr><th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
| 323 | echo '<td class="data1">'; |
||
| 324 | echo '<textarea rows="3" cols="32" name="comment">'; |
||
| 325 | echo htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n"; |
||
| 326 | echo "</table>\n"; |
||
| 327 | echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
||
| 328 | echo '<input type="hidden" name="matview" value="', htmlspecialchars($_REQUEST[$this->subject]), "\" />\n"; |
||
| 329 | echo $this->misc->form; |
||
| 330 | echo "<p><input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />\n"; |
||
| 331 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 332 | echo "</form>\n"; |
||
| 333 | } else { |
||
| 334 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
| 335 | } |
||
| 336 | } else { |
||
| 337 | // For databases that don't allow owner change |
||
| 338 | $this->coalesceArr($_POST, 'owner', ''); |
||
| 339 | |||
| 340 | $this->coalesceArr($_POST, 'newschema', null); |
||
| 341 | |||
| 342 | $status = $data->alterView($_POST[$this->subject], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); |
||
| 343 | if (0 == $status) { |
||
| 344 | // If matview has been renamed, need to change to the new name and |
||
| 345 | // reload the browser frame. |
||
| 346 | if ($_POST[$this->subject] != $_POST['name']) { |
||
| 347 | // Jump them to the new matview name |
||
| 348 | $_REQUEST[$this->subject] = $_POST['name']; |
||
| 349 | // Force a browser reload |
||
| 350 | $this->misc->setReloadBrowser(true); |
||
| 351 | } |
||
| 352 | // If schema has changed, need to change to the new schema and reload the browser |
||
| 353 | if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { |
||
| 354 | // Jump them to the new sequence schema |
||
| 355 | $this->misc->setCurrentSchema($_POST['newschema']); |
||
| 356 | $this->misc->setReloadBrowser(true); |
||
| 357 | } |
||
| 358 | $this->doDefault($this->lang['strviewaltered']); |
||
| 359 | } else { |
||
| 360 | $this->doAlter(true, $this->lang['strviewalteredbad']); |
||
| 361 | } |
||
| 365 |