Passed
Push — master ( 343721...f79b2e )
by Maurício
07:11
created

ReplicationGui::getHtmlForSlaveConfiguration()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 78
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 78
rs 8.3814
c 0
b 0
f 0
cc 6
nc 9
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
3
/**
4
 * Functions for the replication GUI
5
 *
6
 * @package PhpMyAdmin
7
 */
8
declare(strict_types=1);
9
10
namespace PhpMyAdmin;
11
12
use PhpMyAdmin\Core;
13
use PhpMyAdmin\Message;
14
use PhpMyAdmin\Replication;
15
use PhpMyAdmin\Response;
16
use PhpMyAdmin\Url;
17
use PhpMyAdmin\Util;
18
19
/**
20
 * Functions for the replication GUI
21
 *
22
 * @package PhpMyAdmin
23
 */
24
class ReplicationGui
25
{
26
    /**
27
     * @var Replication
28
     */
29
    private $replication;
30
31
    /**
32
     * @var Template
33
     */
34
    private $template;
35
36
    /**
37
     * ReplicationGui constructor.
38
     */
39
    public function __construct()
40
    {
41
        $this->replication = new Replication();
42
        $this->template = new Template();
43
    }
44
45
    /**
46
     * returns HTML for error message
47
     *
48
     * @return string HTML code
49
     */
50
    public function getHtmlForErrorMessage()
51
    {
52
        $html = '';
53
        if (isset($_SESSION['replication']['sr_action_status'])
54
            && isset($_SESSION['replication']['sr_action_info'])
55
        ) {
56
            if ($_SESSION['replication']['sr_action_status'] == 'error') {
57
                $error_message = $_SESSION['replication']['sr_action_info'];
58
                $html .= Message::error($error_message)->getDisplay();
59
                $_SESSION['replication']['sr_action_status'] = 'unknown';
60
            } elseif ($_SESSION['replication']['sr_action_status'] == 'success') {
61
                $success_message = $_SESSION['replication']['sr_action_info'];
62
                $html .= Message::success($success_message)->getDisplay();
63
                $_SESSION['replication']['sr_action_status'] = 'unknown';
64
            }
65
        }
66
        return $html;
67
    }
68
69
    /**
70
     * returns HTML for master replication
71
     *
72
     * @return string HTML code
73
     */
74
    public function getHtmlForMasterReplication()
75
    {
76
        if (! isset($_POST['repl_clear_scr'])) {
77
            $masterStatusTable = $this->getHtmlForReplicationStatusTable('master', true, false);
78
            $slaves = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null);
79
80
            $urlParams = $GLOBALS['url_params'];
81
            $urlParams['mr_adduser'] = true;
82
            $urlParams['repl_clear_scr'] = true;
83
        }
84
85
        if (isset($_POST['mr_adduser'])) {
86
            $masterAddSlaveUser = $this->getHtmlForReplicationMasterAddSlaveUser();
87
        }
88
89
        return $this->template->render('server/replication/master_replication', [
90
            'clear_screen' => isset($_POST['repl_clear_scr']),
91
            'master_status_table' => $masterStatusTable ?? '',
92
            'slaves' => $slaves ?? [],
93
            'url_params' => $urlParams ?? [],
94
            'master_add_user' => isset($_POST['mr_adduser']),
95
            'master_add_slave_user' => $masterAddSlaveUser ?? '',
96
        ]);
97
    }
98
99
    /**
100
     * returns HTML for master replication configuration
101
     *
102
     * @return string HTML code
103
     */
104
    public function getHtmlForMasterConfiguration()
105
    {
106
        $databaseMultibox = $this->getHtmlForReplicationDbMultibox();
107
108
        return $this->template->render('server/replication/master_configuration', [
109
            'database_multibox' => $databaseMultibox,
110
        ]);
111
    }
112
113
    /**
114
     * returns HTML for slave replication configuration
115
     *
116
     * @param bool  $serverSlaveStatus      Whether it is Master or Slave
117
     * @param array $serverSlaveReplication Slave replication
118
     *
119
     * @return string HTML code
120
     */
121
    public function getHtmlForSlaveConfiguration(
122
        $serverSlaveStatus,
123
        array $serverSlaveReplication
124
    ) {
125
        $serverSlaveMultiReplication = $GLOBALS['dbi']->fetchResult(
126
            'SHOW ALL SLAVES STATUS'
127
        );
128
        if ($serverSlaveStatus) {
129
            $urlParams = $GLOBALS['url_params'];
130
            $urlParams['sr_take_action'] = true;
131
            $urlParams['sr_slave_server_control'] = true;
132
133
            if ($serverSlaveReplication[0]['Slave_IO_Running'] == 'No') {
134
                $urlParams['sr_slave_action'] = 'start';
135
            } else {
136
                $urlParams['sr_slave_action'] = 'stop';
137
            }
138
139
            $urlParams['sr_slave_control_parm'] = 'IO_THREAD';
140
            $slaveControlIoLink = Url::getCommon($urlParams, '');
141
142
            if ($serverSlaveReplication[0]['Slave_SQL_Running'] == 'No') {
143
                $urlParams['sr_slave_action'] = 'start';
144
            } else {
145
                $urlParams['sr_slave_action'] = 'stop';
146
            }
147
148
            $urlParams['sr_slave_control_parm'] = 'SQL_THREAD';
149
            $slaveControlSqlLink = Url::getCommon($urlParams, '');
150
151
            if ($serverSlaveReplication[0]['Slave_IO_Running'] == 'No'
152
                || $serverSlaveReplication[0]['Slave_SQL_Running'] == 'No'
153
            ) {
154
                $urlParams['sr_slave_action'] = 'start';
155
            } else {
156
                $urlParams['sr_slave_action'] = 'stop';
157
            }
158
159
            $urlParams['sr_slave_control_parm'] = null;
160
            $slaveControlFullLink = Url::getCommon($urlParams, '');
161
162
            $urlParams['sr_slave_action'] = 'reset';
163
            $slaveControlResetLink = Url::getCommon($urlParams, '');
164
165
            $urlParams = $GLOBALS['url_params'];
166
            $urlParams['sr_take_action'] = true;
167
            $urlParams['sr_slave_skip_error'] = true;
168
            $slaveSkipErrorLink = Url::getCommon($urlParams, '');
169
170
            $urlParams = $GLOBALS['url_params'];
171
            $urlParams['sl_configure'] = true;
172
            $urlParams['repl_clear_scr'] = true;
173
174
            $reconfigureMasterLink =  Url::getCommon($urlParams, '');
175
176
            $slaveStatusTable = $this->getHtmlForReplicationStatusTable('slave', true, false);
177
178
            $slaveIoRunning = $serverSlaveReplication[0]['Slave_IO_Running'] !== 'No';
179
            $slaveSqlRunning = $serverSlaveReplication[0]['Slave_SQL_Running'] !== 'No';
180
181
            $slaveErrorManagement = $this->getHtmlForSlaveErrorManagement($slaveSkipErrorLink);
182
        }
183
184
        return $this->template->render('server/replication/slave_configuration', [
185
            'server_slave_multi_replication' => $serverSlaveMultiReplication,
186
            'url_params' => $GLOBALS['url_params'],
187
            'master_connection' => $_POST['master_connection'] ?? '',
188
            'server_slave_status' => $serverSlaveStatus,
189
            'slave_status_table' => $slaveStatusTable ?? '',
190
            'slave_sql_running' => $slaveSqlRunning ?? false,
191
            'slave_io_running' => $slaveIoRunning ?? false,
192
            'slave_control_full_link' => $slaveControlFullLink ?? '',
193
            'slave_control_reset_link' => $slaveControlResetLink ?? '',
194
            'slave_control_sql_link' => $slaveControlSqlLink ?? '',
195
            'slave_control_io_link' => $slaveControlIoLink ?? '',
196
            'slave_error_management' => $slaveErrorManagement ?? '',
197
            'reconfigure_master_link' => $reconfigureMasterLink ?? '',
198
            'has_slave_configure' => isset($_POST['sl_configure']),
199
        ]);
200
    }
201
202
    /**
203
     * returns HTML for Slave Error Management
204
     *
205
     * @param string $slaveSkipErrorLink error link
206
     *
207
     * @return string HTML code
208
     */
209
    public function getHtmlForSlaveErrorManagement($slaveSkipErrorLink)
210
    {
211
        return $this->template->render('server/replication/slave_error_management', [
212
            'slave_skip_error_link' => $slaveSkipErrorLink,
213
        ]);
214
    }
215
216
    /**
217
     * returns HTML for not configure for a server replication
218
     *
219
     * @return string HTML code
220
     */
221
    public function getHtmlForNotServerReplication()
222
    {
223
        $urlParams = $GLOBALS['url_params'];
224
        $urlParams['mr_configure'] = true;
225
226
        return $this->template->render('server/replication/not_server_replication', [
227
            'url_params' => $urlParams,
228
        ]);
229
    }
230
231
    /**
232
     * returns HTML code for selecting databases
233
     *
234
     * @return string HTML code
235
     */
236
    public function getHtmlForReplicationDbMultibox()
237
    {
238
        $databases = [];
239
        foreach ($GLOBALS['dblist']->databases as $database) {
240
            if (! $GLOBALS['dbi']->isSystemSchema($database)) {
241
                $databases[] = $database;
242
            }
243
        }
244
245
        return $this->template->render('server/replication/database_multibox', [
246
            'databases' => $databases,
247
        ]);
248
    }
249
250
    /**
251
     * returns HTML for changing master
252
     *
253
     * @param string $submitName submit button name
254
     *
255
     * @return string HTML code
256
     */
257
    public function getHtmlForReplicationChangeMaster($submitName)
258
    {
259
        list(
260
            $usernameLength,
261
            $hostnameLength
262
        ) = $this->getUsernameHostnameLength();
263
264
        return $this->template->render('server/replication/change_master', [
265
            'server_id' => time(),
266
            'username_length' => $usernameLength,
267
            'hostname_length' => $hostnameLength,
268
            'submit_name' => $submitName,
269
        ]);
270
    }
271
272
    /**
273
     * This function returns html code for table with replication status.
274
     *
275
     * @param string  $type   either master or slave
276
     * @param boolean $hidden if true, then default style is set to hidden,
277
     *                        default value false
278
     * @param boolean $title  if true, then title is displayed, default true
279
     *
280
     * @return string HTML code
281
     */
282
    public function getHtmlForReplicationStatusTable($type, $hidden = false, $title = true)
283
    {
284
        global ${"{$type}_variables"};
285
        global ${"{$type}_variables_alerts"};
286
        global ${"{$type}_variables_oks"};
287
        global ${"server_{$type}_replication"};
288
        global ${"strReplicationStatus_{$type}"};
289
290
        $html = '';
291
292
        // TODO check the Masters server id?
293
        // seems to default to '1' when queried via SHOW VARIABLES ,
294
        // but resulted in error on the master when slave connects
295
        // [ERROR] Error reading packet from server: Misconfigured master
296
        // - server id was not set ( server_errno=1236)
297
        // [ERROR] Got fatal error 1236: 'Misconfigured master
298
        // - server id was not set' from master when reading data from binary log
299
        //
300
        //$server_id = $GLOBALS['dbi']->fetchValue(
301
        //    "SHOW VARIABLES LIKE 'server_id'", 0, 1
302
        //);
303
304
        $html .= '<div id="replication_' . $type . '_section" style="';
305
        $html .= ($hidden ? 'display: none;' : '') . '"> ';
306
307
        if ($title) {
308
            if ($type == 'master') {
309
                $html .= '<h4><a name="replication_' . $type . '"></a>';
310
                $html .= __('Master status') . '</h4>';
311
            } else {
312
                $html .= '<h4><a name="replication_' . $type . '"></a>';
313
                $html .= __('Slave status') . '</h4>';
314
            }
315
        } else {
316
            $html .= '<br>';
317
        }
318
319
        $html .= '   <table id="server' . $type . 'replicationsummary" class="data"> ';
320
        $html .= '   <thead>';
321
        $html .= '    <tr>';
322
        $html .= '     <th>' . __('Variable') . '</th>';
323
        $html .= '        <th>' . __('Value') . '</th>';
324
        $html .= '    </tr>';
325
        $html .= '   </thead>';
326
        $html .= '   <tbody>';
327
328
        foreach (${"{$type}_variables"} as $variable) {
329
            $html .= '   <tr>';
330
            $html .= '     <td class="name">';
331
            $html .= htmlspecialchars($variable);
332
            $html .= '     </td>';
333
            $html .= '     <td class="value">';
334
335
            // TODO change to regexp or something, to allow for negative match
336
            if (isset(${"{$type}_variables_alerts"}[$variable])
337
                && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
338
            ) {
339
                $html .= '<span class="attention">';
340
            } elseif (isset(${"{$type}_variables_oks"}[$variable])
341
                && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
342
            ) {
343
                $html .= '<span class="allfine">';
344
            } else {
345
                $html .= '<span>';
346
            }
347
            // allow wrapping long table lists into multiple lines
348
            $variables_wrap = [
349
                'Replicate_Do_DB',
350
                'Replicate_Ignore_DB',
351
                'Replicate_Do_Table',
352
                'Replicate_Ignore_Table',
353
                'Replicate_Wild_Do_Table',
354
                'Replicate_Wild_Ignore_Table',
355
            ];
356
            if (in_array($variable, $variables_wrap)) {
357
                $html .= htmlspecialchars(str_replace(
358
                    ',',
359
                    ', ',
360
                    ${"server_{$type}_replication"}[0][$variable]
361
                ));
362
            } else {
363
                $html .= htmlspecialchars(${"server_{$type}_replication"}[0][$variable]);
364
            }
365
            $html .= '</span>';
366
367
            $html .= '  </td>';
368
            $html .= ' </tr>';
369
        }
370
371
        $html .= '   </tbody>';
372
        $html .= ' </table>';
373
        $html .= ' <br>';
374
        $html .= '</div>';
375
376
        return $html;
377
    }
378
379
    /**
380
     * get the correct username and hostname lengths for this MySQL server
381
     *
382
     * @return array   username length, hostname length
383
     */
384
    public function getUsernameHostnameLength()
385
    {
386
        $fields_info = $GLOBALS['dbi']->getColumns('mysql', 'user');
387
        $username_length = 16;
388
        $hostname_length = 41;
389
        foreach ($fields_info as $val) {
390
            if ($val['Field'] == 'User') {
391
                strtok($val['Type'], '()');
392
                $v = strtok('()');
393
                if (is_int($v)) {
394
                    $username_length = $v;
395
                }
396
            } elseif ($val['Field'] == 'Host') {
397
                strtok($val['Type'], '()');
398
                $v = strtok('()');
399
                if (is_int($v)) {
400
                    $hostname_length = $v;
401
                }
402
            }
403
        }
404
        return [
405
            $username_length,
406
            $hostname_length,
407
        ];
408
    }
409
410
    /**
411
     * returns html code to add a replication slave user to the master
412
     *
413
     * @return string HTML code
414
     */
415
    public function getHtmlForReplicationMasterAddSlaveUser()
416
    {
417
        list(
418
            $usernameLength,
419
            $hostnameLength
420
        ) = $this->getUsernameHostnameLength();
421
422
        if (isset($_POST['username']) && strlen($_POST['username']) === 0) {
423
            $GLOBALS['pred_username'] = 'any';
424
        }
425
426
        $username = '';
427
        if (! empty($_POST['username'])) {
428
            $username = $GLOBALS['new_username'] ?? $_POST['username'];
429
        }
430
431
        $currentUser = $GLOBALS['dbi']->fetchValue('SELECT USER();');
432
        if (! empty($currentUser)) {
433
            $userHost = str_replace(
434
                "'",
435
                '',
436
                mb_substr(
437
                    $currentUser,
438
                    mb_strrpos($currentUser, '@') + 1
439
                )
440
            );
441
            if ($userHost !== 'localhost' && $userHost !== '127.0.0.1') {
442
                $thisHost = $userHost;
443
            }
444
        }
445
446
        // when we start editing a user, $GLOBALS['pred_hostname'] is not defined
447
        if (! isset($GLOBALS['pred_hostname']) && isset($_POST['hostname'])) {
448
            switch (mb_strtolower($_POST['hostname'])) {
449
                case 'localhost':
450
                case '127.0.0.1':
451
                    $GLOBALS['pred_hostname'] = 'localhost';
452
                    break;
453
                case '%':
454
                    $GLOBALS['pred_hostname'] = 'any';
455
                    break;
456
                default:
457
                    $GLOBALS['pred_hostname'] = 'userdefined';
458
                    break;
459
            }
460
        }
461
462
        return $this->template->render('server/replication/master_add_slave_user', [
463
            'username_length' => $usernameLength,
464
            'hostname_length' => $hostnameLength,
465
            'has_username' => isset($_POST['username']),
466
            'username' => $username,
467
            'hostname' => $_POST['hostname'] ?? '',
468
            'predefined_username' => $GLOBALS['pred_username'] ?? '',
469
            'predefined_hostname' => $GLOBALS['pred_hostname'] ?? '',
470
            'this_host' => $thisHost ?? null,
471
        ]);
472
    }
473
474
    /**
475
     * handle control requests
476
     *
477
     * @return void
478
     */
479
    public function handleControlRequest()
480
    {
481
        if (isset($_POST['sr_take_action'])) {
482
            $refresh = false;
483
            $result = false;
484
            $messageSuccess = null;
485
            $messageError = null;
486
487
            if (isset($_POST['slave_changemaster']) && ! $GLOBALS['cfg']['AllowArbitraryServer']) {
488
                $_SESSION['replication']['sr_action_status'] = 'error';
489
                $_SESSION['replication']['sr_action_info'] = __('Connection to server is disabled, please enable $cfg[\'AllowArbitraryServer\'] in phpMyAdmin configuration.');
490
            } elseif (isset($_POST['slave_changemaster'])) {
491
                $result = $this->handleRequestForSlaveChangeMaster();
492
            } elseif (isset($_POST['sr_slave_server_control'])) {
493
                $result = $this->handleRequestForSlaveServerControl();
494
                $refresh = true;
495
496
                switch ($_POST['sr_slave_action']) {
497
                    case 'start':
498
                        $messageSuccess = __('Replication started successfully.');
499
                        $messageError = __('Error starting replication.');
500
                        break;
501
                    case 'stop':
502
                        $messageSuccess = __('Replication stopped successfully.');
503
                        $messageError = __('Error stopping replication.');
504
                        break;
505
                    case 'reset':
506
                        $messageSuccess = __('Replication resetting successfully.');
507
                        $messageError = __('Error resetting replication.');
508
                        break;
509
                    default:
510
                        $messageSuccess = __('Success.');
511
                        $messageError = __('Error.');
512
                        break;
513
                }
514
            } elseif (isset($_POST['sr_slave_skip_error'])) {
515
                $result = $this->handleRequestForSlaveSkipError();
516
            }
517
518
            if ($refresh) {
519
                $response = Response::getInstance();
520
                if ($response->isAjax()) {
521
                    $response->setRequestStatus($result);
522
                    $response->addJSON(
523
                        'message',
524
                        $result
525
                        ? Message::success($messageSuccess)
0 ignored issues
show
Bug introduced by
It seems like $messageSuccess can also be of type null; however, parameter $string of PhpMyAdmin\Message::success() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

525
                        ? Message::success(/** @scrutinizer ignore-type */ $messageSuccess)
Loading history...
526
                        : Message::error($messageError)
0 ignored issues
show
Bug introduced by
It seems like $messageError can also be of type null; however, parameter $string of PhpMyAdmin\Message::error() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

526
                        : Message::error(/** @scrutinizer ignore-type */ $messageError)
Loading history...
527
                    );
528
                } else {
529
                    Core::sendHeaderLocation(
530
                        './server_replication.php'
531
                        . Url::getCommonRaw($GLOBALS['url_params'])
532
                    );
533
                }
534
            }
535
            unset($refresh);
536
        }
537
    }
538
539
    /**
540
     * handle control requests for Slave Change Master
541
     *
542
     * @return boolean
543
     */
544
    public function handleRequestForSlaveChangeMaster()
545
    {
546
        $sr = [];
547
        $_SESSION['replication']['m_username'] = $sr['username']
548
            = $GLOBALS['dbi']->escapeString($_POST['username']);
549
        $_SESSION['replication']['m_password'] = $sr['pma_pw']
550
            = $GLOBALS['dbi']->escapeString($_POST['pma_pw']);
551
        $_SESSION['replication']['m_hostname'] = $sr['hostname']
552
            = $GLOBALS['dbi']->escapeString($_POST['hostname']);
553
        $_SESSION['replication']['m_port']     = $sr['port']
554
            = $GLOBALS['dbi']->escapeString($_POST['text_port']);
555
        $_SESSION['replication']['m_correct']  = '';
556
        $_SESSION['replication']['sr_action_status'] = 'error';
557
        $_SESSION['replication']['sr_action_info'] = __('Unknown error');
558
559
        // Attempt to connect to the new master server
560
        $link_to_master = $this->replication->connectToMaster(
561
            $sr['username'],
562
            $sr['pma_pw'],
563
            $sr['hostname'],
564
            $sr['port']
565
        );
566
567
        if (! $link_to_master) {
568
            $_SESSION['replication']['sr_action_status'] = 'error';
569
            $_SESSION['replication']['sr_action_info'] = sprintf(
570
                __('Unable to connect to master %s.'),
571
                htmlspecialchars($sr['hostname'])
572
            );
573
        } else {
574
            // Read the current master position
575
            $position = $this->replication->slaveBinLogMaster($link_to_master);
576
577
            if (empty($position)) {
578
                $_SESSION['replication']['sr_action_status'] = 'error';
579
                $_SESSION['replication']['sr_action_info']
580
                    = __(
581
                        'Unable to read master log position. '
582
                        . 'Possible privilege problem on master.'
583
                    );
584
            } else {
585
                $_SESSION['replication']['m_correct']  = true;
586
587
                if (! $this->replication->slaveChangeMaster(
588
                    $sr['username'],
589
                    $sr['pma_pw'],
590
                    $sr['hostname'],
591
                    $sr['port'],
592
                    $position,
593
                    true,
594
                    false
595
                )
596
                ) {
597
                    $_SESSION['replication']['sr_action_status'] = 'error';
598
                    $_SESSION['replication']['sr_action_info']
599
                        = __('Unable to change master!');
600
                } else {
601
                    $_SESSION['replication']['sr_action_status'] = 'success';
602
                    $_SESSION['replication']['sr_action_info'] = sprintf(
603
                        __('Master server changed successfully to %s.'),
604
                        htmlspecialchars($sr['hostname'])
605
                    );
606
                }
607
            }
608
        }
609
610
        return $_SESSION['replication']['sr_action_status'] === 'success';
611
    }
612
613
    /**
614
     * handle control requests for Slave Server Control
615
     *
616
     * @return boolean
617
     */
618
    public function handleRequestForSlaveServerControl()
619
    {
620
        if (empty($_POST['sr_slave_control_parm'])) {
621
            $_POST['sr_slave_control_parm'] = null;
622
        }
623
        if ($_POST['sr_slave_action'] == 'reset') {
624
            $qStop = $this->replication->slaveControl("STOP");
625
            $qReset = $GLOBALS['dbi']->tryQuery("RESET SLAVE;");
626
            $qStart = $this->replication->slaveControl("START");
627
628
            $result = ($qStop !== false && $qStop !== -1 &&
629
                $qReset !== false && $qReset !== -1 &&
630
                $qStart !== false && $qStart !== -1);
631
        } else {
632
            $qControl = $this->replication->slaveControl(
633
                $_POST['sr_slave_action'],
634
                $_POST['sr_slave_control_parm']
635
            );
636
637
            $result = ($qControl !== false && $qControl !== -1);
638
        }
639
640
        return $result;
641
    }
642
643
    /**
644
     * handle control requests for Slave Skip Error
645
     *
646
     * @return boolean
647
     */
648
    public function handleRequestForSlaveSkipError()
649
    {
650
        $count = 1;
651
        if (isset($_POST['sr_skip_errors_count'])) {
652
            $count = $_POST['sr_skip_errors_count'] * 1;
653
        }
654
655
        $qStop = $this->replication->slaveControl("STOP");
656
        $qSkip = $GLOBALS['dbi']->tryQuery(
657
            "SET GLOBAL SQL_SLAVE_SKIP_COUNTER = " . $count . ";"
658
        );
659
        $qStart = $this->replication->slaveControl("START");
660
661
        $result = ($qStop !== false && $qStop !== -1 &&
662
            $qSkip !== false && $qSkip !== -1 &&
663
            $qStart !== false && $qStart !== -1);
664
665
        return $result;
666
    }
667
}
668