Skip to content

Commit 5e616b2

Browse files
authored
ENGCOM-7016: Add support for char element to dto factory #22442
2 parents 9f82de9 + b82791d commit 5e616b2

File tree

10 files changed

+78
-4
lines changed

10 files changed

+78
-4
lines changed

app/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@
14451445
<item name="mediumtext" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\MediumText</item>
14461446
<item name="text" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Text</item>
14471447
<item name="varchar" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary</item>
1448+
<item name="char" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary</item>
14481449
<item name="varbinary" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\StringBinary</item>
14491450
<item name="blob" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Blob</item>
14501451
<item name="mediumblob" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\MediumBlob</item>
@@ -1592,6 +1593,7 @@
15921593
<item name="longblog" xsi:type="object">Magento\Framework\Setup\SchemaListenerDefinition\TextBlobDefinition</item>
15931594
<item name="varbinary" xsi:type="object">Magento\Framework\Setup\SchemaListenerDefinition\TextBlobDefinition</item>
15941595
<item name="varchar" xsi:type="object">Magento\Framework\Setup\SchemaListenerDefinition\TextBlobDefinition</item>
1596+
<item name="char" xsi:type="object">Magento\Framework\Setup\SchemaListenerDefinition\CharDefinition</item>
15951597
<item name="timestamp" xsi:type="object">Magento\Framework\Setup\SchemaListenerDefinition\TimestampDefinition</item>
15961598
<item name="datetime" xsi:type="object">Magento\Framework\Setup\SchemaListenerDefinition\TimestampDefinition</item>
15971599
<item name="date" xsi:type="object">Magento\Framework\Setup\SchemaListenerDefinition\DateDefinition</item>

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/etc/db_schema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<column xsi:type="longtext" name="longtext"/>
4949
<column xsi:type="mediumtext" name="mediumtext"/>
5050
<column xsi:type="varchar" name="varchar" length="254" nullable="true"/>
51+
<column xsi:type="char" name="char" length="255" nullable="true"/>
5152
<column xsi:type="mediumblob" name="mediumblob"/>
5253
<column xsi:type="blob" name="blob"/>
5354
<column xsi:type="boolean" name="boolean"/>

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/column_modification.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
`longtext` longtext,
3737
`mediumtext` mediumtext,
3838
`varchar` varchar(100) DEFAULT NULL,
39+
`char` char(255) DEFAULT NULL,
3940
`mediumblob` mediumblob,
4041
`blob` blob,
4142
`boolean` tinyint(1) DEFAULT \'1\',

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/declarative_installer/constraint_modification.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
`longtext` longtext,
3939
`mediumtext` mediumtext,
4040
`varchar` varchar(254) DEFAULT NULL,
41+
`char` char(255) DEFAULT NULL,
4142
`mediumblob` mediumblob,
4243
`blob` blob,
4344
`boolean` tinyint(1) DEFAULT NULL,

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/dry_run_log.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
`longtext` longtext NULL ,
3939
`mediumtext` mediumtext NULL ,
4040
`varchar` varchar(254) NULL ,
41+
`char` char(255) NULL ,
4142
`mediumblob` mediumblob NULL ,
4243
`blob` blob NULL ,
4344
`boolean` BOOLEAN NULL ,

dev/tests/setup-integration/_files/Magento/TestSetupDeclarationModule1/fixture/valid_xml_revision_1.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@
199199
'type' => 'mediumtext',
200200
'name' => 'mediumtext',
201201
],
202+
'char' => [
203+
'type' => 'char',
204+
'name' => 'char',
205+
'length' => '255',
206+
'nullable' => 'true',
207+
],
202208
'varchar' => [
203209
'type' => 'varchar',
204210
'name' => 'varchar',

lib/internal/Magento/Framework/Setup/Declaration/Schema/Dto/Columns/StringBinary.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* String or Binary column.
14-
* Declared in SQL, like VARCHAR(L), BINARY(L)
14+
* Declared in SQL, like CHAR(L), VARCHAR(L), BINARY(L)
1515
* where L - length.
1616
*/
1717
class StringBinary extends Column implements
@@ -73,10 +73,9 @@ public function isNullable()
7373
}
7474

7575
/**
76-
* Return default value.
77-
* Note: default value should be string.
76+
* Return default value, Note: default value should be string.
7877
*
79-
* @return string | null
78+
* @return string|null
8079
*/
8180
public function getDefault()
8281
{

lib/internal/Magento/Framework/Setup/Declaration/Schema/etc/schema.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/texts/longtext.xsd" />
2121
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/texts/mediumtext.xsd" />
2222
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/texts/varchar.xsd" />
23+
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/texts/char.xsd" />
2324
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/texts/json.xsd" />
2425
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/binaries/blob.xsd" />
2526
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/binaries/mediumblob.xsd" />
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
9+
<xs:include schemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/types/column.xsd"/>
10+
11+
<xs:complexType name="char">
12+
<xs:complexContent>
13+
<xs:extension base="abstractColumnType">
14+
<xs:annotation>
15+
<xs:documentation>
16+
Here plain text can be persisted without trailing spaces. Length of this field can't be more than 255 characters
17+
When CHAR values are retrieved, trailing spaces are removed unless the PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled.
18+
</xs:documentation>
19+
</xs:annotation>
20+
21+
<xs:attribute name="length">
22+
<xs:simpleType>
23+
<xs:restriction base="xs:integer">
24+
<xs:maxInclusive value="255"/>
25+
</xs:restriction>
26+
</xs:simpleType>
27+
</xs:attribute>
28+
<xs:attribute name="default" type="xs:string" />
29+
<xs:attribute name="nullable" type="xs:boolean" />
30+
</xs:extension>
31+
</xs:complexContent>
32+
</xs:complexType>
33+
</xs:schema>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Setup\SchemaListenerDefinition;
8+
9+
/**
10+
* Char type definition.
11+
*/
12+
class CharDefinition implements DefinitionConverterInterface
13+
{
14+
private const DEFAULT_TEXT_LENGTH = 255;
15+
16+
/**
17+
* @inheritdoc
18+
*/
19+
public function convertToDefinition(array $definition)
20+
{
21+
return [
22+
'xsi:type' => $definition['type'],
23+
'name' => $definition['name'],
24+
'length' => $definition['length'] ?? self::DEFAULT_TEXT_LENGTH,
25+
'default' => isset($definition['default']) ? (bool) $definition['default'] : null,
26+
'nullable' => $definition['nullable'] ?? true,
27+
];
28+
}
29+
}

0 commit comments

Comments
 (0)