/**
 * Defines the url to return to in case of error in a sql statement
 */
$err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
/**
 * Selects the database to work with
 */
PMA_DBI_select_db($db);
/**
 * A target table name has been sent to this script -> do the work
 */
if (isset($new_name) && trim($new_name) != '') {
    if ($db == $target_db && $table == $new_name) {
        $message = isset($submit_move) ? $strMoveTableSameNames : $strCopyTableSameNames;
    } else {
        PMA_Table::moveCopy($db, $table, $target_db, $new_name, $what, isset($submit_move), 'one_table');
        $js_to_run = 'functions.js';
        $message = isset($submit_move) ? $strMoveTableOK : $strCopyTableOK;
        $message = sprintf($message, htmlspecialchars($table), htmlspecialchars($new_name));
        $reload = 1;
        /* Check: Work on new table or on old table? */
        if (isset($submit_move)) {
            $db = $target_db;
            $table = $new_name;
        } else {
            $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
            if (isset($switch_to_new) && $switch_to_new == 'true') {
                PMA_setCookie('pma_switch_to_new', 'true');
                $db = $target_db;
                $table = $new_name;
            } else {
Exemplo n.º 2
0
/**
 * Move or copy a table
 *
 * @param string $db    current database name
 * @param string $table current table name
 *
 * @return void
 */
function PMA_moveOrCopyTable($db, $table)
{
    /**
     * Selects the database to work with
     */
    $GLOBALS['dbi']->selectDb($db);
    /**
     * $_REQUEST['target_db'] could be empty in case we came from an input field
     * (when there are many databases, no drop-down)
     */
    if (empty($_REQUEST['target_db'])) {
        $_REQUEST['target_db'] = $db;
    }
    /**
     * A target table name has been sent to this script -> do the work
     */
    if (PMA_isValid($_REQUEST['new_name'])) {
        if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) {
            if (isset($_REQUEST['submit_move'])) {
                $message = PMA_Message::error(__('Can\'t move table to same one!'));
            } else {
                $message = PMA_Message::error(__('Can\'t copy table to same one!'));
            }
        } else {
            PMA_Table::moveCopy($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'], $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table');
            if (isset($_REQUEST['adjust_privileges']) && !empty($_REQUEST['adjust_privileges'])) {
                if (isset($_REQUEST['submit_move'])) {
                    PMA_AdjustPrivileges_renameOrMoveTable($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']);
                } else {
                    PMA_AdjustPrivileges_copyTable($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']);
                }
                if (isset($_REQUEST['submit_move'])) {
                    $message = PMA_Message::success(__('Table %s has been moved to %s. Privileges have been ' . 'adjusted.'));
                } else {
                    $message = PMA_Message::success(__('Table %s has been copied to %s. Privileges have been ' . 'adjusted.'));
                }
            } else {
                if (isset($_REQUEST['submit_move'])) {
                    $message = PMA_Message::success(__('Table %s has been moved to %s.'));
                } else {
                    $message = PMA_Message::success(__('Table %s has been copied to %s.'));
                }
            }
            $old = PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table);
            $message->addParam($old);
            $new = PMA_Util::backquote($_REQUEST['target_db']) . '.' . PMA_Util::backquote($_REQUEST['new_name']);
            $message->addParam($new);
            /* Check: Work on new table or on old table? */
            if (isset($_REQUEST['submit_move']) || PMA_isValid($_REQUEST['switch_to_new'])) {
            }
        }
    } else {
        /**
         * No new name for the table!
         */
        $message = PMA_Message::error(__('The table name is empty!'));
    }
    if ($GLOBALS['is_ajax_request'] == true) {
        $response = PMA_Response::getInstance();
        $response->addJSON('message', $message);
        if ($message->isSuccess()) {
            $response->addJSON('db', $GLOBALS['db']);
        } else {
            $response->isSuccess(false);
        }
        exit;
    }
}
Exemplo n.º 3
0
             break;
         }
         if (isset($GLOBALS['add_constraints'])) {
             $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];
             unset($GLOBALS['sql_constraints_query']);
         }
     }
     // $sql_query is filled by PMA_Table::moveCopy()
     $sql_query = $back . $sql_query;
 }
 // end (foreach)
 unset($each_table);
 // handle the views
 if (!$_error) {
     foreach ($views as $view) {
         if (!PMA_Table::moveCopy($db, $view, $newname, $view, 'structure', $move, 'db_copy')) {
             $_error = true;
             break;
         }
     }
 }
 unset($view, $views);
 // now that all tables exist, create all the accumulated constraints
 if (!$_error && isset($GLOBALS['add_constraints'])) {
     /**
      * @todo this works with mysqli but not with mysql, because
      * mysql extension does not accept more than one statement; maybe
      * interface with the sql import plugin that handles statement delimiter
      */
     PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);
     // and prepare to display them
Exemplo n.º 4
0
 /**
  * Test for moveCopy
  *
  * @return void
  */
 public function testMoveCopy()
 {
     $source_table = 'PMA_BookMark';
     $source_db = 'PMA';
     $target_table = 'PMA_BookMark_new';
     $target_db = 'PMA_new';
     $what = "dataonly";
     $move = true;
     $mode = "one_table";
     $GLOBALS['dbi']->expects($this->any())->method('getTable')->will($this->returnValue(new PMA_Table($target_table, $target_db)));
     $_REQUEST['drop_if_exists'] = true;
     $return = PMA_Table::moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode);
     //successfully
     $expect = true;
     $this->assertEquals($expect, $return);
     $sql_query = "INSERT INTO `PMA_new`.`PMA_BookMark_new` SELECT * FROM " . "`PMA`.`PMA_BookMark`";
     $this->assertContains($sql_query, $GLOBALS['sql_query']);
     $sql_query = "DROP VIEW `PMA`.`PMA_BookMark`";
     $this->assertContains($sql_query, $GLOBALS['sql_query']);
     $return = PMA_Table::moveCopy($source_db, $source_table, $target_db, $target_table, $what, false, $mode);
     //successfully
     $expect = true;
     $this->assertEquals($expect, $return);
     $sql_query = "INSERT INTO `PMA_new`.`PMA_BookMark_new` SELECT * FROM " . "`PMA`.`PMA_BookMark`;";
     $this->assertContains($sql_query, $GLOBALS['sql_query']);
     $sql_query = "DROP VIEW `PMA`.`PMA_BookMark`";
     $this->assertNotContains($sql_query, $GLOBALS['sql_query']);
 }
Exemplo n.º 5
0
if (empty($_REQUEST['target_db'])) {
    $_REQUEST['target_db'] = $db;
}
/**
 * A target table name has been sent to this script -> do the work
 */
if (PMA_isValid($_REQUEST['new_name'])) {
    if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) {
        if (isset($_REQUEST['submit_move'])) {
            $message = PMA_Message::error(__('Can\'t move table to same one!'));
        } else {
            $message = PMA_Message::error(__('Can\'t copy table to same one!'));
        }
        $result = false;
    } else {
        $result = PMA_Table::moveCopy($db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'], $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table');
        if (isset($_REQUEST['submit_move'])) {
            $message = PMA_Message::success(__('Table %s has been moved to %s.'));
        } else {
            $message = PMA_Message::success(__('Table %s has been copied to %s.'));
        }
        $old = PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table);
        $message->addParam($old);
        $new = PMA_Util::backquote($_REQUEST['target_db']) . '.' . PMA_Util::backquote($_REQUEST['new_name']);
        $message->addParam($new);
        /* Check: Work on new table or on old table? */
        if (isset($_REQUEST['submit_move']) || PMA_isValid($_REQUEST['switch_to_new'])) {
            $db = $_REQUEST['target_db'];
            $table = $_REQUEST['new_name'];
        }
        $reload = 1;
Exemplo n.º 6
0
/**
 * Handle the views, return the boolean value whether table rename/copy or not
 *
 * @param array   $views views as an array
 * @param boolean $move  whether databse name is empty or not
 * @param string  $db    database name
 *
 * @return boolean $_error whether table rename/copy or not
 */
function PMA_handleTheViews($views, $move, $db)
{
    $_error = false;
    // temporarily force to add DROP IF EXIST to CREATE VIEW query,
    // to remove stand-in VIEW that was created earlier
    // ( $_REQUEST['drop_if_exists'] is used in moveCopy() )
    if (isset($_REQUEST['drop_if_exists'])) {
        $temp_drop_if_exists = $_REQUEST['drop_if_exists'];
    }
    $_REQUEST['drop_if_exists'] = 'true';
    foreach ($views as $view) {
        $copying_succeeded = PMA_Table::moveCopy($db, $view, $_REQUEST['newname'], $view, 'structure', $move, 'db_copy');
        if (!$copying_succeeded) {
            $_error = true;
            break;
        }
    }
    unset($_REQUEST['drop_if_exists']);
    if (isset($temp_drop_if_exists)) {
        // restore previous value
        $_REQUEST['drop_if_exists'] = $temp_drop_if_exists;
    }
    return $_error;
}
Exemplo n.º 7
0
     $this_what = $what;
     if (!isset($tables_full[$table]['Engine'])) {
         $tables_full[$table]['Engine'] = $tables_full[$table]['Type'];
     }
     // do not copy the data from a Merge table
     // note: on the calling FORM, 'data' means 'structure and data'
     if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {
         if ($this_what == 'data') {
             $this_what = 'structure';
         }
         if ($this_what == 'dataonly') {
             $this_what = 'nocopy';
         }
     }
     if ($this_what != 'nocopy') {
         PMA_Table::moveCopy($db, $table, $newname, $table, isset($this_what) ? $this_what : 'data', $move, 'db_copy');
         if (isset($GLOBALS['add_constraints'])) {
             $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];
             unset($GLOBALS['sql_constraints_query']);
         }
     }
     $sql_query = $back . $sql_query;
 }
 unset($table);
 // now that all tables exist, create all the accumulated constraints
 if (isset($GLOBALS['add_constraints'])) {
     // FIXME: this works with mysqli but not with mysql,
     // because mysql extension does not accept more than one
     // statement; maybe interface with the sql import plugin
     // that handles statement delimiter
     PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);