Skip to content

Commit 0f2ff29

Browse files
committed
Remove tracking's selection_* global variables
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent db75ac3 commit 0f2ff29

File tree

5 files changed

+38
-73
lines changed

5 files changed

+38
-73
lines changed

libraries/classes/Controllers/Table/TrackingController.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public function __invoke(ServerRequest $request): void
5050
$GLOBALS['filter_ts_from'] = $GLOBALS['filter_ts_from'] ?? null;
5151
$GLOBALS['filter_ts_to'] = $GLOBALS['filter_ts_to'] ?? null;
5252
$GLOBALS['filter_users'] = $GLOBALS['filter_users'] ?? null;
53-
$GLOBALS['selection_schema'] = $GLOBALS['selection_schema'] ?? null;
54-
$GLOBALS['selection_data'] = $GLOBALS['selection_data'] ?? null;
55-
$GLOBALS['selection_both'] = $GLOBALS['selection_both'] ?? null;
5653

5754
$this->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'table/tracking.js']);
5855

@@ -93,16 +90,16 @@ public function __invoke(ServerRequest $request): void
9390
$GLOBALS['filter_ts_from'] = null;
9491
$GLOBALS['filter_ts_to'] = null;
9592
$GLOBALS['filter_users'] = [];
96-
$GLOBALS['selection_schema'] = false;
97-
$GLOBALS['selection_data'] = false;
98-
$GLOBALS['selection_both'] = false;
9993

10094
$report = $request->hasBodyParam('report');
10195
/** @var string $versionParam */
10296
$versionParam = $request->getParsedBodyParam('version');
10397
/** @var string $tableParam */
10498
$tableParam = $request->getParsedBodyParam('table');
10599

100+
$logType = $this->validateLogTypeParam($request->getParsedBodyParam('logtype'));
101+
$_POST['logtype'] = $logType;
102+
106103
// Init vars for tracking report
107104
if ($report || $reportExport !== null) {
108105
$GLOBALS['data'] = Tracker::getTrackedData(
@@ -111,17 +108,6 @@ public function __invoke(ServerRequest $request): void
111108
$versionParam
112109
);
113110

114-
$logType = $this->validateLogTypeParam($request->getParsedBodyParam('logtype'));
115-
$_POST['logtype'] = $logType;
116-
117-
if ($logType === 'schema') {
118-
$GLOBALS['selection_schema'] = true;
119-
} elseif ($logType === 'data') {
120-
$GLOBALS['selection_data'] = true;
121-
} else {
122-
$GLOBALS['selection_both'] = true;
123-
}
124-
125111
/** @var string $dateFrom */
126112
$dateFrom = $request->getParsedBodyParam('date_from', $GLOBALS['data']['date_from']);
127113
if (! isset($_POST['date_from'])) {
@@ -261,9 +247,7 @@ public function __invoke(ServerRequest $request): void
261247
$trackingReport = $this->tracking->getHtmlForTrackingReport(
262248
$GLOBALS['data'],
263249
$GLOBALS['urlParams'],
264-
$GLOBALS['selection_schema'],
265-
$GLOBALS['selection_data'],
266-
$GLOBALS['selection_both'],
250+
$logType,
267251
(int) $GLOBALS['filter_ts_to'],
268252
(int) $GLOBALS['filter_ts_from'],
269253
$GLOBALS['filter_users']

libraries/classes/Tracking.php

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,19 @@ public function getSqlResultForSelectableTables(string $db)
209209
/**
210210
* Function to get html for tracking report and tracking report export
211211
*
212-
* @param array $data data
213-
* @param array $url_params url params
214-
* @param bool $selection_schema selection schema
215-
* @param bool $selection_data selection data
216-
* @param bool $selection_both selection both
217-
* @param int $filter_ts_to filter time stamp from
218-
* @param int $filter_ts_from filter time stamp tp
219-
* @param array $filter_users filter users
212+
* @param array $data data
213+
* @param array $url_params url params
214+
* @param int $filter_ts_to filter time stamp from
215+
* @param int $filter_ts_from filter time stamp tp
216+
* @param array $filter_users filter users
217+
* @psalm-param 'schema'|'data'|'schema_and_data' $logType
220218
*
221219
* @return string
222220
*/
223221
public function getHtmlForTrackingReport(
224222
array $data,
225223
array $url_params,
226-
$selection_schema,
227-
$selection_data,
228-
$selection_both,
224+
string $logType,
229225
$filter_ts_to,
230226
$filter_ts_from,
231227
array $filter_users
@@ -238,11 +234,7 @@ public function getHtmlForTrackingReport(
238234
. htmlspecialchars($data['tracking']) . '</small><br>';
239235
$html .= '<br>';
240236

241-
[$str1, $str2, $str3, $str4, $str5] = $this->getHtmlForElementsOfTrackingReport(
242-
$selection_schema,
243-
$selection_data,
244-
$selection_both
245-
);
237+
[$str1, $str2, $str3, $str4, $str5] = $this->getHtmlForElementsOfTrackingReport($logType);
246238

247239
// Prepare delete link content here
248240
$drop_image_or_text = '';
@@ -266,9 +258,7 @@ public function getHtmlForTrackingReport(
266258
$html .= $this->getHtmlForTrackingReportExportForm1(
267259
$data,
268260
$url_params,
269-
$selection_schema,
270-
$selection_data,
271-
$selection_both,
261+
$logType,
272262
$filter_ts_to,
273263
$filter_ts_from,
274264
$filter_users,
@@ -290,26 +280,21 @@ public function getHtmlForTrackingReport(
290280
/**
291281
* Generate HTML element for report form
292282
*
293-
* @param bool $selection_schema selection schema
294-
* @param bool $selection_data selection data
295-
* @param bool $selection_both selection both
283+
* @psalm-param 'schema'|'data'|'schema_and_data' $logType
296284
*
297285
* @return array
298286
*/
299-
public function getHtmlForElementsOfTrackingReport(
300-
$selection_schema,
301-
$selection_data,
302-
$selection_both
303-
) {
287+
public function getHtmlForElementsOfTrackingReport(string $logType)
288+
{
304289
$str1 = '<select name="logtype">'
305290
. '<option value="schema"'
306-
. ($selection_schema ? ' selected="selected"' : '') . '>'
291+
. ($logType === 'schema' ? ' selected="selected"' : '') . '>'
307292
. __('Structure only') . '</option>'
308293
. '<option value="data"'
309-
. ($selection_data ? ' selected="selected"' : '') . '>'
294+
. ($logType === 'data' ? ' selected="selected"' : '') . '>'
310295
. __('Data only') . '</option>'
311296
. '<option value="schema_and_data"'
312-
. ($selection_both ? ' selected="selected"' : '') . '>'
297+
. ($logType === 'schema_and_data' ? ' selected="selected"' : '') . '>'
313298
. __('Structure and data') . '</option>'
314299
. '</select>';
315300
$str2 = '<input type="text" name="date_from" value="'
@@ -335,9 +320,6 @@ public function getHtmlForElementsOfTrackingReport(
335320
*
336321
* @param array $data data
337322
* @param array $url_params url params
338-
* @param bool $selection_schema selection schema
339-
* @param bool $selection_data selection data
340-
* @param bool $selection_both selection both
341323
* @param int $filter_ts_to filter time stamp from
342324
* @param int $filter_ts_from filter time stamp tp
343325
* @param array $filter_users filter users
@@ -347,15 +329,14 @@ public function getHtmlForElementsOfTrackingReport(
347329
* @param string $str4 HTML for user
348330
* @param string $str5 HTML for "list report"
349331
* @param string $drop_image_or_text HTML for image or text
332+
* @psalm-param 'schema'|'data'|'schema_and_data' $logType
350333
*
351334
* @return string HTML for form
352335
*/
353336
public function getHtmlForTrackingReportExportForm1(
354337
array $data,
355338
array $url_params,
356-
$selection_schema,
357-
$selection_data,
358-
$selection_both,
339+
string $logType,
359340
$filter_ts_to,
360341
$filter_ts_from,
361342
array $filter_users,
@@ -383,7 +364,7 @@ public function getHtmlForTrackingReportExportForm1(
383364
$str5
384365
);
385366

386-
if ($selection_schema || $selection_both && count($data['ddlog']) > 0) {
367+
if ($logType === 'schema' || $logType === 'schema_and_data' && count($data['ddlog']) > 0) {
387368
[$temp, $ddlog_count] = $this->getHtmlForDataDefinitionStatements(
388369
$data,
389370
$filter_users,
@@ -397,7 +378,7 @@ public function getHtmlForTrackingReportExportForm1(
397378
}
398379

399380
// Secondly, list tracked data manipulation statements
400-
if (($selection_data || $selection_both) && count($data['dmlog']) > 0) {
381+
if (($logType === 'data' || $logType === 'schema_and_data') && count($data['dmlog']) > 0) {
401382
$html .= $this->getHtmlForDataManipulationStatements(
402383
$data,
403384
$filter_users,

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11335,6 +11335,11 @@ parameters:
1133511335
count: 1
1133611336
path: test/classes/TrackerTest.php
1133711337

11338+
-
11339+
message: "#^Parameter \\#3 \\$logType of method PhpMyAdmin\\\\Tracking\\:\\:getHtmlForTrackingReport\\(\\) expects 'data'\\|'schema'\\|'schema_and_data', 'logtype' given\\.$#"
11340+
count: 1
11341+
path: test/classes/TrackingTest.php
11342+
1133811343
-
1133911344
message: "#^Method PhpMyAdmin\\\\Tests\\\\TransformationsTest\\:\\:fixupData\\(\\) return type has no value type specified in iterable type array\\.$#"
1134011345
count: 1

psalm-baseline.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,13 +4180,11 @@
41804180
</PossiblyNullArrayAccess>
41814181
</file>
41824182
<file src="libraries/classes/Controllers/Table/TrackingController.php">
4183-
<ArgumentTypeCoercion occurrences="1">
4184-
<code>$_POST['logtype']</code>
4185-
</ArgumentTypeCoercion>
4186-
<MixedArgument occurrences="4">
4183+
<MixedArgument occurrences="5">
41874184
<code>$GLOBALS['data']</code>
41884185
<code>$GLOBALS['data']</code>
41894186
<code>$GLOBALS['data']</code>
4187+
<code>$_POST['logtype']</code>
41904188
<code>$version</code>
41914189
</MixedArgument>
41924190
<MixedArrayAccess occurrences="4">
@@ -4195,7 +4193,7 @@
41954193
<code>$GLOBALS['data']['date_to']</code>
41964194
<code>$GLOBALS['data']['date_to']</code>
41974195
</MixedArrayAccess>
4198-
<MixedAssignment occurrences="19">
4196+
<MixedAssignment occurrences="15">
41994197
<code>$GLOBALS['data']</code>
42004198
<code>$GLOBALS['data']</code>
42014199
<code>$GLOBALS['entries']</code>
@@ -4204,18 +4202,17 @@
42044202
<code>$GLOBALS['filter_ts_to']</code>
42054203
<code>$GLOBALS['filter_users']</code>
42064204
<code>$GLOBALS['msg']</code>
4207-
<code>$GLOBALS['selection_both']</code>
4208-
<code>$GLOBALS['selection_data']</code>
4209-
<code>$GLOBALS['selection_schema']</code>
42104205
<code>$_POST['date_from']</code>
42114206
<code>$_POST['date_to']</code>
4212-
<code>$logType</code>
42134207
<code>$reportExport</code>
42144208
<code>$selectedVersions</code>
42154209
<code>$submitMult</code>
42164210
<code>$toggleActivation</code>
42174211
<code>$version</code>
42184212
</MixedAssignment>
4213+
<PossiblyInvalidArgument occurrences="1">
4214+
<code>$_POST['logtype']</code>
4215+
</PossiblyInvalidArgument>
42194216
<PossiblyInvalidCast occurrences="1">
42204217
<code>$_POST['logtype']</code>
42214218
</PossiblyInvalidCast>
@@ -15988,6 +15985,9 @@
1598815985
</MixedInferredReturnType>
1598915986
</file>
1599015987
<file src="test/classes/TrackingTest.php">
15988+
<InvalidArgument occurrences="1">
15989+
<code>'logtype'</code>
15990+
</InvalidArgument>
1599115991
<MixedArgument occurrences="1">
1599215992
<code>$html</code>
1599315993
</MixedArgument>

test/classes/TrackingTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,19 +279,14 @@ public function testGetHtmlForTrackingReportr(): void
279279
'dmlog' => ['dmlog'],
280280
];
281281
$url_params = [];
282-
$selection_schema = false;
283-
$selection_data = false;
284-
$selection_both = false;
285282
$filter_ts_to = 0;
286283
$filter_ts_from = 0;
287284
$filter_users = [];
288285

289286
$html = $this->tracking->getHtmlForTrackingReport(
290287
$data,
291288
$url_params,
292-
$selection_schema,
293-
$selection_data,
294-
$selection_both,
289+
'logtype',
295290
$filter_ts_to,
296291
$filter_ts_from,
297292
$filter_users

0 commit comments

Comments
 (0)