Skip to content

Commit

Permalink
Merge pull request #19968 from terabytesoftw/remove-deprecated-colums…
Browse files Browse the repository at this point in the history
…chema

Remove deprecated methods to `ColumnSchema::class`.
  • Loading branch information
bizley authored Sep 22, 2023
2 parents 62be1e6 + 4c86705 commit 57d5796
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 56 deletions.
15 changes: 2 additions & 13 deletions framework/db/mysql/ColumnSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@
*/
class ColumnSchema extends \yii\db\ColumnSchema
{
/**
* @var bool whether the column schema should OMIT using JSON support feature.
* You can use this property to make upgrade to Yii 2.0.14 easier.
* Default to `false`, meaning JSON support is enabled.
*
* @since 2.0.14.1
* @deprecated Since 2.0.14.1 and will be removed in 2.1.
*/
public $disableJsonSupport = false;


/**
* {@inheritdoc}
*/
Expand All @@ -42,7 +31,7 @@ public function dbTypecast($value)
return $value;
}

if (!$this->disableJsonSupport && $this->dbType === Schema::TYPE_JSON) {
if ($this->dbType === Schema::TYPE_JSON) {
return new JsonExpression($value, $this->type);
}

Expand All @@ -58,7 +47,7 @@ public function phpTypecast($value)
return null;
}

if (!$this->disableJsonSupport && $this->type === Schema::TYPE_JSON) {
if ($this->type === Schema::TYPE_JSON) {
return json_decode($value, true);
}

Expand Down
42 changes: 4 additions & 38 deletions framework/db/pgsql/ColumnSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,6 @@ class ColumnSchema extends \yii\db\ColumnSchema
* @var int the dimension of array. Defaults to 0, means this column is not an array.
*/
public $dimension = 0;
/**
* @var bool whether the column schema should OMIT using JSON support feature.
* You can use this property to make upgrade to Yii 2.0.14 easier.
* Default to `false`, meaning JSON support is enabled.
*
* @since 2.0.14.1
* @deprecated Since 2.0.14.1 and will be removed in 2.1.
*/
public $disableJsonSupport = false;
/**
* @var bool whether the column schema should OMIT using PgSQL Arrays support feature.
* You can use this property to make upgrade to Yii 2.0.14 easier.
* Default to `false`, meaning Arrays support is enabled.
*
* @since 2.0.14.1
* @deprecated Since 2.0.14.1 and will be removed in 2.1.
*/
public $disableArraySupport = false;
/**
* @var bool whether the Array column value should be unserialized to an [[ArrayExpression]] object.
* You can use this property to make upgrade to Yii 2.0.14 easier.
* Default to `true`, meaning arrays are unserialized to [[ArrayExpression]] objects.
*
* @since 2.0.14.1
* @deprecated Since 2.0.14.1 and will be removed in 2.1.
*/
public $deserializeArrayColumnToArrayExpression = true;
/**
* @var string name of associated sequence if column is auto-incremental
* @since 2.0.29
Expand All @@ -70,11 +43,9 @@ public function dbTypecast($value)
}

if ($this->dimension > 0) {
return $this->disableArraySupport
? (string) $value
: new ArrayExpression($value, $this->dbType, $this->dimension);
return new ArrayExpression($value, $this->dbType, $this->dimension);
}
if (!$this->disableJsonSupport && in_array($this->dbType, [Schema::TYPE_JSON, Schema::TYPE_JSONB], true)) {
if (in_array($this->dbType, [Schema::TYPE_JSON, Schema::TYPE_JSONB], true)) {
return new JsonExpression($value, $this->dbType);
}

Expand All @@ -87,9 +58,6 @@ public function dbTypecast($value)
public function phpTypecast($value)
{
if ($this->dimension > 0) {
if ($this->disableArraySupport) {
return $value;
}
if (!is_array($value)) {
$value = $this->getArrayParser()->parse($value);
}
Expand All @@ -101,9 +69,7 @@ public function phpTypecast($value)
return null;
}

return $this->deserializeArrayColumnToArrayExpression
? new ArrayExpression($value, $this->dbType, $this->dimension)
: $value;
return $value;
}

return $this->phpTypecastValue($value);
Expand Down Expand Up @@ -133,7 +99,7 @@ protected function phpTypecastValue($value)
}
return (bool) $value;
case Schema::TYPE_JSON:
return $this->disableJsonSupport ? $value : json_decode($value, true);
return json_decode($value, true);
}

return parent::phpTypecast($value);
Expand Down
11 changes: 8 additions & 3 deletions tests/framework/db/pgsql/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,17 @@ public function testArrayValues(array $attributes): void
$expected = isset($expected[1]) ? $expected[1] : $expected[0];
$value = $type->$attribute;

if ($expected instanceof ArrayExpression) {
$expected = $expected->getValue();
}

$this->assertEquals($expected, $value, 'In column ' . $attribute);

if ($value instanceof ArrayExpression) {
$this->assertInstanceOf('\ArrayAccess', $value);
$this->assertInstanceOf('\Traversable', $value);
foreach ($type->$attribute as $key => $v) { // testing arrayaccess
$this->assertInstanceOf(ArrayAccess::class, $value);
$this->assertInstanceOf(Traversable::class, $value);
/** testing arrayaccess */
foreach ($type->$attribute as $key => $v) {
$this->assertSame($expected[$key], $value[$key]);
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/framework/db/pgsql/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,13 @@ public function testCustomTypeInNonDefaultSchema()

$schema = $connection->schema->getTableSchema('schema2.custom_type_test_table');
$model = EnumTypeInCustomSchema::find()->one();
$this->assertSame(['VAL2'], $model->test_type->getValue());

$this->assertSame(['VAL2'], $model->test_type);

$model->test_type = ['VAL1'];
$model->save();

$modelAfterUpdate = EnumTypeInCustomSchema::find()->one();
$this->assertSame(['VAL1'], $modelAfterUpdate->test_type->getValue());
$this->assertSame(['VAL1'], $modelAfterUpdate->test_type);
}
}

0 comments on commit 57d5796

Please sign in to comment.