123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- namespace PhpMyAdmin;
- use PhpMyAdmin\Core;
- use PhpMyAdmin\DatabaseInterface;
- class Replication
- {
-
- public static function fillInfo(
- $type, $replicationInfoKey, array $mysqlInfo, $mysqlKey
- ) {
- $GLOBALS['replication_info'][$type][$replicationInfoKey]
- = empty($mysqlInfo[$mysqlKey])
- ? array()
- : explode(
- ",",
- $mysqlInfo[$mysqlKey]
- );
- return $GLOBALS['replication_info'][$type][$replicationInfoKey];
- }
-
- public static function extractDbOrTable($string, $what = 'db')
- {
- $list = explode(".", $string);
- if ('db' == $what) {
- return $list[0];
- } else {
- return $list[1];
- }
- }
-
- public static function slaveControl($action, $control = null, $link = null)
- {
- $action = mb_strtoupper($action);
- $control = mb_strtoupper($control);
- if ($action != "START" && $action != "STOP") {
- return -1;
- }
- if ($control != "SQL_THREAD" && $control != "IO_THREAD" && $control != null) {
- return -1;
- }
- return $GLOBALS['dbi']->tryQuery($action . " SLAVE " . $control . ";", $link);
- }
-
- public static function slaveChangeMaster($user, $password, $host, $port,
- array $pos, $stop = true, $start = true, $link = null
- ) {
- if ($stop) {
- self::slaveControl("STOP", null, $link);
- }
- $out = $GLOBALS['dbi']->tryQuery(
- 'CHANGE MASTER TO ' .
- 'MASTER_HOST=\'' . $host . '\',' .
- 'MASTER_PORT=' . ($port * 1) . ',' .
- 'MASTER_USER=\'' . $user . '\',' .
- 'MASTER_PASSWORD=\'' . $password . '\',' .
- 'MASTER_LOG_FILE=\'' . $pos["File"] . '\',' .
- 'MASTER_LOG_POS=' . $pos["Position"] . ';', $link
- );
- if ($start) {
- self::slaveControl("START", null, $link);
- }
- return $out;
- }
-
- public static function connectToMaster(
- $user, $password, $host = null, $port = null, $socket = null
- ) {
- $server = array();
- $server['user'] = $user;
- $server['password'] = $password;
- $server["host"] = Core::sanitizeMySQLHost($host);
- $server["port"] = $port;
- $server["socket"] = $socket;
-
-
- return $GLOBALS['dbi']->connect(DatabaseInterface::CONNECT_AUXILIARY, $server);
- }
-
- public static function slaveBinLogMaster($link = null)
- {
- $data = $GLOBALS['dbi']->fetchResult('SHOW MASTER STATUS', null, null, $link);
- $output = array();
- if (! empty($data)) {
- $output["File"] = $data[0]["File"];
- $output["Position"] = $data[0]["Position"];
- }
- return $output;
- }
- }
|