Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-13 23:24:54 +02:00
commit d350fabf9e
4 changed files with 48 additions and 27 deletions

View File

@ -60,6 +60,11 @@ class DatabaseStructureController extends DatabaseController
*/
private $relation;
/**
* @var Replication
*/
private $replication;
/**
* Constructor
*/
@ -67,6 +72,7 @@ class DatabaseStructureController extends DatabaseController
{
parent::__construct($response, $dbi, $db);
$this->relation = new Relation();
$this->replication = new Replication();
}
/**
@ -946,10 +952,10 @@ class DatabaseStructureController extends DatabaseController
protected function hasTable(array $db, $truename)
{
foreach ($db as $db_table) {
if ($this->db == Replication::extractDbOrTable($db_table)
if ($this->db == $this->replication->extractDbOrTable($db_table)
&& preg_match(
"@^" .
preg_quote(mb_substr(Replication::extractDbOrTable($db_table, 'table'), 0, -1)) . "@",
preg_quote(mb_substr($this->replication->extractDbOrTable($db_table, 'table'), 0, -1)) . "@",
$truename
)
) {

View File

@ -27,7 +27,7 @@ class Replication
*
* @return array
*/
public static function fillInfo(
public function fillInfo(
$type, $replicationInfoKey, array $mysqlInfo, $mysqlKey
) {
$GLOBALS['replication_info'][$type][$replicationInfoKey]
@ -49,7 +49,7 @@ class Replication
*
* @return string the extracted part
*/
public static function extractDbOrTable($string, $what = 'db')
public function extractDbOrTable($string, $what = 'db')
{
$list = explode(".", $string);
if ('db' == $what) {
@ -71,7 +71,7 @@ class Replication
*
* @return mixed output of DatabaseInterface::tryQuery
*/
public static function slaveControl($action, $control = null, $link = null)
public function slaveControl($action, $control = null, $link = null)
{
$action = mb_strtoupper($action);
$control = mb_strtoupper($control);
@ -101,11 +101,11 @@ class Replication
*
* @return string output of CHANGE MASTER mysql command
*/
public static function slaveChangeMaster($user, $password, $host, $port,
public function slaveChangeMaster($user, $password, $host, $port,
array $pos, $stop = true, $start = true, $link = null
) {
if ($stop) {
self::slaveControl("STOP", null, $link);
$this->slaveControl("STOP", null, $link);
}
$out = $GLOBALS['dbi']->tryQuery(
@ -119,7 +119,7 @@ class Replication
);
if ($start) {
self::slaveControl("START", null, $link);
$this->slaveControl("START", null, $link);
}
return $out;
@ -136,7 +136,7 @@ class Replication
*
* @return mixed $link mysql link on success
*/
public static function connectToMaster(
public function connectToMaster(
$user, $password, $host = null, $port = null, $socket = null
) {
$server = array();
@ -157,9 +157,9 @@ class Replication
* @param mixed $link mysql link
*
* @return array an array containing File and Position in MySQL replication
* on master server, useful for self::slaveChangeMaster
* on master server, useful for slaveChangeMaster()
*/
public static function slaveBinLogMaster($link = null)
public function slaveBinLogMaster($link = null)
{
$data = $GLOBALS['dbi']->fetchResult('SHOW MASTER STATUS', null, null, $link);
$output = array();

View File

@ -21,6 +21,19 @@ use PhpMyAdmin\Util;
*/
class ReplicationGui
{
/**
* @var Replication
*/
private $replication;
/**
* ReplicationGui constructor.
*/
public function __construct()
{
$this->replication = new Replication();
}
/**
* returns HTML for error message
*
@ -986,7 +999,7 @@ class ReplicationGui
$_SESSION['replication']['sr_action_info'] = __('Unknown error');
// Attempt to connect to the new master server
$link_to_master = Replication::connectToMaster(
$link_to_master = $this->replication->connectToMaster(
$sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port']
);
@ -998,7 +1011,7 @@ class ReplicationGui
);
} else {
// Read the current master position
$position = Replication::slaveBinLogMaster($link_to_master);
$position = $this->replication->slaveBinLogMaster($link_to_master);
if (empty($position)) {
$_SESSION['replication']['sr_action_status'] = 'error';
@ -1010,7 +1023,7 @@ class ReplicationGui
} else {
$_SESSION['replication']['m_correct'] = true;
if (! Replication::slaveChangeMaster(
if (! $this->replication->slaveChangeMaster(
$sr['username'],
$sr['pma_pw'],
$sr['hostname'],
@ -1047,15 +1060,15 @@ class ReplicationGui
$_REQUEST['sr_slave_control_parm'] = null;
}
if ($_REQUEST['sr_slave_action'] == 'reset') {
$qStop = Replication::slaveControl("STOP");
$qStop = $this->replication->slaveControl("STOP");
$qReset = $GLOBALS['dbi']->tryQuery("RESET SLAVE;");
$qStart = Replication::slaveControl("START");
$qStart = $this->replication->slaveControl("START");
$result = ($qStop !== false && $qStop !== -1 &&
$qReset !== false && $qReset !== -1 &&
$qStart !== false && $qStart !== -1);
} else {
$qControl = Replication::slaveControl(
$qControl = $this->replication->slaveControl(
$_REQUEST['sr_slave_action'],
$_REQUEST['sr_slave_control_parm']
);
@ -1078,11 +1091,11 @@ class ReplicationGui
$count = $_REQUEST['sr_skip_errors_count'] * 1;
}
$qStop = Replication::slaveControl("STOP");
$qStop = $this->replication->slaveControl("STOP");
$qSkip = $GLOBALS['dbi']->tryQuery(
"SET GLOBAL SQL_SLAVE_SKIP_COUNTER = " . $count . ";"
);
$qStart = Replication::slaveControl("START");
$qStart = $this->replication->slaveControl("START");
$result = ($qStop !== false && $qStop !== -1 &&
$qSkip !== false && $qSkip !== -1 &&

View File

@ -11,6 +11,8 @@ if (! defined('PHPMYADMIN')) {
use PhpMyAdmin\Replication;
$replication = new Replication();
/**
* get master replication from server
*/
@ -128,42 +130,42 @@ foreach ($replication_types as $type) {
}
if ($GLOBALS['replication_info'][$type]['status']) {
if ($type == "master") {
Replication::fillInfo(
$replication->fillInfo(
$type, 'Do_DB', $server_master_replication[0],
'Binlog_Do_DB'
);
Replication::fillInfo(
$replication->fillInfo(
$type, 'Ignore_DB', $server_master_replication[0],
'Binlog_Ignore_DB'
);
} elseif ($type == "slave") {
Replication::fillInfo(
$replication->fillInfo(
$type, 'Do_DB', $server_slave_replication[0],
'Replicate_Do_DB'
);
Replication::fillInfo(
$replication->fillInfo(
$type, 'Ignore_DB', $server_slave_replication[0],
'Replicate_Ignore_DB'
);
Replication::fillInfo(
$replication->fillInfo(
$type, 'Do_Table', $server_slave_replication[0],
'Replicate_Do_Table'
);
Replication::fillInfo(
$replication->fillInfo(
$type, 'Ignore_Table', $server_slave_replication[0],
'Replicate_Ignore_Table'
);
Replication::fillInfo(
$replication->fillInfo(
$type, 'Wild_Do_Table', $server_slave_replication[0],
'Replicate_Wild_Do_Table'
);
Replication::fillInfo(
$replication->fillInfo(
$type, 'Wild_Ignore_Table', $server_slave_replication[0],
'Replicate_Wild_Ignore_Table'
);