diff --git a/chk_rel.php b/chk_rel.php index 915e8b24b4..e7879a52c5 100644 --- a/chk_rel.php +++ b/chk_rel.php @@ -7,6 +7,12 @@ */ require_once 'libraries/common.inc.php'; + +// If request for fixing PMA tables. +if (isset($_REQUEST['fix_pmadb'])) { + PMA_fixPMATables($GLOBALS['db']); +} + $response = PMA_Response::getInstance(); $response->addHTML( PMA_getRelationsParamDiagnostic(PMA_getRelationsParam()) diff --git a/db_operations.php b/db_operations.php index 60f00d0b6b..456f584566 100644 --- a/db_operations.php +++ b/db_operations.php @@ -253,8 +253,7 @@ if (!$is_information_schema) { */ $response->addHTML(PMA_getHtmlForChangeDatabaseCharset($GLOBALS['db'], $table)); - if ($num_tables > 0 - && ! $cfgRelation['allworks'] + if (! $cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false ) { $message = PMA_Message::notice( @@ -270,9 +269,6 @@ if (!$is_information_schema) { if (!empty($cfg['Servers'][$server]['pmadb'])) { $message->isError(true); } - $response->addHTML('
'); - $response->addHTML($message->getDisplay()); - $response->addHTML('
'); } // end if } // end if (!$is_information_schema) diff --git a/doc/config.rst b/doc/config.rst index 9ebf996d9e..f2308b1eab 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1439,6 +1439,20 @@ Navigation panel setup The maximum number of recently used tables shown in the navigation panel. Set this to 0 (zero) to disable the listing of recent tables. +.. config:option:: $cfg['ZeroConf'] + + :type: boolean + :default: true + + Enables Zero Configuration mode in which user will be offered a choice to + create phpMyAdmin configuration storage in the current database + or use existing, if already present. + + .. note:: + If there is no central configuration storage defined then you may end up with + different set of phpMyAdmin configuration storage tables for different + databases. + .. config:option:: $cfg['NavigationLinkWithMainPanel'] :type: boolean diff --git a/index.php b/index.php index 5c9147fa4b..ca74f0ac7c 100644 --- a/index.php +++ b/index.php @@ -513,7 +513,19 @@ if ($server > 0) { if (! $cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false ) { - $msg = PMA_Message::notice(__('The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. To find out why click %shere%s.')); + $msg_text = __( + 'The phpMyAdmin configuration storage is not completely ' + . 'configured, some extended features have been deactivated. ' + . 'To find out why click %shere%s. ' + ); + if ($cfg['ZeroConf'] == true) { + $msg_text .= __( + '
      ' + . 'Or alternately go to \'Operations\' tab of any database ' + . 'to set it up there.' + ); + } + $msg = PMA_Message::notice($msg_text); $msg->addParam( '', diff --git a/libraries/common.inc.php b/libraries/common.inc.php index d30cf964b9..79dbd92d08 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -1147,4 +1147,10 @@ if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) { exit(); } +// If Zero configuration mode enabled, check PMA tables in current db. +if (isset($GLOBALS['cfg']['ZeroConf']) + && $GLOBALS['cfg']['ZeroConf'] == true +) { + PMA_checkAndFixPMATablesInCurrentDb(); +} ?> diff --git a/libraries/config.default.php b/libraries/config.default.php index 964474fab6..64000e727e 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -316,6 +316,13 @@ $cfg['Servers'][$i]['hide_db'] = ''; */ $cfg['Servers'][$i]['verbose'] = ''; +/** + * Zero Configuration mode. + * + * @global boolean $cfg['ZeroConf'] + */ +$cfg['ZeroConf'] = true; + /** * Database used for Relation, Bookmark and PDF Features * (see examples/create_tables.sql) diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 130b8cf67e..58f9b72667 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -786,5 +786,10 @@ $strConfigCaptchaLoginPrivateKey_name = __('Private key for reCaptcha'); $strConfigSendErrorReports_desc = __('Choose the default action when sending error reports.'); $strConfigSendErrorReports_name = __('Send error reports'); +$strConfigZeroConf_desc = __( + 'Enable Zero Configuration mode which lets you to setup phpMyAdmin ' + . 'configuration storage tables automatically.' +); +$strConfigZeroConf_name = __('Enable Zero Configuration mode'); ?> diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index d12df242c0..d91e4ffb52 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -145,6 +145,7 @@ $forms['Features']['Other_core_settings'] = array( 'ProxyUser', 'ProxyPass', 'AllowThirdPartyFraming', + 'ZeroConf' ); $forms['Sql_queries']['Sql_queries'] = array( 'ShowSQL', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index f5161adcc9..3d4c2568da 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -35,7 +35,8 @@ $forms['Features']['General'] = array( 'NumRecentTables', 'NumFavoriteTables', 'ShowHint', - 'SendErrorReports'); + 'SendErrorReports' +); $forms['Features']['Text_fields'] = array( 'CharEditing', 'MinSizeForInputField', diff --git a/libraries/core.lib.php b/libraries/core.lib.php index 14d0a09306..40b6b8237f 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -952,4 +952,39 @@ function PMA_emptyRecursive($value) } return $empty; } + +/** + * Checks and fixes configuration storage in current DB. + * + * @return void + */ +function PMA_checkAndFixPMATablesInCurrentDb() +{ + if (isset($GLOBALS['db']) && ! empty($GLOBALS['db'])) { + if (isset($GLOBALS['cfg']['Server']['pmadb']) + && empty($GLOBALS['cfg']['Server']['pmadb']) + ) { + $default_tables = PMA_getDefaultPMATableNames(); + if (PMA_searchPMATablesInDb( + $GLOBALS['db'], + array_keys($default_tables) + ) + ) { + PMA_fixPMATables($GLOBALS['db']); + // Since configuration storage is updated, we need to + // re-initialize the favorite and recent tables stored in the + // session from the current configuration storage. + include_once 'libraries/RecentFavoriteTable.class.php'; + $fav_tables = PMA_RecentFavoriteTable::getInstance('favorite'); + $recent_tables = PMA_RecentFavoriteTable::getInstance('recent'); + $_SESSION['tmpval']['favorite_tables'][$GLOBALS['server']] + = $fav_tables->getFromDb(); + $_SESSION['tmpval']['recent_tables'][$GLOBALS['server']] + = $recent_tables->getFromDb(); + // Reload navi panel to update the recent/favorite lists. + $GLOBALS['reload'] = true; + } + } + } +} ?> diff --git a/libraries/mult_submits.lib.php b/libraries/mult_submits.lib.php index dbfaed1505..1bb4771a62 100644 --- a/libraries/mult_submits.lib.php +++ b/libraries/mult_submits.lib.php @@ -276,7 +276,7 @@ function PMA_getQueryStrFromSelected( if ($deletes) { $_REQUEST['pos'] = PMA_calculatePosForLastPage( - $db, $table, $_REQUEST['pos'] + $db, $table, isset($_REQUEST['pos']) ? $_REQUEST['pos'] : null ); } diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 190243b397..1a06dede44 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -107,6 +107,9 @@ function PMA_getRelationsParamDiagnostic($cfgRelation) . __('General relation features') . ' ' . __('Disabled') . '' . "\n"; + if (! empty($GLOBALS['db']) && $GLOBALS['cfg']['ZeroConf']) { + $retval .= PMA_getHtmlFixPMATables(); + } } else { $retval .= '' . "\n"; $retval .= PMA_getDiagMessageForParameter( @@ -298,33 +301,37 @@ function PMA_getRelationsParamDiagnostic($cfgRelation) ); $retval .= '
' . "\n"; - $retval .= '

' . __('Quick steps to setup advanced features:') . '

'; - $retval .= ''; + if (! $cfgRelation['allworks']) { + + $retval .= '

' . __('Quick steps to setup advanced features:') + . '

'; + $retval .= ''; + } } return $retval; @@ -1723,4 +1730,156 @@ function PMA_searchColumnInForeigners($foreigners, $column) return false; } + +/** + * Searches a DB for the existence of PMA tables. + * + * @param string $db Database + * @param array $tables Default table names + * + * @return bool + */ +function PMA_searchPMATablesInDb($db, $tables) +{ + $tab_rs = $GLOBALS['dbi']->getTables($db); + + if ($tab_rs === false) { + return false; + } + + foreach ($tab_rs as $curr_table) { + if (in_array($curr_table, $tables)) { + $tables = array_diff($tables, array($curr_table)); + } + } + + if (count($tables) != 0) { + return false; + } + + return true; +} + +/** + * Returns default PMA table names and their create queries. + * + * @return array table name, create query + */ +function PMA_getDefaultPMATableNames() +{ + $pma_tables = array(); + if (PMA_DRIZZLE) { + $create_tables_file = file_get_contents( + 'examples/create_tables_drizzle.sql' + ); + } else { + $create_tables_file = file_get_contents( + 'examples/create_tables.sql' + ); + } + + $queries = explode(';', $create_tables_file); + + foreach ($queries as $query) { + if (preg_match( + '/CREATE TABLE IF NOT EXISTS `(.*)` \(/', + $query, + $table + ) + ) { + $pma_tables[$table[1]] = $query . ';'; + } + } + + return $pma_tables; +} + +/** + * Creates PMA tables in the given db, updates if already exists. + * + * @param string $db Database + * + * @return void + */ +function PMA_fixPMATables($db) +{ + $default_tables = PMA_getDefaultPMATableNames(); + $GLOBALS['dbi']->selectDb($db); + + foreach ($default_tables as $table => $create_query) { + $GLOBALS['dbi']->tryQuery($create_query); + + if ($error = $GLOBALS['dbi']->getError()) { + $GLOBALS['message'] = $error; + break; + } + + if ($table == 'pma__bookmark') { + $GLOBALS['cfg']['Server']['bookmarktable'] = $table; + } elseif ($table == 'pma__relation') { + $GLOBALS['cfg']['Server']['relation'] = $table; + } elseif ($table == 'pma__table_info') { + $GLOBALS['cfg']['Server']['table_info'] = $table; + } elseif ($table == 'pma__table_coords') { + $GLOBALS['cfg']['Server']['table_coords'] = $table; + } elseif ($table == 'pma__column_info') { + $GLOBALS['cfg']['Server']['column_info'] = $table; + } elseif ($table == 'pma__pdf_pages') { + $GLOBALS['cfg']['Server']['pdf_pages'] = $table; + } elseif ($table == 'pma__history') { + $GLOBALS['cfg']['Server']['history'] = $table; + } elseif ($table == 'pma__recent') { + $GLOBALS['cfg']['Server']['recent'] = $table; + } elseif ($table == 'pma__table_uiprefs') { + $GLOBALS['cfg']['Server']['table_uiprefs'] = $table; + } elseif ($table == 'pma__tracking') { + $GLOBALS['cfg']['Server']['tracking'] = $table; + } elseif ($table == 'pma__userconfig') { + $GLOBALS['cfg']['Server']['userconfig'] = $table; + } elseif ($table == 'pma__users') { + $GLOBALS['cfg']['Server']['users'] = $table; + } elseif ($table == 'pma__usergroups') { + $GLOBALS['cfg']['Server']['usergroups'] = $table; + } elseif ($table == 'pma__navigationhiding') { + $GLOBALS['cfg']['Server']['navigationhiding'] = $table; + } elseif ($table == 'pma__savedsearches') { + $GLOBALS['cfg']['Server']['savedsearches'] = $table; + } elseif ($table == 'pma__central_columns') { + $GLOBALS['cfg']['Server']['central_columns'] = $table; + } else if ($table == 'pma__designer_coords') { + $GLOBALS['cfg']['Server']['designer_coords'] = $table; + } + } + $GLOBALS['cfg']['Server']['pmadb'] = $db; + $_SESSION['relation'][$GLOBALS['server']] = PMA_checkRelationsParam(); +} + +/** + * Get Html for PMA tables fixing anchor. + * + * @return string Html + */ +function PMA_getHtmlFixPMATables() +{ + $retval = ''; + + $url_query = PMA_URL_getCommon($GLOBALS['db']); + $url_query .= '&goto=db_operations.php&fix_pmadb=1'; + $message = PMA_Message::notice( + __( + '%sCreate%s the phpMyAdmin configuration storage in the ' + . 'current database.' + ) + ); + $message->addParam( + '
', + false + ); + $message->addParam('', false); + + $retval .= $message->getDisplay(); + + return $retval; +} ?> diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 2bbd2b9b9f..2093514cc0 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -773,6 +773,8 @@ function PMA_getHtmlForBookmark($disp_mode, $cfgBookmark, $sql_query, $db, $tabl . '\'bkm_fields[bkm_label]\');"' . ' id="bookmarkQueryForm">'; $html .= PMA_URL_getHiddenInputs(); + $html .= ''; $html .= ''; $html .= ''; diff --git a/prefs_forms.php b/prefs_forms.php index 2cc37bfa8e..4364260685 100644 --- a/prefs_forms.php +++ b/prefs_forms.php @@ -54,6 +54,10 @@ $error = null; if ($form_display->process(false) && !$form_display->hasErrors()) { // save settings $result = PMA_saveUserprefs($cf->getConfigArray()); + if (! isset($_REQUEST['ZeroConf'])) { + $_SESSION['relation'][$GLOBALS['server']] = null; + } + if ($result === true) { // reload config $GLOBALS['PMA_Config']->loadUserPreferences();