'; /** * Default method to render the controller according to the action parameter. */ public function render() { if ('tree' == $this->action) { return $this->doTree(); } $this->printHeader($this->headerTitle(), $this->scripts); $onloadInit = false; if ('create_index' == $this->action || 'save_create_index' == $this->action) { $onloadInit = true; } $this->printBody(true, 'detailbody', $onloadInit); switch ($this->action) { case 'cluster_index': if (isset($_POST['cluster'])) { $this->doClusterIndex(false); } else { $this->doDefault(); } break; case 'confirm_cluster_index': $this->doClusterIndex(true); break; case 'reindex': $this->doReindex(); break; case 'save_create_index': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doSaveCreateIndex(); } break; case 'create_index': $this->doCreateIndex(); break; case 'drop_index': if (isset($_POST['drop'])) { $this->doDropIndex(false); } else { $this->doDefault(); } break; case 'confirm_drop_index': $this->doDropIndex(true); break; default: $this->doDefault(); break; } return $this->printFooter(); } public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $lang = $this->lang; $indPre = function (&$rowdata, $actions) use ($data, $lang) { if ($data->phpBool($rowdata->fields['indisprimary'])) { $rowdata->fields['+constraints'] = $lang['strprimarykey']; $actions['drop']['disable'] = true; } elseif ($data->phpBool($rowdata->fields['indisunique'])) { $rowdata->fields['+constraints'] = $lang['struniquekey']; $actions['drop']['disable'] = true; } else { $rowdata->fields['+constraints'] = ''; } return $actions; }; $this->coalesceArr($_REQUEST, 'subject', 'table'); $subject = urlencode($_REQUEST['subject']); $object = urlencode($_REQUEST[$_REQUEST['subject']]); $this->printTrail($subject); $this->printTabs($subject, 'indexes'); $this->printMsg($msg); $indexes = $data->getIndexes($_REQUEST[$_REQUEST['subject']]); $columns = [ 'index' => [ 'title' => $this->lang['strname'], 'field' => Decorator::field('indname'), ], 'definition' => [ 'title' => $this->lang['strdefinition'], 'field' => Decorator::field('inddef'), ], 'constraints' => [ 'title' => $this->lang['strconstraints'], 'field' => Decorator::field('+constraints'), 'type' => 'verbatim', 'params' => ['align' => 'center'], ], 'clustered' => [ 'title' => $this->lang['strclustered'], 'field' => Decorator::field('indisclustered'), 'type' => 'yesno', ], 'actions' => [ 'title' => $this->lang['stractions'], ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('idxcomment'), ], ]; $url = \SUBFOLDER.'/src/views/indexes'; $actions = [ 'cluster' => [ 'content' => $this->lang['strclusterindex'], 'attr' => [ 'href' => [ 'url' => $url, 'urlvars' => [ 'action' => 'confirm_cluster_index', 'subject' => $subject, $subject => $object, 'index' => Decorator::field('indname'), ], ], ], ], 'reindex' => [ 'content' => $this->lang['strreindex'], 'attr' => [ 'href' => [ 'url' => $url, 'urlvars' => [ 'action' => 'reindex', 'subject' => $subject, $subject => $object, 'index' => Decorator::field('indname'), ], ], ], ], 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => $url, 'urlvars' => [ 'action' => 'confirm_drop_index', 'subject' => $subject, $subject => $object, 'index' => Decorator::field('indname'), ], ], ], ], ]; echo $this->printTable($indexes, $columns, $actions, 'indexes-indexes', $this->lang['strnoindexes'], $indPre); $this->printNavLinks([ 'create' => [ 'attr' => [ 'href' => [ 'url' => 'indexes', 'urlvars' => [ 'action' => 'create_index', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], $subject => $object, 'subject' => $subject, ], ], ], 'content' => $this->lang['strcreateindex'], ], ], 'indexes-indexes', get_defined_vars()); } public function doTree() { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'subject', 'table'); $subject = urlencode($_REQUEST['subject']); $object = urlencode($_REQUEST[$subject]); $indexes = $data->getIndexes($object); $getIcon = function ($f) { if ('t' == $f['indisprimary']) { return 'PrimaryKey'; } if ('t' == $f['indisunique']) { return 'UniqueConstraint'; } return 'Index'; }; $attrs = [ 'text' => Decorator::field('indname'), 'icon' => Decorator::callback($getIcon), ]; return $this->printTree($indexes, $attrs, 'indexes'); } /** * Show confirmation of cluster index and perform actual cluster. * * @param mixed $confirm */ public function doClusterIndex($confirm) { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'subject', 'table'); $subject = urlencode($_REQUEST['subject']); $object = urlencode($_REQUEST[$subject]); //$this->printTrail($subject); if ($confirm) { // Default analyze to on $_REQUEST['analyze'] = true; $this->printTrail('index'); $this->printTabs($subject, 'indexes'); $this->printTitle($this->lang['strclusterindex'], 'pg.index.cluster'); echo '
', sprintf($this->lang['strconfcluster'], $this->misc->printVal($_REQUEST['index'])), '
'.PHP_EOL; echo ''.PHP_EOL; } else { set_time_limit(0); list($status, $sql) = $data->clusterIndex($object, $_POST['index']); if (0 == $status) { if (isset($_POST['analyze'])) { $status = $data->analyzeDB($object); if (0 == $status) { $this->doDefault($sql.'', sprintf($this->lang['strconfdropindex'], $this->misc->printVal($this->getRequestParam('index'))), '
'.PHP_EOL; echo ''.PHP_EOL; } else { try { list($status, $sql) = $data->dropIndex($this->getPostParam('index'), $this->getPostParam('cascade')); if (0 == $status) { $this->doDefault($sql.PHP_EOL.$this->lang['strindexdropped']); } else { $this->doDefault($sql.PHP_EOL.$this->lang['strindexdroppedbad']); } } catch (\PHPPgAdmin\ADOdbException $e) { $this->doDefault($this->lang['strindexdroppedbad']); } } } }