From 1c92e4c3e57a164f2a24315c4ad0ab146b649dd9 Mon Sep 17 00:00:00 2001 From: Gevik Babakhani Date: Thu, 6 Jun 2013 22:45:30 +0200 Subject: [PATCH 1/7] Force travis to create a postgresql test database --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8dff4a3..da09923 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,6 @@ env: before_script: - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS yiitest;'; fi" - - sh -c "if [ '$DB' = 'postgres' ]; then psql -U postgres -c 'drop database if exists yiitest;'; fi" - - sh -c "if [ '$DB' = 'postgres' ]; then psql -U postgres -c 'create database yiitest;'; fi" + - psql -U postgres -c 'drop database if exists yiitest;'; + - psql -U postgres -c 'create database yiitest;'; script: phpunit \ No newline at end of file From e45e061cc53c326cd3abc9fc8929e5f83bb31159 Mon Sep 17 00:00:00 2001 From: Gevik Babakhani Date: Thu, 6 Jun 2013 22:52:28 +0200 Subject: [PATCH 2/7] Removed conditional pgsql env --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index da09923..01abd50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ php: env: - DB=mysql - - DB=postgres before_script: - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS yiitest;'; fi" From 95b1636a9815da870020403a36f2115785556e41 Mon Sep 17 00:00:00 2001 From: Mojtaba Salehi Date: Sat, 8 Jun 2013 23:26:21 +0430 Subject: [PATCH 3/7] Multilevel Items --- framework/yii/bootstrap/Nav.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/framework/yii/bootstrap/Nav.php b/framework/yii/bootstrap/Nav.php index 8e35010..8069699 100644 --- a/framework/yii/bootstrap/Nav.php +++ b/framework/yii/bootstrap/Nav.php @@ -27,13 +27,19 @@ use yii\helpers\Html; * ), * array( * 'label' => 'Dropdown', - * 'dropdown' => array( + * 'items' => array( * array( - * 'label' => 'DropdownA', + * 'label' => 'Level 1 -DropdownA', * 'url' => '#', + * 'items' => array( + * array( + * 'label' => 'Level 2 -DropdownA', + * 'url' => '#', + * ), + * ), * ), * array( - * 'label' => 'DropdownB', + * 'label' => 'Level 1 -DropdownB', * 'url' => '#', * ), * ), @@ -114,7 +120,7 @@ class Nav extends Widget } $label = $this->encodeLabels ? Html::encode($item['label']) : $item['label']; $options = ArrayHelper::getValue($item, 'options', array()); - $dropdown = ArrayHelper::getValue($item, 'dropdown'); + $items = ArrayHelper::getValue($item, 'items'); $url = Html::url(ArrayHelper::getValue($item, 'url', '#')); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); @@ -122,19 +128,19 @@ class Nav extends Widget $this->addCssClass($options, 'active'); } - if ($dropdown !== null) { + if ($items !== null) { $linkOptions['data-toggle'] = 'dropdown'; $this->addCssClass($options, 'dropdown'); $this->addCssClass($urlOptions, 'dropdown-toggle'); $label .= ' ' . Html::tag('b', '', array('class' => 'caret')); - if (is_array($dropdown)) { - $dropdown = Dropdown::widget(array( - 'items' => $dropdown, + if (is_array($items)) { + $items = Dropdown::widget(array( + 'items' => $items, 'clientOptions' => false, )); } } - return Html::tag('li', Html::a($label, $url, $linkOptions) . $dropdown, $options); + return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options); } } From 19793f7af056e6f3e5fec31ddf9dc252ce3d6b86 Mon Sep 17 00:00:00 2001 From: gevik Date: Sat, 8 Jun 2013 21:51:15 +0200 Subject: [PATCH 4/7] Removed unused columsn from find constraint sql. Fixed typo. Added extra schema check for when a foreign table is not in the same schema. Updated indentation to conform to other classes. --- framework/yii/db/pgsql/Schema.php | 53 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/framework/yii/db/pgsql/Schema.php b/framework/yii/db/pgsql/Schema.php index bec1803..7223a3b 100644 --- a/framework/yii/db/pgsql/Schema.php +++ b/framework/yii/db/pgsql/Schema.php @@ -73,7 +73,7 @@ class Schema extends \yii\db\Schema ); /** - * Creates a query builder for the MySQL database. + * Creates a query builder for the PostgreSQL database. * @return QueryBuilder query builder instance */ public function createQueryBuilder() @@ -89,13 +89,16 @@ class Schema extends \yii\db\Schema protected function resolveTableNames($table, $name) { $parts = explode('.', str_replace('"', '', $name)); - if (isset($parts[1])) { + if (isset($parts[1])) + { $table->schemaName = $parts[0]; $table->name = $parts[1]; - } else { + } else + { $table->name = $parts[0]; } - if ($table->schemaName === null) { + if ($table->schemaName === null) + { $table->schemaName = $this->defaultSchema; } } @@ -120,11 +123,10 @@ class Schema extends \yii\db\Schema { $table = new TableSchema(); $this->resolveTableNames($table, $name); - if ($this->findColumns($table)) { + if ($this->findColumns($table)) + { $this->findConstraints($table); return $table; - } else { - return null; } } @@ -143,14 +145,9 @@ class Schema extends \yii\db\Schema $sql = <<defaultSchema) + { + $foreign_table = $constraint['foreign_table_schema'] . '.' . $constraint['foreign_table_name']; + } else + { + $foreign_table = $constraint['foreign_table_name']; + } + $citem = array($foreign_table); foreach ($columns as $idx => $column) { $citem[] = array($fcolumns[$idx] => $column); } @@ -242,17 +246,21 @@ ORDER BY a.attnum; SQL; - $columns = $this->db->createCommand($sql)->queryAll(); - if (empty($columns)) { + try + { + $columns = $this->db->createCommand($sql)->queryAll(); + } catch (\Exception $e) + { return false; } - foreach ($columns as $column) { $column = $this->loadColumnSchema($column); $table->columns[$column->name] = $column; - if ($column->isPrimaryKey === true) { + if ($column->isPrimaryKey === true) + { $table->primaryKey[] = $column->name; - if ($table->sequenceName === null && preg_match("/nextval\('\w+'(::regclass)?\)/", $column->defaultValue) === 1) { + if ($table->sequenceName === null && preg_match("/nextval\('\w+'(::regclass)?\)/", $column->defaultValue) === 1) + { $table->sequenceName = preg_replace(array('/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'), '', $column->defaultValue); } } @@ -281,12 +289,15 @@ SQL; $column->scale = $info['numeric_scale']; $column->size = $info['size']; - if (isset($this->typeMap[$column->dbType])) { + if (isset($this->typeMap[$column->dbType])) + { $column->type = $this->typeMap[$column->dbType]; - } else { + } else + { $column->type = self::TYPE_STRING; } $column->phpType = $this->getColumnPhpType($column); return $column; } -} + +} \ No newline at end of file From 6fd74f5c27cb37eaacb82b48e3847eaa63c6273d Mon Sep 17 00:00:00 2001 From: gevik Date: Sat, 8 Jun 2013 23:47:24 +0200 Subject: [PATCH 5/7] Updated code style. braces on the same line for control statements. --- framework/yii/db/pgsql/Schema.php | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/framework/yii/db/pgsql/Schema.php b/framework/yii/db/pgsql/Schema.php index 7223a3b..66f0876 100644 --- a/framework/yii/db/pgsql/Schema.php +++ b/framework/yii/db/pgsql/Schema.php @@ -89,16 +89,13 @@ class Schema extends \yii\db\Schema protected function resolveTableNames($table, $name) { $parts = explode('.', str_replace('"', '', $name)); - if (isset($parts[1])) - { + if (isset($parts[1])) { $table->schemaName = $parts[0]; $table->name = $parts[1]; - } else - { + } else { $table->name = $parts[0]; } - if ($table->schemaName === null) - { + if ($table->schemaName === null) { $table->schemaName = $this->defaultSchema; } } @@ -123,8 +120,7 @@ class Schema extends \yii\db\Schema { $table = new TableSchema(); $this->resolveTableNames($table, $name); - if ($this->findColumns($table)) - { + if ($this->findColumns($table)) { $this->findConstraints($table); return $table; } @@ -166,11 +162,9 @@ SQL; foreach ($constraints as $constraint) { $columns = explode(',', $constraint['columns']); $fcolumns = explode(',', $constraint['foreign_columns']); - if ($constraint['foreign_table_schema'] !== $this->defaultSchema) - { + if ($constraint['foreign_table_schema'] !== $this->defaultSchema) { $foreign_table = $constraint['foreign_table_schema'] . '.' . $constraint['foreign_table_name']; - } else - { + } else { $foreign_table = $constraint['foreign_table_name']; } $citem = array($foreign_table); @@ -246,21 +240,17 @@ ORDER BY a.attnum; SQL; - try - { + try { $columns = $this->db->createCommand($sql)->queryAll(); - } catch (\Exception $e) - { + } catch (\Exception $e) { return false; } foreach ($columns as $column) { $column = $this->loadColumnSchema($column); $table->columns[$column->name] = $column; - if ($column->isPrimaryKey === true) - { + if ($column->isPrimaryKey === true) { $table->primaryKey[] = $column->name; - if ($table->sequenceName === null && preg_match("/nextval\('\w+'(::regclass)?\)/", $column->defaultValue) === 1) - { + if ($table->sequenceName === null && preg_match("/nextval\('\w+'(::regclass)?\)/", $column->defaultValue) === 1) { $table->sequenceName = preg_replace(array('/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'), '', $column->defaultValue); } } @@ -289,11 +279,9 @@ SQL; $column->scale = $info['numeric_scale']; $column->size = $info['size']; - if (isset($this->typeMap[$column->dbType])) - { + if (isset($this->typeMap[$column->dbType])) { $column->type = $this->typeMap[$column->dbType]; - } else - { + } else { $column->type = self::TYPE_STRING; } $column->phpType = $this->getColumnPhpType($column); From ec9dab11fad43c869c19cd3119a2ce516d7ae886 Mon Sep 17 00:00:00 2001 From: gevik Date: Sun, 9 Jun 2013 00:04:37 +0200 Subject: [PATCH 6/7] [1] Redone missing code. [2] Added empty line at the end of file [3] Removed exception. --- framework/yii/db/pgsql/Schema.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/framework/yii/db/pgsql/Schema.php b/framework/yii/db/pgsql/Schema.php index 66f0876..8cfb535 100644 --- a/framework/yii/db/pgsql/Schema.php +++ b/framework/yii/db/pgsql/Schema.php @@ -123,6 +123,8 @@ class Schema extends \yii\db\Schema if ($this->findColumns($table)) { $this->findConstraints($table); return $table; + } else { + return null; } } @@ -240,11 +242,7 @@ ORDER BY a.attnum; SQL; - try { - $columns = $this->db->createCommand($sql)->queryAll(); - } catch (\Exception $e) { - return false; - } + $columns = $this->db->createCommand($sql)->queryAll(); foreach ($columns as $column) { $column = $this->loadColumnSchema($column); $table->columns[$column->name] = $column; @@ -288,4 +286,4 @@ SQL; return $column; } -} \ No newline at end of file +} From 864bf936794f8bd7e60be07a31011c0b29908317 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 9 Jun 2013 09:41:32 -0300 Subject: [PATCH 7/7] coding style fix. --- framework/yii/db/pgsql/Schema.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/framework/yii/db/pgsql/Schema.php b/framework/yii/db/pgsql/Schema.php index 8cfb535..94f845f 100644 --- a/framework/yii/db/pgsql/Schema.php +++ b/framework/yii/db/pgsql/Schema.php @@ -165,11 +165,11 @@ SQL; $columns = explode(',', $constraint['columns']); $fcolumns = explode(',', $constraint['foreign_columns']); if ($constraint['foreign_table_schema'] !== $this->defaultSchema) { - $foreign_table = $constraint['foreign_table_schema'] . '.' . $constraint['foreign_table_name']; + $foreignTable = $constraint['foreign_table_schema'] . '.' . $constraint['foreign_table_name']; } else { - $foreign_table = $constraint['foreign_table_name']; + $foreignTable = $constraint['foreign_table_name']; } - $citem = array($foreign_table); + $citem = array($foreignTable); foreach ($columns as $idx => $column) { $citem[] = array($fcolumns[$idx] => $column); } @@ -285,5 +285,4 @@ SQL; $column->phpType = $this->getColumnPhpType($column); return $column; } - }