summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-09-28 16:37:07 (GMT)
committerAlex Pott2014-09-28 16:37:07 (GMT)
commit62b9d58451cdc05271fd3ac2593a4ff9525241e8 (patch)
tree7673e8b51c13269ef3cff226f65fdb73bc91d93f
parente4242c47d671f4ed2bc70304b86623c11dcce6a9 (diff)
Issue #2297993 by cilefen, marthinal, ivanjaros: Fixed MySQL column and table comments are not truncated properly.
-rw-r--r--core/lib/Drupal/Core/Database/Driver/mysql/Schema.php3
-rw-r--r--core/modules/system/src/Tests/Database/SchemaTest.php10
2 files changed, 10 insertions, 3 deletions
diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
index e033bd5..10a01f4 100644
--- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
@@ -13,6 +13,7 @@ use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
use Drupal\Core\Database\Schema as DatabaseSchema;
+use Drupal\Component\Utility\Unicode;
/**
* @addtogroup schemaapi
@@ -492,7 +493,7 @@ class Schema extends DatabaseSchema {
// Truncate comment to maximum comment length.
if (isset($length)) {
// Add table prefixes before truncating.
- $comment = substr($this->connection->prefixTables($comment), 0, $length);
+ $comment = Unicode::truncate($this->connection->prefixTables($comment), $length, TRUE, TRUE);
}
return $this->connection->quote($comment);
diff --git a/core/modules/system/src/Tests/Database/SchemaTest.php b/core/modules/system/src/Tests/Database/SchemaTest.php
index 0264556..0a44375 100644
--- a/core/modules/system/src/Tests/Database/SchemaTest.php
+++ b/core/modules/system/src/Tests/Database/SchemaTest.php
@@ -11,6 +11,7 @@ use Drupal\Core\Database\Database;
use Drupal\Core\Database\SchemaObjectDoesNotExistException;
use Drupal\Core\Database\SchemaObjectExistsException;
use Drupal\simpletest\KernelTestBase;
+use Drupal\Component\Utility\Unicode;
/**
* Tests table creation and modification via the schema API.
@@ -30,7 +31,7 @@ class SchemaTest extends KernelTestBase {
function testSchema() {
// Try creating a table.
$table_specification = array(
- 'description' => 'Schema table description.',
+ 'description' => 'Schema table description may contain "quotes" and could be long—very long indeed.',
'fields' => array(
'id' => array(
'type' => 'int',
@@ -39,7 +40,7 @@ class SchemaTest extends KernelTestBase {
'test_field' => array(
'type' => 'int',
'not null' => TRUE,
- 'description' => 'Schema column description.',
+ 'description' => 'Schema table description may contain "quotes" and could be long—very long indeed. There could be "multiple quoted regions".',
),
'test_field_string' => array(
'type' => 'varchar',
@@ -212,6 +213,11 @@ class SchemaTest extends KernelTestBase {
function checkSchemaComment($description, $table, $column = NULL) {
if (method_exists(Database::getConnection()->schema(), 'getComment')) {
$comment = Database::getConnection()->schema()->getComment($table, $column);
+ // The schema comment truncation for mysql is different.
+ if (Database::getConnection()->databaseType() == 'mysql') {
+ $max_length = $column ? 255 : 60;
+ $description = Unicode::truncate($description, $max_length, TRUE, TRUE);
+ }
$this->assertEqual($comment, $description, 'The comment matches the schema description.');
}
}