11<?php
22/**
3- * Copyright 2017 Adobe All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2017 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
1616use Magento \Framework \Setup \Declaration \Schema \Sharding ;
1717use Magento \Framework \Config \FileResolverByModule ;
1818use Magento \Framework \Setup \Declaration \Schema \Declaration \ReaderComposite ;
19+ use Psr \Log \LoggerInterface ;
20+ use Magento \Framework \Exception \LocalizedException ;
21+ use Magento \Framework \App \ObjectManager ;
1922
2023/**
2124 * This type of builder is responsible for converting ENTIRE data, that comes from db
2730 *
2831 * @see Schema
2932 * @inheritdoc
33+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3034 */
3135class SchemaBuilder
3236{
@@ -55,30 +59,39 @@ class SchemaBuilder
5559 */
5660 private $ readerComposite ;
5761
62+ /**
63+ * @var LoggerInterface
64+ */
65+ private $ logger ;
66+
5867 /**
5968 * Constructor.
6069 *
6170 * @param ElementFactory $elementFactory
6271 * @param DbSchemaReaderInterface $dbSchemaReader
6372 * @param Sharding $sharding
6473 * @param ReaderComposite $readerComposite
74+ * @param LoggerInterface $logger
6575 */
6676 public function __construct (
6777 ElementFactory $ elementFactory ,
6878 DbSchemaReaderInterface $ dbSchemaReader ,
6979 Sharding $ sharding ,
70- ReaderComposite $ readerComposite
80+ ReaderComposite $ readerComposite ,
81+ ?LoggerInterface $ logger = null
7182 ) {
7283 $ this ->elementFactory = $ elementFactory ;
7384 $ this ->dbSchemaReader = $ dbSchemaReader ;
7485 $ this ->sharding = $ sharding ;
7586 $ this ->readerComposite = $ readerComposite ;
87+ $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
7688 }
7789
7890 /**
7991 * @inheritdoc
8092 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
8193 * @SuppressWarnings(PHPMD.NPathComplexity)
94+ * @throws LocalizedException
8295 */
8396 public function build (Schema $ schema )
8497 {
@@ -88,8 +101,22 @@ public function build(Schema $schema)
88101 foreach ($ data ['table ' ] as $ keyTable => $ tableColumns ) {
89102 $ tableColumns ['column ' ] ??= [];
90103 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 ));
93120 }
94121 }
95122 }
0 commit comments