ReplicationController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Server replications
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Controllers\Server;
  7. use PhpMyAdmin\Controllers\AbstractController;
  8. use PhpMyAdmin\DatabaseInterface;
  9. use PhpMyAdmin\ReplicationGui;
  10. use PhpMyAdmin\ReplicationInfo;
  11. use PhpMyAdmin\Response;
  12. use PhpMyAdmin\Template;
  13. use PhpMyAdmin\Url;
  14. use function is_array;
  15. /**
  16. * Server replications
  17. */
  18. class ReplicationController extends AbstractController
  19. {
  20. /** @var ReplicationGui */
  21. private $replicationGui;
  22. /** @var DatabaseInterface */
  23. private $dbi;
  24. /**
  25. * @param Response $response
  26. * @param DatabaseInterface $dbi
  27. */
  28. public function __construct($response, Template $template, ReplicationGui $replicationGui, $dbi)
  29. {
  30. parent::__construct($response, $template);
  31. $this->replicationGui = $replicationGui;
  32. $this->dbi = $dbi;
  33. }
  34. public function index(): void
  35. {
  36. global $url_params, $err_url;
  37. $params = [
  38. 'url_params' => $_POST['url_params'] ?? null,
  39. 'mr_configure' => $_POST['mr_configure'] ?? null,
  40. 'sl_configure' => $_POST['sl_configure'] ?? null,
  41. 'repl_clear_scr' => $_POST['repl_clear_scr'] ?? null,
  42. ];
  43. $err_url = Url::getFromRoute('/');
  44. if ($this->dbi->isSuperUser()) {
  45. $this->dbi->selectDb('mysql');
  46. }
  47. $replicationInfo = new ReplicationInfo($this->dbi);
  48. $replicationInfo->load($_POST['master_connection'] ?? null);
  49. $primaryInfo = $replicationInfo->getPrimaryInfo();
  50. $replicaInfo = $replicationInfo->getReplicaInfo();
  51. $this->addScriptFiles(['server/privileges.js', 'replication.js', 'vendor/zxcvbn.js']);
  52. if (isset($params['url_params']) && is_array($params['url_params'])) {
  53. $url_params = $params['url_params'];
  54. }
  55. if ($this->dbi->isSuperUser()) {
  56. $this->replicationGui->handleControlRequest();
  57. }
  58. $errorMessages = $this->replicationGui->getHtmlForErrorMessage();
  59. if ($primaryInfo['status']) {
  60. $masterReplicationHtml = $this->replicationGui->getHtmlForMasterReplication();
  61. }
  62. if (isset($params['mr_configure'])) {
  63. $masterConfigurationHtml = $this->replicationGui->getHtmlForMasterConfiguration();
  64. } else {
  65. if (! isset($params['repl_clear_scr'])) {
  66. $slaveConfigurationHtml = $this->replicationGui->getHtmlForSlaveConfiguration(
  67. $replicaInfo['status'],
  68. $replicationInfo->getReplicaStatus()
  69. );
  70. }
  71. if (isset($params['sl_configure'])) {
  72. $changeMasterHtml = $this->replicationGui->getHtmlForReplicationChangeMaster('slave_changemaster');
  73. }
  74. }
  75. $this->render('server/replication/index', [
  76. 'url_params' => $url_params,
  77. 'is_super_user' => $this->dbi->isSuperUser(),
  78. 'error_messages' => $errorMessages,
  79. 'is_master' => $primaryInfo['status'],
  80. 'master_configure' => $params['mr_configure'],
  81. 'slave_configure' => $params['sl_configure'],
  82. 'clear_screen' => $params['repl_clear_scr'],
  83. 'master_replication_html' => $masterReplicationHtml ?? '',
  84. 'master_configuration_html' => $masterConfigurationHtml ?? '',
  85. 'slave_configuration_html' => $slaveConfigurationHtml ?? '',
  86. 'change_master_html' => $changeMasterHtml ?? '',
  87. ]);
  88. }
  89. }