models/CiiSettingsModel.php
public function save($runValidation=true)
	{
		if ($this->beforeSave())
		{
			// If we want to run validation AND the validation failed, give up
			
			if ($this->beforeValidate())
			{
				if ($runValidation && !$this->validate())
					return false;
			}
			else
				return false;

			$this->afterValidate();
			
			$connection = Yii::app()->db;
			$transaction = $connection->beginTransaction();

			try {
				foreach($this->attributes as $key=>$value)
				{
					$command = $connection->createCommand('INSERT INTO `configuration` VALUES (:key, :value, UTC_TIMESTAMP(), UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE value = :value2, updated = UTC_TIMESTAMP()');
					$command->bindParam(':key', $key);
					$command->bindParam(':value', $value);
					$command->bindParam(':value2', $value);
					$command->execute();
					Yii::app()->cache->delete('settings_'.$key);
				}
			} catch (Exception $e) {
				$transaciton->rollBack();
				return false;
			}

			$transaction->commit();
			$this->afterSave();

			// Return the commit response
			return true;
		}
	}
public function save($runValidation=true)
	{
		if ($this->beforeSave())
		{
			// If we want to run validation AND the validation failed, give up
			
			if ($this->beforeValidate())
			{
				if ($runValidation && !$this->validate())
					return false;
			}
			else
				return false;

			$this->afterValidate();
			
			$connection = Yii::app()->db;
			$transaction = $connection->beginTransaction();

			try {
				foreach($this->attributes as $key=>$value)
				{
					$command = $connection->createCommand('INSERT INTO `configuration` VALUES (:key, :value, UTC_TIMESTAMP(), UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE value = :value2, updated = UTC_TIMESTAMP()');
					$command->bindParam(':key', $key);
					$command->bindParam(':value', $value);
					$command->bindParam(':value2', $value);
					$command->execute();
					Yii::app()->cache->delete('settings_'.$key);
				}
			} catch (Exception $e) {
				$transaciton->rollBack();
				return false;
			}

			$transaction->commit();
			$this->afterSave();

			// Return the commit response
			return true;
		}
	}
public function save ( $ runValidation = true ) { if ( $ this -> beforeSave ( ) ) { // If we want to run validation AND the validation failed, give up if ( $ this -> beforeValidate ( ) ) { if ( $ runValidation && ! $ this -> validate ( ) ) return false ; } else return false ; $ this -> afterValidate ( ) ; $ connection = Yii :: app ( ) -> db ; $ transaction = $ connection -> beginTransaction ( ) ; try { foreach ( $ this -> attributes as $ key => $ value ) { $ command = $ connection -> createCommand ( 'INSERT INTO `configuration` VALUES (:key, :value, UTC_TIMESTAMP(), UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE value = :value2, updated = UTC_TIMESTAMP()' ) ; $ command -> bindParam ( ':key' , $ key ) ; $ command -> bindParam ( ':value' , $ value ) ; $ command -> bindParam ( ':value2' , $ value ) ; $ command -> execute ( ) ; Yii :: app ( ) -> cache -> delete ( 'settings_' . $ key ) ; } } catch ( Exception $ e ) { $ transaciton -> rollBack ( ) ; return false ; } $ transaction -> commit ( ) ; $ this -> afterSave ( ) ; // Return the commit response return true ; } }
Save function for Configuration
Everything should be wrapped inside of a transaction - if there is an error saving any of the items then there was an error saving all of them
and we should abort
@return boolean|null      Whether or not the save succedded or not
Save function for Configuration Everything should be wrapped inside of a transaction - if there is an error saving any of the items then there was an error saving all of them and we should abort