"Fossies" - the Fresh Open Source Software Archive

Member "phpMyAdmin-5.1.0-all-languages/libraries/classes/Controllers/Server/ReplicationController.php" (24 Feb 2021, 3545 Bytes) of package /linux/www/phpMyAdmin-5.1.0-all-languages.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "ReplicationController.php": 5.0.4-english_vs_5.1.0-english.

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