Skip to content

Commit

Permalink
DP-553 Add logging to catch exception and write them to file
Browse files Browse the repository at this point in the history
  • Loading branch information
anas-srikou authored and daniilly committed Feb 28, 2023
1 parent c70512e commit 0e13961
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/Database/Schema/TableSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DreamFactory\Core\Database\Schema;

use DreamFactory\Core\Enums\DbSimpleTypes;
use Illuminate\Support\Facades\Log;


/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = [];
Expand Down

0 comments on commit 0e13961

Please sign in to comment.