1
1
<?php
2
2
/**
3
- * Copyright 2017 Adobe All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2017 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
16
16
use Magento \Framework \Setup \Declaration \Schema \Sharding ;
17
17
use Magento \Framework \Config \FileResolverByModule ;
18
18
use Magento \Framework \Setup \Declaration \Schema \Declaration \ReaderComposite ;
19
+ use Psr \Log \LoggerInterface ;
20
+ use Magento \Framework \Exception \LocalizedException ;
21
+ use Magento \Framework \App \ObjectManager ;
19
22
20
23
/**
21
24
* This type of builder is responsible for converting ENTIRE data, that comes from db
27
30
*
28
31
* @see Schema
29
32
* @inheritdoc
33
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30
34
*/
31
35
class SchemaBuilder
32
36
{
@@ -55,30 +59,39 @@ class SchemaBuilder
55
59
*/
56
60
private $ readerComposite ;
57
61
62
+ /**
63
+ * @var LoggerInterface
64
+ */
65
+ private $ logger ;
66
+
58
67
/**
59
68
* Constructor.
60
69
*
61
70
* @param ElementFactory $elementFactory
62
71
* @param DbSchemaReaderInterface $dbSchemaReader
63
72
* @param Sharding $sharding
64
73
* @param ReaderComposite $readerComposite
74
+ * @param LoggerInterface $logger
65
75
*/
66
76
public function __construct (
67
77
ElementFactory $ elementFactory ,
68
78
DbSchemaReaderInterface $ dbSchemaReader ,
69
79
Sharding $ sharding ,
70
- ReaderComposite $ readerComposite
80
+ ReaderComposite $ readerComposite ,
81
+ ?LoggerInterface $ logger = null
71
82
) {
72
83
$ this ->elementFactory = $ elementFactory ;
73
84
$ this ->dbSchemaReader = $ dbSchemaReader ;
74
85
$ this ->sharding = $ sharding ;
75
86
$ this ->readerComposite = $ readerComposite ;
87
+ $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
76
88
}
77
89
78
90
/**
79
91
* @inheritdoc
80
92
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
81
93
* @SuppressWarnings(PHPMD.NPathComplexity)
94
+ * @throws LocalizedException
82
95
*/
83
96
public function build (Schema $ schema )
84
97
{
@@ -88,8 +101,22 @@ public function build(Schema $schema)
88
101
foreach ($ data ['table ' ] as $ keyTable => $ tableColumns ) {
89
102
$ tableColumns ['column ' ] ??= [];
90
103
foreach ($ tableColumns ['column ' ] as $ keyColumn => $ columnData ) {
91
- if ($ columnData ['type ' ] == 'json ' ) {
92
- $ tablesWithJsonTypeField [$ keyTable ] = $ keyColumn ;
104
+ try {
105
+ if ($ columnData ['type ' ] == 'json ' ) {
106
+ $ tablesWithJsonTypeField [$ keyTable ] = $ keyColumn ;
107
+ }
108
+ } catch (\Throwable $ e ) {
109
+ // Create a new exception with extended context message
110
+ $ errorMessage = sprintf (
111
+ "%s \nError processing table %s column %s " ,
112
+ $ e ->getMessage (),
113
+ $ keyTable ,
114
+ $ keyColumn
115
+ );
116
+ $ this ->logger ->error ($ errorMessage );
117
+ // Throw a new exception with the extended message
118
+ // This preserves the original error but adds our context
119
+ throw new LocalizedException (new Phrase ($ errorMessage ));
93
120
}
94
121
}
95
122
}
0 commit comments