Browse Source

Merge branch 'master' of github.com:yiisoft/yii2

* 'master' of github.com:yiisoft/yii2:
  Fixes #829: loginRequired now responds with HTTP 403 in case of AJAX or loginUrl is not set (reverted from commit c2c12a9049)
  add missing return to module template
  Update module.php
  Fixes #829: loginRequired now responds with HTTP 403 in case of AJAX or loginUrl is not set
  gii form width adjustment.
  Make sure query cloning works as expected.
  Fixed test break.
  Fixes #828: refactored QueryBuilder::build()
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
0d91021f02
  1. 1
      framework/yii/data/ActiveDataProvider.php
  2. 8
      framework/yii/db/ActiveQuery.php
  3. 14
      framework/yii/db/ActiveRelation.php
  4. 4
      framework/yii/db/Query.php
  5. 20
      framework/yii/db/QueryBuilder.php
  6. 2
      framework/yii/gii/generators/module/templates/controller.php
  7. 2
      framework/yii/gii/generators/module/templates/module.php
  8. 2
      framework/yii/gii/views/default/view.php
  9. 2
      tests/unit/framework/db/QueryBuilderTest.php
  10. 4
      tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php

1
framework/yii/data/ActiveDataProvider.php

@ -9,7 +9,6 @@ namespace yii\data;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\db\Query;
use yii\db\ActiveQuery;

8
framework/yii/db/ActiveQuery.php

@ -156,6 +156,8 @@ class ActiveQuery extends Query
if ($db === null) {
$db = $modelClass::getDb();
}
$params = $this->params;
if ($this->sql === null) {
if ($this->from === null) {
$tableName = $modelClass::tableName();
@ -164,11 +166,9 @@ class ActiveQuery extends Query
}
$this->from = array($tableName);
}
/** @var $qb QueryBuilder */
$qb = $db->getQueryBuilder();
$this->sql = $qb->build($this);
list ($this->sql, $params) = $db->getQueryBuilder()->build($this);
}
return $db->createCommand($this->sql, $this->params);
return $db->createCommand($this->sql, $params);
}
/**

14
framework/yii/db/ActiveRelation.php

@ -50,6 +50,16 @@ class ActiveRelation extends ActiveQuery
*/
public $via;
/**
* Clones internal objects.
*/
public function __clone()
{
if (is_object($this->via)) {
// make a clone of "via" object so that the same query object can be reused multiple times
$this->via = clone $this->via;
}
}
/**
* Specifies the relation associated with the pivot table.
@ -297,7 +307,7 @@ class ActiveRelation extends ActiveQuery
/** @var $primaryModel ActiveRecord */
$primaryModel = reset($primaryModels);
$db = $primaryModel->getDb();
$sql = $db->getQueryBuilder()->build($this);
return $db->createCommand($sql, $this->params)->queryAll();
list ($sql, $params) = $db->getQueryBuilder()->build($this);
return $db->createCommand($sql, $params)->queryAll();
}
}

4
framework/yii/db/Query.php

@ -149,8 +149,8 @@ class Query extends Component
if ($db === null) {
$db = Yii::$app->getDb();
}
$sql = $db->getQueryBuilder()->build($this);
return $db->createCommand($sql, $this->params);
list ($sql, $params) = $db->getQueryBuilder()->build($this);
return $db->createCommand($sql, $params);
}
/**

20
framework/yii/db/QueryBuilder.php

@ -55,22 +55,24 @@ class QueryBuilder extends \yii\base\Object
/**
* Generates a SELECT SQL statement from a [[Query]] object.
* @param Query $query the [[Query]] object from which the SQL statement will be generated
* @return string the generated SQL statement
* @return array the generated SQL statement (the first array element) and the corresponding
* parameters to be bound to the SQL statement (the second array element).
*/
public function build($query)
{
$params = $query->params;
$clauses = array(
$this->buildSelect($query->select, $query->distinct, $query->selectOption),
$this->buildFrom($query->from),
$this->buildJoin($query->join, $query->params),
$this->buildWhere($query->where, $query->params),
$this->buildJoin($query->join, $params),
$this->buildWhere($query->where, $params),
$this->buildGroupBy($query->groupBy),
$this->buildHaving($query->having, $query->params),
$this->buildUnion($query->union, $query->params),
$this->buildHaving($query->having, $params),
$this->buildUnion($query->union, $params),
$this->buildOrderBy($query->orderBy),
$this->buildLimit($query->limit, $query->offset),
);
return implode($this->separator, array_filter($clauses));
return array(implode($this->separator, array_filter($clauses)), $params);
}
/**
@ -718,9 +720,11 @@ class QueryBuilder extends \yii\base\Object
}
foreach ($unions as $i => $union) {
if ($union instanceof Query) {
// save the original parameters so that we can restore them later to prevent from modifying the query object
$originalParams = $union->params;
$union->addParams($params);
$unions[$i] = $this->build($union);
$params = $union->params;
list ($unions[$i], $params) = $this->build($union);
$union->params = $originalParams;
}
}
return "UNION (\n" . implode("\n) UNION (\n", $unions) . "\n)";

2
framework/yii/gii/generators/module/templates/controller.php

@ -16,6 +16,6 @@ class DefaultController extends Controller
{
public function actionIndex()
{
$this->render('index');
return $this->render('index');
}
}

2
framework/yii/gii/generators/module/templates/module.php

@ -16,7 +16,7 @@ echo "<?php\n";
namespace <?php echo $ns; ?>;
class <?php echo $className; ?> extends \yii\web\Module
class <?php echo $className; ?> extends \yii\base\Module
{
public $controllerNamespace = '<?php echo $generator->getControllerNamespace(); ?>';

2
framework/yii/gii/views/default/view.php

@ -30,7 +30,7 @@ foreach ($generator->templates as $name => $path) {
<?php $form = ActiveForm::begin(array('fieldConfig' => array('class' => ActiveField::className()))); ?>
<div class="row">
<div class="col-lg-6">
<div class="col-lg-8">
<?php echo $this->renderFile($generator->formView(), array(
'generator' => $generator,
'form' => $form,

2
tests/unit/framework/db/QueryBuilderTest.php

@ -112,7 +112,7 @@ class QueryBuilderTest extends DatabaseTestCase
}
}
public function testAddDropPrimayKey()
public function testAddDropPrimaryKey()
{
$tableName = 'tbl_constraints';
$pkeyName = $tableName . "_pkey";

4
tests/unit/framework/db/sqlite/SqliteQueryBuilderTest.php

@ -73,9 +73,9 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
);
}
public function testAddDropPrimayKey()
public function testAddDropPrimaryKey()
{
$this->setExpectedException('yii\base\NotSupportedException');
parent::testAddDropPrimayKey();
parent::testAddDropPrimaryKey();
}
}

Loading…
Cancel
Save