3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Controllers\Server
;
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
;
15 use function array_key_exists
;
18 * Handles viewing binary logs
20 class BinlogController
extends AbstractController
27 protected $binaryLogs;
29 /** @var DatabaseInterface */
33 * @param Response $response
34 * @param DatabaseInterface $dbi
36 public function __construct($response, Template
$template, $dbi)
38 parent
::__construct($response, $template);
41 $this->binaryLogs
= $this->dbi
->fetchResult(
45 DatabaseInterface
::CONNECT_USER
,
46 DatabaseInterface
::QUERY_STORE
50 public function index(): void
52 global $cfg, $PMA_Theme;
55 'log' => $_POST['log'] ??
null,
56 'pos' => $_POST['pos'] ??
null,
57 'is_full_query' => $_POST['is_full_query'] ??
null,
62 $position = ! empty($params['pos']) ?
(int) $params['pos'] : 0;
65 if (isset($params['log'])
66 && array_key_exists($params['log'], $this->binaryLogs
)
68 $urlParams['log'] = $params['log'];
72 if (! empty($params['is_full_query'])) {
74 $urlParams['is_full_query'] = 1;
77 $sqlQuery = $this->getSqlQuery(
82 $result = $this->dbi
->query($sqlQuery);
85 if (isset($result) && $result) {
86 $numRows = $this->dbi
->numRows($result);
89 $previousParams = $urlParams;
90 $fullQueriesParams = $urlParams;
91 $nextParams = $urlParams;
93 $fullQueriesParams['pos'] = $position;
94 if ($position > $cfg['MaxRows']) {
95 $previousParams['pos'] = $position - $cfg['MaxRows'];
98 $fullQueriesParams['is_full_query'] = 1;
100 unset($fullQueriesParams['is_full_query']);
102 if ($numRows >= $cfg['MaxRows']) {
103 $nextParams['pos'] = $position +
$cfg['MaxRows'];
107 while ($value = $this->dbi
->fetchAssoc($result)) {
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),
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(
138 $sqlQuery = 'SHOW BINLOG EVENTS';
140 $sqlQuery .= ' IN \'' . $log . '\'';
142 $sqlQuery .= ' LIMIT ' . $position . ', ' . $maxRows;