Browse Source

Merge http://github.com/yiisoft/yii2

* http://github.com/yiisoft/yii2:
  Fixes issue #134
  Rollback word consistencty over entire codebase (ref. #139).
  Add ensureBehaviors() to detachBehavior*()
tags/2.0.0-beta
sensorario 12 years ago
parent
commit
d0a634b935
  1. 4
      docs/api/db/ActiveRecord.md
  2. 2
      framework/base/Component.php
  3. 3
      framework/db/ActiveQuery.php
  4. 2
      framework/db/Connection.php
  5. 8
      framework/db/Migration.php
  6. 6
      framework/db/Transaction.php
  7. 2
      tests/unit/data/ar/Customer.php

4
docs/api/db/ActiveRecord.md

@ -412,7 +412,7 @@ class Customer extends \yii\db\ActiveRecord
/** /**
* @param ActiveQuery $query * @param ActiveQuery $query
*/ */
public function active($query) public static function active($query)
{ {
$query->andWhere('status = 1'); $query->andWhere('status = 1');
} }
@ -435,7 +435,7 @@ class Customer extends \yii\db\ActiveRecord
* @param ActiveQuery $query * @param ActiveQuery $query
* @param integer $age * @param integer $age
*/ */
public function olderThan($query, $age = 30) public static function olderThan($query, $age = 30)
{ {
$query->andWhere('age > :age', array(':age' => $age)); $query->andWhere('age > :age', array(':age' => $age));
} }

2
framework/base/Component.php

@ -496,6 +496,7 @@ class Component extends Object
*/ */
public function detachBehavior($name) public function detachBehavior($name)
{ {
$this->ensureBehaviors();
if (isset($this->_behaviors[$name])) { if (isset($this->_behaviors[$name])) {
$behavior = $this->_behaviors[$name]; $behavior = $this->_behaviors[$name];
unset($this->_behaviors[$name]); unset($this->_behaviors[$name]);
@ -511,6 +512,7 @@ class Component extends Object
*/ */
public function detachBehaviors() public function detachBehaviors()
{ {
$this->ensureBehaviors();
if ($this->_behaviors !== null) { if ($this->_behaviors !== null) {
foreach ($this->_behaviors as $name => $behavior) { foreach ($this->_behaviors as $name => $behavior) {
$this->detachBehavior($name); $this->detachBehavior($name);

3
framework/db/ActiveQuery.php

@ -88,7 +88,8 @@ class ActiveQuery extends Query
{ {
if (method_exists($this->modelClass, $name)) { if (method_exists($this->modelClass, $name)) {
array_unshift($params, $this); array_unshift($params, $this);
return call_user_func_array(array($this->modelClass, $name), $params); call_user_func_array(array($this->modelClass, $name), $params);
return $this;
} else { } else {
return parent::__call($name, $params); return parent::__call($name, $params);
} }

2
framework/db/Connection.php

@ -66,7 +66,7 @@ use yii\caching\Cache;
* // ... executing other SQL statements ... * // ... executing other SQL statements ...
* $transaction->commit(); * $transaction->commit();
* } catch(Exception $e) { * } catch(Exception $e) {
* $transaction->rollBack(); * $transaction->rollback();
* } * }
* ~~~ * ~~~
* *

8
framework/db/Migration.php

@ -64,14 +64,14 @@ class Migration extends \yii\base\Component
$transaction = $this->db->beginTransaction(); $transaction = $this->db->beginTransaction();
try { try {
if ($this->safeUp() === false) { if ($this->safeUp() === false) {
$transaction->rollBack(); $transaction->rollback();
return false; return false;
} }
$transaction->commit(); $transaction->commit();
} catch (\Exception $e) { } catch (\Exception $e) {
echo "Exception: " . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n"; echo "Exception: " . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n";
echo $e->getTraceAsString() . "\n"; echo $e->getTraceAsString() . "\n";
$transaction->rollBack(); $transaction->rollback();
return false; return false;
} }
return null; return null;
@ -89,14 +89,14 @@ class Migration extends \yii\base\Component
$transaction = $this->db->beginTransaction(); $transaction = $this->db->beginTransaction();
try { try {
if ($this->safeDown() === false) { if ($this->safeDown() === false) {
$transaction->rollBack(); $transaction->rollback();
return false; return false;
} }
$transaction->commit(); $transaction->commit();
} catch (\Exception $e) { } catch (\Exception $e) {
echo "Exception: " . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n"; echo "Exception: " . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n";
echo $e->getTraceAsString() . "\n"; echo $e->getTraceAsString() . "\n";
$transaction->rollBack(); $transaction->rollback();
return false; return false;
} }
return null; return null;

6
framework/db/Transaction.php

@ -25,7 +25,7 @@ use yii\base\InvalidConfigException;
* //.... other SQL executions * //.... other SQL executions
* $transaction->commit(); * $transaction->commit();
* } catch(Exception $e) { * } catch(Exception $e) {
* $transaction->rollBack(); * $transaction->rollback();
* } * }
* ~~~ * ~~~
* *
@ -42,14 +42,14 @@ class Transaction extends \yii\base\Object
public $db; public $db;
/** /**
* @var boolean whether this transaction is active. Only an active transaction * @var boolean whether this transaction is active. Only an active transaction
* can [[commit()]] or [[rollBack()]]. This property is set true when the transaction is started. * can [[commit()]] or [[rollback()]]. This property is set true when the transaction is started.
*/ */
private $_active = false; private $_active = false;
/** /**
* Returns a value indicating whether this transaction is active. * Returns a value indicating whether this transaction is active.
* @return boolean whether this transaction is active. Only an active transaction * @return boolean whether this transaction is active. Only an active transaction
* can [[commit()]] or [[rollBack()]]. * can [[commit()]] or [[rollback()]].
*/ */
public function getIsActive() public function getIsActive()
{ {

2
tests/unit/data/ar/Customer.php

@ -22,6 +22,6 @@ class Customer extends ActiveRecord
public static function active($query) public static function active($query)
{ {
return $query->andWhere('status=1'); $query->andWhere('status=1');
} }
} }

Loading…
Cancel
Save