|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHPPgAdmin\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use \PHPPgAdmin\Decorators\Decorator; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Base controller class |
|
9
|
|
|
*/ |
|
10
|
|
|
class IndexesController extends BaseController |
|
11
|
|
|
{ |
|
12
|
|
|
public $_name = 'IndexesController'; |
|
13
|
|
|
|
|
14
|
|
|
public function render() |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
17
|
|
|
$misc = $this->misc; |
|
|
|
|
|
|
18
|
|
|
$lang = $this->lang; |
|
19
|
|
|
|
|
20
|
|
|
$action = $this->action; |
|
21
|
|
|
if ($action == 'tree') { |
|
22
|
|
|
return $this->doTree(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$this->printHeader($lang['strindexes'], '<script src="' . SUBFOLDER . '/js/indexes.js" type="text/javascript"></script>'); |
|
26
|
|
|
|
|
27
|
|
|
if ($action == 'create_index' || $action == 'save_create_index') { |
|
28
|
|
|
echo '<body onload="init();">'; |
|
29
|
|
|
} else { |
|
30
|
|
|
$this->printBody(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
switch ($action) { |
|
34
|
|
|
case 'cluster_index': |
|
35
|
|
|
if (isset($_POST['cluster'])) { |
|
36
|
|
|
$this->doClusterIndex(false); |
|
37
|
|
|
} else { |
|
38
|
|
|
$this->doDefault(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
break; |
|
42
|
|
|
case 'confirm_cluster_index': |
|
43
|
|
|
$this->doClusterIndex(true); |
|
44
|
|
|
break; |
|
45
|
|
|
case 'reindex': |
|
46
|
|
|
$this->doReindex(); |
|
47
|
|
|
break; |
|
48
|
|
|
case 'save_create_index': |
|
49
|
|
|
if (isset($_POST['cancel'])) { |
|
50
|
|
|
$this->doDefault(); |
|
51
|
|
|
} else { |
|
52
|
|
|
$this->doSaveCreateIndex(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
break; |
|
56
|
|
|
case 'create_index': |
|
57
|
|
|
$this->doCreateIndex(); |
|
58
|
|
|
break; |
|
59
|
|
|
case 'drop_index': |
|
60
|
|
|
if (isset($_POST['drop'])) { |
|
61
|
|
|
$this->doDropIndex(false); |
|
62
|
|
|
} else { |
|
63
|
|
|
$this->doDefault(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
break; |
|
67
|
|
|
case 'confirm_drop_index': |
|
68
|
|
|
$this->doDropIndex(true); |
|
69
|
|
|
break; |
|
70
|
|
|
default: |
|
71
|
|
|
$this->doDefault(); |
|
72
|
|
|
break; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->printFooter(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function doDefault($msg = '') |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
$conf = $this->conf; |
|
81
|
|
|
$misc = $this->misc; |
|
82
|
|
|
$lang = $this->lang; |
|
83
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
84
|
|
|
|
|
85
|
|
|
$indPre = function (&$rowdata, $actions) use ($data, $lang) { |
|
86
|
|
|
if ($data->phpBool($rowdata->fields['indisprimary'])) { |
|
87
|
|
|
$rowdata->fields['+constraints'] = $lang['strprimarykey']; |
|
88
|
|
|
$actions['drop']['disable'] = true; |
|
89
|
|
|
} elseif ($data->phpBool($rowdata->fields['indisunique'])) { |
|
90
|
|
|
$rowdata->fields['+constraints'] = $lang['struniquekey']; |
|
91
|
|
|
$actions['drop']['disable'] = true; |
|
92
|
|
|
} else { |
|
93
|
|
|
$rowdata->fields['+constraints'] = ''; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $actions; |
|
97
|
|
|
}; |
|
98
|
|
|
if (!isset($_REQUEST['subject'])) { |
|
99
|
|
|
$_REQUEST['subject'] = 'table'; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$subject = urlencode($_REQUEST['subject']); |
|
103
|
|
|
$object = urlencode($_REQUEST[$_REQUEST['subject']]); |
|
104
|
|
|
|
|
105
|
|
|
$this->printTrail($subject); |
|
106
|
|
|
$this->printTabs($subject, 'indexes'); |
|
107
|
|
|
$this->printMsg($msg); |
|
108
|
|
|
|
|
109
|
|
|
$indexes = $data->getIndexes($_REQUEST[$_REQUEST['subject']]); |
|
110
|
|
|
|
|
111
|
|
|
$columns = [ |
|
112
|
|
|
'index' => [ |
|
113
|
|
|
'title' => $lang['strname'], |
|
114
|
|
|
'field' => Decorator::field('indname'), |
|
115
|
|
|
], |
|
116
|
|
|
'definition' => [ |
|
117
|
|
|
'title' => $lang['strdefinition'], |
|
118
|
|
|
'field' => Decorator::field('inddef'), |
|
119
|
|
|
], |
|
120
|
|
|
'constraints' => [ |
|
121
|
|
|
'title' => $lang['strconstraints'], |
|
122
|
|
|
'field' => Decorator::field('+constraints'), |
|
123
|
|
|
'type' => 'verbatim', |
|
124
|
|
|
'params' => ['align' => 'center'], |
|
125
|
|
|
], |
|
126
|
|
|
'clustered' => [ |
|
127
|
|
|
'title' => $lang['strclustered'], |
|
128
|
|
|
'field' => Decorator::field('indisclustered'), |
|
129
|
|
|
'type' => 'yesno', |
|
130
|
|
|
], |
|
131
|
|
|
'actions' => [ |
|
132
|
|
|
'title' => $lang['stractions'], |
|
133
|
|
|
], |
|
134
|
|
|
'comment' => [ |
|
135
|
|
|
'title' => $lang['strcomment'], |
|
136
|
|
|
'field' => Decorator::field('idxcomment'), |
|
137
|
|
|
], |
|
138
|
|
|
]; |
|
139
|
|
|
|
|
140
|
|
|
$actions = [ |
|
141
|
|
|
'cluster' => [ |
|
142
|
|
|
'content' => $lang['strclusterindex'], |
|
143
|
|
|
'attr' => [ |
|
144
|
|
|
'href' => [ |
|
145
|
|
|
'url' => 'indexes.php', |
|
146
|
|
|
'urlvars' => [ |
|
147
|
|
|
'action' => 'confirm_cluster_index', |
|
148
|
|
|
$subject => $object, |
|
149
|
|
|
'index' => Decorator::field('indname'), |
|
150
|
|
|
], |
|
151
|
|
|
], |
|
152
|
|
|
], |
|
153
|
|
|
], |
|
154
|
|
|
'reindex' => [ |
|
155
|
|
|
'content' => $lang['strreindex'], |
|
156
|
|
|
'attr' => [ |
|
157
|
|
|
'href' => [ |
|
158
|
|
|
'url' => 'indexes.php', |
|
159
|
|
|
'urlvars' => [ |
|
160
|
|
|
'action' => 'reindex', |
|
161
|
|
|
$subject => $object, |
|
162
|
|
|
'index' => Decorator::field('indname'), |
|
163
|
|
|
], |
|
164
|
|
|
], |
|
165
|
|
|
], |
|
166
|
|
|
], |
|
167
|
|
|
'drop' => [ |
|
168
|
|
|
'content' => $lang['strdrop'], |
|
169
|
|
|
'attr' => [ |
|
170
|
|
|
'href' => [ |
|
171
|
|
|
'url' => 'indexes.php', |
|
172
|
|
|
'urlvars' => [ |
|
173
|
|
|
'action' => 'confirm_drop_index', |
|
174
|
|
|
$subject => $object, |
|
175
|
|
|
'index' => Decorator::field('indname'), |
|
176
|
|
|
], |
|
177
|
|
|
], |
|
178
|
|
|
], |
|
179
|
|
|
], |
|
180
|
|
|
]; |
|
181
|
|
|
|
|
182
|
|
|
echo $this->printTable($indexes, $columns, $actions, 'indexes-indexes', $lang['strnoindexes'], $indPre); |
|
183
|
|
|
|
|
184
|
|
|
$this->printNavLinks([ |
|
185
|
|
|
'create' => [ |
|
186
|
|
|
'attr' => [ |
|
187
|
|
|
'href' => [ |
|
188
|
|
|
'url' => 'indexes.php', |
|
189
|
|
|
'urlvars' => [ |
|
190
|
|
|
'action' => 'create_index', |
|
191
|
|
|
'server' => $_REQUEST['server'], |
|
192
|
|
|
'database' => $_REQUEST['database'], |
|
193
|
|
|
'schema' => $_REQUEST['schema'], |
|
194
|
|
|
$subject => $object, |
|
195
|
|
|
'subject' => $subject, |
|
196
|
|
|
], |
|
197
|
|
|
], |
|
198
|
|
|
], |
|
199
|
|
|
'content' => $lang['strcreateindex'], |
|
200
|
|
|
], |
|
201
|
|
|
], 'indexes-indexes', get_defined_vars()); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function doTree() |
|
|
|
|
|
|
205
|
|
|
{ |
|
206
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
207
|
|
|
$misc = $this->misc; |
|
208
|
|
|
$lang = $this->lang; |
|
|
|
|
|
|
209
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
210
|
|
|
if (!isset($_REQUEST['subject'])) { |
|
211
|
|
|
$_REQUEST['subject'] = 'table'; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
$subject = urlencode($_REQUEST['subject']); |
|
215
|
|
|
$object = urlencode($_REQUEST[$_REQUEST['subject']]); |
|
216
|
|
|
|
|
217
|
|
|
$indexes = $data->getIndexes($object); |
|
218
|
|
|
|
|
219
|
|
|
$reqvars = $misc->getRequestVars($subject); |
|
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
$getIcon = function ($f) { |
|
222
|
|
|
if ($f['indisprimary'] == 't') { |
|
223
|
|
|
return 'PrimaryKey'; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
if ($f['indisunique'] == 't') { |
|
227
|
|
|
return 'UniqueConstraint'; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
return 'Index'; |
|
231
|
|
|
}; |
|
232
|
|
|
|
|
233
|
|
|
$attrs = [ |
|
234
|
|
|
'text' => Decorator::field('indname'), |
|
235
|
|
|
'icon' => Decorator::callback($getIcon), |
|
236
|
|
|
]; |
|
237
|
|
|
|
|
238
|
|
|
return $this->printTree($indexes, $attrs, 'indexes'); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Show confirmation of cluster index and perform actual cluster |
|
243
|
|
|
*/ |
|
244
|
|
|
public function doClusterIndex($confirm) |
|
|
|
|
|
|
245
|
|
|
{ |
|
246
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
247
|
|
|
$misc = $this->misc; |
|
248
|
|
|
$lang = $this->lang; |
|
249
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
250
|
|
|
|
|
251
|
|
|
if ($confirm) { |
|
252
|
|
|
// Default analyze to on |
|
253
|
|
|
$_REQUEST['analyze'] = true; |
|
254
|
|
|
|
|
255
|
|
|
$this->printTrail('index'); |
|
256
|
|
|
$this->printTitle($lang['strclusterindex'], 'pg.index.cluster'); |
|
257
|
|
|
|
|
258
|
|
|
echo '<p>', sprintf($lang['strconfcluster'], $misc->printVal($_REQUEST['index'])), '</p>' . "\n"; |
|
259
|
|
|
|
|
260
|
|
|
echo '<form action="' . SUBFOLDER . '/src/views/indexes.php" method="post">' . "\n"; |
|
261
|
|
|
echo '<p><input type="checkbox" id="analyze" name="analyze"', (isset($_REQUEST['analyze']) ? ' checked="checked"' : ''), ' />'; |
|
262
|
|
|
echo "<label for=\"analyze\">{$lang['stranalyze']}</label></p>" . "\n"; |
|
263
|
|
|
echo '<input type="hidden" name="action" value="cluster_index" />' . "\n"; |
|
264
|
|
|
echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), '" />' . "\n"; |
|
265
|
|
|
echo '<input type="hidden" name="index" value="', htmlspecialchars($_REQUEST['index']), '" />' . "\n"; |
|
266
|
|
|
echo $misc->form; |
|
267
|
|
|
echo "<input type=\"submit\" name=\"cluster\" value=\"{$lang['strclusterindex']}\" />" . "\n"; |
|
268
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />" . "\n"; |
|
269
|
|
|
echo '</form>' . "\n"; |
|
270
|
|
|
} else { |
|
271
|
|
|
$status = $data->clusterIndex($_POST['table'], $_POST['index']); |
|
272
|
|
|
if ($status == 0) { |
|
273
|
|
|
if (isset($_POST['analyze'])) { |
|
274
|
|
|
$status = $data->analyzeDB($_POST['table']); |
|
275
|
|
|
if ($status == 0) { |
|
276
|
|
|
$this->doDefault($lang['strclusteredgood'] . ' ' . $lang['stranalyzegood']); |
|
277
|
|
|
} else { |
|
278
|
|
|
$this->doDefault($lang['stranalyzebad']); |
|
279
|
|
|
} |
|
280
|
|
|
} else { |
|
281
|
|
|
$this->doDefault($lang['strclusteredgood']); |
|
282
|
|
|
} |
|
283
|
|
|
} else { |
|
284
|
|
|
$this->doDefault($lang['strclusteredbad']); |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
public function doReindex() |
|
|
|
|
|
|
290
|
|
|
{ |
|
291
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
292
|
|
|
$misc = $this->misc; |
|
293
|
|
|
$lang = $this->lang; |
|
294
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
295
|
|
|
$status = $data->reindex('INDEX', $_REQUEST['index']); |
|
296
|
|
|
if ($status == 0) { |
|
297
|
|
|
$this->doDefault($lang['strreindexgood']); |
|
298
|
|
|
} else { |
|
299
|
|
|
$this->doDefault($lang['strreindexbad']); |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* Displays a screen where they can enter a new index |
|
305
|
|
|
*/ |
|
306
|
|
|
public function doCreateIndex($msg = '') |
|
|
|
|
|
|
307
|
|
|
{ |
|
308
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
309
|
|
|
$misc = $this->misc; |
|
310
|
|
|
$lang = $this->lang; |
|
311
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
312
|
|
|
|
|
313
|
|
|
if (!isset($_REQUEST['subject'])) { |
|
314
|
|
|
$_REQUEST['subject'] = 'table'; |
|
315
|
|
|
} |
|
316
|
|
|
$subject = urlencode($_REQUEST['subject']); |
|
317
|
|
|
$object = urlencode($_REQUEST[$subject]); |
|
318
|
|
|
|
|
319
|
|
|
if (!isset($_POST['formIndexName'])) { |
|
320
|
|
|
$_POST['formIndexName'] = ''; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
if (!isset($_POST['formIndexType'])) { |
|
324
|
|
|
$_POST['formIndexType'] = null; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
if (!isset($_POST['formCols'])) { |
|
328
|
|
|
$_POST['formCols'] = ''; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
if (!isset($_POST['formWhere'])) { |
|
332
|
|
|
$_POST['formWhere'] = ''; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
if (!isset($_POST['formSpc'])) { |
|
336
|
|
|
$_POST['formSpc'] = ''; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
$attrs = $data->getTableAttributes($object); |
|
340
|
|
|
// Fetch all tablespaces from the database |
|
341
|
|
|
if ($data->hasTablespaces()) { |
|
342
|
|
|
$tablespaces = $data->getTablespaces(); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
$this->printTrail($subject); |
|
346
|
|
|
$this->printTitle($lang['strcreateindex'], 'pg.index.create'); |
|
347
|
|
|
$this->printMsg($msg); |
|
348
|
|
|
|
|
349
|
|
|
$selColumns = new \PHPPgAdmin\XHtml\XHtmlSelect('TableColumnList', true, 10); |
|
350
|
|
|
$selColumns->set_style('width: 10em;'); |
|
351
|
|
|
|
|
352
|
|
View Code Duplication |
if ($attrs->recordCount() > 0) { |
|
|
|
|
|
|
353
|
|
|
while (!$attrs->EOF) { |
|
354
|
|
|
$attname = new \PHPPgAdmin\XHtml\XHtmlOption($attrs->fields['attname']); |
|
355
|
|
|
$selColumns->add($attname); |
|
356
|
|
|
$attrs->moveNext(); |
|
357
|
|
|
} |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
$selIndex = new \PHPPgAdmin\XHtml\XHtmlSelect('IndexColumnList[]', true, 10); |
|
361
|
|
|
$selIndex->set_style('width: 10em;'); |
|
362
|
|
|
$selIndex->set_attribute('id', 'IndexColumnList'); |
|
363
|
|
|
$buttonAdd = new \PHPPgAdmin\XHtml\XHtmlButton('add', '>>'); |
|
364
|
|
|
$buttonAdd->set_attribute('onclick', 'buttonPressed(this);'); |
|
365
|
|
|
$buttonAdd->set_attribute('type', 'button'); |
|
366
|
|
|
|
|
367
|
|
|
$buttonRemove = new \PHPPgAdmin\XHtml\XHtmlButton('remove', '<<'); |
|
368
|
|
|
$buttonRemove->set_attribute('onclick', 'buttonPressed(this);'); |
|
369
|
|
|
$buttonRemove->set_attribute('type', 'button'); |
|
370
|
|
|
|
|
371
|
|
|
echo '<form onsubmit="doSelectAll();" name="formIndex" action="indexes.php" method="post">' . "\n"; |
|
372
|
|
|
|
|
373
|
|
|
echo '<table>' . "\n"; |
|
374
|
|
|
echo '<tr><th class="data required" colspan="3">' . $lang['strindexname'] . '</th></tr>'; |
|
375
|
|
|
echo '<tr>'; |
|
376
|
|
|
echo '<td class="data1" colspan="3">'; |
|
377
|
|
|
echo '<input type="text" name="formIndexName" size="32" maxlength="' . $data->_maxNameLen . '" value="' . htmlspecialchars($_POST['formIndexName']) . '" />'; |
|
378
|
|
|
echo '</td></tr>'; |
|
379
|
|
|
echo '<tr><th class="data">' . $lang['strtablecolumnlist'] . '</th><th class="data"> </th>'; |
|
380
|
|
|
echo '<th class="data required">' . $lang['strindexcolumnlist'] . '</th></tr>' . "\n"; |
|
381
|
|
|
echo '<tr><td class="data1">' . $selColumns->fetch() . '</td>' . "\n"; |
|
382
|
|
|
echo '<td class="data1">' . $buttonRemove->fetch() . $buttonAdd->fetch() . '</td>'; |
|
383
|
|
|
echo '<td class="data1">' . $selIndex->fetch() . '</td></tr>' . "\n"; |
|
384
|
|
|
echo '</table>' . "\n"; |
|
385
|
|
|
|
|
386
|
|
|
echo '<table> ' . "\n"; |
|
387
|
|
|
echo '<tr>'; |
|
388
|
|
|
echo '<th class="data left required" scope="row">' . $lang['strindextype'] . '</th>'; |
|
389
|
|
|
echo '<td class="data1"><select name="formIndexType">'; |
|
390
|
|
|
foreach ($data->typIndexes as $v) { |
|
391
|
|
|
echo '<option value="', htmlspecialchars($v), '"', |
|
392
|
|
|
($v == $_POST['formIndexType']) ? ' selected="selected"' : '', '>', htmlspecialchars($v), '</option>' . "\n"; |
|
393
|
|
|
} |
|
394
|
|
|
echo '</select></td></tr>' . "\n"; |
|
395
|
|
|
echo '<tr>'; |
|
396
|
|
|
echo "<th class=\"data left\" scope=\"row\"><label for=\"formUnique\">{$lang['strunique']}</label></th>"; |
|
397
|
|
|
echo '<td class="data1"><input type="checkbox" id="formUnique" name="formUnique"', (isset($_POST['formUnique']) ? 'checked="checked"' : ''), ' /></td>'; |
|
398
|
|
|
echo '</tr>'; |
|
399
|
|
|
echo '<tr>'; |
|
400
|
|
|
echo "<th class=\"data left\" scope=\"row\">{$lang['strwhere']}</th>"; |
|
401
|
|
|
echo '<td class="data1">(<input name="formWhere" size="32" maxlength="' . $data->_maxNameLen . '" value="' . htmlspecialchars($_POST['formWhere']) . '" />)</td>'; |
|
402
|
|
|
echo '</tr>'; |
|
403
|
|
|
|
|
404
|
|
|
// Tablespace (if there are any) |
|
405
|
|
|
if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { |
|
|
|
|
|
|
406
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>" . "\n"; |
|
407
|
|
|
echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">" . "\n"; |
|
408
|
|
|
// Always offer the default (empty) option |
|
409
|
|
|
echo "\t\t\t\t<option value=\"\"", |
|
410
|
|
|
($_POST['formSpc'] == '') ? ' selected="selected"' : '', '></option>' . "\n"; |
|
411
|
|
|
// Display all other tablespaces |
|
412
|
|
|
while (!$tablespaces->EOF) { |
|
413
|
|
|
$spcname = htmlspecialchars($tablespaces->fields['spcname']); |
|
414
|
|
|
echo "\t\t\t\t<option value=\"{$spcname}\"", |
|
415
|
|
|
($spcname == $_POST['formSpc']) ? ' selected="selected"' : '', ">{$spcname}</option>" . "\n"; |
|
416
|
|
|
$tablespaces->moveNext(); |
|
417
|
|
|
} |
|
418
|
|
|
echo "\t\t\t</select>\n\t\t</td>\n\t</tr>" . "\n"; |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
if ($data->hasConcurrentIndexBuild()) { |
|
422
|
|
|
echo '<tr>'; |
|
423
|
|
|
echo "<th class=\"data left\" scope=\"row\"><label for=\"formConcur\">{$lang['strconcurrently']}</label></th>"; |
|
424
|
|
|
echo '<td class="data1"><input type="checkbox" id="formConcur" name="formConcur"', (isset($_POST['formConcur']) ? 'checked="checked"' : ''), ' /></td>'; |
|
425
|
|
|
echo '</tr>'; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
echo '</table>'; |
|
429
|
|
|
|
|
430
|
|
|
echo '<p><input type="hidden" name="action" value="save_create_index" />' . "\n"; |
|
431
|
|
|
echo $misc->form; |
|
432
|
|
|
echo '<input type="hidden" name="subject" value="', htmlspecialchars($subject), '" />' . "\n"; |
|
433
|
|
|
echo '<input type="hidden" name="' . $subject . '" value="', htmlspecialchars($object), '" />' . "\n"; |
|
434
|
|
|
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />" . "\n"; |
|
435
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>" . "\n"; |
|
436
|
|
|
echo '</form>' . "\n"; |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
/** |
|
440
|
|
|
* Actually creates the new index in the database |
|
441
|
|
|
* @@ Note: this function can't handle columns with commas in them |
|
442
|
|
|
*/ |
|
443
|
|
|
public function doSaveCreateIndex() |
|
|
|
|
|
|
444
|
|
|
{ |
|
445
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
446
|
|
|
$misc = $this->misc; |
|
447
|
|
|
$lang = $this->lang; |
|
448
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
449
|
|
|
|
|
450
|
|
|
if (!isset($_POST['subject'])) { |
|
451
|
|
|
$_POST['subject'] = 'table'; |
|
452
|
|
|
} |
|
453
|
|
|
$subject = urlencode($_POST['subject']); |
|
454
|
|
|
$object = urlencode($_POST[$subject]); |
|
455
|
|
|
|
|
456
|
|
|
// Handle databases that don't have partial indexes |
|
457
|
|
|
if (!isset($_POST['formWhere'])) { |
|
458
|
|
|
$_POST['formWhere'] = ''; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
// Default tablespace to null if it isn't set |
|
462
|
|
|
if (!isset($_POST['formSpc'])) { |
|
463
|
|
|
$_POST['formSpc'] = null; |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
// Check that they've given a name and at least one column |
|
467
|
|
|
if ($_POST['formIndexName'] == '') { |
|
468
|
|
|
$this->doCreateIndex($lang['strindexneedsname']); |
|
469
|
|
|
} elseif (!isset($_POST['IndexColumnList']) || $_POST['IndexColumnList'] == '') { |
|
470
|
|
|
$this->doCreateIndex($lang['strindexneedscols']); |
|
471
|
|
|
} else { |
|
472
|
|
|
$status = $data->createIndex($_POST['formIndexName'], $object, $_POST['IndexColumnList'], |
|
473
|
|
|
$_POST['formIndexType'], isset($_POST['formUnique']), $_POST['formWhere'], $_POST['formSpc'], |
|
474
|
|
|
isset($_POST['formConcur'])); |
|
475
|
|
|
if ($status == 0) { |
|
476
|
|
|
$this->doDefault($lang['strindexcreated']); |
|
477
|
|
|
} else { |
|
478
|
|
|
$this->doCreateIndex($lang['strindexcreatedbad']); |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
/** |
|
484
|
|
|
* Show confirmation of drop index and perform actual drop |
|
485
|
|
|
*/ |
|
486
|
|
|
public function doDropIndex($confirm) |
|
|
|
|
|
|
487
|
|
|
{ |
|
488
|
|
|
$conf = $this->conf; |
|
|
|
|
|
|
489
|
|
|
$misc = $this->misc; |
|
490
|
|
|
$lang = $this->lang; |
|
491
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
492
|
|
|
|
|
493
|
|
|
if (!isset($_REQUEST['subject'])) { |
|
494
|
|
|
$_REQUEST['subject'] = 'table'; |
|
495
|
|
|
} |
|
496
|
|
|
$subject = urlencode($_REQUEST['subject']); |
|
|
|
|
|
|
497
|
|
|
$object = urlencode($_REQUEST[$_REQUEST['subject']]); |
|
498
|
|
|
|
|
499
|
|
|
if ($confirm) { |
|
500
|
|
|
$this->printTrail('index'); |
|
501
|
|
|
$this->printTitle($lang['strdrop'], 'pg.index.drop'); |
|
502
|
|
|
|
|
503
|
|
|
echo '<p>', sprintf($lang['strconfdropindex'], $misc->printVal($_REQUEST['index'])), '</p>' . "\n"; |
|
504
|
|
|
|
|
505
|
|
|
echo '<form action="' . SUBFOLDER . '/src/views/indexes.php" method="post">' . "\n"; |
|
506
|
|
|
echo '<input type="hidden" name="action" value="drop_index" />' . "\n"; |
|
507
|
|
|
echo '<input type="hidden" name="table" value="', htmlspecialchars($object), '" />' . "\n"; |
|
508
|
|
|
echo '<input type="hidden" name="index" value="', htmlspecialchars($_REQUEST['index']), '" />' . "\n"; |
|
509
|
|
|
echo $misc->form; |
|
510
|
|
|
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>" . "\n"; |
|
511
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />" . "\n"; |
|
512
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />" . "\n"; |
|
513
|
|
|
echo '</form>' . "\n"; |
|
514
|
|
|
} else { |
|
515
|
|
|
$status = $data->dropIndex($_POST['index'], isset($_POST['cascade'])); |
|
516
|
|
|
if ($status == 0) { |
|
517
|
|
|
$this->doDefault($lang['strindexdropped']); |
|
518
|
|
|
} else { |
|
519
|
|
|
$this->doDefault($lang['strindexdroppedbad']); |
|
520
|
|
|
} |
|
521
|
|
|
} |
|
522
|
|
|
} |
|
523
|
|
|
} |
|
524
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: