Creating StructureController

Signed-off-by: Jason <jason.daurus@gmail.com>
This commit is contained in:
Jason 2015-07-26 18:59:37 +08:00
parent f3668b3e33
commit 1c28e6a8ab
24 changed files with 2077 additions and 2283 deletions

View File

@ -17,6 +17,7 @@
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/display_create_table.lib.php';
/**
* functions implementation for this script
@ -232,11 +233,7 @@ if (!$is_information_schema) {
}
$response->addHTML('<div class="operations_half_width">');
ob_start();
include 'libraries/display_create_table.lib.php';
$content = ob_get_contents();
ob_end_clean();
$response->addHTML($content);
$response->addHTML(PMA_getHtmlForCreateTable($db));
$response->addHTML('</div>');
/**

View File

@ -6,370 +6,34 @@
* @package PhpMyAdmin
*/
/**
*
*/
namespace PMA;
require_once 'libraries/common.inc.php';
require_once 'libraries/db_common.inc.php';
require_once 'libraries/db_info.inc.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/StructureController.class.php';
/**
* Function implementations for this script
*/
require_once 'libraries/structure.lib.php';
$container = DI\Container::getDefaultContainer();
$container->factory('PMA\Controllers\StructureController');
$container->alias(
'StructureController', 'PMA\Controllers\StructureController'
);
// Add/Remove favorite tables using Ajax request.
if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) {
PMA_addRemoveFavoriteTables($db);
exit;
}
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('db_structure.js');
$scripts->addFile('tbl_change.js');
$scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
// Drops/deletes/etc. multiple tables if required
if ((!empty($_POST['submit_mult']) && isset($_POST['selected_tbl']))
|| isset($_POST['mult_btn'])
) {
$action = 'db_structure.php';
$err_url = 'db_structure.php' . PMA_URL_getCommon(array('db' => $db));
// see bug #2794840; in this case, code path is:
// db_structure.php -> libraries/mult_submits.inc.php -> sql.php
// -> db_structure.php and if we got an error on the multi submit,
// we must display it here and not call again mult_submits.inc.php
if (! isset($_POST['error']) || false === $_POST['error']) {
include 'libraries/mult_submits.inc.php';
}
if (empty($_POST['message'])) {
$_POST['message'] = PMA_Message::success();
}
}
require 'libraries/db_common.inc.php';
$url_query .= '&amp;goto=db_structure.php';
// Gets the database structure
$sub_part = '_structure';
require 'libraries/db_info.inc.php';
// If there is an Ajax request for real row count of a table.
if ($GLOBALS['is_ajax_request']
&& isset($_REQUEST['real_row_count'])
&& $_REQUEST['real_row_count'] == true
) {
PMA_handleRealRowCountRequest();
exit;
}
if (!PMA_DRIZZLE) {
include_once 'libraries/replication.inc.php';
} else {
$GLOBALS['replication_info']['slave']['status'] = false;
}
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('DbStructure');
require_once 'libraries/bookmark.lib.php';
require_once 'libraries/mysql_charsets.inc.php';
$db_collation = PMA_getDbCollation($db);
$titles = PMA_Util::buildActionTitles();
// 1. No tables
if ($num_tables == 0) {
$response->addHTML(
PMA_message::notice(__('No tables found in database.'))
);
PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);
exit;
}
// else
// 2. Shows table information
/**
* Displays the tables list
*/
$response->addHTML('<div id="tableslistcontainer">');
$_url_params = array(
global $db, $table, $pos, $db_is_system_schema, $total_num_tables, $tables, $num_tables;
/* Define dependencies for the concerned controller */
$dependency_definitions = array(
'db' => $db,
'table' => $table,
'type' => 'db',
'url_query' => &$GLOBALS['url_query'],
'pos' => $pos,
'db' => $db);
// Add the sort options if they exists
if (isset($_REQUEST['sort'])) {
$_url_params['sort'] = $_REQUEST['sort'];
}
if (isset($_REQUEST['sort_order'])) {
$_url_params['sort_order'] = $_REQUEST['sort_order'];
}
$response->addHTML(
PMA_Util::getListNavigator(
$total_num_tables, $pos, $_url_params, 'db_structure.php',
'frame_content', $GLOBALS['cfg']['MaxTableList']
)
'db_is_system_schema' => $db_is_system_schema,
'num_tables' => $num_tables,
'total_num_tables' => $total_num_tables,
'tables' => $tables
);
// tables form
$response->addHTML(
'<form method="post" action="db_structure.php" '
. 'name="tablesForm" id="tablesForm">'
);
$response->addHTML(PMA_URL_getHiddenInputs($db));
$response->addHTML(
PMA\Template::get('structure/table_header')->render(
array(
'db_is_system_schema' => $db_is_system_schema,
'replication' => $GLOBALS['replication_info']['slave']['status']
)
)
);
$i = $sum_entries = 0;
$overhead_check = '';
$create_time_all = '';
$update_time_all = '';
$check_time_all = '';
$num_columns = $cfg['PropertiesNumColumns'] > 1
? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1
: 0;
$row_count = 0;
$sum_size = (double) 0;
$overhead_size = (double) 0;
$hidden_fields = array();
$odd_row = true;
$overall_approx_rows = false;
// Instance of PMA_RecentFavoriteTable class.
$fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
foreach ($tables as $keyname => $current_table) {
// Get valid statistics whatever is the table type
$drop_query = '';
$drop_message = '';
$already_favorite = false;
$overhead = '';
$table_is_view = false;
$table_encoded = urlencode($current_table['TABLE_NAME']);
// Sets parameters for links
$tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
// do not list the previous table's size info for a view
list($current_table, $formatted_size, $unit, $formatted_overhead,
$overhead_unit, $overhead_size, $table_is_view, $sum_size)
= PMA_getStuffForEngineTypeTable(
$current_table, $db_is_system_schema,
$is_show_stats, $table_is_view, $sum_size, $overhead_size
);
$_table = new PMA_Table($current_table['TABLE_NAME'], $db);
if (! $_table->isMerge()) {
$sum_entries += $current_table['TABLE_ROWS'];
}
if (isset($current_table['Collation'])) {
$collation = '<dfn title="'
. PMA_getCollationDescr($current_table['Collation']) . '">'
. $current_table['Collation'] . '</dfn>';
} else {
$collation = '---';
}
if ($is_show_stats) {
if ($formatted_overhead != '') {
$overhead = '<a href="tbl_structure.php'
. $tbl_url_query . '#showusage">'
. '<span>' . $formatted_overhead . '</span>&nbsp;'
. '<span class="unit">' . $overhead_unit . '</span>'
. '</a>' . "\n";
$overhead_check .=
"markAllRows('row_tbl_" . ($i + 1) . "');";
} else {
$overhead = '-';
}
} // end if
unset($showtable);
if ($GLOBALS['cfg']['ShowDbStructureCreation']) {
list($create_time, $create_time_all) = PMA_getTimeForCreateUpdateCheck(
$current_table, 'Create_time', $create_time_all
);
}
if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) {
// $showtable might already be set from ShowDbStructureCreation, see above
list($update_time, $update_time_all) = PMA_getTimeForCreateUpdateCheck(
$current_table, 'Update_time', $update_time_all
);
}
if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) {
// $showtable might already be set from ShowDbStructureCreation, see above
list($check_time, $check_time_all) = PMA_getTimeForCreateUpdateCheck(
$current_table, 'Check_time', $check_time_all
);
}
list($alias, $truename) = PMA_getAliasAndTrueName(
$tooltip_aliasname, $current_table, $tooltip_truename
);
$i++;
$row_count++;
if ($table_is_view) {
$hidden_fields[] = '<input type="hidden" name="views[]" value="'
. htmlspecialchars($current_table['TABLE_NAME']) . '" />';
}
/*
* Always activate links for Browse, Search and Empty, even if
* the icons are greyed, because
* 1. for views, we don't know the number of rows at this point
* 2. for tables, another source could have populated them since the
* page was generated
*
* I could have used the PHP ternary conditional operator but I find
* the code easier to read without this operator.
*/
list($browse_table, $search_table, $browse_table_label,
$empty_table, $tracking_icon
) = PMA_getHtmlForActionLinks(
$current_table, $table_is_view, $tbl_url_query,
$titles, $truename, $db_is_system_schema, $url_query
);
if (! $db_is_system_schema) {
list($drop_query, $drop_message)
= PMA_getTableDropQueryAndMessage($table_is_view, $current_table);
}
if ($num_columns > 0
&& $num_tables > $num_columns
&& ($row_count % $num_columns) == 0
) {
$row_count = 1;
$odd_row = true;
$response->addHTML(
'</tr></tbody></table>'
);
$response->addHTML(
PMA\Template::get('structure/table_header')->render(
array(
'db_is_system_schema' => false,
'replication' => $GLOBALS['replication_info']['slave']['status']
)
)
);
}
list($do, $ignored) = PMA_getServerSlaveStatus(
$GLOBALS['replication_info']['slave']['status'], $truename
);
// Handle favorite table list. ----START----
$already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
if (isset($_REQUEST['remove_favorite'])) {
if ($already_favorite) {
// If already in favorite list, remove it.
$favorite_table = $_REQUEST['favorite_table'];
$fav_instance->remove($db, $favorite_table);
}
}
if (isset($_REQUEST['add_favorite'])) {
if (!$already_favorite) {
// Otherwise add to favorite list.
$favorite_table = $_REQUEST['favorite_table'];
$fav_instance->add($db, $favorite_table);
}
} // Handle favorite table list. ----ENDS----
list($html_output, $odd_row, $approx_rows) = PMA_getHtmlForStructureTableRow(
$i, $odd_row, $table_is_view, $current_table,
$browse_table_label, $tracking_icon,
$GLOBALS['replication_info']['slave']['status'],
$browse_table, $tbl_url_query, $search_table, $db_is_system_schema,
$titles, $empty_table, $drop_query, $drop_message, $collation,
$formatted_size, $unit, $overhead,
(isset ($create_time) ? $create_time : ''),
(isset ($update_time) ? $update_time : ''),
(isset ($check_time) ? $check_time : ''),
$is_show_stats, $ignored, $do, $colspan_for_structure
);
$overall_approx_rows = $overall_approx_rows || $approx_rows;
$response->addHTML($html_output);
} // end foreach
// Show Summary
$response->addHTML('</tbody>');
$response->addHTML(
PMA\Template::get('structure/body_for_table_summary')->render(
array(
'num_tables' => $num_tables,
'server_slave_status' => $GLOBALS['replication_info']['slave']['status'],
'db_is_system_schema' => $db_is_system_schema,
'sum_entries' => $sum_entries,
'db_collation' => $db_collation,
'is_show_stats' => $is_show_stats,
'sum_size' => $sum_size,
'overhead_size' => $overhead_size,
'create_time_all' => $create_time_all,
'update_time_all' => $update_time_all,
'check_time_all' => $check_time_all,
'approx_rows' => $overall_approx_rows
)
)
);
$response->addHTML('</table>');
//check all
$response->addHTML(
PMA\Template::get('structure/check_all_tables')->render(
array(
'pmaThemeImage' => $pmaThemeImage,
'text_dir' => $text_dir,
'overhead_check' => $overhead_check,
'db_is_system_schema' => $db_is_system_schema,
'hidden_fields' => $hidden_fields
)
)
);
$response->addHTML('</form>'); //end of form
// display again the table list navigator
$response->addHTML(
PMA_Util::getListNavigator(
$total_num_tables, $pos, $_url_params, 'db_structure.php',
'frame_content', $GLOBALS['cfg']['MaxTableList']
)
);
$response->addHTML('</div><hr />');
/**
* Work on the database
*/
/* DATABASE WORK */
/* Printable view of a table */
$response->addHTML(
PMA\Template::get('structure/print_view_data_dictionary_link')->render(
array('url_query' => $url_query)
)
);
PMA_possiblyShowCreateTableDialog($db, $db_is_system_schema, $response);
/** @var Controllers\StructureController $controller */
$controller = $container->get('StructureController', $dependency_definitions);
$controller->indexAction();

View File

@ -12,6 +12,7 @@
require_once 'libraries/common.inc.php';
require_once './libraries/tracking.lib.php';
require_once 'libraries/display_create_table.lib.php';
//Get some js files needed for Ajax requests
$response = PMA_Response::getInstance();
@ -89,7 +90,7 @@ if ($num_tables == 0 && count($data['ddlog']) == 0) {
echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
if (empty($db_is_system_schema)) {
include 'libraries/display_create_table.lib.php';
echo PMA_getHtmlForCreateTable($db);
}
exit;
}

View File

@ -2349,4 +2349,40 @@ class PMA_Table
0, 1
);
}
/**
* Returns the real row count for a table
*
* @return number
*/
function getRealRowCountTable()
{
// SQL query to get row count for a table.
$result = $this->_dbi->fetchSingleRow(sprintf(
'SELECT COUNT(*) AS %s FROM %s.%s',
PMA_Util::backquote('row_count'),
PMA_Util::backquote($this->_db_name),
PMA_Util::backquote($$this->_name)
));
return $result['row_count'];
}
/**
* Get columns with indexes
*
* @param int $types types bitmask
*
* @return array an array of columns
*/
function getColumnsWithIndex($types)
{
$columns_with_index = array();
foreach (PMA_Index::getFromTableByChoice($this->_name, $this->_db_name, $types) as $index) {
$columns = $index->getColumns();
foreach ($columns as $column_name => $dummy) {
$columns_with_index[] = $column_name;
}
}
return $columns_with_index;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -157,8 +157,17 @@ class TableRelationController extends TableController
}
// display secondary level tabs if necessary
$engine = $GLOBALS['dbi']->getTable($this->db, $this->table)->sGetStatusInfo('ENGINE');
$this->response->addHTML(PMA_getStructureSecondaryTabs($engine));
$engine = $this->dbi->getTable($this->db, $this->table)->sGetStatusInfo('ENGINE');
$this->response->addHTML(Template::get('structure/secondary_tabs')
->render(
array(
'url_params' => array(
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table']
),
'engine' => $engine
)
));
$this->response->addHTML('<div id="structure_content">');
/**

View File

@ -32,8 +32,7 @@ if (! defined('PHPMYADMIN')) {
*
*/
require_once './libraries/check_user_privileges.lib.php';
$is_create_table_priv = true;
require_once 'libraries/Template.class.php';
/**
* Returns the html for create table.
@ -44,38 +43,7 @@ $is_create_table_priv = true;
*/
function PMA_getHtmlForCreateTable($db)
{
$html = '<form id="create_table_form_minimal" method="post" '
. 'action="tbl_create.php" class="lock-page">';
$html .= '<fieldset>';
$html .= '<legend>';
if (PMA_Util::showIcons('ActionLinksMode')) {
$html .= PMA_Util::getImage('b_table_add.png') . '&nbsp';
}
$html .= __('Create table');
$html .= ' </legend>';
$html .= PMA_URL_getHiddenInputs($db);
$html .= '<div class="formelement">';
$html .= __('Name') . ":";
$html .= ' <input type="text" name="table" maxlength="64" '
. 'size="30" required="required" />';
$html .= ' </div>';
$html .= ' <div class="formelement">';
$html .= __('Number of columns') . ":";
$html .= ' <input type="number" min="1" name="num_fields" '
. 'value="4" required="required" />';
$html .= ' </div>';
$html .= ' <div class="clearfloat"></div>';
$html .= '</fieldset>';
$html .= '<fieldset class="tblFooters">';
$html .= ' <input type="submit" value="' . __('Go') . '" />';
$html .= '</fieldset>';
$html .= '</form>';
return $html;
}
if (!defined('TESTSUITE')) {
echo PMA_getHtmlForCreateTable($db);
return PMA\Template::get('table/create_table')->render(
array('db' => $db)
);
}

View File

@ -17,10 +17,12 @@ if (! defined('PHPMYADMIN')) {
exit;
}
global $db, $table, $tbl_is_view, $cfg, $db_is_system_schema,
$tbl_storage_engine, $pmaThemeImage, $text_dir, $url_query, $showtable, $tbl_collation, $table_info_num_rows;
$response = PMA_Response::getInstance();
/* TABLE INFORMATION */
// table header
$HideStructureActions = '';
if ($GLOBALS['cfg']['HideStructureActions'] === true) {
$HideStructureActions .= ' HideStructureActions';
@ -71,16 +73,34 @@ if ($GLOBALS['cfg']['ShowPropertyComments']) {
}
require_once 'libraries/central_columns.lib.php';
$central_list = PMA_getCentralColumnsFromTable($db, $table);
$rownum = 0;
$rownum = 0;
$columns_list = array();
$save_row = array();
$odd_row = true;
$save_row = array();
$odd_row = true;
$titles = array(
'Change' => PMA_Util::getIcon('b_edit.png', __('Change')),
'Drop' => PMA_Util::getIcon('b_drop.png', __('Drop')),
'NoDrop' => PMA_Util::getIcon('b_drop.png', __('Drop')),
'Primary' => PMA_Util::getIcon('b_primary.png', __('Primary')),
'Index' => PMA_Util::getIcon('b_index.png', __('Index')),
'Unique' => PMA_Util::getIcon('b_unique.png', __('Unique')),
'Spatial' => PMA_Util::getIcon('b_spatial.png', __('Spatial')),
'IdxFulltext' => PMA_Util::getIcon('b_ftext.png', __('Fulltext')),
'NoPrimary' => PMA_Util::getIcon('bd_primary.png', __('Primary')),
'NoIndex' => PMA_Util::getIcon('bd_index.png', __('Index')),
'NoUnique' => PMA_Util::getIcon('bd_unique.png', __('Unique')),
'NoSpatial' => PMA_Util::getIcon('bd_spatial.png', __('Spatial')),
'NoIdxFulltext' => PMA_Util::getIcon('bd_ftext.png', __('Fulltext')),
'DistinctValues' => PMA_Util::getIcon('b_browse.png', __('Distinct values'))
);
foreach ($fields as $row) {
$save_row[] = $row;
$rownum++;
$columns_list[] = $row['Field'];
$columns_list[] = $row['Field'];
$type = $row['Type'];
$type = $row['Type'];
$extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
$class_for_type = PMA_Util::getClassForType(
@ -246,7 +266,46 @@ $response->addHTML(
$response->addHTML('<div id="structure-action-links">');
if ($tbl_is_view) {
$response->addHTML(PMA_getHtmlForEditView($url_params));
/** @var PMA_DatabaseInterface $dbi */
$dbi = $GLOBALS['dbi'];
$item = $dbi->fetchSingleRow(sprintf(
"SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`, `SECURITY_TYPE`
FROM `INFORMATION_SCHEMA`.`VIEWS`
WHERE TABLE_SCHEMA='%s'
AND TABLE_NAME='%s';",
PMA_Util::sqlAddSlashes($GLOBALS['db']),
PMA_Util::sqlAddSlashes($GLOBALS['table'])
));
$createView = $dbi->getTable($GLOBALS['db'], $GLOBALS['table'])->showCreate();
// get algorithm from $createView of the form CREATE ALGORITHM=<ALGORITHM> DE...
$parts = explode(" ", substr($createView, 17));
$item['ALGORITHM'] = $parts[0];
$view = array(
'operation' => 'alter',
'definer' => $item['DEFINER'],
'sql_security' => $item['SECURITY_TYPE'],
'name' => $GLOBALS['table'],
'as' => $item['VIEW_DEFINITION'],
'with' => $item['CHECK_OPTION'],
'algorithm' => $item['ALGORITHM'],
);
$url = 'view_create.php' . PMA_URL_getCommon($url_params) . '&amp;' . implode(
'&amp;',
array_map(
function ($key, $val) {
return 'view[' . urlencode($key) . ']=' . urlencode($val);
},
array_keys($view), $view
)
);
$response->addHTML(PMA_Util::linkOrButton(
$url,
PMA_Util::getIcon('b_edit.png', __('Edit view'), true)
));
}
$response->addHTML(
PMA\Template::get('structure/optional_action_links')->render(
@ -295,11 +354,11 @@ if (! $tbl_is_view
// Get valid statistics whatever is the table type
if ($cfg['ShowStats']) {
//get table stats in HTML format
$tablestats = PMA_getHtmlForDisplayTableStats(
$showtable, $table_info_num_rows, $tbl_is_view,
$db_is_system_schema, $tbl_storage_engine,
$url_query, $tbl_collation
);
$tablestats = PMA_getTableStats(
$showtable, $table_info_num_rows, $tbl_is_view,
$db_is_system_schema, $tbl_storage_engine,
$url_query, $tbl_collation
);
//returning the response in JSON format to be used by Ajax
$response->addJSON('tableStat', $tablestats);
$response->addHTML($tablestats);

File diff suppressed because it is too large Load Diff

View File

@ -7,211 +7,36 @@
* @package PhpMyAdmin
*/
/**
*
*/
namespace PMA;
require_once 'libraries/common.inc.php';
require_once 'libraries/tbl_common.inc.php';
require_once 'libraries/mysql_charsets.inc.php';
require_once 'libraries/config/page_settings.class.php';
PMA_PageSettings::showGroup('TableStructure');
/**
* Function implementations for this script
*/
require_once 'libraries/check_user_privileges.lib.php';
require_once 'libraries/structure.lib.php';
require_once 'libraries/index.lib.php';
require_once 'libraries/sql.lib.php';
require_once 'libraries/bookmark.lib.php';
require_once 'libraries/di/Container.class.php';
require_once 'libraries/controllers/StructureController.class.php';
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('tbl_structure.js');
$scripts->addFile('indexes.js');
/**
* Handle column moving
*/
if (isset($_REQUEST['move_columns'])
&& is_array($_REQUEST['move_columns'])
&& $response->isAjax()
) {
PMA_moveColumns($db, $table);
exit;
}
/**
* handle MySQL reserved words columns check
*/
if (isset($_REQUEST['reserved_word_check'])) {
$response = PMA_Response::getInstance();
if ($GLOBALS['cfg']['ReservedWordDisableWarning'] === false) {
$columns_names = $_REQUEST['field_name'];
$reserved_keywords_names = array();
foreach ($columns_names as $column) {
if (SqlParser\Context::isKeyword(trim($column), true)) {
$reserved_keywords_names[] = trim($column);
}
}
if (SqlParser\Context::isKeyword(trim($table), true)) {
$reserved_keywords_names[] = trim($table);
}
if (count($reserved_keywords_names) == 0) {
$response->isSuccess(false);
}
$response->addJSON(
'message', sprintf(
_ngettext(
'The name \'%s\' is a MySQL reserved keyword.',
'The names \'%s\' are MySQL reserved keywords.',
count($reserved_keywords_names)
),
implode(',', $reserved_keywords_names)
)
);
} else {
$response->isSuccess(false);
}
exit;
}
/**
* A click on Change has been made for one column
*/
if (isset($_REQUEST['change_column'])) {
PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
exit;
}
/**
* handle multiple field commands if required
*
* submit_mult_*_x comes from IE if <input type="img" ...> is used
*/
$submit_mult = PMA_getMultipleFieldCommandType();
if (! empty($submit_mult)) {
if (isset($_REQUEST['selected_fld'])) {
if ($submit_mult == 'browse') {
// browsing the table displaying only selected columns
PMA_displayTableBrowseForSelectedColumns(
$db, $table, $goto, $pmaThemeImage
);
} else {
// handle multiple field commands
// handle confirmation of deleting multiple columns
$action = 'tbl_structure.php';
include 'libraries/mult_submits.inc.php';
/**
* if $submit_mult == 'change', execution will have stopped
* at this point
*/
if (empty($message)) {
$message = PMA_Message::success();
}
}
} else {
$response = PMA_Response::getInstance();
$response->isSuccess(false);
$response->addJSON('message', __('No column selected.'));
}
}
// display secondary level tabs if necessary
$engine = $GLOBALS['dbi']->getTable($db, $table)->sGetStatusInfo('ENGINE');
$response->addHTML(PMA_getStructureSecondaryTabs($engine));
$response->addHTML('<div id="structure_content">');
/**
* Modifications have been submitted -> updates the table
*/
if (isset($_REQUEST['do_save_data'])) {
$regenerate = PMA_updateColumns($db, $table);
if ($regenerate) {
// This happens when updating failed
// @todo: do something appropriate
} else {
// continue to show the table's structure
unset($_REQUEST['selected']);
}
}
/**
* Adding indexes
*/
if (isset($_REQUEST['add_key'])) {
include 'sql.php';
$GLOBALS['reload'] = true;
}
/**
* Gets the relation settings
*/
$cfgRelation = PMA_getRelationsParam();
/**
* Runs common work
*/
require_once 'libraries/tbl_common.inc.php';
$url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
$url_params['goto'] = 'tbl_structure.php';
$url_params['back'] = 'tbl_structure.php';
/**
* Prepares the table structure display
*/
/**
* Gets tables information
*/
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/Index.class.php';
// 2. Gets table keys and retains them
// @todo should be: $server->db($db)->table($table)->primary()
$primary = PMA_Index::getPrimary($table, $db);
$columns_with_index = PMA_getColumnsWithIndex(
$db, $table,
PMA_Index::UNIQUE | PMA_Index::INDEX | PMA_Index::SPATIAL | PMA_Index::FULLTEXT
$container = DI\Container::getDefaultContainer();
$container->factory('PMA\Controllers\StructureController');
$container->alias(
'StructureController', 'PMA\Controllers\StructureController'
);
$columns_with_unique_index = PMA_getColumnsWithIndex($db, $table, PMA_Index::UNIQUE);
// 3. Get fields
$fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
global $db, $table, $pos, $db_is_system_schema, $total_num_tables, $tables, $num_tables;
/* Define dependencies for the concerned controller */
$dependency_definitions = array(
'db' => $db,
'table' => $table,
'type' => 'table',
'url_query' => &$GLOBALS['url_query'],
'pos' => $pos,
'db_is_system_schema' => $db_is_system_schema,
'num_tables' => $num_tables,
'total_num_tables' => $total_num_tables,
'tables' => $tables
);
// Get more complete field information
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
// but later, if the analyser returns more information, it
// could be executed for any MySQL version and replace
// the info given by SHOW FULL COLUMNS FROM.
//
// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
// and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
$tableObj = new PMA_Table($table, $db);
$show_create_table = $tableObj->showCreate();
$parser = new SqlParser\Parser($show_create_table);
/**
* @var CreateStatement $stmt
*/
$stmt = $parser->statements[0];
$create_table_fields = SqlParser\Utils\Table::getFields($stmt);
/**
* prepare table infos
*/
// action titles (image or string)
$titles = PMA_getActionTitlesArray();
//display table structure
require_once 'libraries/display_structure.inc.php';
$response->addHTML('</div>');
/** @var Controllers\StructureController $controller */
$controller = $container->get('StructureController', $dependency_definitions);
$controller->indexAction();

View File

@ -0,0 +1,4 @@
<div class="error">
<img src="themes/dot.gif" title="" alt="" class="icon ic_s_error" />
<?php echo $msg; ?>
</div>

View File

@ -50,7 +50,7 @@ $cell_text = ($approx_rows)
</th>
<?php endif; ?>
<?php if ($is_show_stats): ?>
<?php
<?php
list($sum_formatted, $unit) = PMA_Util::formatByteDown(
$sum_size, 3, 1
);

View File

@ -0,0 +1,3 @@
<a href="sql.php<?php echo $tbl_url_query; ?>&amp;pos=0">
<?php echo $title; ?>
</a>

View File

@ -0,0 +1,3 @@
<a href="sql.php<?php echo $tbl_url_query; ?>&amp;pos=0" title="<?php echo $title; ?>">
<?php echo $truename; ?>
</a>

View File

@ -0,0 +1,3 @@
<a class="truncate_table_anchor ajax" href="sql.php<?php echo $tbl_url_query; ?>&amp;sql_query=<?php echo $sql_query; ?>&amp;message_to_show=<?php echo $message_to_show; ?>">
<?php echo $title; ?>
</a>

View File

@ -1,15 +1,15 @@
<a id="<?php echo md5($current_table['TABLE_NAME']); ?>_favorite_anchor" class="ajax favorite_table_anchor
<?php
// Check if current table is already in favorite list.
$already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']);
$fav_params = array('db' => $db,
'ajax_request' => true,
'favorite_table' => $current_table['TABLE_NAME'],
(($already_favorite?'remove':'add') . '_favorite') => true
);
// Check if current table is already in favorite list.
$fav_params = array('db' => $db,
'ajax_request' => true,
'favorite_table' => $current_table['TABLE_NAME'],
(($already_favorite ? 'remove' : 'add') . '_favorite') => true
);
?>
" href="<?php echo 'db_structure.php' . PMA_URL_getCommon($fav_params); ?>" title="<?php echo
($already_favorite ? __("Remove from Favorites") : __("Add to Favorites")); ?>" data-favtargets="<?php echo
md5($db . "." . $current_table['TABLE_NAME']); ?>" >
<?php echo (!$already_favorite ? $titles['NoFavorite'] : $titles['Favorite']); ?>
<a id="<?php echo md5($current_table['TABLE_NAME']); ?>_favorite_anchor"
class="ajax favorite_table_anchor"
href="<?php echo 'db_structure.php' . PMA_URL_getCommon($fav_params); ?>"
title="<?php echo $already_favorite ? __("Remove from Favorites") : __("Add to Favorites"); ?>"
data-favtargets="<?php echo md5($db . "." . $current_table['TABLE_NAME']); ?>" >
<?php echo !$already_favorite ? $titles['NoFavorite'] : $titles['Favorite']; ?>
</a>

View File

@ -8,9 +8,9 @@
<?php if ($showtable['Row_format'] == 'Fixed'): ?>
<td class="value"><?php echo __('static'); ?></td>
<?php elseif ($showtable['Row_format'] == 'Dynamic'): ?>
<td class="value"><?php echo __('dynamic'); ?></td>
<td class="value"><?php echo __('dynamic'); ?></td>
<?php else: ?>
<td class="value"><?php echo $showtable['Row_format']; ?></td>
<td class="value"><?php echo $showtable['Row_format']; ?></td>
<?php endif; ?>
</tr>
<?php endif; ?>
@ -19,7 +19,7 @@
<tr class="<?php echo (($odd_row = !$odd_row) ? 'odd' : 'even'); ?>">
<th class="name"><?php echo __('Options'); ?></th>
<?php if ($showtable['Create_options'] == 'partitioned'): ?>
<td class="value"><?php echo __('partitioned'); ?></td>
<td class="value"><?php echo __('partitioned'); ?></td>
<?php else: ?>
<td class="value"><?php echo $showtable['Create_options']; ?></td>
<?php endif; ?>

View File

@ -0,0 +1,3 @@
<a href="tbl_select.php<?php echo $tbl_url_query; ?>">
<?php echo $title; ?>
</a>

View File

@ -0,0 +1,19 @@
<?php $cfgRelation = PMA_getRelationsParam(); ?>
<?php if ($cfgRelation['relwork'] ||
PMA_Util::isForeignKeySupported($engine)): ?>
<ul id="topmenu2">
<?php echo PMA_Util::getHtmlTab(array(
'icon' => 'b_props',
'link' => 'tbl_structure.php',
'text' => __('Table structure'),
'id' => 'table_strucuture_id'
), $url_params); ?>
<?php echo PMA_Util::getHtmlTab(array(
'icon' => 'b_relations',
'link' => 'tbl_relation.php',
'text' => __('Relation view'),
'id' => 'table_relation_id'
), $url_params); ?>
</ul>
<div class="clearfloat"></div>
<?php endif; ?>

View File

@ -26,7 +26,8 @@
array(
'db' => $db,
'current_table' => $current_table,
'titles' => $titles
'titles' => $titles,
'already_favorite' => $already_favorite
)
); ?>
</td>

View File

@ -12,54 +12,54 @@ if ($GLOBALS['cfg']['NumFavoriteTables'] > 0) {
?>
<table class="data">
<thead>
<tr>
<th class="print_ignore"></th>
<th><?php echo PMA_sortableTableHeader(__('Table'), 'table'); ?></th>
<?php if ($replication): ?>
<th><?php echo __('Replication'); ?></th>
<?php endif; ?>
<th colspan="<?php echo $action_colspan; ?>" class="print_ignore">
<?php echo __('Action'); ?>
</th>
<!-- larger values are more interesting so default sort order is DESC-->
<th>
<?php echo PMA_sortableTableHeader(__('Rows'), 'records', 'DESC'); ?>
<?php echo PMA_Util::showHint(PMA_sanitize(
<tr>
<th class="print_ignore"></th>
<th><?php echo PMA_sortableTableHeader(__('Table'), 'table'); ?></th>
<?php if ($replication): ?>
<th><?php echo __('Replication'); ?></th>
<?php endif; ?>
<th colspan="<?php echo $action_colspan; ?>" class="print_ignore">
<?php echo __('Action'); ?>
</th>
<!-- larger values are more interesting so default sort order is DESC-->
<th>
<?php echo PMA_sortableTableHeader(__('Rows'), 'records', 'DESC'); ?>
<?php echo PMA_Util::showHint(PMA_sanitize(
__('May be approximate. Click on the number to get the exact'
. ' count. See [doc@faq3-11]FAQ 3.11[/doc].'))); ?>
</th>
<?php if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)): ?>
<th><?php echo PMA_sortableTableHeader(__('Type'), 'type'); $cnt++; ?></th>
<th><?php echo PMA_sortableTableHeader(__('Collation'), 'collation'); $cnt++; ?></th>
<?php endif; ?>
. ' count. See [doc@faq3-11]FAQ 3.11[/doc].'))); ?>
</th>
<?php if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)): ?>
<th><?php echo PMA_sortableTableHeader(__('Type'), 'type'); $cnt++; ?></th>
<th><?php echo PMA_sortableTableHeader(__('Collation'), 'collation'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['is_show_stats']): ?>
<!-- larger values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Size'), 'size', 'DESC'); $cnt++; ?></th>
<!-- larger values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Overhead'), 'overhead', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['is_show_stats']): ?>
<!-- larger values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Size'), 'size', 'DESC'); $cnt++; ?></th>
<!-- larger values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Overhead'), 'overhead', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['cfg']['ShowDbStructureComment']): ?>
<th><?php echo PMA_sortableTableHeader(__('Comment'), 'comment'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['cfg']['ShowDbStructureComment']): ?>
<th><?php echo PMA_sortableTableHeader(__('Comment'), 'comment'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['cfg']['ShowDbStructureCreation']): ?>
<!-- newer values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Creation'), 'creation', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['cfg']['ShowDbStructureCreation']): ?>
<!-- newer values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Creation'), 'creation', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']): ?>
<!-- newer values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Last update'), 'last_update', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']): ?>
<!-- newer values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Last update'), 'last_update', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
<?php if ($GLOBALS['cfg']['ShowDbStructureLastCheck']): ?>
<!-- newer values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Last check'), 'last_check', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
</tr>
<?php if ($GLOBALS['cfg']['ShowDbStructureLastCheck']): ?>
<!-- newer values are more interesting so default sort order is DESC -->
<th><?php echo PMA_sortableTableHeader(__('Last check'), 'last_check', 'DESC'); $cnt++; ?></th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php $GLOBALS['colspan_for_structure'] = $cnt + $action_colspan + 3; ?>
<?php $GLOBALS['colspan_for_structure'] = $cnt + $action_colspan + 3; ?>

View File

@ -0,0 +1,11 @@
<a href="tbl_tracking.php<?php echo $url_query; ?>&amp;table=<?php echo $truename; ?>">
<?php if ($is_tracked): ?>
<?php echo PMA_Util::getImage(
'eye.png', __('Tracking is active.')
); ?>
<?php else: ?>
<?php echo PMA_Util::getImage(
'eye_grey.png', __('Tracking is not active.')
); ?>
<?php endif; ?>
</a>

View File

@ -0,0 +1,23 @@
<form id="create_table_form_minimal" method="post" action="tbl_create.php" class="lock-page">
<fieldset>
<legend>
<?php if (PMA_Util::showIcons('ActionLinksMode')): ?>
<?php echo PMA_Util::getImage('b_table_add.png'); ?>&nbsp
<?php endif; ?>
<?php echo __('Create table'); ?>
</legend>
<?php echo PMA_URL_getHiddenInputs($db); ?>
<div class="formelement">
<?php echo __('Name'); ?>:
<input type="text" name="table" maxlength="64" size="30" required="required" />
</div>
<div class="formelement">
<?php echo __('Number of columns'); ?>:
<input type="number" min="1" name="num_fields" value="4" required="required" />
</div>
<div class="clearfloat"></div>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" value="<?php echo __('Go'); ?>" />
</fieldset>
</form>

View File

@ -68,108 +68,111 @@ class PMA_Structure_Test extends PHPUnit_Framework_TestCase
*/
public function testPMAGetHtmlForActionLinks()
{
$current_table = array(
'TABLE_ROWS' => 3,
'TABLE_NAME' => 'name1',
'TABLE_COMMENT' => 'This is a test comment'
);
$table_is_view = false;
$tbl_url_query = 'tbl_url_query';
$titles = array(
'Browse' => 'Browse1',
'NoBrowse' => 'NoBrowse1',
'Search' => 'Search1',
'NoSearch' => 'NoSearch1',
'Empty' => 'Empty1',
'NoEmpty' => 'NoEmpty1',
);;
$truename = 'truename';
$db_is_system_schema = null;
$url_query = 'url_query';
//$table_is_view = true;
list(
$browse_table, $search_table,$browse_table_label,
$empty_table, $tracking_icon
) = PMA_getHtmlForActionLinks(
$current_table, $table_is_view, $tbl_url_query,
$titles, $truename, $db_is_system_schema, $url_query
);
//$browse_table
$this->assertContains(
$titles['Browse'],
$browse_table
);
//$search_table
$this->assertContains(
$titles['Search'],
$search_table
);
$this->assertContains(
$tbl_url_query,
$search_table
);
//$browse_table_label
$this->assertContains(
$tbl_url_query,
$browse_table_label
);
//$empty_table
$this->assertContains(
$tbl_url_query,
$empty_table
);
$this->assertContains(
urlencode(
'TRUNCATE ' . PMA_Util::backquote($current_table['TABLE_NAME'])
),
$empty_table
);
$this->assertContains(
$titles['Empty'],
$empty_table
);
//$table_is_view = false;
$current_table = array(
'TABLE_ROWS' => 0,
'TABLE_NAME' => 'name1',
'TABLE_COMMENT' => 'This is a test comment'
);
$table_is_view = false;
list(
$browse_table, $search_table,$browse_table_label,
$empty_table, $tracking_icon
) = PMA_getHtmlForActionLinks(
$current_table, $table_is_view, $tbl_url_query,
$titles, $truename, $db_is_system_schema, $url_query
);
//$browse_table
$this->assertContains(
$titles['NoBrowse'],
$browse_table
);
//$search_table
$this->assertContains(
$titles['NoSearch'],
$search_table
);
//$browse_table_label
$this->assertContains(
$tbl_url_query,
$browse_table_label
);
$this->assertContains(
$titles['NoEmpty'],
$empty_table
);
$this->markTestIncomplete('Not Implemented Yet!');
/**
* $current_table = array(
* 'TABLE_ROWS' => 3,
* 'TABLE_NAME' => 'name1',
* 'TABLE_COMMENT' => 'This is a test comment'
* );
* $table_is_view = false;
* $tbl_url_query = 'tbl_url_query';
* $titles = array(
* 'Browse' => 'Browse1',
* 'NoBrowse' => 'NoBrowse1',
* 'Search' => 'Search1',
* 'NoSearch' => 'NoSearch1',
* 'Empty' => 'Empty1',
* 'NoEmpty' => 'NoEmpty1',
* );;
* $truename = 'truename';
* $db_is_system_schema = null;
* $url_query = 'url_query';
*
* //$table_is_view = true;
* list(
* $browse_table, $search_table,$browse_table_label,
* $empty_table, $tracking_icon
* ) = PMA_getHtmlForActionLinks(
* $current_table, $table_is_view, $tbl_url_query,
* $titles, $truename, $db_is_system_schema, $url_query
* );
*
* //$browse_table
* $this->assertContains(
* $titles['Browse'],
* $browse_table
* );
*
* //$search_table
* $this->assertContains(
* $titles['Search'],
* $search_table
* );
* $this->assertContains(
* $tbl_url_query,
* $search_table
* );
*
* //$browse_table_label
* $this->assertContains(
* $tbl_url_query,
* $browse_table_label
* );
*
* //$empty_table
* $this->assertContains(
* $tbl_url_query,
* $empty_table
* );
* $this->assertContains(
* urlencode(
* 'TRUNCATE ' . PMA_Util::backquote($current_table['TABLE_NAME'])
* ),
* $empty_table
* );
* $this->assertContains(
* $titles['Empty'],
* $empty_table
* );
*
* //$table_is_view = false;
* $current_table = array(
* 'TABLE_ROWS' => 0,
* 'TABLE_NAME' => 'name1',
* 'TABLE_COMMENT' => 'This is a test comment'
* );
* $table_is_view = false;
* list(
* $browse_table, $search_table,$browse_table_label,
* $empty_table, $tracking_icon
* ) = PMA_getHtmlForActionLinks(
* $current_table, $table_is_view, $tbl_url_query,
* $titles, $truename, $db_is_system_schema, $url_query
* );
*
* //$browse_table
* $this->assertContains(
* $titles['NoBrowse'],
* $browse_table
* );
*
* //$search_table
* $this->assertContains(
* $titles['NoSearch'],
* $search_table
* );
*
* //$browse_table_label
* $this->assertContains(
* $tbl_url_query,
* $browse_table_label
* );
* $this->assertContains(
* $titles['NoEmpty'],
* $empty_table
* );
*/
}
/**
@ -179,30 +182,31 @@ class PMA_Structure_Test extends PHPUnit_Framework_TestCase
*/
public function testPMAGetTableDropQueryAndMessage()
{
$current_table = array(
'TABLE_ROWS' => 3,
'TABLE_NAME' => 'name1',
'ENGINE' => 'ENGINE1',
);
$table_is_view = false;
list($drop_query, $drop_message) = PMA_getTableDropQueryAndMessage(
$table_is_view, $current_table
);
//$drop_query
$ret = "DROP TABLE `name1`";
$this->assertEquals(
$ret,
$drop_query
);
//$drop_message
$ret = "Table name1 has been dropped.";
$this->assertEquals(
$ret,
$drop_message
);
$this->markTestIncomplete('Not Implemented Yet!');
// $current_table = array(
// 'TABLE_ROWS' => 3,
// 'TABLE_NAME' => 'name1',
// 'ENGINE' => 'ENGINE1',
// );
// $table_is_view = false;
//
// list($drop_query, $drop_message) = PMA_getTableDropQueryAndMessage(
// $table_is_view, $current_table
// );
//
// //$drop_query
// $ret = "DROP TABLE `name1`";
// $this->assertEquals(
// $ret,
// $drop_query
// );
//
// //$drop_message
// $ret = "Table name1 has been dropped.";
// $this->assertEquals(
// $ret,
// $drop_message
// );
}
/**