Browse Source

Fixes #15353: Remove side effect of ActiveQuery::getTablesUsedInFrom() introduced in 2.0.13

tags/2.0.14
Alexander 7 years ago committed by Alexander Makarov
parent
commit
f8990ac97a
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/db/ActiveQuery.php
  3. 13
      framework/db/Query.php
  4. 8
      tests/framework/db/ActiveQueryTest.php

1
framework/CHANGELOG.md

@ -25,6 +25,7 @@ Yii Framework 2 Change Log
- Bug #15317: Regenerate CSRF token if an empty value is given (sammousa) - Bug #15317: Regenerate CSRF token if an empty value is given (sammousa)
- Bug #15320: Fixed special role checks in `yii\filters\AccessRule::matchRole()` (Izumi-kun) - Bug #15320: Fixed special role checks in `yii\filters\AccessRule::matchRole()` (Izumi-kun)
- Bug #15322: Fixed PHP 7.2 compatibility of `FileHelper::getExtensionsByMimeType()` (samdark) - Bug #15322: Fixed PHP 7.2 compatibility of `FileHelper::getExtensionsByMimeType()` (samdark)
- Bug #15353: Remove side effect of ActiveQuery::getTablesUsedInFrom() introduced in 2.0.13 (terales)
- Bug #15355: Fixed `yii\db\Query::from()` does not work with `yii\db\Expression` (vladis84, silverfire, samdark) - Bug #15355: Fixed `yii\db\Query::from()` does not work with `yii\db\Expression` (vladis84, silverfire, samdark)
- Bug #15356: Fixed multiple bugs in `yii\db\Query::getTablesUsedInFrom()` (vladis84, samdark) - Bug #15356: Fixed multiple bugs in `yii\db\Query::getTablesUsedInFrom()` (vladis84, samdark)
- Bug #15380: `FormatConverter::convertDateIcuToPhp()` now converts `a` ICU symbols to `A` (brandonkelly) - Bug #15380: `FormatConverter::convertDateIcuToPhp()` now converts `a` ICU symbols to `A` (brandonkelly)

2
framework/db/ActiveQuery.php

@ -809,7 +809,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
public function getTablesUsedInFrom() public function getTablesUsedInFrom()
{ {
if (empty($this->from)) { if (empty($this->from)) {
$this->from = [$this->getPrimaryTableName()]; return $this->cleanUpTableNames([$this->getPrimaryTableName()]);
} }
return parent::getTablesUsedInFrom(); return parent::getTablesUsedInFrom();

13
framework/db/Query.php

@ -479,7 +479,18 @@ class Query extends Component implements QueryInterface
throw new InvalidConfigException(gettype($this->from) . ' in $from is not supported.'); throw new InvalidConfigException(gettype($this->from) . ' in $from is not supported.');
} }
// Clean up table names and aliases return $this->cleanUpTableNames($tableNames);
}
/**
* Clean up table names and aliases
* Both aliases and names are enclosed into {{ and }}.
* @param array $tableNames non-empty array
* @return string[] table names indexed by aliases
* @since 2.0.14
*/
protected function cleanUpTableNames($tableNames)
{
$cleanedUpTableNames = []; $cleanedUpTableNames = [];
foreach ($tableNames as $alias => $tableName) { foreach ($tableNames as $alias => $tableName) {
if (is_string($tableName) && !is_string($alias)) { if (is_string($tableName) && !is_string($alias)) {

8
tests/framework/db/ActiveQueryTest.php

@ -253,4 +253,12 @@ abstract class ActiveQueryTest extends DatabaseTestCase
'{{' . Profile::tableName() . '}}' => '{{' . Profile::tableName() . '}}', '{{' . Profile::tableName() . '}}' => '{{' . Profile::tableName() . '}}',
], $tables); ], $tables);
} }
public function testGetTableNames_wontFillFrom()
{
$query = new ActiveQuery(Profile::className());
$this->assertEquals($query->from, null);
$query->getTablesUsedInFrom();
$this->assertEquals($query->from, null);
}
} }

Loading…
Cancel
Save