* 17769 - use Request object instead of SuperGlobals Signed-off-by: Luca Perna <luca@perna.rocks>
This commit is contained in:
parent
932933d357
commit
cca381a415
@ -45,12 +45,11 @@ class ReplicationController extends AbstractController
|
||||
$GLOBALS['urlParams'] = $GLOBALS['urlParams'] ?? null;
|
||||
$GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null;
|
||||
|
||||
$params = [
|
||||
'url_params' => $_POST['url_params'] ?? null,
|
||||
'primary_configure' => $_POST['primary_configure'] ?? null,
|
||||
'replica_configure' => $_POST['replica_configure'] ?? null,
|
||||
'repl_clear_scr' => $_POST['repl_clear_scr'] ?? null,
|
||||
];
|
||||
/** @var bool|null $replClearScr */
|
||||
$replClearScr = $request->getParsedBodyParam('repl_clear_scr');
|
||||
$replicaConfigure = $request->getParsedBodyParam('replica_configure');
|
||||
$primaryConfigure = $request->getParsedBodyParam('primary_configure');
|
||||
|
||||
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
|
||||
|
||||
if ($this->dbi->isSuperUser()) {
|
||||
@ -58,31 +57,41 @@ class ReplicationController extends AbstractController
|
||||
}
|
||||
|
||||
$replicationInfo = new ReplicationInfo($this->dbi);
|
||||
$replicationInfo->load($_POST['primary_connection'] ?? null);
|
||||
/** @var string $primaryConnection */
|
||||
$primaryConnection = $request->getParsedBodyParam('primary_connection');
|
||||
$replicationInfo->load($primaryConnection);
|
||||
|
||||
$primaryInfo = $replicationInfo->getPrimaryInfo();
|
||||
$replicaInfo = $replicationInfo->getReplicaInfo();
|
||||
|
||||
$this->addScriptFiles(['server/privileges.js', 'replication.js', 'vendor/zxcvbn-ts.js']);
|
||||
|
||||
if (isset($params['url_params']) && is_array($params['url_params'])) {
|
||||
$GLOBALS['urlParams'] = $params['url_params'];
|
||||
$urlParams = $request->getParsedBodyParam('url_params');
|
||||
if (is_array($urlParams)) {
|
||||
$GLOBALS['urlParams'] = $urlParams;
|
||||
}
|
||||
|
||||
if ($this->dbi->isSuperUser()) {
|
||||
/** @var string|null $srReplicaAction */
|
||||
$srReplicaAction = $request->getParsedBodyParam('sr_replica_action');
|
||||
/** @var string|int $srSkipErrorsCount */
|
||||
$srSkipErrorsCount = $request->getParsedBodyParam('sr_skip_errors_count', 1);
|
||||
/** @var string|null $srReplicaControlParam */
|
||||
$srReplicaControlParam = $request->getParsedBodyParam('sr_replica_control_param');
|
||||
|
||||
$this->replicationGui->handleControlRequest(
|
||||
isset($_POST['sr_take_action']),
|
||||
isset($_POST['replica_changeprimary']),
|
||||
isset($_POST['sr_replica_server_control']),
|
||||
$_POST['sr_replica_action'] ?? null,
|
||||
isset($_POST['sr_replica_skip_error']),
|
||||
isset($_POST['sr_skip_errors_count']) ? (int) $_POST['sr_skip_errors_count'] : 1,
|
||||
$_POST['sr_replica_control_param'] ?? null,
|
||||
$request->getParsedBodyParam('sr_take_action') !== null,
|
||||
$request->getParsedBodyParam('replica_changeprimary') !== null,
|
||||
$request->getParsedBodyParam('sr_replica_server_control') !== null,
|
||||
$srReplicaAction,
|
||||
$request->getParsedBodyParam('sr_replica_skip_error') !== null,
|
||||
(int) $srSkipErrorsCount,
|
||||
$srReplicaControlParam,
|
||||
[
|
||||
'username' => $GLOBALS['dbi']->escapeString($_POST['username']),
|
||||
'pma_pw' => $GLOBALS['dbi']->escapeString($_POST['pma_pw']),
|
||||
'hostname' => $GLOBALS['dbi']->escapeString($_POST['hostname']),
|
||||
'port' => (int) $GLOBALS['dbi']->escapeString($_POST['text_port']),
|
||||
'username' => $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('username')),
|
||||
'pma_pw' => $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('pma_pw')),
|
||||
'hostname' => $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('hostname')),
|
||||
'port' => (int) $GLOBALS['dbi']->escapeString($request->getParsedBodyParam('text_port')),
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -90,28 +99,35 @@ class ReplicationController extends AbstractController
|
||||
$errorMessages = $this->replicationGui->getHtmlForErrorMessage();
|
||||
|
||||
if ($primaryInfo['status']) {
|
||||
/** @var string|null $primaryAddUser */
|
||||
$primaryAddUser = $request->getParsedBodyParam('primary_add_user');
|
||||
/** @var string $username */
|
||||
$username = $request->getParsedBodyParam('username');
|
||||
/** @var string $hostname */
|
||||
$hostname = $request->getParsedBodyParam('hostname');
|
||||
|
||||
$primaryReplicationHtml = $this->replicationGui->getHtmlForPrimaryReplication(
|
||||
$_POST['primary_connection'] ?? null,
|
||||
$params['repl_clear_scr'],
|
||||
$_POST['primary_add_user'] ?? null,
|
||||
$_POST['username'] ?? null,
|
||||
$_POST['hostname'] ?? null
|
||||
$primaryConnection,
|
||||
$replClearScr,
|
||||
$primaryAddUser,
|
||||
$username,
|
||||
$hostname
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['primary_configure'])) {
|
||||
if ($primaryConfigure !== null) {
|
||||
$primaryConfigurationHtml = $this->replicationGui->getHtmlForPrimaryConfiguration();
|
||||
} else {
|
||||
if (! isset($params['repl_clear_scr'])) {
|
||||
if ($replClearScr === null) {
|
||||
$replicaConfigurationHtml = $this->replicationGui->getHtmlForReplicaConfiguration(
|
||||
$_POST['primary_connection'] ?? null,
|
||||
$primaryConnection,
|
||||
$replicaInfo['status'],
|
||||
$replicationInfo->getReplicaStatus(),
|
||||
isset($_POST['replica_configure'])
|
||||
$replicaConfigure !== null
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['replica_configure'])) {
|
||||
if ($replicaConfigure !== null) {
|
||||
$changePrimaryHtml = $this->replicationGui->getHtmlForReplicationChangePrimary('replica_changeprimary');
|
||||
}
|
||||
}
|
||||
@ -121,9 +137,9 @@ class ReplicationController extends AbstractController
|
||||
'is_super_user' => $this->dbi->isSuperUser(),
|
||||
'error_messages' => $errorMessages,
|
||||
'is_primary' => $primaryInfo['status'],
|
||||
'primary_configure' => $params['primary_configure'],
|
||||
'replica_configure' => $params['replica_configure'],
|
||||
'clear_screen' => $params['repl_clear_scr'],
|
||||
'primary_configure' => $primaryConfigure,
|
||||
'replica_configure' => $replicaConfigure,
|
||||
'clear_screen' => $replClearScr,
|
||||
'primary_replication_html' => $primaryReplicationHtml ?? '',
|
||||
'primary_configuration_html' => $primaryConfigurationHtml ?? '',
|
||||
'replica_configuration_html' => $replicaConfigurationHtml ?? '',
|
||||
|
||||
@ -20,6 +20,7 @@ use function array_map;
|
||||
use function define;
|
||||
use function explode;
|
||||
use function htmlspecialchars;
|
||||
use function is_array;
|
||||
use function sprintf;
|
||||
use function strtotime;
|
||||
|
||||
@ -65,13 +66,14 @@ final class TrackingController extends AbstractController
|
||||
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
|
||||
|
||||
$activeMessage = '';
|
||||
$toggleActivation = $request->getParsedBodyParam('toggle_activation');
|
||||
$reportExport = $request->getParsedBodyParam('report_export');
|
||||
|
||||
if (
|
||||
Tracker::isActive()
|
||||
&& Tracker::isTracked($GLOBALS['db'], $GLOBALS['table'])
|
||||
&& ! (isset($_POST['toggle_activation'])
|
||||
&& $_POST['toggle_activation'] === 'deactivate_now')
|
||||
&& ! (isset($_POST['report_export'])
|
||||
&& $_POST['export_type'] === 'sqldumpfile')
|
||||
&& $toggleActivation !== 'deactivate_now'
|
||||
&& $reportExport !== 'sqldumpfile'
|
||||
) {
|
||||
$GLOBALS['msg'] = Message::notice(
|
||||
sprintf(
|
||||
@ -94,41 +96,44 @@ final class TrackingController extends AbstractController
|
||||
$GLOBALS['selection_data'] = false;
|
||||
$GLOBALS['selection_both'] = false;
|
||||
|
||||
$report = $request->getParsedBodyParam('report');
|
||||
/** @var string $versionParam */
|
||||
$versionParam = $request->getParsedBodyParam('version');
|
||||
/** @var string $tableParam */
|
||||
$tableParam = $request->getParsedBodyParam('table');
|
||||
|
||||
// Init vars for tracking report
|
||||
if (isset($_POST['report']) || isset($_POST['report_export'])) {
|
||||
$GLOBALS['data'] = Tracker::getTrackedData($GLOBALS['db'], $GLOBALS['table'], $_POST['version']);
|
||||
if ($report !== null || $reportExport !== null) {
|
||||
$GLOBALS['data'] = Tracker::getTrackedData(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$versionParam
|
||||
);
|
||||
|
||||
if (! isset($_POST['logtype'])) {
|
||||
$_POST['logtype'] = 'schema_and_data';
|
||||
}
|
||||
$logType = $request->getParsedBodyParam('logtype', 'schema_and_data');
|
||||
|
||||
if ($_POST['logtype'] === 'schema') {
|
||||
if ($logType === 'schema') {
|
||||
$GLOBALS['selection_schema'] = true;
|
||||
} elseif ($_POST['logtype'] === 'data') {
|
||||
} elseif ($logType === 'data') {
|
||||
$GLOBALS['selection_data'] = true;
|
||||
} else {
|
||||
$GLOBALS['selection_both'] = true;
|
||||
}
|
||||
|
||||
if (! isset($_POST['date_from'])) {
|
||||
$_POST['date_from'] = $GLOBALS['data']['date_from'];
|
||||
}
|
||||
/** @var string $dateFrom */
|
||||
$dateFrom = $request->getParsedBodyParam('date_from', $GLOBALS['data']['date_from']);
|
||||
/** @var string $dateTo */
|
||||
$dateTo = $request->getParsedBodyParam('date_to', $GLOBALS['data']['date_to']);
|
||||
/** @var string $users */
|
||||
$users = $request->getParsedBodyParam('users', '*');
|
||||
|
||||
if (! isset($_POST['date_to'])) {
|
||||
$_POST['date_to'] = $GLOBALS['data']['date_to'];
|
||||
}
|
||||
|
||||
if (! isset($_POST['users'])) {
|
||||
$_POST['users'] = '*';
|
||||
}
|
||||
|
||||
$GLOBALS['filter_ts_from'] = strtotime($_POST['date_from']);
|
||||
$GLOBALS['filter_ts_to'] = strtotime($_POST['date_to']);
|
||||
$GLOBALS['filter_users'] = array_map('trim', explode(',', $_POST['users']));
|
||||
$GLOBALS['filter_ts_from'] = strtotime($dateFrom);
|
||||
$GLOBALS['filter_ts_to'] = strtotime($dateTo);
|
||||
$GLOBALS['filter_users'] = array_map('trim', explode(',', $users));
|
||||
}
|
||||
|
||||
// Prepare export
|
||||
if (isset($_POST['report_export'])) {
|
||||
if ($reportExport !== null) {
|
||||
$GLOBALS['entries'] = $this->tracking->getEntries(
|
||||
$GLOBALS['data'],
|
||||
(int) $GLOBALS['filter_ts_from'],
|
||||
@ -138,15 +143,17 @@ final class TrackingController extends AbstractController
|
||||
}
|
||||
|
||||
// Export as file download
|
||||
if (isset($_POST['report_export']) && $_POST['export_type'] === 'sqldumpfile') {
|
||||
$this->tracking->exportAsFileDownload($_POST['table'], $GLOBALS['entries']);
|
||||
if ($reportExport !== null && $request->getParsedBodyParam('export_type') === 'sqldumpfile') {
|
||||
$this->tracking->exportAsFileDownload($tableParam, $GLOBALS['entries']);
|
||||
}
|
||||
|
||||
$actionMessage = '';
|
||||
if (isset($_POST['submit_mult'])) {
|
||||
if (! empty($_POST['selected_versions'])) {
|
||||
if ($_POST['submit_mult'] === 'delete_version') {
|
||||
foreach ($_POST['selected_versions'] as $version) {
|
||||
$submitMult = $request->getParsedBodyParam('submit_mult');
|
||||
$selectedVersions = $request->getParsedBodyParam('selected_versions');
|
||||
if ($submitMult !== null) {
|
||||
if (is_array($selectedVersions) && $selectedVersions !== []) {
|
||||
if ($submitMult === 'delete_version') {
|
||||
foreach ($selectedVersions as $version) {
|
||||
$this->tracking->deleteTrackingVersion($GLOBALS['db'], $GLOBALS['table'], $version);
|
||||
}
|
||||
|
||||
@ -162,79 +169,83 @@ final class TrackingController extends AbstractController
|
||||
}
|
||||
|
||||
$deleteVersion = '';
|
||||
if (isset($_POST['submit_delete_version'])) {
|
||||
if ($request->getParsedBodyParam('submit_delete_version') !== null) {
|
||||
$deleteVersion = $this->tracking->deleteTrackingVersion(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$_POST['version']
|
||||
$versionParam
|
||||
);
|
||||
}
|
||||
|
||||
$createVersion = '';
|
||||
if (isset($_POST['submit_create_version'])) {
|
||||
if ($request->getParsedBodyParam('submit_create_version') !== null) {
|
||||
$createVersion = $this->tracking->createTrackingVersion(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$_POST['version']
|
||||
$versionParam
|
||||
);
|
||||
}
|
||||
|
||||
$deactivateTracking = '';
|
||||
if (isset($_POST['toggle_activation']) && $_POST['toggle_activation'] === 'deactivate_now') {
|
||||
$activateTracking = '';
|
||||
|
||||
if ($toggleActivation === 'deactivate_now') {
|
||||
$deactivateTracking = $this->tracking->changeTracking(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$_POST['version'],
|
||||
$versionParam,
|
||||
'deactivate'
|
||||
);
|
||||
}
|
||||
|
||||
$activateTracking = '';
|
||||
if (isset($_POST['toggle_activation']) && $_POST['toggle_activation'] === 'activate_now') {
|
||||
} elseif ($toggleActivation === 'activate_now') {
|
||||
$activateTracking = $this->tracking->changeTracking(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$_POST['version'],
|
||||
$versionParam,
|
||||
'activate'
|
||||
);
|
||||
}
|
||||
|
||||
// Export as SQL execution
|
||||
$message = '';
|
||||
if (isset($_POST['report_export']) && $_POST['export_type'] === 'execution') {
|
||||
$sqlDump = '';
|
||||
|
||||
if ($reportExport === 'execution') {
|
||||
$this->tracking->exportAsSqlExecution($GLOBALS['entries']);
|
||||
$GLOBALS['msg'] = Message::success(__('SQL statements executed.'));
|
||||
$message = $GLOBALS['msg']->getDisplay();
|
||||
}
|
||||
|
||||
$sqlDump = '';
|
||||
if (isset($_POST['report_export']) && $_POST['export_type'] === 'sqldump') {
|
||||
} elseif ($reportExport === 'sqldump') {
|
||||
$this->addScriptFiles(['sql.js']);
|
||||
$sqlDump = $this->tracking->exportAsSqlDump($GLOBALS['db'], $GLOBALS['table'], $GLOBALS['entries']);
|
||||
}
|
||||
|
||||
$schemaSnapshot = '';
|
||||
if (isset($_POST['snapshot'])) {
|
||||
if ($request->getParsedBodyParam('snapshot') !== null) {
|
||||
/** @var string $db */
|
||||
$db = $request->getParsedBodyParam('db');
|
||||
$schemaSnapshot = $this->tracking->getHtmlForSchemaSnapshot(
|
||||
$_POST['db'],
|
||||
$_POST['table'],
|
||||
$_POST['version'],
|
||||
$db,
|
||||
$tableParam,
|
||||
$versionParam,
|
||||
$GLOBALS['urlParams']
|
||||
);
|
||||
}
|
||||
|
||||
$trackingReportRows = '';
|
||||
if (isset($_POST['report']) && (isset($_POST['delete_ddlog']) || isset($_POST['delete_dmlog']))) {
|
||||
if (
|
||||
$report !== null
|
||||
&& ($request->getParsedBodyParam('delete_ddlog') !== null
|
||||
|| $request->getParsedBodyParam('delete_dmlog') !== null)
|
||||
) {
|
||||
$trackingReportRows = $this->tracking->deleteTrackingReportRows(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$_POST['version'],
|
||||
$versionParam,
|
||||
$GLOBALS['data']
|
||||
);
|
||||
}
|
||||
|
||||
$trackingReport = '';
|
||||
if (isset($_POST['report']) || isset($_POST['report_export'])) {
|
||||
if ($report !== null || $reportExport !== null) {
|
||||
$trackingReport = $this->tracking->getHtmlForTrackingReport(
|
||||
$GLOBALS['data'],
|
||||
$GLOBALS['urlParams'],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user