diff --git a/ChangeLog b/ChangeLog index 0cb5b567c..dff173c3c 100755 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,9 @@ $Source$ libraries/get_foreign.lib.php, libraries/relation.lib.php: moved PMA_generateFieldSpec(), PMA_tableIsView(), PMA_countRecords(), PMA_generateAlterTable() into class PMA_Table + * db_operations.php, tbl_move_copy.php, tbl_properties_operations.php, + libraries\Table.class.php, libraries\tbl_move_copy.php: + merged libraries\tbl_move_copy.php in class PMA_Table 2006-02-20 Marc Delisle diff --git a/db_operations.php b/db_operations.php index 575b39134..213e37674 100644 --- a/db_operations.php +++ b/db_operations.php @@ -15,8 +15,9 @@ /** * requirements */ -require_once('./libraries/common.lib.php'); -require_once('./libraries/mysql_charsets.lib.php'); +require_once './libraries/common.lib.php'; +require_once './libraries/Table.class.php'; +require_once './libraries/mysql_charsets.lib.php'; /** * Rename/move or copy database @@ -25,12 +26,10 @@ if (isset($db) && ((isset($db_rename) && $db_rename == 'true') || (isset($db_copy) && $db_copy == 'true'))) { - require_once('./libraries/tbl_move_copy.php'); - if (isset($db_rename) && $db_rename == 'true') { - $move = TRUE; + $move = true; } else { - $move = FALSE; + $move = false; } if (!isset($newname) || !strlen($newname)) { @@ -70,7 +69,7 @@ if (isset($db) && } if ($this_what != 'nocopy') { - PMA_table_move_copy($db, $table, $newname, $table, + PMA_Table::moveCopy($db, $table, $newname, $table, isset($this_what) ? $this_what : 'data', $move); } @@ -83,13 +82,13 @@ if (isset($db) && $get_fields = array('user', 'label', 'query'); $where_fields = array('dbase' => $db); $new_fields = array('dbase' => $newname); - PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, + PMA_Table::duplicateInfo('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields); } if ($move) { // cleanup pmadb stuff for this db - require_once('./libraries/relation_cleanup.lib.php'); + require_once './libraries/relation_cleanup.lib.php'; PMA_relationsCleanupDatabase($db); $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';'; @@ -101,17 +100,17 @@ if (isset($db) && $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname)); } - $reload = TRUE; + $reload = true; /* Change database to be used */ if ($move) { $db = $newname; } else { if (isset($switch_to_new) && $switch_to_new == 'true') { - PMA_setCookie( 'pma_switch_to_new', 'true' ); + PMA_setCookie('pma_switch_to_new', 'true'); $db = $newname; } else { - PMA_setCookie( 'pma_switch_to_new', '' ); + PMA_setCookie('pma_switch_to_new', ''); } } } @@ -120,7 +119,7 @@ if (isset($db) && * Settings for relations stuff */ -require_once('./libraries/relation.lib.php'); +require_once './libraries/relation.lib.php'; $cfgRelation = PMA_getRelationsParam(); /** @@ -133,15 +132,15 @@ if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') { /** * Prepares the tables list if the user where not redirected to this script - * because there is no table in the database ($is_info is TRUE) + * because there is no table in the database ($is_info is true) */ if (empty($is_info)) { - require('./libraries/db_details_common.inc.php'); + require './libraries/db_details_common.inc.php'; $url_query .= '&goto=db_operations.php'; // Gets the database structure $sub_part = '_structure'; - require('./libraries/db_details_db_info.inc.php'); + require './libraries/db_details_db_info.inc.php'; echo "\n"; } @@ -150,14 +149,14 @@ if (PMA_MYSQL_INT_VERSION >= 40101) { } if (PMA_MYSQL_INT_VERSION < 50002 || (PMA_MYSQL_INT_VERSION >= 50002 && $db != 'information_schema')) { - $is_information_schema = FALSE; + $is_information_schema = false; } else { - $is_information_schema = TRUE; + $is_information_schema = true; } if (!$is_information_schema) { - require('./libraries/display_create_table.lib.php'); + require './libraries/display_create_table.lib.php'; if ($cfgRelation['commwork']) { /** @@ -299,17 +298,17 @@ if (!$is_information_schema) { echo ' ' . "\n" . ' ' . "\n" . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, - 'db_collation', 'select_db_collation', $db_collation, FALSE, 3) + 'db_collation', 'select_db_collation', $db_collation, false, 3) . ' ' . "\n" . '' . "\n" . '' . "\n"; } - if ( $num_tables > 0 - && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) { + if ($num_tables > 0 + && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) { echo '

' . $strError . '

' - . sprintf( $strRelationNotWorking, + . sprintf($strRelationNotWorking, '', '') . '
'; @@ -415,9 +414,9 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?> 0 +if ($num_tables > 0 && $cfgRelation['relwork'] && $cfgRelation['commwork'] - && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir']) ) { + && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) { /** * import docSQL files */ @@ -434,5 +433,5 @@ if ( $num_tables > 0 /** * Displays the footer */ -require_once('./libraries/footer.inc.php'); +require_once './libraries/footer.inc.php'; ?> diff --git a/libraries/Table.class.php b/libraries/Table.class.php index abde3f373..c51c58f59 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -68,7 +68,7 @@ class PMA_Table { */ function getName($quoted = false) { - if ( $quoted ) { + if ($quoted) { return PMA_backquote($this->name); } return $this->name; @@ -94,7 +94,7 @@ class PMA_Table { */ function getDbName($quoted = false) { - if ( $quoted ) { + if ($quoted) { return PMA_backquote($this->db_name); } return $this->db_name; @@ -116,7 +116,7 @@ class PMA_Table { return PMA_Table::_isView($db, $table); } - if ( strpos($this->get('TABLE TYPE'), 'VIEW') ) { + if (strpos($this->get('TABLE TYPE'), 'VIEW')) { return true; } @@ -144,7 +144,7 @@ class PMA_Table { */ function get($param) { - if ( isset( $this->settings[$param]) ) { + if (isset($this->settings[$param])) { return $this->settings[$param]; } @@ -158,13 +158,13 @@ class PMA_Table { { $table_info = PMA_DBI_get_tables_full($this->getDbName(), $this->getName()); - if ( false === $table_info ) { + if (false === $table_info) { return false; } $this->settings = $table_info; - if ( $this->get('TABLE_ROWS') === null ) { + if ($this->get('TABLE_ROWS') === null) { $this->set('TABLE_ROWS', PMA_Table::countRecords($this->getDbName(), $this->getName(), true, true)); } @@ -173,9 +173,9 @@ class PMA_Table { // export create options by its name as variables into gloabel namespace // f.e. pack_keys=1 becomes available as $pack_keys with value of '1' - foreach ( $create_options as $each_create_option ) { + foreach ($create_options as $each_create_option) { $each_create_option = explode('=', $each_create_option); - if ( isset( $each_create_option[1] ) ) { + if (isset($each_create_option[1])) { $this->set($$each_create_option[0], $each_create_option[1]); } } @@ -213,7 +213,7 @@ class PMA_Table { if (PMA_MYSQL_INT_VERSION < 50000) { return false; } - if ( false === PMA_DBI_fetch_value('SELECT TABLE_NAME FROM `information_schema`.`VIEWS` WHERE `TABLE_SCHEMA` = \'' . $db . '\' AND `TABLE_NAME` = \'' . $table . '\';')) { + if (false === PMA_DBI_fetch_value('SELECT TABLE_NAME FROM `information_schema`.`VIEWS` WHERE `TABLE_SCHEMA` = \'' . $db . '\' AND `TABLE_NAME` = \'' . $table . '\';')) { return false; } else { return true; @@ -361,5 +361,449 @@ class PMA_Table { $comment, $empty_a, -1, $default_orig); } // end function + /** + * Inserts existing entries in a PMA_* table by reading a value from an old entry + * + * @param string The array index, which Relation feature to check + * ('relwork', 'commwork', ...) + * @param string The array index, which PMA-table to update + * ('bookmark', 'relation', ...) + * @param array Which fields will be SELECT'ed from the old entry + * @param array Which fields will be used for the WHERE query + * (array('FIELDNAME' => 'FIELDVALUE')) + * @param array Which fields will be used as new VALUES. These are the important + * keys which differ from the old entry. + * (array('FIELDNAME' => 'NEW FIELDVALUE')) + + * @global string relation variable + * + * @author Garvin Hicking + */ + function duplicateInfo($work, $pma_table, $get_fields, $where_fields, $new_fields) { + global $cfgRelation; + + $last_id = -1; + + if ($cfgRelation[$work]) { + $select_parts = array(); + $row_fields = array(); + foreach ($get_fields AS $nr => $get_field) { + $select_parts[] = PMA_backquote($get_field); + $row_fields[$get_field] = 'cc'; + } + + $where_parts = array(); + foreach ($where_fields AS $_where => $_value) { + $where_parts[] = PMA_backquote($_where) . ' = \'' . PMA_sqlAddslashes($_value) . '\''; + } + + $new_parts = array(); + $new_value_parts = array(); + foreach ($new_fields AS $_where => $_value) { + $new_parts[] = PMA_backquote($_where); + $new_value_parts[] = PMA_sqlAddslashes($_value); + } + + $table_copy_query = 'SELECT ' . implode(', ', $select_parts) + . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation[$pma_table]) + . ' WHERE ' . implode(' AND ', $where_parts); + + // must use PMA_DBI_QUERY_STORE here, since we execute another + // query inside the loop + $table_copy_rs = PMA_query_as_cu($table_copy_query, true, PMA_DBI_QUERY_STORE); + + while ($table_copy_row = @PMA_DBI_fetch_assoc($table_copy_rs)) { + $value_parts = array(); + foreach ($table_copy_row AS $_key => $_val) { + if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') { + $value_parts[] = PMA_sqlAddslashes($_val); + } + } + + $new_table_query = 'INSERT IGNORE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation[$pma_table]) + . ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ')' + . ' VALUES ' + . ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')'; + + $new_table_rs = PMA_query_as_cu($new_table_query); + $last_id = PMA_DBI_insert_id(); + } // end while + + return $last_id; + } + + return true; + } // end of 'PMA_Table::duplicateInfo()' function + + + /** + * Copies or renames table + * FIXME: use RENAME + * + * @author Michal Čihař + */ + function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move) { + global $cfgRelation, $dblist, $err_url, $sql_query; + + // set export settings we need + $GLOBALS['use_backquotes'] = 1; + $GLOBALS['asfile'] = 1; + + // Ensure the target is valid + if (count($dblist) > 0 && + (! in_array($source_db, $dblist) || ! in_array($target_db, $dblist))) { + exit(); + } + + $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table); + if (! isset($target_db) || ! strlen($target_db)) { + $target_db = $source_db; + } + + // Doing a select_db could avoid some problems with replicated databases, + // when moving table from replicated one to not replicated one + PMA_DBI_select_db($target_db); + + $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table); + + // do not create the table if dataonly + if ($what != 'dataonly') { + require_once('./libraries/export/sql.php'); + + $no_constraints_comments = true; + $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url); + unset($no_constraints_comments); + + $parsed_sql = PMA_SQP_parse($sql_structure); + + /* nijel: Find table name in query and replace it */ + $i = 0; + while ($parsed_sql[$i]['type'] != 'quote_backtick') $i++; + + /* no need to PMA_backquote() */ + $parsed_sql[$i]['data'] = $target; + + /* Generate query back */ + $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only'); + // If table exists, and 'add drop table' is selected: Drop it! + $drop_query = ''; + if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') { + $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table); + $result = PMA_DBI_query($drop_query); + + if (isset($sql_query)) { + $sql_query .= "\n" . $drop_query . ';'; + } else { + $sql_query = $drop_query . ';'; + } + + // garvin: If an existing table gets deleted, maintain any entries + // for the PMA_* tables + $maintain_relations = true; + } + + $result = @PMA_DBI_query($sql_structure); + if (isset($sql_query)) { + $sql_query .= "\n" . $sql_structure . ';'; + } else { + $sql_query = $sql_structure . ';'; + } + + if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) { + $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']); + $i = 0; + + // find the first quote_backtick, it must be the source table name + while ($parsed_sql[$i]['type'] != 'quote_backtick') { + $i++; + } + + // replace it by the target table name, no need to PMA_backquote() + $parsed_sql[$i]['data'] = $target; + + // now we must remove all quote_backtick that follow a CONSTRAINT + // keyword, because a constraint name must be unique in a db + + $cnt = $parsed_sql['len'] - 1; + + for ($j = $i; $j < $cnt; $j++) { + if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' + && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') { + if ($parsed_sql[$j+1]['type'] == 'quote_backtick') { + $parsed_sql[$j+1]['data'] = ''; + } + } + } + + + // Generate query back + $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only'); + $result = PMA_DBI_query($GLOBALS['sql_constraints']); + if (isset($sql_query)) { + $sql_query .= "\n" . $GLOBALS['sql_constraints']; + } else { + $sql_query = $GLOBALS['sql_constraints']; + } + + unset($GLOBALS['sql_constraints']); + } + + } else { + $sql_query=''; + } + + // Copy the data + //if ($result != false && ($what == 'data' || $what == 'dataonly')) { + if ($what == 'data' || $what == 'dataonly') { + $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source; + PMA_DBI_query($sql_insert_data); + $sql_query .= "\n\n" . $sql_insert_data . ';'; + } + + require_once('./libraries/relation.lib.php'); + $cfgRelation = PMA_getRelationsParam(); + + // Drops old table if the user has requested to move it + if ($move) { + + // This could avoid some problems with replicated databases, when + // moving table from replicated one to not replicated one + PMA_DBI_select_db($source_db); + + $sql_drop_table = 'DROP TABLE ' . $source; + PMA_DBI_query($sql_drop_table); + + // garvin: Move old entries from PMA-DBs to new table + if ($cfgRelation['commwork']) { + $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) + . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' + . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' + . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; + $rmv_rs = PMA_query_as_cu($remove_query); + unset($remove_query); + } + + // garvin: updating bookmarks is not possible since only a single table is moved, + // and not the whole DB. + // if ($cfgRelation['bookmarkwork']) { + // $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['bookmark']) + // . ' SET dbase = \'' . PMA_sqlAddslashes($target_db) . '\'' + // . ' WHERE dbase = \'' . PMA_sqlAddslashes($source_db) . '\''; + // $rmv_rs = PMA_query_as_cu($remove_query); + // unset($rmv_query); + // } + + if ($cfgRelation['displaywork']) { + $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) + . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' + . ' table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' + . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; + $tb_rs = PMA_query_as_cu($table_query); + unset($table_query); + unset($tb_rs); + } + + if ($cfgRelation['relwork']) { + $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) + . ' SET foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' + . ' foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' + . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($source_db) . '\'' + . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\''; + $tb_rs = PMA_query_as_cu($table_query); + unset($table_query); + unset($tb_rs); + + $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) + . ' SET master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' + . ' master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' + . ' WHERE master_db = \'' . PMA_sqlAddslashes($source_db) . '\'' + . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\''; + $tb_rs = PMA_query_as_cu($table_query); + unset($table_query); + unset($tb_rs); + } + + // garvin: [TODO] Can't get moving PDFs the right way. The page numbers always + // get screwed up independently from duplication because the numbers do not + // seem to be stored on a per-database basis. Would the author of pdf support + // please have a look at it? + + if ($cfgRelation['pdfwork']) { + $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) + . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' + . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' + . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; + $tb_rs = PMA_query_as_cu($table_query); + unset($table_query); + unset($tb_rs); + /* + $pdf_query = 'SELECT pdf_page_number ' + . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\''; + $pdf_rs = PMA_query_as_cu($pdf_query); + + while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) { + $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) + . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' + . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' + . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\''; + $tb_rs = PMA_query_as_cu($table_query); + unset($table_query); + unset($tb_rs); + } + */ + } + + $sql_query .= "\n\n" . $sql_drop_table . ';'; + } else { + // garvin: Create new entries as duplicates from old PMA DBs + if ($what != 'dataonly' && !isset($maintain_relations)) { + if ($cfgRelation['commwork']) { + // Get all comments and MIME-Types for current table + $comments_copy_query = 'SELECT + column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ' + FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' + WHERE + db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND + table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; + $comments_copy_rs = PMA_query_as_cu($comments_copy_query); + + // Write every comment as new copied entry. [MIME] + while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) { + $new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) + . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' + . ' VALUES(' + . '\'' . PMA_sqlAddslashes($target_db) . '\',' + . '\'' . PMA_sqlAddslashes($target_table) . '\',' + . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' + . ($cfgRelation['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' + . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' + . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' + . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') + . ')'; + $new_comment_rs = PMA_query_as_cu($new_comment_query); + } // end while + } + + // duplicating the bookmarks must not be done here, but + // just once per db + + $get_fields = array('display_field'); + $where_fields = array('db_name' => $source_db, 'table_name' => $source_table); + $new_fields = array('db_name' => $target_db, 'table_name' => $target_table); + PMA_Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields); + + $get_fields = array('master_field', 'foreign_db', 'foreign_table', 'foreign_field'); + $where_fields = array('master_db' => $source_db, 'master_table' => $source_table); + $new_fields = array('master_db' => $target_db, 'master_table' => $target_table); + PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields); + + $get_fields = array('foreign_field', 'master_db', 'master_table', 'master_field'); + $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table); + $new_fields = array('foreign_db' => $target_db, 'foreign_table' => $target_table); + PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields); + + // garvin: [TODO] Can't get duplicating PDFs the right way. The page numbers always + // get screwed up independently from duplication because the numbers do not + // seem to be stored on a per-database basis. Would the author of pdf support + // please have a look at it? + /* + $get_fields = array('page_descr'); + $where_fields = array('db_name' => $source_db); + $new_fields = array('db_name' => $target_db); + $last_id = PMA_Table::duplicateInfo('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields); + + if (isset($last_id) && $last_id >= 0) { + $get_fields = array('x', 'y'); + $where_fields = array('db_name' => $source_db, 'table_name' => $source_table); + $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id); + PMA_Table::duplicateInfo('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields); + } + */ + } + } + + } + + /** + * renames table + * + * @param string old tbale name + * @param string new table name + * @return boolean success + */ + function rename($old_name, $new_name) + { + // Ensure the target is valid + if (count($GLOBALS['dblist']) > 0 + && ! in_array($GLOBALS['db'], $GLOBALS['dblist'])) { + return false; + } + + PMA_DBI_select_db($GLOBALS['db']); + + $sql_query = ' + ALTER TABLE ' . PMA_backquote($old_name) . ' + RENAME ' . PMA_backquote($new_name) . ';'; + if (! PMA_DBI_query($sql_query)) { + return false; + } + + // garvin: Move old entries from comments to new table + require_once('./libraries/relation.lib.php'); + $cfgRelation = PMA_getRelationsParam(); + if ($cfgRelation['commwork']) { + $remove_query = ' + UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' + SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' + WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' + AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; + PMA_query_as_cu($remove_query); + unset($remove_query); + } + + if ($cfgRelation['displaywork']) { + $table_query = ' + UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' + SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' + WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' + AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; + PMA_query_as_cu($table_query); + unset($table_query); + } + + if ($cfgRelation['relwork']) { + $table_query = ' + UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' + SET foreign_table = \'' . PMA_sqlAddslashes($new_name) . '\' + WHERE foreign_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' + AND foreign_table = \'' . PMA_sqlAddslashes($old_name) . '\''; + PMA_query_as_cu($table_query); + + $table_query = ' + UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' + SET master_table = \'' . PMA_sqlAddslashes($new_name) . '\' + WHERE master_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' + AND master_table = \'' . PMA_sqlAddslashes($old_name) . '\''; + PMA_query_as_cu($table_query); + unset($table_query); + } + + if ($cfgRelation['pdfwork']) { + $table_query = ' + UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' + SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' + WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' + AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; + PMA_query_as_cu($table_query); + unset($table_query); + } + + return true; + } } ?> \ No newline at end of file diff --git a/libraries/tbl_move_copy.php b/libraries/tbl_move_copy.php deleted file mode 100644 index f28d91e2e..000000000 --- a/libraries/tbl_move_copy.php +++ /dev/null @@ -1,449 +0,0 @@ - 'FIELDVALUE')) - * @param array Which fields will be used as new VALUES. These are the important - * keys which differ from the old entry. - * (array('FIELDNAME' => 'NEW FIELDVALUE')) - - * @global string relation variable - * - * @author Garvin Hicking - */ -function PMA_duplicate_table_info($work, $pma_table, $get_fields, $where_fields, $new_fields) { - global $cfgRelation; - - $last_id = -1; - - if ($cfgRelation[$work]) { - $select_parts = array(); - $row_fields = array(); - foreach ($get_fields AS $nr => $get_field) { - $select_parts[] = PMA_backquote($get_field); - $row_fields[$get_field] = 'cc'; - } - - $where_parts = array(); - foreach ($where_fields AS $_where => $_value) { - $where_parts[] = PMA_backquote($_where) . ' = \'' . PMA_sqlAddslashes($_value) . '\''; - } - - $new_parts = array(); - $new_value_parts = array(); - foreach ($new_fields AS $_where => $_value) { - $new_parts[] = PMA_backquote($_where); - $new_value_parts[] = PMA_sqlAddslashes($_value); - } - - $table_copy_query = 'SELECT ' . implode(', ', $select_parts) - . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation[$pma_table]) - . ' WHERE ' . implode(' AND ', $where_parts); - - // must use PMA_DBI_QUERY_STORE here, since we execute another - // query inside the loop - $table_copy_rs = PMA_query_as_cu($table_copy_query, TRUE, PMA_DBI_QUERY_STORE); - - while ($table_copy_row = @PMA_DBI_fetch_assoc($table_copy_rs)) { - $value_parts = array(); - foreach ($table_copy_row AS $_key => $_val) { - if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') { - $value_parts[] = PMA_sqlAddslashes($_val); - } - } - - $new_table_query = 'INSERT IGNORE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation[$pma_table]) - . ' (' . implode(', ', $select_parts) . ', ' . implode(', ', $new_parts) . ')' - . ' VALUES ' - . ' (\'' . implode('\', \'', $value_parts) . '\', \'' . implode('\', \'', $new_value_parts) . '\')'; - - $new_table_rs = PMA_query_as_cu($new_table_query); - $last_id = PMA_DBI_insert_id(); - } // end while - - return $last_id; - } - - return true; -} // end of 'PMA_duplicate_table_info()' function - - -/** - * Copies or renames table - * FIXME: use RENAME - * - * @author Michal Čihař - */ -function PMA_table_move_copy($source_db, $source_table, $target_db, $target_table, $what, $move) { - global $cfgRelation, $dblist, $err_url, $sql_query; - - // set export settings we need - $GLOBALS['use_backquotes'] = 1; - $GLOBALS['asfile'] = 1; - - // Ensure the target is valid - if ( count($dblist) > 0 && - ( ! in_array($source_db, $dblist) || ! in_array($target_db, $dblist) )) { - exit(); - } - - $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table); - if ( ! isset($target_db) || ! strlen($target_db) ) { - $target_db = $source_db; - } - - // Doing a select_db could avoid some problems with replicated databases, - // when moving table from replicated one to not replicated one - PMA_DBI_select_db($target_db); - - $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table); - - // do not create the table if dataonly - if ($what != 'dataonly') { - require_once('./libraries/export/sql.php'); - - $no_constraints_comments = true; - $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url); - unset($no_constraints_comments); - - $parsed_sql = PMA_SQP_parse($sql_structure); - - /* nijel: Find table name in query and replace it */ - $i = 0; - while ($parsed_sql[$i]['type'] != 'quote_backtick') $i++; - - /* no need to PMA_backquote() */ - $parsed_sql[$i]['data'] = $target; - - /* Generate query back */ - $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only'); - // If table exists, and 'add drop table' is selected: Drop it! - $drop_query = ''; - if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') { - $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table); - $result = PMA_DBI_query($drop_query); - - if (isset($sql_query)) { - $sql_query .= "\n" . $drop_query . ';'; - } else { - $sql_query = $drop_query . ';'; - } - - // garvin: If an existing table gets deleted, maintain any entries - // for the PMA_* tables - $maintain_relations = TRUE; - } - - $result = @PMA_DBI_query($sql_structure); - if (isset($sql_query)) { - $sql_query .= "\n" . $sql_structure . ';'; - } else { - $sql_query = $sql_structure . ';'; - } - - if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) { - $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']); - $i = 0; - - // find the first quote_backtick, it must be the source table name - while ($parsed_sql[$i]['type'] != 'quote_backtick') { - $i++; - } - - // replace it by the target table name, no need to PMA_backquote() - $parsed_sql[$i]['data'] = $target; - - // now we must remove all quote_backtick that follow a CONSTRAINT - // keyword, because a constraint name must be unique in a db - - $cnt = $parsed_sql['len'] - 1; - - for ($j = $i; $j < $cnt; $j++) { - if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' - && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') { - if ($parsed_sql[$j+1]['type'] == 'quote_backtick') { - $parsed_sql[$j+1]['data'] = ''; - } - } - } - - - // Generate query back - $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only'); - $result = PMA_DBI_query($GLOBALS['sql_constraints']); - if (isset($sql_query)) { - $sql_query .= "\n" . $GLOBALS['sql_constraints']; - } else { - $sql_query = $GLOBALS['sql_constraints']; - } - - unset($GLOBALS['sql_constraints']); - } - - } else { - $sql_query=''; - } - - // Copy the data - //if ($result != FALSE && ($what == 'data' || $what == 'dataonly')) { - if ($what == 'data' || $what == 'dataonly') { - $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source; - PMA_DBI_query($sql_insert_data); - $sql_query .= "\n\n" . $sql_insert_data . ';'; - } - - require_once('./libraries/relation.lib.php'); - $cfgRelation = PMA_getRelationsParam(); - - // Drops old table if the user has requested to move it - if ($move) { - - // This could avoid some problems with replicated databases, when - // moving table from replicated one to not replicated one - PMA_DBI_select_db($source_db); - - $sql_drop_table = 'DROP TABLE ' . $source; - PMA_DBI_query($sql_drop_table); - - // garvin: Move old entries from PMA-DBs to new table - if ($cfgRelation['commwork']) { - $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) - . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' - . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' - . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; - $rmv_rs = PMA_query_as_cu($remove_query); - unset($remove_query); - } - - // garvin: updating bookmarks is not possible since only a single table is moved, - // and not the whole DB. - // if ($cfgRelation['bookmarkwork']) { - // $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['bookmark']) - // . ' SET dbase = \'' . PMA_sqlAddslashes($target_db) . '\'' - // . ' WHERE dbase = \'' . PMA_sqlAddslashes($source_db) . '\''; - // $rmv_rs = PMA_query_as_cu($remove_query); - // unset($rmv_query); - // } - - if ($cfgRelation['displaywork']) { - $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) - . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' - . ' table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' - . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; - $tb_rs = PMA_query_as_cu($table_query); - unset($table_query); - unset($tb_rs); - } - - if ($cfgRelation['relwork']) { - $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) - . ' SET foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' - . ' foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' - . ' WHERE foreign_db = \'' . PMA_sqlAddslashes($source_db) . '\'' - . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\''; - $tb_rs = PMA_query_as_cu($table_query); - unset($table_query); - unset($tb_rs); - - $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) - . ' SET master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' - . ' master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' - . ' WHERE master_db = \'' . PMA_sqlAddslashes($source_db) . '\'' - . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\''; - $tb_rs = PMA_query_as_cu($table_query); - unset($table_query); - unset($tb_rs); - } - - // garvin: [TODO] Can't get moving PDFs the right way. The page numbers always - // get screwed up independently from duplication because the numbers do not - // seem to be stored on a per-database basis. Would the author of pdf support - // please have a look at it? - - if ($cfgRelation['pdfwork']) { - $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) - . ' SET table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' - . ' db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' - . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; - $tb_rs = PMA_query_as_cu($table_query); - unset($table_query); - unset($tb_rs); - /* - $pdf_query = 'SELECT pdf_page_number ' - . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\''; - $pdf_rs = PMA_query_as_cu($pdf_query); - - while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) { - $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) - . ' SET db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' - . ' WHERE db_name = \'' . PMA_sqlAddslashes($source_db) . '\'' - . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\''; - $tb_rs = PMA_query_as_cu($table_query); - unset($table_query); - unset($tb_rs); - } - */ - } - - $sql_query .= "\n\n" . $sql_drop_table . ';'; - } else { - // garvin: Create new entries as duplicates from old PMA DBs - if ($what != 'dataonly' && !isset($maintain_relations)) { - if ($cfgRelation['commwork']) { - // Get all comments and MIME-Types for current table - $comments_copy_query = 'SELECT - column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ' - FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' - WHERE - db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND - table_name = \'' . PMA_sqlAddslashes($source_table) . '\''; - $comments_copy_rs = PMA_query_as_cu($comments_copy_query); - - // Write every comment as new copied entry. [MIME] - while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) { - $new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) - . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' - . ' VALUES(' - . '\'' . PMA_sqlAddslashes($target_db) . '\',' - . '\'' . PMA_sqlAddslashes($target_table) . '\',' - . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' - . ($cfgRelation['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' - . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' - . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' - . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') - . ')'; - $new_comment_rs = PMA_query_as_cu($new_comment_query); - } // end while - } - - // duplicating the bookmarks must not be done here, but - // just once per db - - $get_fields = array('display_field'); - $where_fields = array('db_name' => $source_db, 'table_name' => $source_table); - $new_fields = array('db_name' => $target_db, 'table_name' => $target_table); - PMA_duplicate_table_info('displaywork', 'table_info', $get_fields, $where_fields, $new_fields); - - $get_fields = array('master_field', 'foreign_db', 'foreign_table', 'foreign_field'); - $where_fields = array('master_db' => $source_db, 'master_table' => $source_table); - $new_fields = array('master_db' => $target_db, 'master_table' => $target_table); - PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields); - - $get_fields = array('foreign_field', 'master_db', 'master_table', 'master_field'); - $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table); - $new_fields = array('foreign_db' => $target_db, 'foreign_table' => $target_table); - PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields); - - // garvin: [TODO] Can't get duplicating PDFs the right way. The page numbers always - // get screwed up independently from duplication because the numbers do not - // seem to be stored on a per-database basis. Would the author of pdf support - // please have a look at it? - /* - $get_fields = array('page_descr'); - $where_fields = array('db_name' => $source_db); - $new_fields = array('db_name' => $target_db); - $last_id = PMA_duplicate_table_info('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields); - - if (isset($last_id) && $last_id >= 0) { - $get_fields = array('x', 'y'); - $where_fields = array('db_name' => $source_db, 'table_name' => $source_table); - $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id); - PMA_duplicate_table_info('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields); - } - */ - } - } - -} - -/** - * renames table - * - * @param string old tbale name - * @param string new table name - * @return boolean success - */ -function PMA_table_rename( $old_name, $new_name ) -{ - // Ensure the target is valid - if ( count($GLOBALS['dblist']) > 0 - && ! in_array($GLOBALS['db'], $GLOBALS['dblist']) ) { - return false; - } - - PMA_DBI_select_db($GLOBALS['db']); - - $sql_query = ' - ALTER TABLE ' . PMA_backquote($old_name) . ' - RENAME ' . PMA_backquote($new_name) . ';'; - if ( ! PMA_DBI_query($sql_query) ) { - return false; - } - - // garvin: Move old entries from comments to new table - require_once('./libraries/relation.lib.php'); - $cfgRelation = PMA_getRelationsParam(); - if ( $cfgRelation['commwork'] ) { - $remove_query = ' - UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' - SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' - WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' - AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; - PMA_query_as_cu($remove_query); - unset($remove_query); - } - - if ( $cfgRelation['displaywork'] ) { - $table_query = ' - UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' - SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' - WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' - AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; - PMA_query_as_cu($table_query); - unset($table_query); - } - - if ( $cfgRelation['relwork'] ) { - $table_query = ' - UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' - SET foreign_table = \'' . PMA_sqlAddslashes($new_name) . '\' - WHERE foreign_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' - AND foreign_table = \'' . PMA_sqlAddslashes($old_name) . '\''; - PMA_query_as_cu($table_query); - - $table_query = ' - UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' - SET master_table = \'' . PMA_sqlAddslashes($new_name) . '\' - WHERE master_db = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' - AND master_table = \'' . PMA_sqlAddslashes($old_name) . '\''; - PMA_query_as_cu($table_query); - unset($table_query); - } - - if ( $cfgRelation['pdfwork'] ) { - $table_query = ' - UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) . ' - SET table_name = \'' . PMA_sqlAddslashes($new_name) . '\' - WHERE db_name = \'' . PMA_sqlAddslashes($GLOBALS['db']) . '\' - AND table_name = \'' . PMA_sqlAddslashes($old_name) . '\''; - PMA_query_as_cu($table_query); - unset($table_query); - } - - return true; -} -?> diff --git a/tbl_move_copy.php b/tbl_move_copy.php index 53ccd83ea..3deb2f961 100644 --- a/tbl_move_copy.php +++ b/tbl_move_copy.php @@ -5,14 +5,13 @@ /** * Gets some core libraries */ -require_once('./libraries/common.lib.php'); +require_once './libraries/common.lib.php'; +require_once './libraries/Table.class.php'; // Check parameters PMA_checkParameters(array('db', 'table')); -require_once('./libraries/tbl_move_copy.php'); - /** * Defines the url to return to in case of error in a sql statement */ @@ -31,7 +30,7 @@ if (isset($new_name) && trim($new_name) != '') { if ($db == $target_db && $table == $new_name) { $message = (isset($submit_move) ? $strMoveTableSameNames : $strCopyTableSameNames); } else { - PMA_table_move_copy($db, $table, $target_db, $new_name, $what, isset($submit_move)); + PMA_Table::moveCopy($db, $table, $target_db, $new_name, $what, isset($submit_move)); $js_to_run = 'functions.js'; $message = (isset($submit_move) ? $strMoveTableOK : $strCopyTableOK); $message = sprintf($message, htmlspecialchars($table), htmlspecialchars($new_name)); @@ -51,7 +50,7 @@ if (isset($new_name) && trim($new_name) != '') { } } } - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; } // end is target table name @@ -59,7 +58,7 @@ if (isset($new_name) && trim($new_name) != '') { * No new name for the table! */ else { - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; PMA_mysqlDie($strTableEmpty, '', '', $err_url); } @@ -68,5 +67,5 @@ else { * Back to the calling script */ -require('./tbl_properties.php'); +require './tbl_properties.php'; ?> diff --git a/tbl_properties_operations.php b/tbl_properties_operations.php index 3a6c8e2e6..cba8aa529 100644 --- a/tbl_properties_operations.php +++ b/tbl_properties_operations.php @@ -2,25 +2,26 @@ /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: -require_once('./libraries/common.lib.php'); +require_once './libraries/common.lib.php'; +require_once './libraries/Table.class.php'; /** * Runs common work */ -require('./libraries/tbl_properties_common.php'); +require './libraries/tbl_properties_common.php'; $url_query .= '&goto=tbl_properties_operations.php&back=tbl_properties_operations.php'; /** * Gets relation settings */ -require_once('./libraries/relation.lib.php'); +require_once './libraries/relation.lib.php'; $cfgRelation = PMA_getRelationsParam(); /** * Gets available MySQL charsets and storage engines */ -require_once('./libraries/mysql_charsets.lib.php'); -require_once('./libraries/storage_engines.lib.php'); +require_once './libraries/mysql_charsets.lib.php'; +require_once './libraries/storage_engines.lib.php'; // reselect current db (needed in some cases probably due to // the calling of relation.lib.php) @@ -30,8 +31,7 @@ PMA_DBI_select_db($GLOBALS['db']); * Gets tables informations */ -require_once('./libraries/tbl_move_copy.php'); -require('./libraries/tbl_properties_table_info.inc.php'); +require './libraries/tbl_properties_table_info.inc.php'; $reread_info = false; $errors = array(); @@ -40,14 +40,14 @@ $table_alters = array(); /** * Updates table comment, type and options if required */ -if ( isset( $_REQUEST['submitoptions'] ) ) { - if ( isset( $_REQUEST['new_name'] ) && $_REQUEST['new_name'] !== $GLOBALS['table'] ) { - if ( trim($_REQUEST['new_name']) === '' ) { +if (isset($_REQUEST['submitoptions'])) { + if (isset($_REQUEST['new_name']) && $_REQUEST['new_name'] !== $GLOBALS['table']) { + if (trim($_REQUEST['new_name']) === '') { $errors[] = $strTableEmpty; - } elseif ( strpos($_REQUEST['new_name'], '.') !== false ) { + } elseif (strpos($_REQUEST['new_name'], '.') !== false) { $errors[] = $strError . ': ' . $_REQUEST['new_name']; } else { - if ( PMA_table_rename( $GLOBALS['table'], $_REQUEST['new_name'] ) ) { + if (PMA_Table::rename($GLOBALS['table'], $_REQUEST['new_name'])) { $message = sprintf($GLOBALS['strRenameTableOK'], htmlspecialchars($GLOBALS['table']), htmlspecialchars($_REQUEST['new_name'])); $GLOBALS['table'] = $_REQUEST['new_name']; @@ -58,82 +58,82 @@ if ( isset( $_REQUEST['submitoptions'] ) ) { } } } - if ( isset( $_REQUEST['comment'] ) - && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment'] ) { + if (isset($_REQUEST['comment']) + && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) { $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\''; } - if ( ! empty( $_REQUEST['new_tbl_type'] ) - && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type) ) { + if (! empty($_REQUEST['new_tbl_type']) + && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) { $table_alters[] = 'TYPE = ' . $_REQUEST['new_tbl_type']; $tbl_type = $_REQUEST['new_tbl_type']; } - if ( ! empty( $_REQUEST['tbl_collation'] ) - && $_REQUEST['tbl_collation'] !== $tbl_collation ) { + if (! empty($_REQUEST['tbl_collation']) + && $_REQUEST['tbl_collation'] !== $tbl_collation) { $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']); } - $l_tbl_type = strtolower( $tbl_type ); + $l_tbl_type = strtolower($tbl_type); - $pack_keys = empty( $pack_keys ) ? '0' : '1'; - $_REQUEST['new_pack_keys'] = empty( $_REQUEST['new_pack_keys'] ) ? '0' : '1'; - if ( ( $l_tbl_type === 'myisam' || $l_tbl_type === 'isam' ) - && $_REQUEST['new_pack_keys'] !== $pack_keys ) { + $pack_keys = empty($pack_keys) ? '0' : '1'; + $_REQUEST['new_pack_keys'] = empty($_REQUEST['new_pack_keys']) ? '0' : '1'; + if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam') + && $_REQUEST['new_pack_keys'] !== $pack_keys) { $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys']; } - $checksum = empty( $checksum ) ? '0' : '1'; - $_REQUEST['new_checksum'] = empty( $_REQUEST['new_checksum'] ) ? '0' : '1'; - if ( ( $l_tbl_type === 'myisam' ) - && $_REQUEST['new_checksum'] !== $checksum ) { + $checksum = empty($checksum) ? '0' : '1'; + $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1'; + if (($l_tbl_type === 'myisam') + && $_REQUEST['new_checksum'] !== $checksum) { $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum']; } - $delay_key_write = empty( $delay_key_write ) ? '0' : '1'; - $_REQUEST['new_delay_key_write'] = empty( $_REQUEST['new_delay_key_write'] ) ? '0' : '1'; - if ( ( $l_tbl_type === 'myisam' ) - && $_REQUEST['new_delay_key_write'] !== $delay_key_write ) { + $delay_key_write = empty($delay_key_write) ? '0' : '1'; + $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1'; + if (($l_tbl_type === 'myisam') + && $_REQUEST['new_delay_key_write'] !== $delay_key_write) { $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write']; } - if ( ( $l_tbl_type === 'myisam' || $l_tbl_type === 'innodb' ) - && ! empty( $_REQUEST['new_auto_increment'] ) - && ( ! isset( $auto_increment ) || $_REQUEST['new_auto_increment'] !== $auto_increment ) ) { + if (($l_tbl_type === 'myisam' || $l_tbl_type === 'innodb') + && ! empty($_REQUEST['new_auto_increment']) + && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) { $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']); } - if ( count($table_alters) > 0 ) { + if (count($table_alters) > 0) { $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']); $sql_query .= "\r\n" . implode("\r\n", $table_alters); $message = PMA_DBI_query($sql_query) ? $strSuccess : $strError; $reread_info = true; - unset( $table_alters ); + unset($table_alters); } } /** * Reordering the table has been requested by the user */ -if ( isset( $_REQUEST['submitorderby'] ) && ! empty( $_REQUEST['order_field'] ) ) { +if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) { $sql_query = ' ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field'])); - if ( isset( $_REQUEST['order_order'] ) && $_REQUEST['order_order'] === 'desc' ) { + if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') { $sql_query .= ' DESC'; } $message = PMA_DBI_query($sql_query) ? $strSuccess : $strError; } // end if -if ( $reread_info ) { +if ($reread_info) { $pack_keys = $checksum = $delay_key_write = 0; - require('./libraries/tbl_properties_table_info.inc.php'); + require './libraries/tbl_properties_table_info.inc.php'; } -unset( $reread_info ); +unset($reread_info); /** * Displays top menu links */ -require_once('./libraries/tbl_properties_links.inc.php'); +require_once './libraries/tbl_properties_links.inc.php'; $url_params['goto'] = 'tbl_properties_operations.php'; $url_params['back'] = 'tbl_properties_operations.php'; @@ -146,7 +146,7 @@ $local_query = ' FROM ' . PMA_backquote($GLOBALS['table']) . ' FROM ' . PMA_backquote($GLOBALS['db']); $columns = PMA_DBI_fetch_result($local_query, null, 'Field'); -unset( $local_query ); +unset($local_query); /** * Displays the page @@ -160,7 +160,7 @@ unset( $local_query ); 0 /> @@ -394,12 +394,12 @@ foreach ( $dblist as $each_db ) {
    'CHECK TABLE ' . PMA_backquote($GLOBALS['table']) )); + array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table']))); ?> -
  • +
  • @@ -407,9 +407,9 @@ if ( $tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB' } if ($tbl_type == 'INNODB') { $this_url_params = array_merge($url_params, - array( 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' TYPE=InnoDB' )); + array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' TYPE=InnoDB')); ?> -
  • +
  • @@ -417,9 +417,9 @@ if ( $tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB' } if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') { $this_url_params = array_merge($url_params, - array( 'sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table']) )); + array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table']))); ?> -
  • +
  • @@ -427,9 +427,9 @@ if ( $tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB' } if ($tbl_type == 'MYISAM') { $this_url_params = array_merge($url_params, - array( 'sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table']) )); + array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table']))); ?> -
  • +
  • @@ -437,9 +437,9 @@ if ( $tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB' } if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') { $this_url_params = array_merge($url_params, - array( 'sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table']) )); + array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table']))); ?> -
  • +
  • @@ -452,9 +452,9 @@ $this_url_params = array_merge($url_params, 'zero_rows' => sprintf($strTableHasBeenFlushed, htmlspecialchars($GLOBALS['table'])), 'reload' => 1, - )); + )); ?> -
  • +
  • @@ -466,7 +466,7 @@ $this_url_params = array_merge($url_params, // so I assume that if the current table is InnoDB, I don't display // this choice (InnoDB maintains integrity by itself) -if ( $cfgRelation['relwork'] && $tbl_type != "INNODB" ) { +if ($cfgRelation['relwork'] && $tbl_type != "INNODB") { // we need this PMA_DBI_select_db if the user has access to more than one db // and $GLOBALS['db'] is not the last of the list, because PMA_availableDatabases() @@ -500,10 +500,10 @@ if ( $cfgRelation['relwork'] && $tbl_type != "INNODB" ) { . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master) . ' IS NOT NULL'; $this_url_params = array_merge($url_params, - array( 'sql_query' => $join_query )); + array('sql_query' => $join_query)); echo '
  • ' . '' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field'] . '
  • ' . "\n"; } // foreach $foreign @@ -519,5 +519,5 @@ if ( $cfgRelation['relwork'] && $tbl_type != "INNODB" ) { /** * Displays the footer */ -require_once('./libraries/footer.inc.php'); +require_once './libraries/footer.inc.php'; ?>