|
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 |
@@ -49,35 +51,47 @@ class SchemaBuilder |
49 | 51 | private $tables; |
50 | 52 |
|
51 | 53 | /** |
52 | | - * declared tables. |
53 | | - * |
54 | | - * @var array |
| 54 | + * @var ReaderComposite |
55 | 55 | */ |
56 | | - private array $tablesWithJsonTypeField = []; |
| 56 | + private $readerComposite; |
57 | 57 |
|
58 | 58 | /** |
59 | 59 | * Constructor. |
60 | 60 | * |
61 | 61 | * @param ElementFactory $elementFactory |
62 | 62 | * @param DbSchemaReaderInterface $dbSchemaReader |
63 | 63 | * @param Sharding $sharding |
| 64 | + * @param ReaderComposite $readerComposite |
64 | 65 | */ |
65 | 66 | public function __construct( |
66 | 67 | ElementFactory $elementFactory, |
67 | 68 | DbSchemaReaderInterface $dbSchemaReader, |
68 | | - Sharding $sharding |
| 69 | + Sharding $sharding, |
| 70 | + ReaderComposite $readerComposite |
69 | 71 | ) { |
70 | 72 | $this->elementFactory = $elementFactory; |
71 | 73 | $this->dbSchemaReader = $dbSchemaReader; |
72 | 74 | $this->sharding = $sharding; |
| 75 | + $this->readerComposite = $readerComposite; |
73 | 76 | } |
74 | 77 |
|
75 | 78 | /** |
76 | 79 | * @inheritdoc |
77 | 80 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
| 81 | + * @SuppressWarnings(PHPMD.NPathComplexity) |
78 | 82 | */ |
79 | 83 | public function build(Schema $schema) |
80 | 84 | { |
| 85 | + $data = $this->readerComposite->read(FileResolverByModule::ALL_MODULES); |
| 86 | + $tablesWithJsonTypeField = []; |
| 87 | + foreach ($data['table'] as $keyTable => $tableColumns) { |
| 88 | + foreach ($tableColumns['column'] as $keyColumn => $columnData) { |
| 89 | + if ($columnData['type'] == 'json') { |
| 90 | + $tablesWithJsonTypeField[$keyTable] = $keyColumn; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
81 | 95 | foreach ($this->sharding->getResources() as $resource) { |
82 | 96 | foreach ($this->dbSchemaReader->readTables($resource) as $tableName) { |
83 | 97 | $columns = []; |
@@ -105,7 +119,6 @@ public function build(Schema $schema) |
105 | 119 | ); |
106 | 120 |
|
107 | 121 | $isJsonType = false; |
108 | | - $tablesWithJsonTypeField = $this->getTablesWithJsonTypeField(); |
109 | 122 | if (count($tablesWithJsonTypeField) > 0 && isset($tablesWithJsonTypeField[$tableName])) { |
110 | 123 | $isJsonType = true; |
111 | 124 | } |
@@ -223,25 +236,4 @@ private function resolveInternalRelations(array $columns, array $data) |
223 | 236 |
|
224 | 237 | return $referenceColumns; |
225 | 238 | } |
226 | | - |
227 | | - /** |
228 | | - * Get tables name with JSON type fields. |
229 | | - * |
230 | | - * @return array |
231 | | - */ |
232 | | - public function getTablesWithJsonTypeField(): array |
233 | | - { |
234 | | - return $this->tablesWithJsonTypeField; |
235 | | - } |
236 | | - |
237 | | - /** |
238 | | - * Set tables name with JSON type fields. |
239 | | - * |
240 | | - * @param array $tablesWithJsonTypeField |
241 | | - * @return array |
242 | | - */ |
243 | | - public function setTablesWithJsonTypeField(array $tablesWithJsonTypeField): array |
244 | | - { |
245 | | - return $this->tablesWithJsonTypeField = $tablesWithJsonTypeField; |
246 | | - } |
247 | 239 | } |
0 commit comments