Skip to content

Commit 85742a8

Browse files
batyrmastyrsamdarkCopilotTigrovvjik
authored
Fix #1127 Schema->hasTable and Schema->hasView does not support yii-quoted names (#1128)
* Fix #1127 Schema->hasTable and Schema->hasView does not support yii-quoted names * Update CHANGELOG.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Sergei Tigrov <rrr-r@ya.ru> * Update CHANGELOG.md Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com> * Update tests/Common/CommonSchemaTest.php Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com> --------- Co-authored-by: Alexander Makarov <sam@rmcreative.ru> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sergei Tigrov <rrr-r@ya.ru> Co-authored-by: Sergei Predvoditelev <sergey.predvoditelev@gmail.com>
1 parent 25c359f commit 85742a8

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## 2.0.1 under development
44

5-
- no changes in this release.
5+
- Bug #1127: Fix `AbstractSchema::hasTable()` and `AbstractSchema::hasView()` methods to support names quoted with curly
6+
brackets `{{%table}}` (@batyrmastyr)
67

78
## 2.0.0 December 05, 2025
89

src/Schema/AbstractSchema.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ public function getViewNames(string $schema = '', bool $refresh = false): array
270270
public function hasTable(string $tableName, string $schema = '', bool $refresh = false): bool
271271
{
272272
$tables = $this->getTableNames($schema, $refresh);
273+
$rawTableName = $this->db->getQuoter()->getRawTableName($tableName);
273274

274-
return in_array($tableName, $tables);
275+
return in_array($rawTableName, $tables);
275276
}
276277

277278
public function hasSchema(string $schema, bool $refresh = false): bool
@@ -284,8 +285,9 @@ public function hasSchema(string $schema, bool $refresh = false): bool
284285
public function hasView(string $viewName, string $schema = '', bool $refresh = false): bool
285286
{
286287
$views = $this->getViewNames($schema, $refresh);
288+
$rawViewName = $this->db->getQuoter()->getRawTableName($viewName);
287289

288-
return in_array($viewName, $views);
290+
return in_array($rawViewName, $views);
289291
}
290292

291293
/**

tests/Common/CommonSchemaTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ public function testHasTable(): void
283283
$schema = $db->getSchema();
284284

285285
$tempTableName = 'testTemporaryTable';
286+
$this->dropTable('testTemporaryTable');
287+
286288
$db->createCommand()
287289
->createTable(
288290
$tempTableName,
@@ -294,7 +296,8 @@ public function testHasTable(): void
294296
->execute();
295297

296298
$this->assertTrue($schema->hasTable('order'));
297-
$this->assertTrue($schema->hasTable($tempTableName));
299+
$this->assertTrue($schema->hasTable($tempTableName), 'raw new table name');
300+
$this->assertTrue($schema->hasTable('{{%' . $tempTableName . '}}'), 'quoted new table name');
298301
$this->assertFalse($schema->hasTable('no_such_table'));
299302

300303
$db->createCommand()->dropTable($tempTableName)->execute();
@@ -409,6 +412,7 @@ public function testHasView(): void
409412

410413
$this->assertTrue($schema->hasView('v1'));
411414
$this->assertTrue($schema->hasView('v2'));
415+
$this->assertTrue($schema->hasView('{{%v2}}'), 'quoted view name');
412416
$this->assertFalse($schema->hasView('v3'));
413417

414418
$db->createCommand()->dropView('v1')->execute();

0 commit comments

Comments
 (0)