Total Complexity | 93 |
Total Lines | 858 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like SequencesController 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 SequencesController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class SequencesController extends BaseController |
||
15 | { |
||
16 | public $controller_name = 'SequencesController'; |
||
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 | // Print header |
||
31 | $this->printHeader($lang['strsequences']); |
||
32 | $this->printBody(); |
||
33 | |||
34 | switch ($action) { |
||
35 | case 'create': |
||
36 | $this->doCreateSequence(); |
||
37 | |||
38 | break; |
||
39 | case 'save_create_sequence': |
||
40 | if (isset($_POST['create'])) { |
||
41 | $this->doSaveCreateSequence(); |
||
42 | } else { |
||
43 | $this->doDefault(); |
||
44 | } |
||
45 | |||
46 | break; |
||
47 | case 'properties': |
||
48 | $this->doProperties(); |
||
49 | |||
50 | break; |
||
51 | case 'drop': |
||
52 | if (isset($_POST['drop'])) { |
||
53 | $this->doDrop(false); |
||
54 | } else { |
||
55 | $this->doDefault(); |
||
56 | } |
||
57 | |||
58 | break; |
||
59 | case 'confirm_drop': |
||
60 | $this->doDrop(true); |
||
61 | |||
62 | break; |
||
63 | case 'restart': |
||
64 | $this->doRestart(); |
||
65 | |||
66 | break; |
||
67 | case 'reset': |
||
68 | $this->doReset(); |
||
69 | |||
70 | break; |
||
71 | case 'nextval': |
||
72 | $this->doNextval(); |
||
73 | |||
74 | break; |
||
75 | case 'setval': |
||
76 | if (isset($_POST['setval'])) { |
||
77 | $this->doSaveSetval(); |
||
78 | } else { |
||
79 | $this->doDefault(); |
||
80 | } |
||
81 | |||
82 | break; |
||
83 | case 'confirm_setval': |
||
84 | $this->doSetval(); |
||
85 | |||
86 | break; |
||
87 | case 'alter': |
||
88 | if (isset($_POST['alter'])) { |
||
89 | $this->doSaveAlter(); |
||
90 | } else { |
||
91 | $this->doDefault(); |
||
92 | } |
||
93 | |||
94 | break; |
||
95 | case 'confirm_alter': |
||
96 | $this->doAlter(); |
||
97 | |||
98 | break; |
||
99 | default: |
||
100 | $this->doDefault(); |
||
101 | |||
102 | break; |
||
103 | } |
||
104 | |||
105 | // Print footer |
||
106 | return $this->printFooter(); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Display list of all sequences in the database/schema. |
||
111 | * |
||
112 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
113 | */ |
||
114 | public function doDefault($msg = '') |
||
115 | { |
||
116 | $lang = $this->lang; |
||
117 | $data = $this->misc->getDatabaseAccessor(); |
||
118 | |||
119 | $this->printTrail('schema'); |
||
120 | $this->printTabs('schema', 'sequences'); |
||
121 | $this->printMsg($msg); |
||
122 | |||
123 | // Get all sequences |
||
124 | $sequences = $data->getSequences(); |
||
125 | |||
126 | $columns = [ |
||
127 | 'sequence' => [ |
||
128 | 'title' => $lang['strsequence'], |
||
129 | 'field' => Decorator::field('seqname'), |
||
130 | 'url' => "sequences.php?action=properties&{$this->misc->href}&", |
||
131 | 'vars' => ['sequence' => 'seqname'], |
||
132 | ], |
||
133 | 'owner' => [ |
||
134 | 'title' => $lang['strowner'], |
||
135 | 'field' => Decorator::field('seqowner'), |
||
136 | ], |
||
137 | 'actions' => [ |
||
138 | 'title' => $lang['stractions'], |
||
139 | ], |
||
140 | 'comment' => [ |
||
141 | 'title' => $lang['strcomment'], |
||
142 | 'field' => Decorator::field('seqcomment'), |
||
143 | ], |
||
144 | ]; |
||
145 | |||
146 | $actions = [ |
||
147 | 'multiactions' => [ |
||
148 | 'keycols' => ['sequence' => 'seqname'], |
||
149 | 'url' => 'sequences.php', |
||
150 | ], |
||
151 | 'alter' => [ |
||
152 | 'content' => $lang['stralter'], |
||
153 | 'attr' => [ |
||
154 | 'href' => [ |
||
155 | 'url' => 'sequences.php', |
||
156 | 'urlvars' => [ |
||
157 | 'action' => 'confirm_alter', |
||
158 | 'subject' => 'sequence', |
||
159 | 'sequence' => Decorator::field('seqname'), |
||
160 | ], |
||
161 | ], |
||
162 | ], |
||
163 | ], |
||
164 | 'drop' => [ |
||
165 | 'content' => $lang['strdrop'], |
||
166 | 'attr' => [ |
||
167 | 'href' => [ |
||
168 | 'url' => 'sequences.php', |
||
169 | 'urlvars' => [ |
||
170 | 'action' => 'confirm_drop', |
||
171 | 'sequence' => Decorator::field('seqname'), |
||
172 | ], |
||
173 | ], |
||
174 | ], |
||
175 | 'multiaction' => 'confirm_drop', |
||
176 | ], |
||
177 | 'privileges' => [ |
||
178 | 'content' => $lang['strprivileges'], |
||
179 | 'attr' => [ |
||
180 | 'href' => [ |
||
181 | 'url' => 'privileges.php', |
||
182 | 'urlvars' => [ |
||
183 | 'subject' => 'sequence', |
||
184 | 'sequence' => Decorator::field('seqname'), |
||
185 | ], |
||
186 | ], |
||
187 | ], |
||
188 | ], |
||
189 | ]; |
||
190 | |||
191 | echo $this->printTable($sequences, $columns, $actions, 'sequences-sequences', $lang['strnosequences']); |
||
192 | |||
193 | $this->printNavLinks(['create' => [ |
||
1 ignored issue
–
show
|
|||
194 | 'attr' => [ |
||
195 | 'href' => [ |
||
196 | 'url' => 'sequences.php', |
||
197 | 'urlvars' => [ |
||
198 | 'action' => 'create', |
||
199 | 'server' => $_REQUEST['server'], |
||
200 | 'database' => $_REQUEST['database'], |
||
201 | 'schema' => $_REQUEST['schema'], |
||
202 | ], |
||
203 | ], |
||
204 | ], |
||
205 | 'content' => $lang['strcreatesequence'], |
||
206 | ]], 'sequences-sequences', get_defined_vars()); |
||
1 ignored issue
–
show
|
|||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Generate XML for the browser tree. |
||
211 | */ |
||
212 | public function doTree() |
||
213 | { |
||
214 | $lang = $this->lang; |
||
215 | $data = $this->misc->getDatabaseAccessor(); |
||
216 | |||
217 | $sequences = $data->getSequences(); |
||
218 | |||
219 | $reqvars = $this->misc->getRequestVars('sequence'); |
||
220 | |||
221 | $attrs = [ |
||
222 | 'text' => Decorator::field('seqname'), |
||
223 | 'icon' => 'Sequence', |
||
224 | 'toolTip' => Decorator::field('seqcomment'), |
||
225 | 'action' => Decorator::actionurl( |
||
226 | 'sequences.php', |
||
227 | $reqvars, |
||
228 | [ |
||
229 | 'action' => 'properties', |
||
230 | 'sequence' => Decorator::field('seqname'), |
||
231 | ] |
||
232 | ), |
||
233 | ]; |
||
234 | |||
235 | return $this->printTree($sequences, $attrs, 'sequences'); |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Display the properties of a sequence. |
||
240 | * |
||
241 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
242 | */ |
||
243 | public function doProperties($msg = '') |
||
244 | { |
||
245 | $lang = $this->lang; |
||
246 | $data = $this->misc->getDatabaseAccessor(); |
||
247 | $this->printTrail('sequence'); |
||
248 | $this->printTitle($lang['strproperties'], 'pg.sequence'); |
||
249 | $this->printMsg($msg); |
||
250 | |||
251 | // Fetch the sequence information |
||
252 | $sequence = $data->getSequence($_REQUEST['sequence']); |
||
253 | |||
254 | if (is_object($sequence) && $sequence->recordCount() > 0) { |
||
255 | $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']); |
||
256 | $sequence->fields['is_called'] = $data->phpBool($sequence->fields['is_called']); |
||
257 | |||
258 | // Show comment if any |
||
259 | if (null !== $sequence->fields['seqcomment']) { |
||
260 | echo '<p class="comment">', $this->misc->printVal($sequence->fields['seqcomment']), "</p>\n"; |
||
261 | } |
||
262 | |||
263 | echo '<table border="0">'; |
||
264 | echo "<tr><th class=\"data\">{$lang['strname']}</th>"; |
||
265 | if ($data->hasAlterSequenceStart()) { |
||
266 | echo "<th class=\"data\">{$lang['strstartvalue']}</th>"; |
||
267 | } |
||
268 | echo "<th class=\"data\">{$lang['strlastvalue']}</th>"; |
||
269 | echo "<th class=\"data\">{$lang['strincrementby']}</th>"; |
||
270 | echo "<th class=\"data\">{$lang['strmaxvalue']}</th>"; |
||
271 | echo "<th class=\"data\">{$lang['strminvalue']}</th>"; |
||
272 | echo "<th class=\"data\">{$lang['strcachevalue']}</th>"; |
||
273 | echo "<th class=\"data\">{$lang['strlogcount']}</th>"; |
||
274 | echo "<th class=\"data\">{$lang['strcancycle']}</th>"; |
||
275 | echo "<th class=\"data\">{$lang['striscalled']}</th></tr>"; |
||
276 | echo '<tr>'; |
||
277 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['seqname']), '</td>'; |
||
278 | if ($data->hasAlterSequenceStart()) { |
||
279 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['start_value']), '</td>'; |
||
280 | } |
||
281 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['last_value']), '</td>'; |
||
282 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['increment_by']), '</td>'; |
||
283 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['max_value']), '</td>'; |
||
284 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['min_value']), '</td>'; |
||
285 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['cache_value']), '</td>'; |
||
286 | echo '<td class="data1">', $this->misc->printVal($sequence->fields['log_cnt']), '</td>'; |
||
287 | echo '<td class="data1">', ($sequence->fields['is_cycled'] ? $lang['stryes'] : $lang['strno']), '</td>'; |
||
288 | echo '<td class="data1">', ($sequence->fields['is_called'] ? $lang['stryes'] : $lang['strno']), '</td>'; |
||
289 | echo '</tr>'; |
||
290 | echo '</table>'; |
||
291 | |||
292 | $navlinks = [ |
||
293 | 'alter' => [ |
||
294 | 'attr' => [ |
||
295 | 'href' => [ |
||
296 | 'url' => 'sequences.php', |
||
297 | 'urlvars' => [ |
||
298 | 'action' => 'confirm_alter', |
||
299 | 'server' => $_REQUEST['server'], |
||
300 | 'database' => $_REQUEST['database'], |
||
301 | 'schema' => $_REQUEST['schema'], |
||
302 | 'sequence' => $sequence->fields['seqname'], |
||
303 | ], |
||
304 | ], |
||
305 | ], |
||
306 | 'content' => $lang['stralter'], |
||
307 | ], |
||
308 | 'setval' => [ |
||
309 | 'attr' => [ |
||
310 | 'href' => [ |
||
311 | 'url' => 'sequences.php', |
||
312 | 'urlvars' => [ |
||
313 | 'action' => 'confirm_setval', |
||
314 | 'server' => $_REQUEST['server'], |
||
315 | 'database' => $_REQUEST['database'], |
||
316 | 'schema' => $_REQUEST['schema'], |
||
317 | 'sequence' => $sequence->fields['seqname'], |
||
318 | ], |
||
319 | ], |
||
320 | ], |
||
321 | 'content' => $lang['strsetval'], |
||
322 | ], |
||
323 | 'nextval' => [ |
||
324 | 'attr' => [ |
||
325 | 'href' => [ |
||
326 | 'url' => 'sequences.php', |
||
327 | 'urlvars' => [ |
||
328 | 'action' => 'nextval', |
||
329 | 'server' => $_REQUEST['server'], |
||
330 | 'database' => $_REQUEST['database'], |
||
331 | 'schema' => $_REQUEST['schema'], |
||
332 | 'sequence' => $sequence->fields['seqname'], |
||
333 | ], |
||
334 | ], |
||
335 | ], |
||
336 | 'content' => $lang['strnextval'], |
||
337 | ], |
||
338 | 'restart' => [ |
||
339 | 'attr' => [ |
||
340 | 'href' => [ |
||
341 | 'url' => 'sequences.php', |
||
342 | 'urlvars' => [ |
||
343 | 'action' => 'restart', |
||
344 | 'server' => $_REQUEST['server'], |
||
345 | 'database' => $_REQUEST['database'], |
||
346 | 'schema' => $_REQUEST['schema'], |
||
347 | 'sequence' => $sequence->fields['seqname'], |
||
348 | ], |
||
349 | ], |
||
350 | ], |
||
351 | 'content' => $lang['strrestart'], |
||
352 | ], |
||
353 | 'reset' => [ |
||
354 | 'attr' => [ |
||
355 | 'href' => [ |
||
356 | 'url' => 'sequences.php', |
||
357 | 'urlvars' => [ |
||
358 | 'action' => 'reset', |
||
359 | 'server' => $_REQUEST['server'], |
||
360 | 'database' => $_REQUEST['database'], |
||
361 | 'schema' => $_REQUEST['schema'], |
||
362 | 'sequence' => $sequence->fields['seqname'], |
||
363 | ], |
||
364 | ], |
||
365 | ], |
||
366 | 'content' => $lang['strreset'], |
||
367 | ], |
||
368 | 'showall' => [ |
||
369 | 'attr' => [ |
||
370 | 'href' => [ |
||
371 | 'url' => 'sequences.php', |
||
372 | 'urlvars' => [ |
||
373 | 'server' => $_REQUEST['server'], |
||
374 | 'database' => $_REQUEST['database'], |
||
375 | 'schema' => $_REQUEST['schema'], |
||
376 | ], |
||
377 | ], |
||
378 | ], |
||
379 | 'content' => $lang['strshowallsequences'], |
||
380 | ], |
||
381 | ]; |
||
382 | |||
383 | if (!$data->hasAlterSequenceStart()) { |
||
384 | unset($navlinks['restart']); |
||
385 | } |
||
386 | |||
387 | $this->printNavLinks($navlinks, 'sequences-properties', get_defined_vars()); |
||
388 | } else { |
||
389 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
390 | } |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * Drop a sequence. |
||
395 | * |
||
396 | * @param mixed $confirm |
||
1 ignored issue
–
show
|
|||
397 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
398 | */ |
||
399 | public function doDrop($confirm, $msg = '') |
||
400 | { |
||
401 | $lang = $this->lang; |
||
402 | $data = $this->misc->getDatabaseAccessor(); |
||
403 | |||
404 | if (empty($_REQUEST['sequence']) && empty($_REQUEST['ma'])) { |
||
405 | return $this->doDefault($lang['strspecifysequencetodrop']); |
||
406 | } |
||
407 | |||
408 | if ($confirm) { |
||
409 | $this->printTrail('sequence'); |
||
410 | $this->printTitle($lang['strdrop'], 'pg.sequence.drop'); |
||
411 | $this->printMsg($msg); |
||
412 | |||
413 | echo '<form action="' . \SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
||
414 | |||
415 | //If multi drop |
||
416 | if (isset($_REQUEST['ma'])) { |
||
417 | foreach ($_REQUEST['ma'] as $v) { |
||
418 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
419 | echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($a['sequence'])), "</p>\n"; |
||
420 | printf('<input type="hidden" name="sequence[]" value="%s" />', htmlspecialchars($a['sequence'])); |
||
421 | } |
||
422 | } else { |
||
423 | echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($_REQUEST['sequence'])), "</p>\n"; |
||
424 | echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
||
425 | } |
||
426 | |||
427 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n"; |
||
428 | echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
429 | echo $this->misc->form; |
||
430 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
431 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
432 | echo "</form>\n"; |
||
433 | } else { |
||
434 | if (is_array($_POST['sequence'])) { |
||
435 | $msg = ''; |
||
436 | $status = $data->beginTransaction(); |
||
437 | if (0 == $status) { |
||
438 | foreach ($_POST['sequence'] as $s) { |
||
439 | $status = $data->dropSequence($s, isset($_POST['cascade'])); |
||
440 | if (0 == $status) { |
||
441 | $msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedropped']); |
||
442 | } else { |
||
443 | $data->endTransaction(); |
||
444 | $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedroppedbad'])); |
||
445 | |||
446 | return; |
||
447 | } |
||
448 | } |
||
449 | } |
||
450 | if (0 == $data->endTransaction()) { |
||
451 | // Everything went fine, back to the Default page.... |
||
452 | $this->misc->setReloadBrowser(true); |
||
453 | $this->doDefault($msg); |
||
454 | } else { |
||
455 | $this->doDefault($lang['strsequencedroppedbad']); |
||
456 | } |
||
457 | } else { |
||
458 | $status = $data->dropSequence($_POST['sequence'], isset($_POST['cascade'])); |
||
459 | if (0 == $status) { |
||
460 | $this->misc->setReloadBrowser(true); |
||
461 | $this->doDefault($lang['strsequencedropped']); |
||
462 | } else { |
||
463 | $this->doDrop(true, $lang['strsequencedroppedbad']); |
||
464 | } |
||
465 | } |
||
466 | } |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * Displays a screen where they can enter a new sequence. |
||
471 | * |
||
472 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
473 | */ |
||
474 | public function doCreateSequence($msg = '') |
||
475 | { |
||
476 | $lang = $this->lang; |
||
477 | $data = $this->misc->getDatabaseAccessor(); |
||
478 | |||
479 | if (!isset($_POST['formSequenceName'])) { |
||
480 | $_POST['formSequenceName'] = ''; |
||
481 | } |
||
482 | |||
483 | if (!isset($_POST['formIncrement'])) { |
||
484 | $_POST['formIncrement'] = ''; |
||
485 | } |
||
486 | |||
487 | if (!isset($_POST['formMinValue'])) { |
||
488 | $_POST['formMinValue'] = ''; |
||
489 | } |
||
490 | |||
491 | if (!isset($_POST['formMaxValue'])) { |
||
492 | $_POST['formMaxValue'] = ''; |
||
493 | } |
||
494 | |||
495 | if (!isset($_POST['formStartValue'])) { |
||
496 | $_POST['formStartValue'] = ''; |
||
497 | } |
||
498 | |||
499 | if (!isset($_POST['formCacheValue'])) { |
||
500 | $_POST['formCacheValue'] = ''; |
||
501 | } |
||
502 | |||
503 | $this->printTrail('schema'); |
||
504 | $this->printTitle($lang['strcreatesequence'], 'pg.sequence.create'); |
||
505 | $this->printMsg($msg); |
||
506 | |||
507 | echo '<form action="' . \SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
||
508 | echo "<table>\n"; |
||
509 | |||
510 | echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
511 | echo "<td class=\"data1\"><input name=\"formSequenceName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
512 | htmlspecialchars($_POST['formSequenceName']), "\" /></td></tr>\n"; |
||
513 | |||
514 | echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n"; |
||
515 | echo '<td class="data1"><input name="formIncrement" size="5" value="', |
||
516 | htmlspecialchars($_POST['formIncrement']), "\" /> </td></tr>\n"; |
||
517 | |||
518 | echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n"; |
||
519 | echo '<td class="data1"><input name="formMinValue" size="5" value="', |
||
520 | htmlspecialchars($_POST['formMinValue']), "\" /></td></tr>\n"; |
||
521 | |||
522 | echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n"; |
||
523 | echo '<td class="data1"><input name="formMaxValue" size="5" value="', |
||
524 | htmlspecialchars($_POST['formMaxValue']), "\" /></td></tr>\n"; |
||
525 | |||
526 | echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n"; |
||
527 | echo '<td class="data1"><input name="formStartValue" size="5" value="', |
||
528 | htmlspecialchars($_POST['formStartValue']), "\" /></td></tr>\n"; |
||
529 | |||
530 | echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n"; |
||
531 | echo '<td class="data1"><input name="formCacheValue" size="5" value="', |
||
532 | htmlspecialchars($_POST['formCacheValue']), "\" /></td></tr>\n"; |
||
533 | |||
534 | echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n"; |
||
535 | echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ', |
||
536 | (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n"; |
||
537 | |||
538 | echo "</table>\n"; |
||
539 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n"; |
||
540 | echo $this->misc->form; |
||
541 | echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; |
||
542 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
543 | echo "</form>\n"; |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * Actually creates the new sequence in the database. |
||
548 | */ |
||
549 | public function doSaveCreateSequence() |
||
550 | { |
||
551 | $lang = $this->lang; |
||
552 | $data = $this->misc->getDatabaseAccessor(); |
||
553 | |||
554 | // Check that they've given a name and at least one column |
||
555 | if ('' == $_POST['formSequenceName']) { |
||
556 | $this->doCreateSequence($lang['strsequenceneedsname']); |
||
557 | } else { |
||
558 | $status = $data->createSequence( |
||
559 | $_POST['formSequenceName'], |
||
560 | $_POST['formIncrement'], |
||
561 | $_POST['formMinValue'], |
||
562 | $_POST['formMaxValue'], |
||
563 | $_POST['formStartValue'], |
||
564 | $_POST['formCacheValue'], |
||
565 | isset($_POST['formCycledValue']) |
||
566 | ); |
||
567 | if (0 == $status) { |
||
568 | $this->doDefault($lang['strsequencecreated']); |
||
569 | } else { |
||
570 | $this->doCreateSequence($lang['strsequencecreatedbad']); |
||
571 | } |
||
572 | } |
||
573 | } |
||
574 | |||
575 | /** |
||
576 | * Restarts a sequence. |
||
577 | */ |
||
578 | public function doRestart() |
||
579 | { |
||
580 | $lang = $this->lang; |
||
581 | $data = $this->misc->getDatabaseAccessor(); |
||
582 | |||
583 | $status = $data->restartSequence($_REQUEST['sequence']); |
||
584 | if (0 == $status) { |
||
585 | $this->doProperties($lang['strsequencerestart']); |
||
586 | } else { |
||
587 | $this->doProperties($lang['strsequencerestartbad']); |
||
588 | } |
||
589 | } |
||
590 | |||
591 | /** |
||
592 | * Resets a sequence. |
||
593 | */ |
||
594 | public function doReset() |
||
595 | { |
||
596 | $lang = $this->lang; |
||
597 | $data = $this->misc->getDatabaseAccessor(); |
||
598 | |||
599 | $status = $data->resetSequence($_REQUEST['sequence']); |
||
600 | if (0 == $status) { |
||
601 | $this->doProperties($lang['strsequencereset']); |
||
602 | } else { |
||
603 | $this->doProperties($lang['strsequenceresetbad']); |
||
604 | } |
||
605 | } |
||
606 | |||
607 | /** |
||
608 | * Set Nextval of a sequence. |
||
609 | */ |
||
610 | public function doNextval() |
||
611 | { |
||
612 | $lang = $this->lang; |
||
613 | $data = $this->misc->getDatabaseAccessor(); |
||
614 | |||
615 | $status = $data->nextvalSequence($_REQUEST['sequence']); |
||
616 | if (0 == $status) { |
||
617 | $this->doProperties($lang['strsequencenextval']); |
||
618 | } else { |
||
619 | $this->doProperties($lang['strsequencenextvalbad']); |
||
620 | } |
||
621 | } |
||
622 | |||
623 | /** |
||
624 | * Function to save after 'setval'ing a sequence. |
||
625 | */ |
||
626 | public function doSaveSetval() |
||
627 | { |
||
628 | $lang = $this->lang; |
||
629 | $data = $this->misc->getDatabaseAccessor(); |
||
630 | |||
631 | $status = $data->setvalSequence($_POST['sequence'], $_POST['nextvalue']); |
||
632 | if (0 == $status) { |
||
633 | $this->doProperties($lang['strsequencesetval']); |
||
634 | } else { |
||
635 | $this->doProperties($lang['strsequencesetvalbad']); |
||
636 | } |
||
637 | } |
||
638 | |||
639 | /** |
||
640 | * Function to allow 'setval'ing of a sequence. |
||
641 | * |
||
642 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
643 | */ |
||
644 | public function doSetval($msg = '') |
||
645 | { |
||
646 | $lang = $this->lang; |
||
647 | $data = $this->misc->getDatabaseAccessor(); |
||
648 | |||
649 | $this->printTrail('sequence'); |
||
650 | $this->printTitle($lang['strsetval'], 'pg.sequence'); |
||
651 | $this->printMsg($msg); |
||
652 | |||
653 | // Fetch the sequence information |
||
654 | $sequence = $data->getSequence($_REQUEST['sequence']); |
||
655 | |||
656 | if (is_object($sequence) && $sequence->recordCount() > 0) { |
||
657 | echo '<form action="' . \SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n"; |
||
658 | echo '<table border="0">'; |
||
659 | echo "<tr><th class=\"data left required\">{$lang['strlastvalue']}</th>\n"; |
||
660 | echo '<td class="data1">'; |
||
661 | echo "<input name=\"nextvalue\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
662 | $this->misc->printVal($sequence->fields['last_value']), "\" /></td></tr>\n"; |
||
663 | echo "</table>\n"; |
||
664 | echo "<p><input type=\"hidden\" name=\"action\" value=\"setval\" />\n"; |
||
665 | echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n"; |
||
666 | echo $this->misc->form; |
||
667 | echo "<input type=\"submit\" name=\"setval\" value=\"{$lang['strsetval']}\" />\n"; |
||
668 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
669 | echo "</form>\n"; |
||
670 | } else { |
||
671 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
672 | } |
||
673 | } |
||
674 | |||
675 | /** |
||
676 | * Function to save after altering a sequence. |
||
677 | */ |
||
678 | public function doSaveAlter() |
||
749 | } |
||
750 | } |
||
751 | |||
752 | /** |
||
753 | * Function to allow altering of a sequence. |
||
754 | * |
||
755 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
756 | */ |
||
757 | public function doAlter($msg = '') |
||
872 | } |
||
873 | } |
||
874 | } |
||
875 |