From 50672a1afc337a2f29771305031329a151388622 Mon Sep 17 00:00:00 2001 From: Daniil Lytvyn Date: Fri, 30 Dec 2022 10:02:01 +0200 Subject: [PATCH] DP-460 Upgrade to PHP 8.1 / Laravel 9 - 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. --- composer.json | 4 +- src/Database/Schema/OracleSchema.php | 59 ++++++++++++++-------------- src/Models/OracleDbConfig.php | 7 ++-- src/Resources/OracleTable.php | 15 ++++--- src/ServiceProvider.php | 2 +- src/Services/OracleDb.php | 5 ++- 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/composer.json b/composer.json index 250151d..a70fabc 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Database/Schema/OracleSchema.php b/src/Database/Schema/OracleSchema.php index f124759..8640925 100644 --- a/src/Database/Schema/OracleSchema.php +++ b/src/Database/Schema/OracleSchema.php @@ -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. @@ -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']); @@ -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 = <<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) { @@ -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']); @@ -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 = <<extractDefault($c, $column['data_default']); - $c->comment = array_get($column, 'column_comment', ''); + $c->comment = Arr::get($column, 'column_comment', ''); return $c; } @@ -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); @@ -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);; @@ -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);; @@ -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; @@ -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'), ] )); } @@ -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': diff --git a/src/Models/OracleDbConfig.php b/src/Models/OracleDbConfig.php index ebbf05c..0530897 100644 --- a/src/Models/OracleDbConfig.php +++ b/src/Models/OracleDbConfig.php @@ -3,6 +3,7 @@ use DreamFactory\Core\Exceptions\BadRequestException; use DreamFactory\Core\SqlDb\Models\SqlDbConfig; +use Arr; /** * OracleDbConfig @@ -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)."); } diff --git a/src/Resources/OracleTable.php b/src/Resources/OracleTable.php index 1eeeb13..c2111a5 100644 --- a/src/Resources/OracleTable.php +++ b/src/Resources/OracleTable.php @@ -9,7 +9,7 @@ use DreamFactory\Core\SqlDb\Resources\Table; use Illuminate\Database\Query\Builder; use Illuminate\Support\Collection; - +use Arr; /** * Class Table @@ -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)) { @@ -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(); } @@ -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; } @@ -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"); diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 555574f..8cdf55c 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -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); }); diff --git a/src/Services/OracleDb.php b/src/Services/OracleDb.php index 373728c..6af27d3 100644 --- a/src/Services/OracleDb.php +++ b/src/Services/OracleDb.php @@ -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 @@ -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);