Replace static methods with instance methods

Replace PhpMyAdmin\Operations static methods with instance methods.

Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
Maurício Meneghini Fauth 2018-02-25 12:43:49 -03:00
parent 628107418b
commit a862add418
8 changed files with 160 additions and 131 deletions

View File

@ -40,6 +40,8 @@ $scripts->addFile('db_operations.js');
$sql_query = '';
$operations = new Operations();
/**
* Rename/move or copy database
*/
@ -69,7 +71,7 @@ if (strlen($GLOBALS['db']) > 0
} else {
$_error = false;
if ($move || ! empty($_REQUEST['create_database_before_copying'])) {
Operations::createDbBeforeCopy();
$operations->createDbBeforeCopy();
}
// here I don't use DELIMITER because it's not part of the
@ -78,7 +80,7 @@ if (strlen($GLOBALS['db']) > 0
// to avoid selecting alternatively the current and new db
// we would need to modify the CREATE definitions to qualify
// the db name
Operations::runProcedureAndFunctionDefinitions($GLOBALS['db']);
$operations->runProcedureAndFunctionDefinitions($GLOBALS['db']);
// go back to current db, just in case
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
@ -98,24 +100,24 @@ if (strlen($GLOBALS['db']) > 0
);
// create stand-in tables for views
$views = Operations::getViewsAndCreateSqlViewStandIn(
$views = $operations->getViewsAndCreateSqlViewStandIn(
$tables_full, $export_sql_plugin, $GLOBALS['db']
);
// copy tables
$sqlConstratints = Operations::copyTables(
$sqlConstratints = $operations->copyTables(
$tables_full, $move, $GLOBALS['db']
);
// handle the views
if (! $_error) {
Operations::handleTheViews($views, $move, $GLOBALS['db']);
$operations->handleTheViews($views, $move, $GLOBALS['db']);
}
unset($views);
// now that all tables exist, create all the accumulated constraints
if (! $_error && count($sqlConstratints) > 0) {
Operations::createAllAccumulatedConstraints($sqlConstratints);
$operations->createAllAccumulatedConstraints($sqlConstratints);
}
unset($sqlConstratints);
@ -123,20 +125,20 @@ if (strlen($GLOBALS['db']) > 0
// here DELIMITER is not used because it's not part of the
// language; each statement is sent one by one
Operations::runEventDefinitionsForDb($GLOBALS['db']);
$operations->runEventDefinitionsForDb($GLOBALS['db']);
}
// go back to current db, just in case
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
// Duplicate the bookmarks for this db (done once for each db)
Operations::duplicateBookmarks($_error, $GLOBALS['db']);
$operations->duplicateBookmarks($_error, $GLOBALS['db']);
if (! $_error && $move) {
if (isset($_REQUEST['adjust_privileges'])
&& ! empty($_REQUEST['adjust_privileges'])
) {
Operations::adjustPrivilegesMoveDb($GLOBALS['db'], $_REQUEST['newname']);
$operations->adjustPrivilegesMoveDb($GLOBALS['db'], $_REQUEST['newname']);
}
/**
@ -159,7 +161,7 @@ if (strlen($GLOBALS['db']) > 0
if (isset($_REQUEST['adjust_privileges'])
&& ! empty($_REQUEST['adjust_privileges'])
) {
Operations::adjustPrivilegesCopyDb($GLOBALS['db'], $_REQUEST['newname']);
$operations->adjustPrivilegesCopyDb($GLOBALS['db'], $_REQUEST['newname']);
}
$message = Message::success(
@ -252,7 +254,7 @@ if (!$is_information_schema) {
/**
* database comment
*/
$response->addHTML(Operations::getHtmlForDatabaseComment($GLOBALS['db']));
$response->addHTML($operations->getHtmlForDatabaseComment($GLOBALS['db']));
}
$response->addHTML('<div>');
@ -263,7 +265,7 @@ if (!$is_information_schema) {
* rename database
*/
if ($GLOBALS['db'] != 'mysql') {
$response->addHTML(Operations::getHtmlForRenameDatabase($GLOBALS['db']));
$response->addHTML($operations->getHtmlForRenameDatabase($GLOBALS['db']));
}
// Drop link if allowed
@ -274,17 +276,17 @@ if (!$is_information_schema) {
&& ! $db_is_system_schema
&& $GLOBALS['db'] != 'mysql'
) {
$response->addHTML(Operations::getHtmlForDropDatabaseLink($GLOBALS['db']));
$response->addHTML($operations->getHtmlForDropDatabaseLink($GLOBALS['db']));
}
/**
* Copy database
*/
$response->addHTML(Operations::getHtmlForCopyDatabase($GLOBALS['db']));
$response->addHTML($operations->getHtmlForCopyDatabase($GLOBALS['db']));
/**
* Change database charset
*/
$response->addHTML(Operations::getHtmlForChangeDatabaseCharset($GLOBALS['db'], $table));
$response->addHTML($operations->getHtmlForChangeDatabaseCharset($GLOBALS['db'], $table));
if (! $cfgRelation['allworks']
&& $cfg['PmaNoRelation_DisableWarning'] == false

View File

@ -319,7 +319,13 @@ class MultSubmits
'one_table'
);
if (isset($_POST['adjust_privileges']) && !empty($_POST['adjust_privileges'])) {
Operations::adjustPrivilegesCopyTable($db, $selected[$i], $_POST['target_db'], $selected[$i]);
$operations = new Operations();
$operations->adjustPrivilegesCopyTable(
$db,
$selected[$i],
$_POST['target_db'],
$selected[$i]
);
}
break;
} // end switch

View File

@ -1,7 +1,7 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* set of functions with the operations section in pma
* Holds the PhpMyAdmin\Operations class
*
* @package PhpMyAdmin
*/
@ -21,7 +21,7 @@ use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
/**
* PhpMyAdmin\Operations
* Set of functions with the operations section in phpMyAdmin
*
* @package PhpMyAdmin
*/
@ -34,7 +34,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForDatabaseComment($db)
public function getHtmlForDatabaseComment($db)
{
$html_output = '<div>'
. '<form method="post" action="db_operations.php" id="formDatabaseComment">'
@ -66,7 +66,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForRenameDatabase($db)
public function getHtmlForRenameDatabase($db)
{
$html_output = '<div>'
. '<form id="rename_db_form" '
@ -131,7 +131,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForDropDatabaseLink($db)
public function getHtmlForDropDatabaseLink($db)
{
$this_sql_query = 'DROP DATABASE ' . Util::backquote($db);
$this_url_params = array(
@ -156,7 +156,7 @@ class Operations
$html_output .= __('Remove database')
. '</legend>';
$html_output .= '<ul>';
$html_output .= self::getDeleteDataOrTablelink(
$html_output .= $this->getDeleteDataOrTablelink(
$this_url_params,
'DROP_DATABASE',
__('Drop the database (DROP)'),
@ -175,7 +175,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForCopyDatabase($db)
public function getHtmlForCopyDatabase($db)
{
$drop_clause = 'DROP TABLE / DROP VIEW';
$choices = array(
@ -273,7 +273,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForChangeDatabaseCharset($db, $table)
public function getHtmlForChangeDatabaseCharset($db, $table)
{
$html_output = '<div>'
. '<form id="change_db_charset_form" ';
@ -331,7 +331,7 @@ class Operations
*
* @return void
*/
public static function runProcedureAndFunctionDefinitions($db)
public function runProcedureAndFunctionDefinitions($db)
{
$procedure_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE');
if ($procedure_names) {
@ -367,7 +367,7 @@ class Operations
*
* @return void
*/
public static function createDbBeforeCopy()
public function createDbBeforeCopy()
{
$local_query = 'CREATE DATABASE IF NOT EXISTS '
. Util::backquote($_REQUEST['newname']);
@ -404,7 +404,7 @@ class Operations
*
* @return array $views
*/
public static function getViewsAndCreateSqlViewStandIn(
public function getViewsAndCreateSqlViewStandIn(
array $tables_full, $export_sql_plugin, $db
) {
$views = array();
@ -449,7 +449,7 @@ class Operations
*
* @return array SQL queries for the constraints
*/
public static function copyTables(array $tables_full, $move, $db)
public function copyTables(array $tables_full, $move, $db)
{
$sqlContraints = array();
foreach ($tables_full as $each_table => $tmp) {
@ -518,7 +518,7 @@ class Operations
*
* @return void
*/
public static function runEventDefinitionsForDb($db)
public function runEventDefinitionsForDb($db)
{
$event_names = $GLOBALS['dbi']->fetchResult(
'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
@ -545,7 +545,7 @@ class Operations
*
* @return void
*/
public static function handleTheViews(array $views, $move, $db)
public function handleTheViews(array $views, $move, $db)
{
// temporarily force to add DROP IF EXIST to CREATE VIEW query,
// to remove stand-in VIEW that was created earlier
@ -580,7 +580,7 @@ class Operations
*
* @return void
*/
public static function adjustPrivilegesMoveDb($oldDb, $newname)
public function adjustPrivilegesMoveDb($oldDb, $newname)
{
if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
&& $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
@ -628,7 +628,7 @@ class Operations
*
* @return void
*/
public static function adjustPrivilegesCopyDb($oldDb, $newname)
public function adjustPrivilegesCopyDb($oldDb, $newname)
{
if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
&& $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
@ -734,7 +734,7 @@ class Operations
*
* @return void
*/
public static function createAllAccumulatedConstraints(array $sqlConstratints)
public function createAllAccumulatedConstraints(array $sqlConstratints)
{
$GLOBALS['dbi']->selectDb($_REQUEST['newname']);
foreach ($sqlConstratints as $one_query) {
@ -752,7 +752,7 @@ class Operations
*
* @return void
*/
public static function duplicateBookmarks($_error, $db)
public function duplicateBookmarks($_error, $db)
{
if (! $_error && $db != $_REQUEST['newname']) {
$get_fields = array('user', 'label', 'query');
@ -772,7 +772,7 @@ class Operations
*
* @return string $html_out
*/
public static function getHtmlForOrderTheTable(array $columns)
public function getHtmlForOrderTheTable(array $columns)
{
$html_output = '<div>';
$html_output .= '<form method="post" id="alterTableOrderby" '
@ -813,7 +813,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForMoveTable()
public function getHtmlForMoveTable()
{
$html_output = '<div>';
$html_output .= '<form method="post" action="tbl_operations.php"'
@ -894,7 +894,7 @@ class Operations
*
* @return string $html_output
*/
public static function getTableOptionDiv($pma_table, $comment, $tbl_collation, $tbl_storage_engine,
public function getTableOptionDiv($pma_table, $comment, $tbl_collation, $tbl_storage_engine,
$pack_keys, $auto_increment, $delay_key_write,
$transactional, $page_checksum, $checksum
) {
@ -906,7 +906,7 @@ class Operations
);
$html_output .= '<input type="hidden" name="reload" value="1" />';
$html_output .= self::getTableOptionFieldset(
$html_output .= $this->getTableOptionFieldset(
$pma_table, $comment, $tbl_collation,
$tbl_storage_engine, $pack_keys,
$delay_key_write, $auto_increment, $transactional, $page_checksum,
@ -928,7 +928,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForRenameTable()
private function getHtmlForRenameTable()
{
$html_output = '<tr><td class="vmiddle">' . __('Rename table to') . '</td>'
. '<td>'
@ -967,7 +967,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForTableComments($current_value)
private function getHtmlForTableComments($current_value)
{
$commentLength = $GLOBALS['dbi']->getVersion() >= 50503 ? 2048 : 60;
$html_output = '<tr><td class="vmiddle">' . __('Table comments') . '</td>'
@ -989,7 +989,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForPackKeys($current_value)
private function getHtmlForPackKeys($current_value)
{
$html_output = '<tr>'
. '<td class="vmiddle"><label for="new_pack_keys">PACK_KEYS</label></td>'
@ -1033,7 +1033,7 @@ class Operations
*
* @return string $html_output
*/
public static function getTableOptionFieldset($pma_table, $comment, $tbl_collation,
private function getTableOptionFieldset($pma_table, $comment, $tbl_collation,
$tbl_storage_engine, $pack_keys,
$delay_key_write, $auto_increment, $transactional,
$page_checksum, $checksum
@ -1042,8 +1042,8 @@ class Operations
. '<legend>' . __('Table options') . '</legend>';
$html_output .= '<table>';
$html_output .= self::getHtmlForRenameTable();
$html_output .= self::getHtmlForTableComments($comment);
$html_output .= $this->getHtmlForRenameTable();
$html_output .= $this->getHtmlForTableComments($comment);
//Storage engine
$html_output .= '<tr><td class="vmiddle">' . __('Storage Engine')
@ -1080,17 +1080,17 @@ class Operations
. '</td></tr>';
if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'ISAM'))) {
$html_output .= self::getHtmlForPackKeys($pack_keys);
$html_output .= $this->getHtmlForPackKeys($pack_keys);
} // end if (MYISAM|ISAM)
if ($pma_table->isEngine(array('MYISAM', 'ARIA'))) {
$html_output .= self::getHtmlForTableRow(
$html_output .= $this->getHtmlForTableRow(
'new_checksum',
'CHECKSUM',
$checksum
);
$html_output .= self::getHtmlForTableRow(
$html_output .= $this->getHtmlForTableRow(
'new_delay_key_write',
'DELAY_KEY_WRITE',
$delay_key_write
@ -1098,13 +1098,13 @@ class Operations
} // end if (MYISAM)
if ($pma_table->isEngine('ARIA')) {
$html_output .= self::getHtmlForTableRow(
$html_output .= $this->getHtmlForTableRow(
'new_transactional',
'TRANSACTIONAL',
$transactional
);
$html_output .= self::getHtmlForTableRow(
$html_output .= $this->getHtmlForTableRow(
'new_page_checksum',
'PAGE_CHECKSUM',
$page_checksum
@ -1122,7 +1122,7 @@ class Operations
. '</tr> ';
} // end if (MYISAM|INNODB)
$possible_row_formats = self::getPossibleRowFormat();
$possible_row_formats = $this->getPossibleRowFormat();
// for MYISAM there is also COMPRESSED but it can be set only by the
// myisampack utility, so don't offer here the choice because if we
@ -1158,7 +1158,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForTableRow($attribute, $label, $val)
private function getHtmlForTableRow($attribute, $label, $val)
{
return '<tr>'
. '<td class="vmiddle">'
@ -1177,7 +1177,7 @@ class Operations
*
* @return array $possible_row_formats
*/
public static function getPossibleRowFormat()
private function getPossibleRowFormat()
{
// the outer array is for engines, the inner array contains the dropdown
// option values as keys then the dropdown option labels
@ -1233,7 +1233,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForCopytable()
public function getHtmlForCopytable()
{
$html_output = '<div>';
$html_output .= '<form method="post" action="tbl_operations.php" '
@ -1336,7 +1336,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForTableMaintenance($pma_table, array $url_params)
public function getHtmlForTableMaintenance($pma_table, array $url_params)
{
$html_output = '<div>';
$html_output .= '<fieldset>'
@ -1344,7 +1344,7 @@ class Operations
$html_output .= '<ul id="tbl_maintenance">';
// Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
$html_output .= self::getListofMaintainActionLink($pma_table, $url_params);
$html_output .= $this->getListofMaintainActionLink($pma_table, $url_params);
$html_output .= '</ul>'
. '</fieldset>'
@ -1361,7 +1361,7 @@ class Operations
*
* @return string $html_output
*/
public static function getListofMaintainActionLink($pma_table, array $url_params)
private function getListofMaintainActionLink($pma_table, array $url_params)
{
$html_output = '';
@ -1372,7 +1372,7 @@ class Operations
. Util::backquote($GLOBALS['table']),
'table_maintenance' => 'Go',
);
$html_output .= self::getMaintainActionlink(
$html_output .= $this->getMaintainActionlink(
__('Analyze table'),
$params,
$url_params,
@ -1387,7 +1387,7 @@ class Operations
. Util::backquote($GLOBALS['table']),
'table_maintenance' => 'Go',
);
$html_output .= self::getMaintainActionlink(
$html_output .= $this->getMaintainActionlink(
__('Check table'),
$params,
$url_params,
@ -1401,7 +1401,7 @@ class Operations
. Util::backquote($GLOBALS['table']),
'table_maintenance' => 'Go',
);
$html_output .= self::getMaintainActionlink(
$html_output .= $this->getMaintainActionlink(
__('Checksum table'),
$params,
$url_params,
@ -1415,7 +1415,7 @@ class Operations
. Util::backquote($GLOBALS['table'])
. ' ENGINE = InnoDB;'
);
$html_output .= self::getMaintainActionlink(
$html_output .= $this->getMaintainActionlink(
__('Defragment table'),
$params,
$url_params,
@ -1433,7 +1433,7 @@ class Operations
),
'reload' => 1,
);
$html_output .= self::getMaintainActionlink(
$html_output .= $this->getMaintainActionlink(
__('Flush the table (FLUSH)'),
$params,
$url_params,
@ -1447,7 +1447,7 @@ class Operations
. Util::backquote($GLOBALS['table']),
'table_maintenance' => 'Go',
);
$html_output .= self::getMaintainActionlink(
$html_output .= $this->getMaintainActionlink(
__('Optimize table'),
$params,
$url_params,
@ -1462,7 +1462,7 @@ class Operations
. Util::backquote($GLOBALS['table']),
'table_maintenance' => 'Go',
);
$html_output .= self::getMaintainActionlink(
$html_output .= $this->getMaintainActionlink(
__('Repair table'),
$params,
$url_params,
@ -1483,7 +1483,7 @@ class Operations
*
* @return string $html_output
*/
public static function getMaintainActionlink($action_message, array $params, array $url_params, $link)
private function getMaintainActionlink($action_message, array $params, array $url_params, $link)
{
return '<li>'
. Util::linkOrButton(
@ -1503,7 +1503,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForDeleteDataOrTable(
public function getHtmlForDeleteDataOrTable(
array $truncate_table_url_params,
array $dropTableUrlParams
) {
@ -1514,7 +1514,7 @@ class Operations
$html_output .= '<ul>';
if (! empty($truncate_table_url_params)) {
$html_output .= self::getDeleteDataOrTablelink(
$html_output .= $this->getDeleteDataOrTablelink(
$truncate_table_url_params,
'TRUNCATE_TABLE',
__('Empty the table (TRUNCATE)'),
@ -1522,7 +1522,7 @@ class Operations
);
}
if (!empty($dropTableUrlParams)) {
$html_output .= self::getDeleteDataOrTablelink(
$html_output .= $this->getDeleteDataOrTablelink(
$dropTableUrlParams,
'DROP_TABLE',
__('Delete the table (DROP)'),
@ -1542,9 +1542,9 @@ class Operations
* @param string $link link to be shown
* @param string $htmlId id of the link
*
* @return String html output
* @return string html output
*/
public static function getDeleteDataOrTablelink(array $url_params, $syntax, $link, $htmlId)
public function getDeleteDataOrTablelink(array $url_params, $syntax, $link, $htmlId)
{
return '<li><a '
. 'href="sql.php' . Url::getCommon($url_params) . '"'
@ -1562,7 +1562,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForPartitionMaintenance(array $partition_names, array $url_params)
public function getHtmlForPartitionMaintenance(array $partition_names, array $url_params)
{
$choices = array(
'ANALYZE' => __('Analyze'),
@ -1650,7 +1650,7 @@ class Operations
*
* @return string $html_output
*/
public static function getHtmlForReferentialIntegrityCheck(array $foreign, array $url_params)
public function getHtmlForReferentialIntegrityCheck(array $foreign, array $url_params)
{
$html_output = '<div>'
. '<fieldset>'
@ -1712,7 +1712,7 @@ class Operations
*
* @return array SQL query and result
*/
public static function getQueryAndResultForReorderingTable()
public function getQueryAndResultForReorderingTable()
{
$sql_query = 'ALTER TABLE '
. Util::backquote($GLOBALS['table'])
@ -1746,7 +1746,7 @@ class Operations
*
* @return array $table_alters
*/
public static function getTableAltersArray($pma_table, $pack_keys,
public function getTableAltersArray($pma_table, $pack_keys,
$checksum, $page_checksum, $delay_key_write,
$row_format, $newTblStorageEngine, $transactional, $tbl_collation
) {
@ -1840,7 +1840,7 @@ class Operations
*
* @return array $warning_messages
*/
public static function getWarningMessagesArray()
public function getWarningMessagesArray()
{
$warning_messages = array();
foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
@ -1868,7 +1868,7 @@ class Operations
*
* @return array $sql_query, $result
*/
public static function getQueryAndResultForPartition()
public function getQueryAndResultForPartition()
{
$sql_query = 'ALTER TABLE '
. Util::backquote($GLOBALS['table']) . ' '
@ -1896,7 +1896,7 @@ class Operations
*
* @return void
*/
public static function adjustPrivilegesRenameOrMoveTable($oldDb, $oldTable, $newDb, $newTable)
public function adjustPrivilegesRenameOrMoveTable($oldDb, $oldTable, $newDb, $newTable)
{
if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
&& $GLOBALS['is_reload_priv']
@ -1933,7 +1933,7 @@ class Operations
*
* @return void
*/
public static function adjustPrivilegesCopyTable($oldDb, $oldTable, $newDb, $newTable)
public function adjustPrivilegesCopyTable($oldDb, $oldTable, $newDb, $newTable)
{
if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
&& $GLOBALS['is_reload_priv']
@ -1995,7 +1995,7 @@ class Operations
*
* @return void
*/
public static function changeAllColumnsCollation($db, $table, $tbl_collation)
public function changeAllColumnsCollation($db, $table, $tbl_collation)
{
$GLOBALS['dbi']->selectDb($db);
@ -2019,7 +2019,7 @@ class Operations
*
* @return void
*/
public static function moveOrCopyTable($db, $table)
public function moveOrCopyTable($db, $table)
{
/**
* Selects the database to work with
@ -2054,11 +2054,11 @@ class Operations
&& ! empty($_REQUEST['adjust_privileges'])
) {
if (isset($_REQUEST['submit_move'])) {
self::adjustPrivilegesRenameOrMoveTable(
$this->adjustPrivilegesRenameOrMoveTable(
$db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
);
} else {
self::adjustPrivilegesCopyTable(
$this->adjustPrivilegesCopyTable(
$db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
);
}

View File

@ -2201,7 +2201,8 @@ EOT;
isset($extra_data) ? $extra_data : null
);
$warning_messages = Operations::getWarningMessagesArray();
$operations = new Operations();
$warning_messages = $operations->getWarningMessagesArray();
// No rows returned -> move back to the calling page
if ((0 == $num_rows && 0 == $unlim_num_rows)

View File

@ -116,7 +116,8 @@ if (isset($_REQUEST['submitcollation'])
isset($_REQUEST['change_all_tables_columns_collations']) &&
$_REQUEST['change_all_tables_columns_collations'] == 'on'
) {
Operations::changeAllColumnsCollation($db, $tableName, $_REQUEST['db_collation']);
$operations = new Operations();
$operations->changeAllColumnsCollation($db, $tableName, $_REQUEST['db_collation']);
}
}

View File

@ -94,12 +94,14 @@ $pma_table = $GLOBALS['dbi']->getTable(
$reread_info = false;
$table_alters = array();
$operations = new Operations();
/**
* If the table has to be moved to some other database
*/
if (isset($_REQUEST['submit_move']) || isset($_REQUEST['submit_copy'])) {
//$_message = '';
Operations::moveOrCopyTable($db, $table);
$operations->moveOrCopyTable($db, $table);
// This was ended in an Ajax call
exit;
}
@ -126,7 +128,7 @@ if (isset($_REQUEST['submitoptions'])) {
if (isset($_REQUEST['adjust_privileges'])
&& ! empty($_REQUEST['adjust_privileges'])
) {
Operations::adjustPrivilegesRenameOrMoveTable(
$operations->adjustPrivilegesRenameOrMoveTable(
$oldDb, $oldTable, $_REQUEST['db'], $_REQUEST['new_name']
);
}
@ -164,7 +166,7 @@ if (isset($_REQUEST['submitoptions'])) {
? $create_options['row_format']
: $pma_table->getRowFormat();
$table_alters = Operations::getTableAltersArray(
$table_alters = $operations->getTableAltersArray(
$pma_table,
$create_options['pack_keys'],
(empty($create_options['checksum']) ? '0' : '1'),
@ -184,7 +186,7 @@ if (isset($_REQUEST['submitoptions'])) {
$result .= $GLOBALS['dbi']->query($sql_query) ? true : false;
$reread_info = true;
unset($table_alters);
$warning_messages = Operations::getWarningMessagesArray();
$warning_messages = $operations->getWarningMessagesArray();
}
if (isset($_REQUEST['tbl_collation'])
@ -192,7 +194,7 @@ if (isset($_REQUEST['submitoptions'])) {
&& isset($_REQUEST['change_all_collations'])
&& ! empty($_REQUEST['change_all_collations'])
) {
Operations::changeAllColumnsCollation(
$operations->changeAllColumnsCollation(
$GLOBALS['db'], $GLOBALS['table'], $_REQUEST['tbl_collation']
);
}
@ -201,7 +203,7 @@ if (isset($_REQUEST['submitoptions'])) {
* Reordering the table has been requested by the user
*/
if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
list($sql_query, $result) = Operations::getQueryAndResultForReorderingTable();
list($sql_query, $result) = $operations->getQueryAndResultForReorderingTable();
} // end if
/**
@ -210,7 +212,7 @@ if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
if (isset($_REQUEST['submit_partition'])
&& ! empty($_REQUEST['partition_operation'])
) {
list($sql_query, $result) = Operations::getQueryAndResultForPartition();
list($sql_query, $result) = $operations->getQueryAndResultForPartition();
} // end if
if ($reread_info) {
@ -333,13 +335,13 @@ if ($tbl_storage_engine == 'INNODB') {
}
}
if (! $hideOrderTable) {
$response->addHTML(Operations::getHtmlForOrderTheTable($columns));
$response->addHTML($operations->getHtmlForOrderTheTable($columns));
}
/**
* Move table
*/
$response->addHTML(Operations::getHtmlForMoveTable());
$response->addHTML($operations->getHtmlForMoveTable());
if (mb_strstr($show_comment, '; InnoDB free') === false) {
if (mb_strstr($show_comment, 'InnoDB free') === false) {
@ -363,7 +365,7 @@ if (mb_strstr($show_comment, '; InnoDB free') === false) {
// check for version
$response->addHTML(
Operations::getTableOptionDiv(
$operations->getTableOptionDiv(
$pma_table, $comment, $tbl_collation, $tbl_storage_engine,
$create_options['pack_keys'],
$auto_increment,
@ -377,13 +379,13 @@ $response->addHTML(
/**
* Copy table
*/
$response->addHTML(Operations::getHtmlForCopytable());
$response->addHTML($operations->getHtmlForCopytable());
/**
* Table maintenance
*/
$response->addHTML(
Operations::getHtmlForTableMaintenance($pma_table, $url_params)
$operations->getHtmlForTableMaintenance($pma_table, $url_params)
);
if (! (isset($db_is_system_schema) && $db_is_system_schema)) {
@ -432,7 +434,7 @@ if (! (isset($db_is_system_schema) && $db_is_system_schema)) {
);
}
$response->addHTML(
Operations::getHtmlForDeleteDataOrTable(
$operations->getHtmlForDeleteDataOrTable(
$truncate_table_url_params,
$drop_table_url_params
)
@ -444,7 +446,7 @@ if (Partition::havePartitioning()) {
// show the Partition maintenance section only if we detect a partition
if (! is_null($partition_names[0])) {
$response->addHTML(
Operations::getHtmlForPartitionMaintenance($partition_names, $url_params)
$operations->getHtmlForPartitionMaintenance($partition_names, $url_params)
);
} // end if
} // end if
@ -462,7 +464,7 @@ if ($cfgRelation['relwork'] && ! $pma_table->isEngine("INNODB")) {
if (! empty($foreign)) {
$response->addHTML(
Operations::getHtmlForReferentialIntegrityCheck($foreign, $url_params)
$operations->getHtmlForReferentialIntegrityCheck($foreign, $url_params)
);
} // end if ($foreign)

View File

@ -10,6 +10,7 @@ namespace PhpMyAdmin\Tests;
use PhpMyAdmin\Operations;
use PhpMyAdmin\Theme;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;
/**
* tests for operations
@ -18,12 +19,17 @@ use PHPUnit\Framework\TestCase;
*/
class OperationsTest extends TestCase
{
/**
* @var Operations
*/
private $operations;
/**
* Set up global environment.
*
* @return void
*/
public function setup()
protected function setUp()
{
$GLOBALS['server'] = 1;
$GLOBALS['table'] = 'table';
@ -31,6 +37,7 @@ class OperationsTest extends TestCase
$GLOBALS['cfg'] = array(
'ServerDefault' => 1,
'ActionLinksMode' => 'icons',
'LinkLengthLimit' => 1000,
);
$GLOBALS['cfg']['DBG']['sql'] = false;
$GLOBALS['server'] = 1;
@ -42,10 +49,12 @@ class OperationsTest extends TestCase
$GLOBALS['flush_priv'] = true;
$GLOBALS['is_reload_priv'] = false;
$GLOBALS['cfg']['Server']['DisableIS'] = false;
$this->operations = new Operations();
}
/**
* Test for Operations::getHtmlForDatabaseComment
* Test for getHtmlForDatabaseComment
*
* @return void
*/
@ -54,12 +63,12 @@ class OperationsTest extends TestCase
$this->assertRegExp(
'/.*db_operations.php(.|[\n])*Database comment.*name="comment"([\n]|.)*/m',
Operations::getHtmlForDatabaseComment("pma")
$this->operations->getHtmlForDatabaseComment("pma")
);
}
/**
* Test for Operations::getHtmlForRenameDatabase
* Test for getHtmlForRenameDatabase
*
* @return void
*/
@ -67,7 +76,7 @@ class OperationsTest extends TestCase
{
$_REQUEST['db_collation'] = 'db1';
$html = Operations::getHtmlForRenameDatabase("pma");
$html = $this->operations->getHtmlForRenameDatabase("pma");
$this->assertContains('db_operations.php', $html);
$this->assertRegExp(
'/.*db_rename.*Rename database to.*/',
@ -76,7 +85,7 @@ class OperationsTest extends TestCase
}
/**
* Test for Operations::getHtmlForDropDatabaseLink
* Test for getHtmlForDropDatabaseLink
*
* @return void
*/
@ -85,26 +94,26 @@ class OperationsTest extends TestCase
$this->assertRegExp(
'/.*DROP.DATABASE.*db_operations.php.*Drop the database.*/',
Operations::getHtmlForDropDatabaseLink("pma")
$this->operations->getHtmlForDropDatabaseLink("pma")
);
}
/**
* Test for Operations::getHtmlForCopyDatabase
* Test for getHtmlForCopyDatabase
*
* @return void
*/
public function testGetHtmlForCopyDatabase()
{
$_REQUEST['db_collation'] = 'db1';
$html = Operations::getHtmlForCopyDatabase("pma");
$html = $this->operations->getHtmlForCopyDatabase("pma");
$this->assertRegExp('/.*db_operations.php.*/', $html);
$this->assertRegExp('/.*db_copy.*/', $html);
$this->assertRegExp('/.*Copy database to.*/', $html);
}
/**
* Test for Operations::getHtmlForChangeDatabaseCharset
* Test for getHtmlForChangeDatabaseCharset
*
* @return void
*/
@ -112,7 +121,7 @@ class OperationsTest extends TestCase
{
$_REQUEST['db_collation'] = 'db1';
$result = Operations::getHtmlForChangeDatabaseCharset("pma", "bookmark");
$result = $this->operations->getHtmlForChangeDatabaseCharset("pma", "bookmark");
$this->assertRegExp(
'/.*select_db_collation.*Collation.*/m', $result
);
@ -122,7 +131,7 @@ class OperationsTest extends TestCase
}
/**
* Test for Operations::getHtmlForOrderTheTable
* Test for getHtmlForOrderTheTable
*
* @return void
*/
@ -131,47 +140,53 @@ class OperationsTest extends TestCase
$this->assertRegExp(
'/.*tbl_operations.php(.|[\n])*Alter table order by([\n]|.)*order_order.*/m',
Operations::getHtmlForOrderTheTable(
$this->operations->getHtmlForOrderTheTable(
array(array('Field' => "column1"), array('Field' => "column2"))
)
);
}
/**
* Test for Operations::getHtmlForTableRow
* Test for getHtmlForTableRow
*
* @return void
*/
public function testGetHtmlForTableRow()
{
$method = new ReflectionMethod(Operations::class, 'getHtmlForTableRow');
$method->setAccessible(true);
$result = $method->invokeArgs($this->operations, ['name', 'lable', 'value']);
$this->assertEquals(
'<tr><td class="vmiddle"><label for="name">lable</label></td><td><input type="checkbox" name="name" id="name" value="1"/></td></tr>',
Operations::getHtmlForTableRow("name", "lable", "value")
$result
);
}
/**
* Test for Operations::getMaintainActionlink
* Test for getMaintainActionlink
*
* @return void
*/
public function testGetMaintainActionlink()
{
$GLOBALS['cfg']['LinkLengthLimit'] = 1000;
$method = new ReflectionMethod(Operations::class, 'getMaintainActionlink');
$method->setAccessible(true);
$result = $method->invokeArgs($this->operations, [
'post',
['name' => 'foo', 'value' => 'bar'],
[],
'doclink'
]);
$this->assertRegExp(
'/.*href="sql.php.*post.*/',
Operations::getMaintainActionlink(
"post",
array("name" => 'foo', "value" => 'bar'),
array(),
'doclink'
)
$result
);
}
/**
* Test for Operations::getHtmlForDeleteDataOrTable
* Test for getHtmlForDeleteDataOrTable
*
* @return void
*/
@ -180,14 +195,14 @@ class OperationsTest extends TestCase
$this->assertRegExp(
'/.*Delete data or table.*Empty the table.*Delete the table.*/m',
Operations::getHtmlForDeleteDataOrTable(
$this->operations->getHtmlForDeleteDataOrTable(
array("truncate" => 'foo'), array("drop" => 'bar')
)
);
}
/**
* Test for Operations::getDeleteDataOrTablelink
* Test for getDeleteDataOrTablelink
*
* @return void
*/
@ -196,7 +211,7 @@ class OperationsTest extends TestCase
$this->assertRegExp(
'/.*TRUNCATE.TABLE.foo.*id_truncate.*Truncate table.*/m',
Operations::getDeleteDataOrTablelink(
$this->operations->getDeleteDataOrTablelink(
array("sql" => 'TRUNCATE TABLE foo'),
"TRUNCATE_TABLE",
"Truncate table",
@ -206,13 +221,13 @@ class OperationsTest extends TestCase
}
/**
* Test for Operations::getHtmlForPartitionMaintenance
* Test for getHtmlForPartitionMaintenance
*
* @return void
*/
public function testGetHtmlForPartitionMaintenance()
{
$html = Operations::getHtmlForPartitionMaintenance(
$html = $this->operations->getHtmlForPartitionMaintenance(
array("partition1", "partion2"),
array("param1" => 'foo', "param2" => 'bar')
);
@ -222,7 +237,7 @@ class OperationsTest extends TestCase
}
/**
* Test for Operations::getHtmlForReferentialIntegrityCheck
* Test for getHtmlForReferentialIntegrityCheck
*
* @return void
*/
@ -231,7 +246,7 @@ class OperationsTest extends TestCase
$this->assertRegExp(
'/.*Check referential integrity.*href="sql.php(.|[\n])*/m',
Operations::getHtmlForReferentialIntegrityCheck(
$this->operations->getHtmlForReferentialIntegrityCheck(
array(
array(
'foreign_db' => 'db1',

View File

@ -34,6 +34,8 @@ require './libraries/tbl_common.inc.php';
$url_query .= '&amp;goto=view_operations.php&amp;back=view_operations.php';
$url_params['goto'] = $url_params['back'] = 'view_operations.php';
$operations = new Operations();
/**
* Updates if required
*/
@ -55,7 +57,7 @@ if (isset($_REQUEST['submitoptions'])) {
}
}
$warning_messages = Operations::getWarningMessagesArray();
$warning_messages = $operations->getWarningMessagesArray();
}
if (isset($result)) {
@ -136,7 +138,7 @@ echo '<fieldset class="caution">';
echo '<legend>' , __('Delete data or table') , '</legend>';
echo '<ul>';
echo Operations::getDeleteDataOrTablelink(
echo $operations->getDeleteDataOrTablelink(
$drop_view_url_params,
'DROP VIEW',
__('Delete the view (DROP)'),