Skip to content

Commit 40b167a

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.com.br>
2 parents 65f19ca + e5255f8 commit 40b167a

11 files changed

Lines changed: 102 additions & 68 deletions

File tree

‎.github/workflows/lint-and-analyse-php.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
uses: shivammathur/setup-php@v2
2828
with:
2929
php-version: ${{ matrix.php-version }}
30+
coverage: none
3031

3132
- name: Validate composer.json and composer.lock
3233
run: composer validate --strict
@@ -78,6 +79,7 @@ jobs:
7879
with:
7980
php-version: ${{ matrix.php-version }}
8081
extensions: mbstring, iconv, mysqli, zip, gd, bz2
82+
coverage: none
8183

8284
- name: Install Composer dependencies
8385
uses: ramsey/composer-install@v4

‎.github/workflows/mutation-tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
with:
5858
php-version: ${{ matrix.php-version }}
5959
coverage: pcov
60-
tools: composer:v2, infection:0.27.11
60+
tools: infection:0.27.11
6161

6262
- name: Install Composer dependencies
6363
uses: ramsey/composer-install@v4

‎.github/workflows/other-tools.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
with:
4848
php-version: ${{ matrix.php-version }}
4949
extensions: mbstring, iconv, mysqli, zip, gd
50-
tools: composer:v2
50+
coverage: none
5151

5252
- name: Install Composer dependencies
5353
uses: ramsey/composer-install@v4

‎.github/workflows/test-selenium.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ jobs:
9393
- name: Set up PHP ${{ env.php-version }}
9494
uses: shivammathur/setup-php@v2
9595
with:
96-
coverage: "none"
9796
php-version: ${{ env.php-version }}
9897
extensions: :opcache, mbstring, iconv, mysqli, zip, gd, bz2
98+
coverage: none
9999

100100
- name: Install Composer dependencies
101101
uses: ramsey/composer-install@v4

‎.github/workflows/tests.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
with:
9898
php-version: ${{ matrix.php-version }}
9999
extensions: ${{ matrix.php-extensions }}
100-
coverage: xdebug
100+
coverage: pcov
101101

102102
- name: Install Composer dependencies
103103
uses: ramsey/composer-install@v4
@@ -160,7 +160,7 @@ jobs:
160160
with:
161161
php-version: ${{ matrix.php-version }}
162162
extensions: ${{ matrix.extension }}, mbstring, iconv, mysqli, zip, gd
163-
coverage: xdebug
163+
coverage: pcov
164164

165165
- name: Install Composer dependencies
166166
uses: ramsey/composer-install@v4
@@ -218,6 +218,7 @@ jobs:
218218
with:
219219
php-version: ${{ matrix.php }}
220220
extensions: mbstring, iconv, mysqli, zip, gd, bz2
221+
coverage: none
221222

222223
- name: Update composer.json
223224
shell: bash

‎.github/workflows/update-po.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: shivammathur/setup-php@v2
3434
with:
3535
php-version: ${{ matrix.php-version }}
36-
tools: composer:v2
36+
coverage: none
3737

3838
- name: Install Composer dependencies
3939
uses: ramsey/composer-install@v4

‎phpstan-baseline.neon‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,12 @@ parameters:
16381638
count: 1
16391639
path: src/Controllers/Database/StructureController.php
16401640

1641+
-
1642+
message: '#^PHPDoc tag @var with type list\<array\{COLUMN_NAME\: string, HAS_QUOTES\: numeric\-string\}\> is not subtype of native type string\|false\|null\.$#'
1643+
identifier: varTag.nativeType
1644+
count: 1
1645+
path: src/Controllers/Database/StructureController.php
1646+
16411647
-
16421648
message: '#^Parameter \#1 \$db of method PhpMyAdmin\\Controllers\\Database\\StructureController\:\:hasTable\(\) expects array\<mixed\>, mixed given\.$#'
16431649
identifier: argument.type
@@ -1665,7 +1671,7 @@ parameters:
16651671
-
16661672
message: '#^Parameter \#1 \$str of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:quoteString\(\) expects string, int\|string\|null given\.$#'
16671673
identifier: argument.type
1668-
count: 2
1674+
count: 1
16691675
path: src/Controllers/Database/StructureController.php
16701676

16711677
-
@@ -14862,7 +14868,7 @@ parameters:
1486214868
Use dependency injection instead\.$#
1486314869
'''
1486414870
identifier: staticMethod.deprecated
14865-
count: 9
14871+
count: 7
1486614872
path: tests/unit/Controllers/Database/StructureControllerTest.php
1486714873

1486814874
-
@@ -14911,19 +14917,13 @@ parameters:
1491114917
path: tests/unit/Controllers/Database/StructureControllerTest.php
1491214918

1491314919
-
14914-
message: '#^Parameter \#2 \$array of static method PHPUnit\\Framework\\Assert\:\:assertArrayNotHasKey\(\) expects array\<mixed\>\|ArrayAccess\<\(int\|string\), mixed\>, mixed given\.$#'
14915-
identifier: argument.type
14916-
count: 1
14917-
path: tests/unit/Controllers/Database/StructureControllerTest.php
14918-
14919-
-
14920-
message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#'
14920+
message: '#^Parameter \#1 \$needle of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#'
1492114921
identifier: argument.type
14922-
count: 4
14922+
count: 2
1492314923
path: tests/unit/Controllers/Database/StructureControllerTest.php
1492414924

1492514925
-
14926-
message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringNotContainsString\(\) expects string, mixed given\.$#'
14926+
message: '#^Parameter \#2 \$array of static method PHPUnit\\Framework\\Assert\:\:assertArrayNotHasKey\(\) expects array\<mixed\>\|ArrayAccess\<\(int\|string\), mixed\>, mixed given\.$#'
1492714927
identifier: argument.type
1492814928
count: 1
1492914929
path: tests/unit/Controllers/Database/StructureControllerTest.php

‎psalm-baseline.xml‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,6 @@
10311031
<code><![CDATA[list{(string|int|null)[], string, string, string, string, int, bool, int}]]></code>
10321032
</MoreSpecificReturnType>
10331033
<PossiblyFalseOperand>
1034-
<code><![CDATA[$columnNames]]></code>
10351034
<code><![CDATA[$this->config->config->NavigationTreeTableSeparator]]></code>
10361035
<code><![CDATA[$this->config->config->NavigationTreeTableSeparator]]></code>
10371036
</PossiblyFalseOperand>
@@ -1047,7 +1046,6 @@
10471046
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
10481047
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
10491048
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
1050-
<code><![CDATA[$currentTable['TABLE_NAME']]]></code>
10511049
<code><![CDATA[$truename]]></code>
10521050
<code><![CDATA[$truename]]></code>
10531051
</PossiblyInvalidArgument>
@@ -1068,7 +1066,6 @@
10681066
<code><![CDATA[$trackedTables]]></code>
10691067
</PossiblyNullArrayOffset>
10701068
<PossiblyNullOperand>
1071-
<code><![CDATA[$columnNames]]></code>
10721069
<code><![CDATA[$currentTable['Data_length']]]></code>
10731070
<code><![CDATA[$currentTable['Data_length']]]></code>
10741071
<code><![CDATA[$currentTable['Data_length']]]></code>
@@ -8697,8 +8694,6 @@
86978694
<code><![CDATA[Config::getInstance()]]></code>
86988695
<code><![CDATA[Config::getInstance()]]></code>
86998696
<code><![CDATA[Config::getInstance()]]></code>
8700-
<code><![CDATA[Config::getInstance()]]></code>
8701-
<code><![CDATA[Config::getInstance()]]></code>
87028697
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
87038698
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
87048699
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
@@ -8709,8 +8704,6 @@
87098704
</DeprecatedMethod>
87108705
<MixedArgument>
87118706
<code><![CDATA[$currentTable]]></code>
8712-
<code><![CDATA[$result]]></code>
8713-
<code><![CDATA[$result]]></code>
87148707
</MixedArgument>
87158708
<MixedArrayAccess>
87168709
<code><![CDATA[$currentTable]]></code>
@@ -8743,7 +8736,6 @@
87438736
<code><![CDATA[$currentTable['ENGINE']]]></code>
87448737
</MixedArrayAssignment>
87458738
<MixedAssignment>
8746-
<code><![CDATA[$result]]></code>
87478739
<code><![CDATA[$result]]></code>
87488740
<code><![CDATA[[$currentTable, , , $sumSize]]]></code>
87498741
<code><![CDATA[[$currentTable, , , $sumSize]]]></code>

‎resources/templates/database/structure/body_for_table_summary.twig‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,13 @@
6666
<th></th>
6767
{% endif %}
6868
{% if show_creation %}
69-
<th class="value tbl_creation font-monospace text-end">
70-
{{ create_time_all }}
71-
</th>
69+
<th class="value tbl_creation font-monospace text-end">{{ create_time_all }}</th>
7270
{% endif %}
7371
{% if show_last_update %}
74-
<th class="value tbl_last_update font-monospace text-end">
75-
{{ update_time_all }}
76-
</th>
72+
<th class="value tbl_last_update font-monospace text-end">{{ update_time_all }}</th>
7773
{% endif %}
7874
{% if show_last_check %}
79-
<th class="value tbl_last_check font-monospace text-end">
80-
{{ check_time_all }}
81-
</th>
75+
<th class="value tbl_last_check font-monospace text-end">{{ check_time_all }}</th>
8276
{% endif %}
8377
</tr>
8478
</tfoot>

‎src/Controllers/Database/StructureController.php‎

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
use Throwable;
4040

4141
use function __;
42+
use function array_map;
43+
use function array_reduce;
4244
use function array_reverse;
4345
use function array_search;
4446
use function array_slice;
@@ -326,15 +328,15 @@ private function displayTableList(array $replicaInfo): string
326328
$updateTime = null;
327329
if ($this->config->config->ShowDbStructureLastUpdate && isset($currentTable['Update_time'])) {
328330
$updateTime = $this->createDateTime($currentTable['Update_time']);
329-
if ($updateTime !== null && ($updateTimeAll === null || $updateTime < $updateTimeAll)) {
331+
if ($updateTime !== null && ($updateTimeAll === null || $updateTime > $updateTimeAll)) {
330332
$updateTimeAll = $updateTime;
331333
}
332334
}
333335

334336
$checkTime = null;
335337
if ($this->config->config->ShowDbStructureLastCheck && isset($currentTable['Check_time'])) {
336338
$checkTime = $this->createDateTime($currentTable['Check_time']);
337-
if ($checkTime !== null && ($checkTimeAll === null || $checkTime < $checkTimeAll)) {
339+
if ($checkTime !== null && ($checkTimeAll === null || $checkTime > $checkTimeAll)) {
338340
$checkTimeAll = $checkTime;
339341
}
340342
}
@@ -859,35 +861,45 @@ private function getValuesForCsvTable(array $currentTable, int $sumSize): array
859861
->countRecords(true);
860862

861863
if ($this->isShowStats) {
862-
// Only count columns that have double quotes
863-
$columnCount = (int) $this->dbi->fetchValue(
864-
'SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '
865-
. $this->dbi->quoteString(Current::$database) . ' AND TABLE_NAME = '
866-
. $this->dbi->quoteString($currentTable['TABLE_NAME']) . ' AND NUMERIC_SCALE IS NULL;',
867-
);
868-
869864
// Get column names
870-
$columnNames = $this->dbi->fetchValue(
871-
'SELECT GROUP_CONCAT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '
865+
/** @var list<array{COLUMN_NAME: string, HAS_QUOTES: numeric-string}> $columns */
866+
$columns = $this->dbi->fetchValue(
867+
'SELECT COLUMN_NAME, NUMERIC_SCALE IS NULL AS HAS_QUOTES'
868+
. ' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '
872869
. $this->dbi->quoteString(Current::$database) . ' AND TABLE_NAME = '
873870
. $this->dbi->quoteString($currentTable['TABLE_NAME']) . ';',
874871
);
875872

876-
// 10Mb buffer for CONCAT_WS
877-
// not sure if is needed
873+
$columnsString = implode(',', array_map(
874+
static function (array $column): string {
875+
return Util::backquote($column['COLUMN_NAME']);
876+
},
877+
$columns,
878+
));
879+
880+
// 10Mb buffer for CONCAT not sure if is needed
878881
$this->dbi->query('SET SESSION group_concat_max_len = 10 * 1024 * 1024');
879882

880883
// Calculate data length
884+
// literal new line, double quote and backslash characters are escaped in csv
885+
// and use up two bytes instead of one.
881886
$dataLength = (int) $this->dbi->fetchValue('
882-
SELECT SUM(CHAR_LENGTH(REPLACE(REPLACE(REPLACE(
883-
CONCAT_WS(\',\', ' . $columnNames . '),
884-
UNHEX(\'0A\'), \'nn\'), UNHEX(\'22\'), \'nn\'), UNHEX(\'5C\'), \'nn\'
885-
))) FROM ' . Util::backquote(Current::$database) . '.' . Util::backquote($currentTable['TABLE_NAME']));
887+
SELECT SUM(LENGTH(REPLACE(
888+
REPLACE(
889+
REPLACE(CONCAT(' . $columnsString . "), '\\n', 'nl'),
890+
'\"',
891+
'qu'
892+
),
893+
'\\\\',
894+
'bs'
895+
))) FROM " . Util::backquote(Current::$database) . '.' . Util::backquote($currentTable['TABLE_NAME']));
886896

887-
// Calculate quotes length
888-
$quotesLength = $currentTable['TABLE_ROWS'] * $columnCount * 2;
897+
$quotedColumns = array_reduce($columns, static function (int $sum, array $column): int {
898+
return $sum + (int) $column['HAS_QUOTES'];
899+
}, 0);
900+
$separatorsAndNewLine = count($columns);
889901

890-
$tblsize = $dataLength + $quotesLength + $currentTable['TABLE_ROWS'];
902+
$tblsize = $dataLength + $currentTable['TABLE_ROWS'] * ($quotedColumns * 2 + $separatorsAndNewLine);
891903

892904
$sumSize += $tblsize;
893905
[$formattedSize, $unit] = Util::formatByteDown($tblsize, 3, $tblsize > 0 ? 1 : 0);

0 commit comments

Comments
 (0)