Browse Source

renamed attributes to attributeNames in model

fixes #3034
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
fa767ceaca
  1. 10
      extensions/sphinx/ActiveRecord.php
  2. 17
      framework/base/Model.php
  3. 10
      framework/db/ActiveRecord.php
  4. 8
      framework/db/ActiveRecordInterface.php
  5. 16
      framework/db/BaseActiveRecord.php

10
extensions/sphinx/ActiveRecord.php

@ -443,7 +443,7 @@ abstract class ActiveRecord extends BaseActiveRecord
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
@ -451,16 +451,16 @@ abstract class ActiveRecord extends BaseActiveRecord
* being updated is outdated.
* @throws \Exception in case update failed.
*/
public function update($runValidation = true, $attributes = null)
public function update($runValidation = true, $attributeNames = null)
{
if ($runValidation && !$this->validate($attributes)) {
if ($runValidation && !$this->validate($attributeNames)) {
return false;
}
$db = static::getDb();
if ($this->isTransactional(self::OP_UPDATE) && $db->getTransaction() === null) {
$transaction = $db->beginTransaction();
try {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
if ($result === false) {
$transaction->rollBack();
} else {
@ -471,7 +471,7 @@ abstract class ActiveRecord extends BaseActiveRecord
throw $e;
}
} else {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
}
return $result;

17
framework/base/Model.php

@ -302,14 +302,14 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* Errors found during the validation can be retrieved via [[getErrors()]],
* [[getFirstErrors()]] and [[getFirstError()]].
*
* @param array $attributes list of attributes that should be validated.
* @param array $attributeNames list of attribute names that should be validated.
* If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated.
* @param boolean $clearErrors whether to call [[clearErrors()]] before performing validation
* @return boolean whether the validation is successful without any error.
* @throws InvalidParamException if the current scenario is unknown.
*/
public function validate($attributes = null, $clearErrors = true)
public function validate($attributeNames = null, $clearErrors = true)
{
$scenarios = $this->scenarios();
$scenario = $this->getScenario();
@ -320,12 +320,12 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
if ($clearErrors) {
$this->clearErrors();
}
if ($attributes === null) {
$attributes = $this->activeAttributes();
if ($attributeNames === null) {
$attributeNames = $this->activeAttributes();
}
if ($this->beforeValidate()) {
foreach ($this->getActiveValidators() as $validator) {
$validator->validateAttributes($this, $attributes);
$validator->validateAttributes($this, $attributeNames);
}
$this->afterValidate();
@ -791,18 +791,18 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* This method will validate every model. The models being validated may
* be of the same or different types.
* @param array $models the models to be validated
* @param array $attributes list of attributes that should be validated.
* @param array $attributeNames list of attribute names that should be validated.
* If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated.
* @return boolean whether all models are valid. False will be returned if one
* or multiple models have validation error.
*/
public static function validateMultiple($models, $attributes = null)
public static function validateMultiple($models, $attributeNames = null)
{
$valid = true;
/** @var Model $model */
foreach ($models as $model) {
$valid = $model->validate($attributes) && $valid;
$valid = $model->validate($attributeNames) && $valid;
}
return $valid;
@ -906,7 +906,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
public function getIterator()
{
$attributes = $this->getAttributes();
return new ArrayIterator($attributes);
}

10
framework/db/ActiveRecord.php

@ -480,7 +480,7 @@ class ActiveRecord extends BaseActiveRecord
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
@ -488,9 +488,9 @@ class ActiveRecord extends BaseActiveRecord
* being updated is outdated.
* @throws \Exception in case update failed.
*/
public function update($runValidation = true, $attributes = null)
public function update($runValidation = true, $attributeNames = null)
{
if ($runValidation && !$this->validate($attributes)) {
if ($runValidation && !$this->validate($attributeNames)) {
Yii::info('Model not updated due to validation error.', __METHOD__);
return false;
}
@ -498,7 +498,7 @@ class ActiveRecord extends BaseActiveRecord
if ($this->isTransactional(self::OP_UPDATE)) {
$transaction = $db->beginTransaction();
try {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
if ($result === false) {
$transaction->rollBack();
} else {
@ -509,7 +509,7 @@ class ActiveRecord extends BaseActiveRecord
throw $e;
}
} else {
$result = $this->updateInternal($attributes);
$result = $this->updateInternal($attributeNames);
}
return $result;

8
framework/db/ActiveRecordInterface.php

@ -272,11 +272,11 @@ interface ActiveRecordInterface
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be saved to database. `false` will be returned
* in this case.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the saving succeeds
*/
public function save($runValidation = true, $attributes = null);
public function save($runValidation = true, $attributeNames = null);
/**
* Inserts the record into the database using the attribute values of this record.
@ -312,14 +312,14 @@ interface ActiveRecordInterface
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or updating process is stopped for other reasons.
* Note that it is possible that the number of rows affected is 0, even though the
* update execution is successful.
*/
public function update($runValidation = true, $attributes = null);
public function update($runValidation = true, $attributeNames = null);
/**
* Deletes the record from the database.

16
framework/db/BaseActiveRecord.php

@ -565,16 +565,16 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be saved to database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the saving succeeds
*/
public function save($runValidation = true, $attributes = null)
public function save($runValidation = true, $attributeNames = null)
{
if ($this->getIsNewRecord()) {
return $this->insert($runValidation, $attributes);
return $this->insert($runValidation, $attributeNames);
} else {
return $this->update($runValidation, $attributes) !== false;
return $this->update($runValidation, $attributeNames) !== false;
}
}
@ -620,7 +620,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* @param array $attributeNames list of attribute names that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process.
@ -628,12 +628,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* being updated is outdated.
* @throws \Exception in case update failed.
*/
public function update($runValidation = true, $attributes = null)
public function update($runValidation = true, $attributeNames = null)
{
if ($runValidation && !$this->validate($attributes)) {
if ($runValidation && !$this->validate($attributeNames)) {
return false;
}
return $this->updateInternal($attributes);
return $this->updateInternal($attributeNames);
}
/**

Loading…
Cancel
Save