Skip to content

Commit e349be1

Browse files
authored
Merge pull request #7421 from magento-atwix-pyrrans/AC-2123-fix-php81-deprecation-in-db-expression-converter
[Pyrrans] Fixed failures Integration Test in CI for AWS Aurora
2 parents f34651e + f665785 commit e349be1

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lib/internal/Magento/Framework/DB/ExpressionConverter.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?php
22
/**
3-
* DB expression converter
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
6+
87
namespace Magento\Framework\DB;
98

9+
/**
10+
* The Database expression converter
11+
*/
1012
class ExpressionConverter
1113
{
1214
/**
1315
* Maximum length for many MySql identifiers, including database, table, trigger, and column names
1416
*/
15-
const MYSQL_IDENTIFIER_LEN = 64;
17+
public const MYSQL_IDENTIFIER_LEN = 64;
1618

1719
/**
1820
* Dictionary maps common words in identifiers to abbreviations
@@ -90,6 +92,8 @@ public static function addTranslate($from, $to)
9092
}
9193

9294
/**
95+
* Retrieves shorten entity name.
96+
*
9397
* Shorten the name of a MySql identifier, by abbreviating common words and hashing if necessary. Prepends the
9498
* given prefix to clarify what kind of entity the identifier represents, in case hashing is used.
9599
*
@@ -125,12 +129,14 @@ public static function shortenEntityName($entityName, $prefix)
125129
* @param int $maxCharacters
126130
* @return string
127131
*/
128-
private static function trimHash($hash, $prefix, $maxCharacters)
129-
{
130-
$diff = strlen($hash) + strlen($prefix) - $maxCharacters;
131-
$superfluous = $diff / 2;
132-
$odd = $diff % 2;
133-
$hash = substr($hash, $superfluous, - ($superfluous + $odd));
134-
return $hash;
132+
private static function trimHash(
133+
string $hash,
134+
string $prefix,
135+
int $maxCharacters
136+
): string {
137+
$diff = strlen($hash) + strlen($prefix) - $maxCharacters;
138+
$superfluous = intdiv($diff, 2);
139+
$odd = $diff % 2;
140+
return substr($hash, $superfluous, - ($superfluous + $odd));
135141
}
136142
}

lib/internal/Magento/Framework/DB/Test/Unit/ExpressionConverterTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ public function shortenEntityNameDataProvider()
3939
'pre_',
4040
'pre_'
4141
],
42+
'Hashed identifer with long prefix' => [
43+
$length64 . '_cannotBeAbbreviated',
44+
'pre_' . $length40,
45+
'8d703c761bf8a322a999'
46+
],
4247
'Abbreviated identifier' => [
4348
$length40 . 'downloadable_notification_index',
4449
'pre_',
4550
$length40 . 'dl_ntfc_idx'
46-
],
51+
]
4752
];
4853
}
4954

0 commit comments

Comments
 (0)