Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
briedis authored Jun 19, 2024
2 parents 783a5f8 + 8dacd2a commit 0e9d2c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 33 deletions.
2 changes: 2 additions & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Yii Framework 2 Change Log
2.0.51 under development
------------------------

- Bug #20195: Do not set non abstract values into `ColumnSchema->type` on MSSQL version less then 2017 (axeltomasson)
- Bug #16116: Codeception: oci does not support enabling/disabling integrity check (@terabytesoftw)
- Bug #20191: Fix `ActiveRecord::getDirtyAttributes()` for JSON columns with multi-dimensional array values (brandonkelly)
- Bug #20175: Fix bad result for pagination when used with GridView (@lav45)
- Enh #20198: Boolean values of the `value` HTML attribute are now converted to integer values (@s1lver)


2.0.50 May 30, 2024
Expand Down
11 changes: 2 additions & 9 deletions framework/data/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ protected function prepareKeys($models)
return array_keys($models);
}

private $_totalCount = [];

/**
* {@inheritdoc}
*/
Expand All @@ -161,13 +159,8 @@ protected function prepareTotalCount()
if (!$this->query instanceof QueryInterface) {
throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.');
}
$query = (clone $this->query)->limit(-1)->offset(-1)->orderBy([]);
$key = md5((string)$query);

if (!array_key_exists($key, $this->_totalCount)) {
$this->_totalCount[$key] = (int)$query->count('*', $this->db);
}
return $this->_totalCount[$key];
$query = clone $this->query;
return (int) $query->limit(-1)->offset(-1)->orderBy([])->count('*', $this->db);
}

/**
Expand Down
32 changes: 9 additions & 23 deletions framework/db/mssql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,15 @@ protected function loadColumnSchema($info)
}

if ($isVersion2017orLater === false) {
$column->type = $this->booleanTypeLegacy($column->size, $type);
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
$column->type = 'boolean';
} elseif ($type === 'bit') {
if ($column->size > 32) {
$column->type = 'bigint';
} elseif ($column->size === 32) {
$column->type = 'integer';
}
}
}
}
}
Expand Down Expand Up @@ -816,26 +824,4 @@ public function createColumnSchemaBuilder($type, $length = null)
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length, $this->db]);
}

/**
* Assigns a type boolean for the column type bit, for legacy versions of MSSQL.
*
* @param int $size column size.
* @param string $type column type.
*
* @return string column type.
*/
private function booleanTypeLegacy($size, $type)
{
if ($size === 1 && ($type === 'tinyint' || $type === 'bit')) {
return 'boolean';
} elseif ($type === 'bit') {
if ($size > 32) {
return 'bigint';
} elseif ($size === 32) {
return 'integer';
}
}

return $type;
}
}
4 changes: 3 additions & 1 deletion framework/helpers/BaseHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,10 @@ public static function renderTagAttributes($attributes)
$html = '';
foreach ($attributes as $name => $value) {
if (is_bool($value)) {
if ($value) {
if ($value && 'value' !== $name) {
$html .= " $name";
} elseif ('value' === $name) {
$html .= " $name=\"" . static::encode((int)$value) . '"';
}
} elseif (is_array($value)) {
if (in_array($name, static::$dataAttributes)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/framework/helpers/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,16 @@ public function testRenderTagAttributes()
$this->assertEquals('', Html::renderTagAttributes(['class' => []]));
$this->assertEquals(' style="width: 100px; height: 200px;"', Html::renderTagAttributes(['style' => ['width' => '100px', 'height' => '200px']]));
$this->assertEquals('', Html::renderTagAttributes(['style' => []]));
$this->assertEquals(' type="submit" value="1"', Html::renderTagAttributes(['type' => 'submit', 'value' => true]));
$this->assertEquals(' type="submit" value="0"', Html::renderTagAttributes(['type' => 'submit', 'value' => false]));
$this->assertEquals(
' type="submit" value="1" disabled',
Html::renderTagAttributes(['type' => 'submit', 'value' => true, 'disabled' => true])
);
$this->assertEquals(
' type="submit" value="0"',
Html::renderTagAttributes(['type' => 'submit', 'value' => false, 'disabled' => false])
);

$attributes = [
'data' => [
Expand Down

0 comments on commit 0e9d2c3

Please sign in to comment.