Skip to content

Commit 813fa45

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-43906-long-db-prefix' into PR_Branch
2 parents 95a31b5 + 5ef31f3 commit 813fa45

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

setup/src/Magento/Setup/Test/Unit/Validator/DbValidatorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ public function testCheckDatabaseTablePrefixWrongFormat()
108108
$this->assertEquals(true, $this->dbValidator->checkDatabaseTablePrefix('_wrong_format'));
109109
}
110110

111+
/**
112+
* @expectedException \InvalidArgumentException
113+
* @expectedExceptionMessage Table prefix length can't be more than
114+
*/
115+
public function testCheckDatabaseTablePrefixWrongLength()
116+
{
117+
$this->assertEquals(
118+
true,
119+
$this->dbValidator->checkDatabaseTablePrefix('mvbXzXzItSIr0wrZW3gqgV2UKrWiK1Mj7bkBlW72rZW3gqgV2UKrWiK1M')
120+
);
121+
}
122+
111123
/**
112124
* @expectedException \Magento\Setup\Exception
113125
* @expectedExceptionMessage Database connection failure.

setup/src/Magento/Setup/Validator/DbValidator.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616
class DbValidator
1717
{
18+
19+
/**
20+
* Db prefix max length
21+
*/
22+
const DB_PREFIX_LENGTH = 5;
23+
1824
/**
1925
* DB connection factory
2026
*
@@ -44,7 +50,16 @@ public function checkDatabaseTablePrefix($prefix)
4450
//The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_);
4551
// the first character should be a letter.
4652
if ($prefix !== '' && !preg_match('/^([a-zA-Z])([[:alnum:]_]+)$/', $prefix)) {
47-
throw new \InvalidArgumentException('Please correct the table prefix format.');
53+
throw new \InvalidArgumentException(
54+
'Please correct the table prefix format, should contain only numbers, letters or underscores.'
55+
.' The first character should be a letter.'
56+
);
57+
}
58+
59+
if (strlen($prefix) > self::DB_PREFIX_LENGTH) {
60+
throw new \InvalidArgumentException(
61+
'Table prefix length can\'t be more than ' . self::DB_PREFIX_LENGTH . ' characters.'
62+
);
4863
}
4964

5065
return true;

setup/view/magento/setup/add-database.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
id="dbTablePrefix"
336336
class="form-el-input"
337337
tooltip-placement="right"
338-
tooltip="Enter a prefix for database tables created in this installation. Use letters, numbers or underscores, and begin with a letter (Ex: ‘mg1_’)"
338+
tooltip="Enter a prefix for database tables created in this installation. Use letters, numbers or underscores, and begin with a letter (Ex: ‘mg1_’). Table prefix length can't be more than 5 characters."
339339
tooltip-trigger="focus"
340340
tooltip-append-to-body="true"
341341
type="text"

0 commit comments

Comments
 (0)