diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 8029a4ce3c..89cd27e256 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -33,6 +33,7 @@ Yii Framework 2 Change Log - Bug #11774: Fixed incorrect recusuive symlinks check in FileHelper (AnikanovD) - Bug #11739: Fixed `ArrayHelper::index()` losing precision for float keys (AnikanovD) - Bug #11549: Fixed `ArrayHelper::getValue()` to work properly with float keys (zsounder, AnikanovD) +- Bug #8644: Fixed trying to ENABLE/DISABLE TRIGGER ALL on a view in PostgreSQL (ricpelo) 2.0.8 April 28, 2016 -------------------- diff --git a/framework/db/pgsql/QueryBuilder.php b/framework/db/pgsql/QueryBuilder.php index 7498ee2928..b544ee45b5 100644 --- a/framework/db/pgsql/QueryBuilder.php +++ b/framework/db/pgsql/QueryBuilder.php @@ -190,6 +190,8 @@ class QueryBuilder extends \yii\db\QueryBuilder $enable = $check ? 'ENABLE' : 'DISABLE'; $schema = $schema ? $schema : $this->db->getSchema()->defaultSchema; $tableNames = $table ? [$table] : $this->db->getSchema()->getTableNames($schema); + $viewNames = $this->db->getSchema()->getViewNames($schema); + $tableNames = array_diff($tableNames, $viewNames); $command = ''; foreach ($tableNames as $tableName) { diff --git a/framework/db/pgsql/Schema.php b/framework/db/pgsql/Schema.php index 1e7d3b5946..149245cb3d 100644 --- a/framework/db/pgsql/Schema.php +++ b/framework/db/pgsql/Schema.php @@ -107,6 +107,10 @@ class Schema extends \yii\db\Schema 'jsonb' => self::TYPE_STRING, 'xml' => self::TYPE_STRING, ]; + /** + * @var array list of ALL view names in the database + */ + private $_viewNames = []; /** @@ -212,6 +216,52 @@ SQL; return $names; } + /** + * Returns all views names in the database. + * @param string $schema the schema of the views. Defaults to empty string, meaning the current or default schema. + * @return array all views names in the database. The names have NO schema name prefix. + * @since 2.0.9 + */ + protected function findViewNames($schema = '') + { + if ($schema === '') { + $schema = $this->defaultSchema; + } + $sql = <<db->createCommand($sql, [':schemaName' => $schema]); + $rows = $command->queryAll(); + $names = []; + foreach ($rows as $row) { + $names[] = $row['table_name']; + } + + return $names; + } + + /** + * Returns all view names in the database. + * @param string $schema the schema of the views. Defaults to empty string, meaning the current or default schema name. + * If not empty, the returned view names will be prefixed with the schema name. + * @param boolean $refresh whether to fetch the latest available view names. If this is false, + * view names fetched previously (if available) will be returned. + * @return string[] all view names in the database. + * @since 2.0.9 + */ + public function getViewNames($schema = '', $refresh = false) + { + if (!isset($this->_viewNames[$schema]) || $refresh) { + $this->_viewNames[$schema] = $this->findViewNames($schema); + } + + return $this->_viewNames[$schema]; + } + /** * Collects the foreign key column details for the given table. * @param TableSchema $table the table metadata