|
14 | 14 | use Magento\Framework\Setup\Declaration\Schema\Dto\Schema;
|
15 | 15 | use Magento\Framework\Setup\Declaration\Schema\Dto\Table;
|
16 | 16 | use Magento\Framework\Setup\Declaration\Schema\Sharding;
|
| 17 | +use Magento\Framework\Config\FileResolverByModule; |
| 18 | +use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite; |
17 | 19 |
|
18 | 20 | /**
|
19 | 21 | * This type of builder is responsible for converting ENTIRE data, that comes from db
|
@@ -48,28 +50,50 @@ class SchemaBuilder
|
48 | 50 | */
|
49 | 51 | private $tables;
|
50 | 52 |
|
| 53 | + /** |
| 54 | + * @var ReaderComposite |
| 55 | + */ |
| 56 | + private $readerComposite; |
| 57 | + |
51 | 58 | /**
|
52 | 59 | * Constructor.
|
53 | 60 | *
|
54 | 61 | * @param ElementFactory $elementFactory
|
55 | 62 | * @param DbSchemaReaderInterface $dbSchemaReader
|
56 | 63 | * @param Sharding $sharding
|
| 64 | + * @param ReaderComposite $readerComposite |
57 | 65 | */
|
58 | 66 | public function __construct(
|
59 | 67 | ElementFactory $elementFactory,
|
60 | 68 | DbSchemaReaderInterface $dbSchemaReader,
|
61 |
| - Sharding $sharding |
| 69 | + Sharding $sharding, |
| 70 | + ReaderComposite $readerComposite |
62 | 71 | ) {
|
63 | 72 | $this->elementFactory = $elementFactory;
|
64 | 73 | $this->dbSchemaReader = $dbSchemaReader;
|
65 | 74 | $this->sharding = $sharding;
|
| 75 | + $this->readerComposite = $readerComposite; |
66 | 76 | }
|
67 | 77 |
|
68 | 78 | /**
|
69 | 79 | * @inheritdoc
|
| 80 | + * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
| 81 | + * @SuppressWarnings(PHPMD.NPathComplexity) |
70 | 82 | */
|
71 | 83 | public function build(Schema $schema)
|
72 | 84 | {
|
| 85 | + $data = $this->readerComposite->read(FileResolverByModule::ALL_MODULES); |
| 86 | + $tablesWithJsonTypeField = []; |
| 87 | + if (isset($data['table'])) { |
| 88 | + foreach ($data['table'] as $keyTable => $tableColumns) { |
| 89 | + foreach ($tableColumns['column'] as $keyColumn => $columnData) { |
| 90 | + if ($columnData['type'] == 'json') { |
| 91 | + $tablesWithJsonTypeField[$keyTable] = $keyColumn; |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
73 | 97 | foreach ($this->sharding->getResources() as $resource) {
|
74 | 98 | foreach ($this->dbSchemaReader->readTables($resource) as $tableName) {
|
75 | 99 | $columns = [];
|
@@ -98,6 +122,10 @@ public function build(Schema $schema)
|
98 | 122 |
|
99 | 123 | // Process columns
|
100 | 124 | foreach ($columnsData as $columnData) {
|
| 125 | + if (isset($tablesWithJsonTypeField[$tableName]) |
| 126 | + && $tablesWithJsonTypeField[$tableName] === $columnData['name']) { |
| 127 | + $columnData['type'] = 'json'; |
| 128 | + } |
101 | 129 | $columnData['table'] = $table;
|
102 | 130 | $column = $this->elementFactory->create($columnData['type'], $columnData);
|
103 | 131 | $columns[$column->getName()] = $column;
|
|
0 commit comments