From 0e139615b8d80d5aea70b2c766b4f1c3c2fe87e9 Mon Sep 17 00:00:00 2001 From: anas-srikou Date: Fri, 6 Jan 2023 11:30:03 +0900 Subject: [PATCH] DP-553 Add logging to catch exception and write them to file --- src/Database/Schema/TableSchema.php | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Database/Schema/TableSchema.php b/src/Database/Schema/TableSchema.php index 22b39974..c4a01511 100644 --- a/src/Database/Schema/TableSchema.php +++ b/src/Database/Schema/TableSchema.php @@ -3,6 +3,7 @@ namespace DreamFactory\Core\Database\Schema; use DreamFactory\Core\Enums\DbSimpleTypes; +use Illuminate\Support\Facades\Log; /** @@ -203,20 +204,28 @@ public function getColumnNames($use_alias = false) * * @return ColumnSchema[] */ - public function getColumns($use_alias = false) + public function getColumns(bool $use_alias = false): array { - if ($use_alias) { - // re-index for alias usage, easier to find requested fields from client - $columns = []; - /** @var ColumnSchema $column */ + if (!$use_alias) { + return !is_array($this->columns) ? [] : $this->columns; + } + + // re-index for alias usage, easier to find requested fields from client + $columns = []; + $this->columns = null; + + /** @var ColumnSchema $column */ + try { foreach ($this->columns as $column) { $columns[strtolower($column->getName(true))] = $column; } - - return $columns; + } catch (\Exception $exception) { + Log::info("Columns field type: " . gettype($this->columns)); + Log::error($exception->getMessage()); + Log::error($exception->getTraceAsString()); } - return $this->columns; + return $columns; } public function addRelation(RelationSchema $relation) @@ -301,9 +310,16 @@ public function toArray($use_alias = false) $fields = []; /** @var ColumnSchema $column */ - foreach ($this->columns as $column) { - $fields[] = $column->toArray($use_alias); + try { + foreach ($this->columns as $column) { + $fields[] = $column->toArray($use_alias); + } + } catch (\Exception $exception) { + Log::info("Columns field type: " . gettype($this->columns)); + Log::error($exception->getMessage()); + Log::error($exception->getTraceAsString()); } + $out['field'] = $fields; $relations = [];