Skip to content

Commit 4b226f8

Browse files
author
Dale Sikkema
committed
MAGETWO-37848: Generate data fails when table prefix exceeds length of 5
- update docblock descriptions and typehints
1 parent 449099f commit 4b226f8

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,7 @@ public function getDateExtractSql($date, $unit)
31233123
*
31243124
* @param string $tableName
31253125
* @return string
3126-
* @codeCoverageIgnore Covered by tests on ExpressionConverter
3126+
* @codeCoverageIgnore
31273127
*/
31283128
public function getTableName($tableName)
31293129
{
@@ -3137,7 +3137,7 @@ public function getTableName($tableName)
31373137
* @param string $time Either "before" or "after"
31383138
* @param string $event The DB level event which activates the trigger, i.e. "update" or "insert"
31393139
* @return string
3140-
* @codeCoverageIgnore Covered by tests on ExpressionConverter
3140+
* @codeCoverageIgnore
31413141
*/
31423142

31433143
public function getTriggerName($tableName, $time, $event)
@@ -3184,6 +3184,7 @@ public function getIndexName($tableName, $fields, $indexType = '')
31843184
* @param string $refTableName
31853185
* @param string $refColumnName
31863186
* @return string
3187+
* @codeCoverageIgnore
31873188
*/
31883189
public function getForeignKeyName($priTableName, $priColumnName, $refTableName, $refColumnName)
31893190
{

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ExpressionConverter
1515
const MYSQL_IDENTIFIER_LEN = 64;
1616

1717
/**
18-
* Dictionary for generate short name
18+
* Dictionary maps common words in identifiers to abbreviations
1919
*
2020
* @var array
2121
*/
@@ -67,7 +67,7 @@ class ExpressionConverter
6767
];
6868

6969
/**
70-
* Convert name using dictionary
70+
* Shorten name by abbreviating words
7171
*
7272
* @param string $name
7373
* @return string
@@ -78,7 +78,7 @@ public static function shortName($name)
7878
}
7979

8080
/**
81-
* Add or replace translate to dictionary
81+
* Add an abbreviation to the dictionary, or replace if it already exists
8282
*
8383
* @param string $from
8484
* @param string $to
@@ -90,30 +90,33 @@ public static function addTranslate($from, $to)
9090
}
9191

9292
/**
93-
* @param string $tableName
93+
* Shorten the name of a MySql identifier, by abbreviating common words and hashing if necessary. Prepends the
94+
* given prefix to clarify what kind of entity the identifier represents, in case hashing is used.
95+
*
96+
* @param string $entityName
9497
* @param string $prefix
9598
* @return string
9699
*/
97-
public static function shortenEntityName($tableName, $prefix)
100+
public static function shortenEntityName($entityName, $prefix)
98101
{
99-
if (strlen($tableName) > self::MYSQL_IDENTIFIER_LEN) {
100-
$shortName = ExpressionConverter::shortName($tableName);
102+
if (strlen($entityName) > self::MYSQL_IDENTIFIER_LEN) {
103+
$shortName = ExpressionConverter::shortName($entityName);
101104
if (strlen($shortName) > self::MYSQL_IDENTIFIER_LEN) {
102-
$hash = md5($tableName);
105+
$hash = md5($entityName);
103106
if (strlen($prefix . $hash) > self::MYSQL_IDENTIFIER_LEN) {
104-
$tableName = self::trimHash($hash, $prefix, self::MYSQL_IDENTIFIER_LEN);
107+
$entityName = self::trimHash($hash, $prefix, self::MYSQL_IDENTIFIER_LEN);
105108
} else {
106-
$tableName = $prefix . $hash;
109+
$entityName = $prefix . $hash;
107110
}
108111
} else {
109-
$tableName = $shortName;
112+
$entityName = $shortName;
110113
}
111114
}
112-
return $tableName;
115+
return $entityName;
113116
}
114117

115118
/**
116-
* Remove superfluous characters from hash.
119+
* Remove superfluous characters from hash
117120
*
118121
* @param string $hash
119122
* @param string $prefix

lib/internal/Magento/Framework/Mview/View/Subscription.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use Magento\Framework\App\Resource;
1212
use Magento\Framework\DB\Ddl\Trigger;
13-
use Magento\Framework\DB\ExpressionConverter;
1413

1514
class Subscription implements SubscriptionInterface
1615
{
@@ -22,7 +21,7 @@ class Subscription implements SubscriptionInterface
2221
protected $write;
2322

2423
/**
25-
* @var Trigger
24+
* @var \Magento\Framework\DB\Ddl\TriggerFactory
2625
*/
2726
protected $triggerFactory;
2827

0 commit comments

Comments
 (0)