Remove some useless comments
[phpmyadmin.git] / libraries / classes / Controllers / Server / BinlogController.php
blob1c389c412212c5457a9abd5af4bcfc12ed8359ec
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Controllers\Server;
7 use PhpMyAdmin\Common;
8 use PhpMyAdmin\Controllers\AbstractController;
9 use PhpMyAdmin\DatabaseInterface;
10 use PhpMyAdmin\Html\Generator;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Template;
14 use PhpMyAdmin\Util;
15 use function array_key_exists;
17 /**
18 * Handles viewing binary logs
20 class BinlogController extends AbstractController
22 /**
23 * binary log files
25 * @var array
27 protected $binaryLogs;
29 /** @var DatabaseInterface */
30 private $dbi;
32 /**
33 * @param Response $response
34 * @param DatabaseInterface $dbi
36 public function __construct($response, Template $template, $dbi)
38 parent::__construct($response, $template);
39 $this->dbi = $dbi;
41 $this->binaryLogs = $this->dbi->fetchResult(
42 'SHOW MASTER LOGS',
43 'Log_name',
44 null,
45 DatabaseInterface::CONNECT_USER,
46 DatabaseInterface::QUERY_STORE
50 public function index(): void
52 global $cfg, $PMA_Theme;
54 $params = [
55 'log' => $_POST['log'] ?? null,
56 'pos' => $_POST['pos'] ?? null,
57 'is_full_query' => $_POST['is_full_query'] ?? null,
60 Common::server();
62 $position = ! empty($params['pos']) ? (int) $params['pos'] : 0;
64 $urlParams = [];
65 if (isset($params['log'])
66 && array_key_exists($params['log'], $this->binaryLogs)
67 ) {
68 $urlParams['log'] = $params['log'];
71 $isFullQuery = false;
72 if (! empty($params['is_full_query'])) {
73 $isFullQuery = true;
74 $urlParams['is_full_query'] = 1;
77 $sqlQuery = $this->getSqlQuery(
78 $params['log'] ?? '',
79 $position,
80 (int) $cfg['MaxRows']
82 $result = $this->dbi->query($sqlQuery);
84 $numRows = 0;
85 if (isset($result) && $result) {
86 $numRows = $this->dbi->numRows($result);
89 $previousParams = $urlParams;
90 $fullQueriesParams = $urlParams;
91 $nextParams = $urlParams;
92 if ($position > 0) {
93 $fullQueriesParams['pos'] = $position;
94 if ($position > $cfg['MaxRows']) {
95 $previousParams['pos'] = $position - $cfg['MaxRows'];
98 $fullQueriesParams['is_full_query'] = 1;
99 if ($isFullQuery) {
100 unset($fullQueriesParams['is_full_query']);
102 if ($numRows >= $cfg['MaxRows']) {
103 $nextParams['pos'] = $position + $cfg['MaxRows'];
106 $values = [];
107 while ($value = $this->dbi->fetchAssoc($result)) {
108 $values[] = $value;
111 $this->render('server/binlog/index', [
112 'url_params' => $urlParams,
113 'binary_logs' => $this->binaryLogs,
114 'log' => $params['log'],
115 'sql_message' => Generator::getMessage(Message::success(), $sqlQuery),
116 'values' => $values,
117 'has_previous' => $position > 0,
118 'has_next' => $numRows >= $cfg['MaxRows'],
119 'previous_params' => $previousParams,
120 'full_queries_params' => $fullQueriesParams,
121 'next_params' => $nextParams,
122 'has_icons' => Util::showIcons('TableNavigationLinksMode'),
123 'is_full_query' => $isFullQuery,
124 'image_path' => $PMA_Theme->getImgPath(),
129 * @param string $log Binary log file name
130 * @param int $position Position to display
131 * @param int $maxRows Maximum number of rows
133 private function getSqlQuery(
134 string $log,
135 int $position,
136 int $maxRows
137 ): string {
138 $sqlQuery = 'SHOW BINLOG EVENTS';
139 if (! empty($log)) {
140 $sqlQuery .= ' IN \'' . $log . '\'';
142 $sqlQuery .= ' LIMIT ' . $position . ', ' . $maxRows;
144 return $sqlQuery;