Skip to content

Commit

Permalink
DP-460 Upgrade to PHP 8.1 / Laravel 9
Browse files Browse the repository at this point in the history
- Update dependencies
- Get rid of global helper functions
- Resolve conflict with db.schema component

App code used `db.schema` name for  `DbSchemaExtensions` component.
Starting from Laravel 9 this name is used internally
because of migration to string based accessor for Schema facade
laravel/framework@8059b39.
The cure is to use `df` prefix for app `db.schema` component.
  • Loading branch information
daniilly committed Mar 2, 2023
1 parent 545f880 commit 50672a1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 45 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"dreamfactory/df-sqldb": "~0.17",
"yajra/laravel-oci8": "5.5.*|5.6.*|5.7.*|5.8.*|^6.0"
"dreamfactory/df-sqldb": "~1.0",
"yajra/laravel-oci8": "^9.0"
},
"autoload": {
"psr-4": {
Expand Down
59 changes: 30 additions & 29 deletions src/Database/Schema/OracleSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use DreamFactory\Core\Database\Schema\TableSchema;
use DreamFactory\Core\Enums\DbSimpleTypes;
use DreamFactory\Core\SqlDb\Database\Schema\SqlSchema;
use Arr;

/**
* Schema is the class for retrieving metadata information from an Oracle database.
Expand Down Expand Up @@ -306,7 +307,7 @@ protected function loadTableColumns(TableSchema $table)
$c->quotedName = $this->quoteColumnName($c->name);
$c->autoIncrement = array_get_bool($column, 'identity_column');
$c->allowNull = $column['nullable'] === 'Y';
$c->isPrimaryKey = strpos(strval(array_get($column, 'key')), 'P') !== false;
$c->isPrimaryKey = strpos(strval(Arr::get($column, 'key')), 'P') !== false;
$c->dbType = $column['data_type'];
$c->precision = intval($column['data_precision']);
$c->scale = intval($column['data_scale']);
Expand All @@ -327,12 +328,12 @@ protected function loadTableColumns(TableSchema $table)
$this->extractLimit($c, $c->dbType);
$c->fixedLength = $this->extractFixedLength($c->dbType);
$c->supportsMultibyte = $this->extractMultiByteSupport($c->dbType);
$collectionType = array_get($column, 'collection_type');
$collectionType = Arr::get($column, 'collection_type');
switch (strtolower($collectionType)) {
case 'table':
$this->extractType($c, 'table');
$nestedTable = array_get($column, 'nested_table_name');
$nestedTableOwner = array_get($column, 'nested_table_owner');
$nestedTable = Arr::get($column, 'nested_table_name');
$nestedTableOwner = Arr::get($column, 'nested_table_owner');
$sql = <<<EOD
SELECT column_name, data_type, data_precision, data_scale, data_length, nullable, data_default
FROM ALL_NESTED_TABLE_COLS
Expand All @@ -357,7 +358,7 @@ protected function loadTableColumns(TableSchema $table)
break;
}
$this->extractDefault($c, $column['data_default']);
$c->comment = array_get($column, 'column_comment', '');
$c->comment = Arr::get($column, 'column_comment', '');

if ($c->isPrimaryKey) {
foreach ($triggers as $trigger) {
Expand Down Expand Up @@ -389,10 +390,10 @@ protected function loadTableColumns(TableSchema $table)
protected function createColumn($column)
{
$c = new ColumnSchema(['name' => $column['column_name']]);
$c->autoIncrement = array_get($column, 'auto_increment', false);
$c->autoIncrement = Arr::get($column, 'auto_increment', false);
$c->quotedName = $this->quoteColumnName($c->name);
$c->allowNull = $column['nullable'] === 'Y';
$c->isPrimaryKey = strpos(strval(array_get($column, 'key')), 'P') !== false;
$c->isPrimaryKey = strpos(strval(Arr::get($column, 'key')), 'P') !== false;
$c->dbType = $column['data_type'];
$c->precision = intval($column['data_precision']);
$c->scale = intval($column['data_scale']);
Expand All @@ -413,12 +414,12 @@ protected function createColumn($column)
$this->extractLimit($c, $c->dbType);
$c->fixedLength = $this->extractFixedLength($c->dbType);
$c->supportsMultibyte = $this->extractMultiByteSupport($c->dbType);
$collectionType = array_get($column, 'collection_type');
$collectionType = Arr::get($column, 'collection_type');
switch (strtolower($collectionType)) {
case 'table':
$this->extractType($c, 'table');
$nestedTable = array_get($column, 'nested_table_name');
$nestedTableOwner = array_get($column, 'nested_table_owner');
$nestedTable = Arr::get($column, 'nested_table_name');
$nestedTableOwner = Arr::get($column, 'nested_table_owner');
$sql = <<<EOD
SELECT column_name, data_type, data_precision, data_scale, data_length, nullable, data_default
FROM ALL_NESTED_TABLE_COLS
Expand All @@ -443,7 +444,7 @@ protected function createColumn($column)
break;
}
$this->extractDefault($c, $column['data_default']);
$c->comment = array_get($column, 'column_comment', '');
$c->comment = Arr::get($column, 'column_comment', '');

return $c;
}
Expand Down Expand Up @@ -477,8 +478,8 @@ protected function getTableConstraints($schema = '')
if ('R' === $row['constraint_type']) {
$row['constraint_type'] = 'foreign key';
}
$colName = array_get($row, 'column_name');
$refColName = array_get($row, 'referenced_column_name');
$colName = Arr::get($row, 'column_name');
$refColName = Arr::get($row, 'referenced_column_name');
if (isset($constraints[$ts][$tn][$cn])) {
$constraints[$ts][$tn][$cn]['column_name'] =
array_merge((array)$constraints[$ts][$tn][$cn]['column_name'], (array)$colName);
Expand Down Expand Up @@ -522,8 +523,8 @@ protected function getTableNames($schema = '')
$names = [];
foreach ($rows as $row) {
$row = array_change_key_case((array)$row, CASE_UPPER);
$schemaName = array_get($row, 'TABLE_SCHEMA', '');
$resourceName = array_get($row, 'TABLE_NAME', '');
$schemaName = Arr::get($row, 'TABLE_SCHEMA', '');
$resourceName = Arr::get($row, 'TABLE_NAME', '');
$internalName = $schemaName . '.' . $resourceName;
$name = $resourceName;
$quotedName = $this->quoteTableName($schemaName) . '.' . $this->quoteTableName($resourceName);;
Expand Down Expand Up @@ -552,8 +553,8 @@ protected function getViewNames($schema = '')
$names = [];
foreach ($rows as $row) {
$row = array_change_key_case((array)$row, CASE_UPPER);
$schemaName = array_get($row, 'TABLE_SCHEMA', '');
$resourceName = array_get($row, 'TABLE_NAME', '');
$schemaName = Arr::get($row, 'TABLE_SCHEMA', '');
$resourceName = Arr::get($row, 'TABLE_NAME', '');
$internalName = $schemaName . '.' . $resourceName;
$name = $resourceName;
$quotedName = $this->quoteTableName($schemaName) . '.' . $this->quoteTableName($resourceName);;
Expand Down Expand Up @@ -604,12 +605,12 @@ protected function getRoutineNames($type, $schema = '')
$names = [];
foreach ($rows as $row) {
$row = array_change_key_case((array)$row, CASE_UPPER);
$resourceName = array_get($row, 'OBJECT_NAME');
$resourceName = Arr::get($row, 'OBJECT_NAME');
$schemaName = $schema;
$internalName = $schemaName . '.' . $resourceName;
$name = $resourceName;
$quotedName = $this->quoteTableName($schemaName) . '.' . $this->quoteTableName($resourceName);
if (!empty($addPackage = array_get($row, 'PROCEDURE_NAME'))) {
if (!empty($addPackage = Arr::get($row, 'PROCEDURE_NAME'))) {
$resourceName .= '.' . $addPackage;
$name .= '.' . $addPackage;
$internalName .= '.' . $addPackage;
Expand Down Expand Up @@ -645,23 +646,23 @@ protected function loadParameters(RoutineSchema $holder)
$rows = $this->connection->select($sql, $bindings);
foreach ($rows as $row) {
$row = array_change_key_case((array)$row, CASE_UPPER);
$name = array_get($row, 'ARGUMENT_NAME');
$pos = intval(array_get($row, 'POSITION'));
$simpleType = static::extractSimpleType(array_get($row, 'DATA_TYPE'));
$name = Arr::get($row, 'ARGUMENT_NAME');
$pos = intval(Arr::get($row, 'POSITION'));
$simpleType = static::extractSimpleType(Arr::get($row, 'DATA_TYPE'));
if ((0 === $pos) || is_null($name)) {
$holder->returnType = $simpleType;
} else {
$holder->addParameter(new ParameterSchema([
'name' => $name,
'position' => $pos,
'param_type' => str_replace('/', '', array_get($row, 'IN_OUT')),
'param_type' => str_replace('/', '', Arr::get($row, 'IN_OUT')),
'type' => $simpleType,
'db_type' => array_get($row, 'DATA_TYPE'),
'length' => (isset($row['DATA_LENGTH']) ? intval(array_get($row, 'DATA_LENGTH')) : null),
'precision' => (isset($row['DATA_PRECISION']) ? intval(array_get($row, 'DATA_PRECISION'))
'db_type' => Arr::get($row, 'DATA_TYPE'),
'length' => (isset($row['DATA_LENGTH']) ? intval(Arr::get($row, 'DATA_LENGTH')) : null),
'precision' => (isset($row['DATA_PRECISION']) ? intval(Arr::get($row, 'DATA_PRECISION'))
: null),
'scale' => (isset($row['DATA_SCALE']) ? intval(array_get($row, 'DATA_SCALE')) : null),
'default_value' => array_get($row, 'DEFAULT_VALUE'),
'scale' => (isset($row['DATA_SCALE']) ? intval(Arr::get($row, 'DATA_SCALE')) : null),
'default_value' => Arr::get($row, 'DEFAULT_VALUE'),
]
));
}
Expand Down Expand Up @@ -969,7 +970,7 @@ protected function doRoutineBinding($statement, array $paramSchemas, array &$val
foreach ($paramSchemas as $key => $paramSchema) {
switch ($paramSchema->paramType) {
case 'IN':
$this->bindValue($statement, ':' . $paramSchema->name, array_get($values, $key));
$this->bindValue($statement, ':' . $paramSchema->name, Arr::get($values, $key));
break;
case 'INOUT':
case 'OUT':
Expand Down
7 changes: 4 additions & 3 deletions src/Models/OracleDbConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use DreamFactory\Core\Exceptions\BadRequestException;
use DreamFactory\Core\SqlDb\Models\SqlDbConfig;
use Arr;

/**
* OracleDbConfig
Expand All @@ -28,15 +29,15 @@ public static function getDefaultCharset()
public function validate($data, $throwException = true)
{
$connection = $this->getAttribute('connection');
if (!empty(array_get($connection, 'tns'))) {
if (!empty(Arr::get($connection, 'tns'))) {
return true; // overrides everything else
}

if (empty(array_get($connection, 'host'))) {
if (empty(Arr::get($connection, 'host'))) {
throw new BadRequestException("If not using TNS, connection information must contain host name.");
}

if (empty(array_get($connection, 'database')) && empty(array_get($connection, 'service_name'))) {
if (empty(Arr::get($connection, 'database')) && empty(Arr::get($connection, 'service_name'))) {
throw new BadRequestException("If not using TNS, connection information must contain either database (SID) or service_name (SERVICE_NAME).");
}

Expand Down
15 changes: 7 additions & 8 deletions src/Resources/OracleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use DreamFactory\Core\SqlDb\Resources\Table;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;

use Arr;

/**
* Class Table
Expand All @@ -20,7 +20,7 @@ class OracleTable extends Table
{
protected function getQueryResults(TableSchema $schema, Builder $builder, $extras)
{
$fields = array_get($extras, ApiOptions::FIELDS);
$fields = Arr::get($extras, ApiOptions::FIELDS);
$nestedFields = [];
$otherFields = [];
if (!empty($fields)) {
Expand Down Expand Up @@ -73,7 +73,7 @@ protected function getQueryResults(TableSchema $schema, Builder $builder, $extra
return $item;
});

$idFields = array_get($extras, ApiOptions::ID_FIELD);
$idFields = Arr::get($extras, ApiOptions::ID_FIELD);
if (empty($idFields)) {
$idFields = $schema->getPrimaryKey();
}
Expand All @@ -85,15 +85,14 @@ protected function getQueryResults(TableSchema $schema, Builder $builder, $extra
$result = [];
/** @var Collection $group */
foreach ($nestedResults as $group) {
$record = array_only($group->first(), array_keys($otherFields));
$record = Arr::only($group->first(), array_keys($otherFields));
foreach ($nestedFields as $nestedField => $nestedFieldInfo) {
$nestedTableFields = array_keys((array)array_get($nestedFieldInfo->native, 'nested_columns'));
$nestedTableFields = array_keys((array)Arr::get($nestedFieldInfo->native, 'nested_columns'));
$nestedOutput = [];
foreach ($group as $member) {
$nestedRecord = [];
foreach ($nestedTableFields as $nestedTableField) {
$nestedRecord[$nestedTableField] = array_get($member,
$nestedField . '_' . $nestedTableField, array_get($member, $nestedTableField));
$nestedRecord[$nestedTableField] = Arr::get($member, $nestedField . '_' . $nestedTableField, Arr::get($member, $nestedTableField));
}
$nestedOutput[] = $nestedRecord;
}
Expand All @@ -116,7 +115,7 @@ protected function parseFieldForSelect($field)
{
switch ($field->type) {
case DbSimpleTypes::TYPE_TABLE:
if (!empty($nestedTableFields = array_get($field->native, 'nested_columns'))) {
if (!empty($nestedTableFields = Arr::get($field->native, 'nested_columns'))) {
$nestedOutput = [];
foreach (array_keys($nestedTableFields) as $member) {
$nestedOutput[] = DB::raw($field->name . "_t.$member AS {$field->name}_$member");
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function register()
});

// Add our database extensions.
$this->app->resolving('db.schema', function (DbSchemaExtensions $db) {
$this->app->resolving('df.db.schema', function (DbSchemaExtensions $db) {
$db->extend('oracle', function ($connection) {
return new OracleSchema($connection);
});
Expand Down
5 changes: 3 additions & 2 deletions src/Services/OracleDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DreamFactory\Core\SqlDb\Resources\StoredProcedure;
use DreamFactory\Core\SqlDb\Services\SqlDb;
use DreamFactory\Core\SqlDb\Resources\Table;
use Arr;

/**
* Class OracleDb
Expand All @@ -25,10 +26,10 @@ public function __construct($settings = [])
parent::__construct($settings);

$prefix = parent::getConfigBasedCachePrefix();
if ($service = array_get($this->config, 'service_name')) {
if ($service = Arr::get($this->config, 'service_name')) {
$prefix = $service . $prefix;
}
if ($tns = array_get($this->config, 'tns')) {
if ($tns = Arr::get($this->config, 'tns')) {
$prefix = $tns . $prefix;
}
$this->setConfigBasedCachePrefix($prefix);
Expand Down

0 comments on commit 50672a1

Please sign in to comment.