Commit fa767cea by Carsten Brandt

renamed attributes to attributeNames in model

fixes #3034
parent 3fdcf11f
...@@ -443,7 +443,7 @@ abstract class ActiveRecord extends BaseActiveRecord ...@@ -443,7 +443,7 @@ abstract class ActiveRecord extends BaseActiveRecord
* *
* @param boolean $runValidation whether to perform validation before saving the record. * @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database. * 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. * meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails * @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process. * or [[beforeSave()]] stops the updating process.
...@@ -451,16 +451,16 @@ abstract class ActiveRecord extends BaseActiveRecord ...@@ -451,16 +451,16 @@ abstract class ActiveRecord extends BaseActiveRecord
* being updated is outdated. * being updated is outdated.
* @throws \Exception in case update failed. * @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 false;
} }
$db = static::getDb(); $db = static::getDb();
if ($this->isTransactional(self::OP_UPDATE) && $db->getTransaction() === null) { if ($this->isTransactional(self::OP_UPDATE) && $db->getTransaction() === null) {
$transaction = $db->beginTransaction(); $transaction = $db->beginTransaction();
try { try {
$result = $this->updateInternal($attributes); $result = $this->updateInternal($attributeNames);
if ($result === false) { if ($result === false) {
$transaction->rollBack(); $transaction->rollBack();
} else { } else {
...@@ -471,7 +471,7 @@ abstract class ActiveRecord extends BaseActiveRecord ...@@ -471,7 +471,7 @@ abstract class ActiveRecord extends BaseActiveRecord
throw $e; throw $e;
} }
} else { } else {
$result = $this->updateInternal($attributes); $result = $this->updateInternal($attributeNames);
} }
return $result; return $result;
......
...@@ -302,14 +302,14 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab ...@@ -302,14 +302,14 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* Errors found during the validation can be retrieved via [[getErrors()]], * Errors found during the validation can be retrieved via [[getErrors()]],
* [[getFirstErrors()]] and [[getFirstError()]]. * [[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 * If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated. * validation rules should be validated.
* @param boolean $clearErrors whether to call [[clearErrors()]] before performing validation * @param boolean $clearErrors whether to call [[clearErrors()]] before performing validation
* @return boolean whether the validation is successful without any error. * @return boolean whether the validation is successful without any error.
* @throws InvalidParamException if the current scenario is unknown. * @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(); $scenarios = $this->scenarios();
$scenario = $this->getScenario(); $scenario = $this->getScenario();
...@@ -320,12 +320,12 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab ...@@ -320,12 +320,12 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
if ($clearErrors) { if ($clearErrors) {
$this->clearErrors(); $this->clearErrors();
} }
if ($attributes === null) { if ($attributeNames === null) {
$attributes = $this->activeAttributes(); $attributeNames = $this->activeAttributes();
} }
if ($this->beforeValidate()) { if ($this->beforeValidate()) {
foreach ($this->getActiveValidators() as $validator) { foreach ($this->getActiveValidators() as $validator) {
$validator->validateAttributes($this, $attributes); $validator->validateAttributes($this, $attributeNames);
} }
$this->afterValidate(); $this->afterValidate();
...@@ -791,18 +791,18 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab ...@@ -791,18 +791,18 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
* This method will validate every model. The models being validated may * This method will validate every model. The models being validated may
* be of the same or different types. * be of the same or different types.
* @param array $models the models to be validated * @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 * If this parameter is empty, it means any attribute listed in the applicable
* validation rules should be validated. * validation rules should be validated.
* @return boolean whether all models are valid. False will be returned if one * @return boolean whether all models are valid. False will be returned if one
* or multiple models have validation error. * or multiple models have validation error.
*/ */
public static function validateMultiple($models, $attributes = null) public static function validateMultiple($models, $attributeNames = null)
{ {
$valid = true; $valid = true;
/** @var Model $model */ /** @var Model $model */
foreach ($models as $model) { foreach ($models as $model) {
$valid = $model->validate($attributes) && $valid; $valid = $model->validate($attributeNames) && $valid;
} }
return $valid; return $valid;
...@@ -906,7 +906,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab ...@@ -906,7 +906,6 @@ class Model extends Component implements IteratorAggregate, ArrayAccess, Arrayab
public function getIterator() public function getIterator()
{ {
$attributes = $this->getAttributes(); $attributes = $this->getAttributes();
return new ArrayIterator($attributes); return new ArrayIterator($attributes);
} }
......
...@@ -480,7 +480,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -480,7 +480,7 @@ class ActiveRecord extends BaseActiveRecord
* *
* @param boolean $runValidation whether to perform validation before saving the record. * @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database. * 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. * meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails * @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process. * or [[beforeSave()]] stops the updating process.
...@@ -488,9 +488,9 @@ class ActiveRecord extends BaseActiveRecord ...@@ -488,9 +488,9 @@ class ActiveRecord extends BaseActiveRecord
* being updated is outdated. * being updated is outdated.
* @throws \Exception in case update failed. * @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__); Yii::info('Model not updated due to validation error.', __METHOD__);
return false; return false;
} }
...@@ -498,7 +498,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -498,7 +498,7 @@ class ActiveRecord extends BaseActiveRecord
if ($this->isTransactional(self::OP_UPDATE)) { if ($this->isTransactional(self::OP_UPDATE)) {
$transaction = $db->beginTransaction(); $transaction = $db->beginTransaction();
try { try {
$result = $this->updateInternal($attributes); $result = $this->updateInternal($attributeNames);
if ($result === false) { if ($result === false) {
$transaction->rollBack(); $transaction->rollBack();
} else { } else {
...@@ -509,7 +509,7 @@ class ActiveRecord extends BaseActiveRecord ...@@ -509,7 +509,7 @@ class ActiveRecord extends BaseActiveRecord
throw $e; throw $e;
} }
} else { } else {
$result = $this->updateInternal($attributes); $result = $this->updateInternal($attributeNames);
} }
return $result; return $result;
......
...@@ -272,11 +272,11 @@ interface ActiveRecordInterface ...@@ -272,11 +272,11 @@ interface ActiveRecordInterface
* @param boolean $runValidation whether to perform validation before saving the record. * @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 * If the validation fails, the record will not be saved to database. `false` will be returned
* in this case. * 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. * meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the saving succeeds * @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. * Inserts the record into the database using the attribute values of this record.
...@@ -312,14 +312,14 @@ interface ActiveRecordInterface ...@@ -312,14 +312,14 @@ interface ActiveRecordInterface
* *
* @param boolean $runValidation whether to perform validation before saving the record. * @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database. * 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. * meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails * @return integer|boolean the number of rows affected, or false if validation fails
* or updating process is stopped for other reasons. * or updating process is stopped for other reasons.
* Note that it is possible that the number of rows affected is 0, even though the * Note that it is possible that the number of rows affected is 0, even though the
* update execution is successful. * update execution is successful.
*/ */
public function update($runValidation = true, $attributes = null); public function update($runValidation = true, $attributeNames = null);
/** /**
* Deletes the record from the database. * Deletes the record from the database.
......
...@@ -565,16 +565,16 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -565,16 +565,16 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* *
* @param boolean $runValidation whether to perform validation before saving the record. * @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be saved to database. * 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. * meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the saving succeeds * @return boolean whether the saving succeeds
*/ */
public function save($runValidation = true, $attributes = null) public function save($runValidation = true, $attributeNames = null)
{ {
if ($this->getIsNewRecord()) { if ($this->getIsNewRecord()) {
return $this->insert($runValidation, $attributes); return $this->insert($runValidation, $attributeNames);
} else { } else {
return $this->update($runValidation, $attributes) !== false; return $this->update($runValidation, $attributeNames) !== false;
} }
} }
...@@ -620,7 +620,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -620,7 +620,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* *
* @param boolean $runValidation whether to perform validation before saving the record. * @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be inserted into the database. * 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. * meaning all attributes that are loaded from DB will be saved.
* @return integer|boolean the number of rows affected, or false if validation fails * @return integer|boolean the number of rows affected, or false if validation fails
* or [[beforeSave()]] stops the updating process. * or [[beforeSave()]] stops the updating process.
...@@ -628,12 +628,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -628,12 +628,12 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
* being updated is outdated. * being updated is outdated.
* @throws \Exception in case update failed. * @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 false;
} }
return $this->updateInternal($attributes); return $this->updateInternal($attributeNames);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment