aboutsummaryrefslogtreecommitdiff
path: root/srcs/phpmyadmin/libraries/classes/Relation.php
diff options
context:
space:
mode:
Diffstat (limited to 'srcs/phpmyadmin/libraries/classes/Relation.php')
-rw-r--r--srcs/phpmyadmin/libraries/classes/Relation.php2280
1 files changed, 0 insertions, 2280 deletions
diff --git a/srcs/phpmyadmin/libraries/classes/Relation.php b/srcs/phpmyadmin/libraries/classes/Relation.php
deleted file mode 100644
index 2e05aff..0000000
--- a/srcs/phpmyadmin/libraries/classes/Relation.php
+++ /dev/null
@@ -1,2280 +0,0 @@
-<?php
-/* vim: set expandtab sw=4 ts=4 sts=4: */
-/**
- * Set of functions used with the relation and PDF feature
- *
- * @package PhpMyAdmin
- */
-declare(strict_types=1);
-
-namespace PhpMyAdmin;
-
-use PhpMyAdmin\SqlParser\Parser;
-use PhpMyAdmin\SqlParser\Statements\CreateStatement;
-use PhpMyAdmin\SqlParser\Utils\Table as TableUtils;
-
-/**
- * Set of functions used with the relation and PDF feature
- *
- * @package PhpMyAdmin
- */
-class Relation
-{
- /**
- * @var DatabaseInterface
- */
- public $dbi;
-
- /**
- * @var Template
- */
- public $template;
-
- /**
- * Relation constructor.
- *
- * @param DatabaseInterface|null $dbi Database interface
- * @param Template|null $template Template instance
- */
- public function __construct(?DatabaseInterface $dbi, ?Template $template = null)
- {
- $this->dbi = $dbi;
- $this->template = $template ?? new Template();
- }
-
- /**
- * Executes a query as controluser if possible, otherwise as normal user
- *
- * @param string $sql the query to execute
- * @param boolean $show_error whether to display SQL error messages or not
- * @param int $options query options
- *
- * @return resource|boolean the result set, or false if no result set
- *
- * @access public
- *
- */
- public function queryAsControlUser($sql, $show_error = true, $options = 0)
- {
- // Avoid caching of the number of rows affected; for example, this function
- // is called for tracking purposes but we want to display the correct number
- // of rows affected by the original query, not by the query generated for
- // tracking.
- $cache_affected_rows = false;
-
- if ($show_error) {
- $result = $this->dbi->query(
- $sql,
- DatabaseInterface::CONNECT_CONTROL,
- $options,
- $cache_affected_rows
- );
- } else {
- $result = @$this->dbi->tryQuery(
- $sql,
- DatabaseInterface::CONNECT_CONTROL,
- $options,
- $cache_affected_rows
- );
- } // end if... else...
-
- if ($result) {
- return $result;
- }
-
- return false;
- }
-
- /**
- * Returns current relation parameters
- *
- * @return array
- */
- public function getRelationsParam()
- {
- if (empty($_SESSION['relation'][$GLOBALS['server']])
- || empty($_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'])
- || $_SESSION['relation'][$GLOBALS['server']]['PMA_VERSION'] != PMA_VERSION
- ) {
- $_SESSION['relation'][$GLOBALS['server']] = $this->checkRelationsParam();
- }
-
- // just for BC but needs to be before getRelationsParamDiagnostic()
- // which uses it
- $GLOBALS['cfgRelation'] = $_SESSION['relation'][$GLOBALS['server']];
-
- return $_SESSION['relation'][$GLOBALS['server']];
- }
-
- /**
- * prints out diagnostic info for pma relation feature
- *
- * @param array $cfgRelation Relation configuration
- *
- * @return string
- */
- public function getRelationsParamDiagnostic(array $cfgRelation)
- {
- $retval = '<br>';
-
- $messages = [];
- $messages['error'] = '<span class="caution"><strong>'
- . __('not OK')
- . '</strong></span>';
-
- $messages['ok'] = '<span class="success"><strong>'
- . _pgettext('Correctly working', 'OK')
- . '</strong></span>';
-
- $messages['enabled'] = '<span class="success">' . __('Enabled') . '</span>';
- $messages['disabled'] = '<span class="caution">' . __('Disabled') . '</span>';
-
- if (strlen((string) $cfgRelation['db']) == 0) {
- $retval .= __('Configuration of pmadb…') . ' '
- . $messages['error']
- . Util::showDocu('setup', 'linked-tables')
- . '<br>' . "\n"
- . __('General relation features')
- . ' <font color="green">' . __('Disabled')
- . '</font>' . "\n";
- if ($GLOBALS['cfg']['ZeroConf']) {
- if (strlen($GLOBALS['db']) == 0) {
- $retval .= $this->getHtmlFixPmaTables(true, true);
- } else {
- $retval .= $this->getHtmlFixPmaTables(true);
- }
- }
- } else {
- $retval .= '<table>' . "\n";
-
- if (! $cfgRelation['allworks']
- && $GLOBALS['cfg']['ZeroConf']
- // Avoid showing a "Create missing tables" link if it's a
- // problem of missing definition
- && $this->arePmadbTablesDefined()
- ) {
- $retval .= $this->getHtmlFixPmaTables(false);
- $retval .= '<br>';
- }
-
- $retval .= $this->getDiagMessageForParameter(
- 'pmadb',
- $cfgRelation['db'],
- $messages,
- 'pmadb'
- );
- $retval .= $this->getDiagMessageForParameter(
- 'relation',
- isset($cfgRelation['relation']),
- $messages,
- 'relation'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('General relation features'),
- 'relwork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'table_info',
- isset($cfgRelation['table_info']),
- $messages,
- 'table_info'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Display Features'),
- 'displaywork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'table_coords',
- isset($cfgRelation['table_coords']),
- $messages,
- 'table_coords'
- );
- $retval .= $this->getDiagMessageForParameter(
- 'pdf_pages',
- isset($cfgRelation['pdf_pages']),
- $messages,
- 'pdf_pages'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Designer and creation of PDFs'),
- 'pdfwork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'column_info',
- isset($cfgRelation['column_info']),
- $messages,
- 'column_info'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Displaying Column Comments'),
- 'commwork',
- $messages,
- false
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Browser transformation'),
- 'mimework',
- $messages
- );
- if ($cfgRelation['commwork'] && ! $cfgRelation['mimework']) {
- $retval .= '<tr><td colspan=2 class="left error">';
- $retval .= __(
- 'Please see the documentation on how to'
- . ' update your column_info table.'
- );
- $retval .= Util::showDocu(
- 'config',
- 'cfg_Servers_column_info'
- );
- $retval .= '</td></tr>';
- }
- $retval .= $this->getDiagMessageForParameter(
- 'bookmarktable',
- isset($cfgRelation['bookmark']),
- $messages,
- 'bookmark'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Bookmarked SQL query'),
- 'bookmarkwork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'history',
- isset($cfgRelation['history']),
- $messages,
- 'history'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('SQL history'),
- 'historywork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'recent',
- isset($cfgRelation['recent']),
- $messages,
- 'recent'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Persistent recently used tables'),
- 'recentwork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'favorite',
- isset($cfgRelation['favorite']),
- $messages,
- 'favorite'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Persistent favorite tables'),
- 'favoritework',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'table_uiprefs',
- isset($cfgRelation['table_uiprefs']),
- $messages,
- 'table_uiprefs'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Persistent tables\' UI preferences'),
- 'uiprefswork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'tracking',
- isset($cfgRelation['tracking']),
- $messages,
- 'tracking'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Tracking'),
- 'trackingwork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'userconfig',
- isset($cfgRelation['userconfig']),
- $messages,
- 'userconfig'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('User preferences'),
- 'userconfigwork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'users',
- isset($cfgRelation['users']),
- $messages,
- 'users'
- );
- $retval .= $this->getDiagMessageForParameter(
- 'usergroups',
- isset($cfgRelation['usergroups']),
- $messages,
- 'usergroups'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Configurable menus'),
- 'menuswork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'navigationhiding',
- isset($cfgRelation['navigationhiding']),
- $messages,
- 'navigationhiding'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Hide/show navigation items'),
- 'navwork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'savedsearches',
- isset($cfgRelation['savedsearches']),
- $messages,
- 'savedsearches'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Saving Query-By-Example searches'),
- 'savedsearcheswork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'central_columns',
- isset($cfgRelation['central_columns']),
- $messages,
- 'central_columns'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Managing Central list of columns'),
- 'centralcolumnswork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'designer_settings',
- isset($cfgRelation['designer_settings']),
- $messages,
- 'designer_settings'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Remembering Designer Settings'),
- 'designersettingswork',
- $messages
- );
- $retval .= $this->getDiagMessageForParameter(
- 'export_templates',
- isset($cfgRelation['export_templates']),
- $messages,
- 'export_templates'
- );
- $retval .= $this->getDiagMessageForFeature(
- __('Saving export templates'),
- 'exporttemplateswork',
- $messages
- );
- $retval .= '</table>' . "\n";
-
- if (! $cfgRelation['allworks']) {
- $retval .= '<p>' . __('Quick steps to set up advanced features:')
- . '</p>';
-
- $items = [];
- $items[] = sprintf(
- __(
- 'Create the needed tables with the '
- . '<code>%screate_tables.sql</code>.'
- ),
- htmlspecialchars(SQL_DIR)
- ) . ' ' . Util::showDocu('setup', 'linked-tables');
- $items[] = __('Create a pma user and give access to these tables.') . ' '
- . Util::showDocu('config', 'cfg_Servers_controluser');
- $items[] = __(
- 'Enable advanced features in configuration file '
- . '(<code>config.inc.php</code>), for example by '
- . 'starting from <code>config.sample.inc.php</code>.'
- ) . ' ' . Util::showDocu('setup', 'quick-install');
- $items[] = __(
- 'Re-login to phpMyAdmin to load the updated configuration file.'
- );
-
- $retval .= $this->template->render('list/unordered', ['items' => $items]);
- }
- }
-
- return $retval;
- }
-
- /**
- * prints out one diagnostic message for a feature
- *
- * @param string $feature_name feature name in a message string
- * @param string $relation_parameter the $GLOBALS['cfgRelation'] parameter to check
- * @param array $messages utility messages
- * @param boolean $skip_line whether to skip a line after the message
- *
- * @return string
- */
- public function getDiagMessageForFeature(
- $feature_name,
- $relation_parameter,
- array $messages,
- $skip_line = true
- ) {
- $retval = ' <tr><td colspan=2 class="right">' . $feature_name . ': ';
- if (isset($GLOBALS['cfgRelation'][$relation_parameter])
- && $GLOBALS['cfgRelation'][$relation_parameter]
- ) {
- $retval .= $messages['enabled'];
- } else {
- $retval .= $messages['disabled'];
- }
- $retval .= '</td></tr>';
- if ($skip_line) {
- $retval .= '<tr><td>&nbsp;</td></tr>';
- }
- return $retval;
- }
-
- /**
- * prints out one diagnostic message for a configuration parameter
- *
- * @param string $parameter config parameter name to display
- * @param boolean $relationParameterSet whether this parameter is set
- * @param array $messages utility messages
- * @param string $docAnchor anchor in documentation
- *
- * @return string
- */
- public function getDiagMessageForParameter(
- $parameter,
- $relationParameterSet,
- array $messages,
- $docAnchor
- ) {
- $retval = '<tr><th class="left">';
- $retval .= '$cfg[\'Servers\'][$i][\'' . $parameter . '\'] ... ';
- $retval .= '</th><td class="right">';
- if ($relationParameterSet) {
- $retval .= $messages['ok'];
- } else {
- $retval .= sprintf(
- $messages['error'],
- Util::getDocuLink('config', 'cfg_Servers_' . $docAnchor)
- );
- }
- $retval .= '</td></tr>' . "\n";
- return $retval;
- }
-
- /**
- * Defines the relation parameters for the current user
- * just a copy of the functions used for relations ;-)
- * but added some stuff to check what will work
- *
- * @access protected
- * @return array the relation parameters for the current user
- */
- public function checkRelationsParam()
- {
- $cfgRelation = [];
- $cfgRelation['PMA_VERSION'] = PMA_VERSION;
-
- $workToTable = [
- 'relwork' => 'relation',
- 'displaywork' => [
- 'relation',
- 'table_info',
- ],
- 'bookmarkwork' => 'bookmarktable',
- 'pdfwork' => [
- 'table_coords',
- 'pdf_pages',
- ],
- 'commwork' => 'column_info',
- 'mimework' => 'column_info',
- 'historywork' => 'history',
- 'recentwork' => 'recent',
- 'favoritework' => 'favorite',
- 'uiprefswork' => 'table_uiprefs',
- 'trackingwork' => 'tracking',
- 'userconfigwork' => 'userconfig',
- 'menuswork' => [
- 'users',
- 'usergroups',
- ],
- 'navwork' => 'navigationhiding',
- 'savedsearcheswork' => 'savedsearches',
- 'centralcolumnswork' => 'central_columns',
- 'designersettingswork' => 'designer_settings',
- 'exporttemplateswork' => 'export_templates',
- ];
-
- foreach ($workToTable as $work => $table) {
- $cfgRelation[$work] = false;
- }
- $cfgRelation['allworks'] = false;
- $cfgRelation['user'] = null;
- $cfgRelation['db'] = null;
-
- if ($GLOBALS['server'] == 0
- || empty($GLOBALS['cfg']['Server']['pmadb'])
- || ! $this->dbi->selectDb(
- $GLOBALS['cfg']['Server']['pmadb'],
- DatabaseInterface::CONNECT_CONTROL
- )
- ) {
- // No server selected -> no bookmark table
- // we return the array with the falses in it,
- // to avoid some 'Uninitialized string offset' errors later
- $GLOBALS['cfg']['Server']['pmadb'] = false;
- return $cfgRelation;
- }
-
- $cfgRelation['user'] = $GLOBALS['cfg']['Server']['user'];
- $cfgRelation['db'] = $GLOBALS['cfg']['Server']['pmadb'];
-
- // Now I just check if all tables that i need are present so I can for
- // example enable relations but not pdf...
- // I was thinking of checking if they have all required columns but I
- // fear it might be too slow
-
- $tab_query = 'SHOW TABLES FROM '
- . Util::backquote(
- $GLOBALS['cfg']['Server']['pmadb']
- );
- $tab_rs = $this->queryAsControlUser(
- $tab_query,
- false,
- DatabaseInterface::QUERY_STORE
- );
-
- if (! $tab_rs) {
- // query failed ... ?
- //$GLOBALS['cfg']['Server']['pmadb'] = false;
- return $cfgRelation;
- }
-
- while ($curr_table = @$this->dbi->fetchRow($tab_rs)) {
- if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) {
- $cfgRelation['bookmark'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) {
- $cfgRelation['relation'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_info']) {
- $cfgRelation['table_info'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_coords']) {
- $cfgRelation['table_coords'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['column_info']) {
- $cfgRelation['column_info'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['pdf_pages']) {
- $cfgRelation['pdf_pages'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) {
- $cfgRelation['history'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) {
- $cfgRelation['recent'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['favorite']) {
- $cfgRelation['favorite'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['table_uiprefs']) {
- $cfgRelation['table_uiprefs'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) {
- $cfgRelation['tracking'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) {
- $cfgRelation['userconfig'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['users']) {
- $cfgRelation['users'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['usergroups']) {
- $cfgRelation['usergroups'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['navigationhiding']) {
- $cfgRelation['navigationhiding'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['savedsearches']) {
- $cfgRelation['savedsearches'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['central_columns']) {
- $cfgRelation['central_columns'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['designer_settings']) {
- $cfgRelation['designer_settings'] = $curr_table[0];
- } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['export_templates']) {
- $cfgRelation['export_templates'] = $curr_table[0];
- }
- } // end while
- $this->dbi->freeResult($tab_rs);
-
- if (isset($cfgRelation['relation'])) {
- if ($this->canAccessStorageTable($cfgRelation['relation'])) {
- $cfgRelation['relwork'] = true;
- }
- }
-
- if (isset($cfgRelation['relation']) && isset($cfgRelation['table_info'])) {
- if ($this->canAccessStorageTable($cfgRelation['table_info'])) {
- $cfgRelation['displaywork'] = true;
- }
- }
-
- if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) {
- if ($this->canAccessStorageTable($cfgRelation['table_coords'])) {
- if ($this->canAccessStorageTable($cfgRelation['pdf_pages'])) {
- $cfgRelation['pdfwork'] = true;
- }
- }
- }
-
- if (isset($cfgRelation['column_info'])) {
- if ($this->canAccessStorageTable($cfgRelation['column_info'])) {
- $cfgRelation['commwork'] = true;
- // phpMyAdmin 4.3+
- // Check for input transformations upgrade.
- $cfgRelation['mimework'] = $this->tryUpgradeTransformations();
- }
- }
-
- if (isset($cfgRelation['history'])) {
- if ($this->canAccessStorageTable($cfgRelation['history'])) {
- $cfgRelation['historywork'] = true;
- }
- }
-
- if (isset($cfgRelation['recent'])) {
- if ($this->canAccessStorageTable($cfgRelation['recent'])) {
- $cfgRelation['recentwork'] = true;
- }
- }
-
- if (isset($cfgRelation['favorite'])) {
- if ($this->canAccessStorageTable($cfgRelation['favorite'])) {
- $cfgRelation['favoritework'] = true;
- }
- }
-
- if (isset($cfgRelation['table_uiprefs'])) {
- if ($this->canAccessStorageTable($cfgRelation['table_uiprefs'])) {
- $cfgRelation['uiprefswork'] = true;
- }
- }
-
- if (isset($cfgRelation['tracking'])) {
- if ($this->canAccessStorageTable($cfgRelation['tracking'])) {
- $cfgRelation['trackingwork'] = true;
- }
- }
-
- if (isset($cfgRelation['userconfig'])) {
- if ($this->canAccessStorageTable($cfgRelation['userconfig'])) {
- $cfgRelation['userconfigwork'] = true;
- }
- }
-
- if (isset($cfgRelation['bookmark'])) {
- if ($this->canAccessStorageTable($cfgRelation['bookmark'])) {
- $cfgRelation['bookmarkwork'] = true;
- }
- }
-
- if (isset($cfgRelation['users']) && isset($cfgRelation['usergroups'])) {
- if ($this->canAccessStorageTable($cfgRelation['users'])) {
- if ($this->canAccessStorageTable($cfgRelation['usergroups'])) {
- $cfgRelation['menuswork'] = true;
- }
- }
- }
-
- if (isset($cfgRelation['navigationhiding'])) {
- if ($this->canAccessStorageTable($cfgRelation['navigationhiding'])) {
- $cfgRelation['navwork'] = true;
- }
- }
-
- if (isset($cfgRelation['savedsearches'])) {
- if ($this->canAccessStorageTable($cfgRelation['savedsearches'])) {
- $cfgRelation['savedsearcheswork'] = true;
- }
- }
-
- if (isset($cfgRelation['central_columns'])) {
- if ($this->canAccessStorageTable($cfgRelation['central_columns'])) {
- $cfgRelation['centralcolumnswork'] = true;
- }
- }
-
- if (isset($cfgRelation['designer_settings'])) {
- if ($this->canAccessStorageTable($cfgRelation['designer_settings'])) {
- $cfgRelation['designersettingswork'] = true;
- }
- }
-
- if (isset($cfgRelation['export_templates'])) {
- if ($this->canAccessStorageTable($cfgRelation['export_templates'])) {
- $cfgRelation['exporttemplateswork'] = true;
- }
- }
-
- $allWorks = true;
- foreach ($workToTable as $work => $table) {
- if (! $cfgRelation[$work]) {
- if (is_string($table)) {
- if (isset($GLOBALS['cfg']['Server'][$table])
- && $GLOBALS['cfg']['Server'][$table] !== false
- ) {
- $allWorks = false;
- break;
- }
- } elseif (is_array($table)) {
- $oneNull = false;
- foreach ($table as $t) {
- if (isset($GLOBALS['cfg']['Server'][$t])
- && $GLOBALS['cfg']['Server'][$t] === false
- ) {
- $oneNull = true;
- break;
- }
- }
- if (! $oneNull) {
- $allWorks = false;
- break;
- }
- }
- }
- }
- $cfgRelation['allworks'] = $allWorks;
-
- return $cfgRelation;
- }
-
- /**
- * Check if the table is accessible
- *
- * @param string $tableDbName The table or table.db
- * @return boolean The table is accessible
- */
- public function canAccessStorageTable($tableDbName)
- {
- $result = $this->queryAsControlUser(
- 'SELECT NULL FROM ' . $tableDbName . ' LIMIT 0',
- false,
- DatabaseInterface::QUERY_STORE
- );
- return $result !== false;
- }
-
- /**
- * Check whether column_info table input transformation
- * upgrade is required and try to upgrade silently
- *
- * @return bool false if upgrade failed
- *
- * @access public
- */
- public function tryUpgradeTransformations()
- {
- // From 4.3, new input oriented transformation feature was introduced.
- // Check whether column_info table has input transformation columns
- $new_cols = [
- "input_transformation",
- "input_transformation_options",
- ];
- $query = 'SHOW COLUMNS FROM '
- . Util::backquote($GLOBALS['cfg']['Server']['pmadb'])
- . '.' . Util::backquote(
- $GLOBALS['cfg']['Server']['column_info']
- )
- . ' WHERE Field IN (\'' . implode('\', \'', $new_cols) . '\')';
- $result = $this->queryAsControlUser(
- $query,
- false,
- DatabaseInterface::QUERY_STORE
- );
- if ($result) {
- $rows = $this->dbi->numRows($result);
- $this->dbi->freeResult($result);
- // input transformations are present
- // no need to upgrade
- if ($rows === 2) {
- return true;
- // try silent upgrade without disturbing the user
- }
-
- // read upgrade query file
- $query = @file_get_contents(SQL_DIR . 'upgrade_column_info_4_3_0+.sql');
- // replace database name from query to with set in config.inc.php
- // replace pma__column_info table name from query
- // to with set in config.inc.php
- $query = str_replace(
- [
- '`phpmyadmin`',
- '`pma__column_info`',
- ],
- [
- Util::backquote($GLOBALS['cfg']['Server']['pmadb']),
- Util::backquote($GLOBALS['cfg']['Server']['column_info']),
- ],
- $query
- );
- $this->dbi->tryMultiQuery($query, DatabaseInterface::CONNECT_CONTROL);
- // skips result sets of query as we are not interested in it
- do {
- $hasResult = (
- $this->dbi->moreResults(DatabaseInterface::CONNECT_CONTROL)
- && $this->dbi->nextResult(DatabaseInterface::CONNECT_CONTROL)
- );
- } while ($hasResult);
- $error = $this->dbi->getError(DatabaseInterface::CONNECT_CONTROL);
- // return true if no error exists otherwise false
- return empty($error);
- }
- // some failure, either in upgrading or something else
- // make some noise, time to wake up user.
- return false;
- }
-
- /**
- * Gets all Relations to foreign tables for a given table or
- * optionally a given column in a table
- *
- * @param string $db the name of the db to check for
- * @param string $table the name of the table to check for
- * @param string $column the name of the column to check for
- * @param string $source the source for foreign key information
- *
- * @return array db,table,column
- *
- * @access public
- */
- public function getForeigners($db, $table, $column = '', $source = 'both')
- {
- $cfgRelation = $this->getRelationsParam();
- $foreign = [];
-
- if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
- $rel_query = '
- SELECT `master_field`,
- `foreign_db`,
- `foreign_table`,
- `foreign_field`
- FROM ' . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['relation']) . '
- WHERE `master_db` = \'' . $this->dbi->escapeString($db) . '\'
- AND `master_table` = \'' . $this->dbi->escapeString($table)
- . '\' ';
- if (strlen($column) > 0) {
- $rel_query .= ' AND `master_field` = '
- . '\'' . $this->dbi->escapeString($column) . '\'';
- }
- $foreign = $this->dbi->fetchResult(
- $rel_query,
- 'master_field',
- null,
- DatabaseInterface::CONNECT_CONTROL
- );
- }
-
- if (($source == 'both' || $source == 'foreign') && strlen($table) > 0) {
- $tableObj = new Table($table, $db);
- $show_create_table = $tableObj->showCreate();
- if ($show_create_table) {
- $parser = new Parser($show_create_table);
- /**
- * @var CreateStatement $stmt
- */
- $stmt = $parser->statements[0];
- $foreign['foreign_keys_data'] = TableUtils::getForeignKeys(
- $stmt
- );
- }
- }
-
- /**
- * Emulating relations for some information_schema tables
- */
- $isInformationSchema = mb_strtolower($db) == 'information_schema';
- $isMysql = mb_strtolower($db) == 'mysql';
- if (($isInformationSchema || $isMysql)
- && ($source == 'internal' || $source == 'both')
- ) {
- if ($isInformationSchema) {
- $internalRelations = InternalRelations::getInformationSchema();
- } else {
- $internalRelations = InternalRelations::getMySql();
- }
- if (isset($internalRelations[$table])) {
- foreach ($internalRelations[$table] as $field => $relations) {
- if ((strlen($column) === 0 || $column == $field)
- && (! isset($foreign[$field])
- || strlen($foreign[$field]) === 0)
- ) {
- $foreign[$field] = $relations;
- }
- }
- }
- }
-
- return $foreign;
- }
-
- /**
- * Gets the display field of a table
- *
- * @param string $db the name of the db to check for
- * @param string $table the name of the table to check for
- *
- * @return string|false field name or false
- *
- * @access public
- */
- public function getDisplayField($db, $table)
- {
- $cfgRelation = $this->getRelationsParam();
-
- /**
- * Try to fetch the display field from DB.
- */
- if ($cfgRelation['displaywork']) {
- $disp_query = '
- SELECT `display_field`
- FROM ' . Util::backquote($cfgRelation['db'])
- . '.' . Util::backquote($cfgRelation['table_info']) . '
- WHERE `db_name` = \'' . $this->dbi->escapeString((string) $db) . '\'
- AND `table_name` = \'' . $this->dbi->escapeString((string) $table)
- . '\'';
-
- $row = $this->dbi->fetchSingleRow(
- $disp_query,
- 'ASSOC',
- DatabaseInterface::CONNECT_CONTROL
- );
- if (isset($row['display_field'])) {
- return $row['display_field'];
- }
- }
-
- /**
- * Emulating the display field for some information_schema tables.
- */
- if ($db == 'information_schema') {
- switch ($table) {
- case 'CHARACTER_SETS':
- return 'DESCRIPTION';
- case 'TABLES':
- return 'TABLE_COMMENT';
- }
- }
-
- /**
- * Pick first char field
- */
- $columns = $this->dbi->getColumnsFull($db, $table);
- if ($columns) {
- foreach ($columns as $column) {
- if ($this->dbi->types->getTypeClass($column['DATA_TYPE']) == 'CHAR') {
- return $column['COLUMN_NAME'];
- }
- }
- }
- return false;
- }
-
- /**
- * Gets the comments for all columns of a table or the db itself
- *
- * @param string $db the name of the db to check for
- * @param string $table the name of the table to check for
- *
- * @return array [column_name] = comment
- *
-