| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -20,7 +20,7 @@ use yii\db\TableSchema; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					/** | 
					 | 
					 | 
					 | 
					/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * ActiveRecord is the base class for classes representing relational data in terms of objects. | 
					 | 
					 | 
					 | 
					 * ActiveRecord is the base class for classes representing relational data in terms of objects. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * | 
					 | 
					 | 
					 | 
					 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * @include @yii/db/ActiveRecord.md | 
					 | 
					 | 
					 | 
					 * | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * | 
					 | 
					 | 
					 | 
					 * | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * @author Carsten Brandt <mail@cebe.cc> | 
					 | 
					 | 
					 | 
					 * @author Carsten Brandt <mail@cebe.cc> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * @since 2.0 | 
					 | 
					 | 
					 | 
					 * @since 2.0 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -68,31 +68,19 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							return $query; | 
					 | 
					 | 
					 | 
							return $query; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						public static function hashPk($pk) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							return (is_array($pk) ? implode('-', $pk) : $pk); // TODO escape PK glue | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						/** | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * Creates an [[ActiveQuery]] instance with a given SQL statement. | 
					 | 
					 | 
					 | 
						 * @inheritdoc | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * Note that because the SQL statement is already specified, calling additional | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * query modification methods (such as `where()`, `order()`) on the created [[ActiveQuery]] | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * instance will have no effect. However, calling `with()`, `asArray()` or `indexBy()` is | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * still fine. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * Below is an example: | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * ~~~ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * $customers = Customer::findBySql('SELECT * FROM tbl_customer')->all(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * ~~~ | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param string $sql the SQL statement to be executed | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @param array $params parameters to be bound to the SQL statement during execution. | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @return ActiveQuery the newly created [[ActiveQuery]] instance | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 */ | 
					 | 
					 | 
					 | 
						 */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						public static function findBySql($sql, $params = array()) | 
					 | 
					 | 
					 | 
						public static function findBySql($sql, $params = array()) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						{ | 
					 | 
					 | 
					 | 
						{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							throw new NotSupportedException('findBySql() is not supported by redis ActiveRecord'); | 
					 | 
					 | 
					 | 
							throw new NotSupportedException('findBySql() is not supported by redis ActiveRecord'); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						/** | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * Creates an [[ActiveQuery]] instance. | 
					 | 
					 | 
					 | 
						 * Creates an [[ActiveQuery]] instance. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * This method is called by [[find()]], [[findBySql()]] and [[count()]] to start a SELECT query. | 
					 | 
					 | 
					 | 
						 * This method is called by [[find()]], [[findBySql()]] and [[count()]] to start a SELECT query. | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -107,6 +95,14 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							)); | 
					 | 
					 | 
					 | 
							)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						 * Declares the name of the database table associated with this AR class. | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						 * @return string the table name | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						 */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						public static function tableName() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							return static::getTableSchema()->name; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						/** | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * Returns the schema information of the DB table associated with this AR class. | 
					 | 
					 | 
					 | 
						 * Returns the schema information of the DB table associated with this AR class. | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -114,6 +110,7 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 */ | 
					 | 
					 | 
					 | 
						 */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						public static function getTableSchema() | 
					 | 
					 | 
					 | 
						public static function getTableSchema() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						{ | 
					 | 
					 | 
					 | 
						{ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
							// TODO should be cached | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							throw new InvalidConfigException(__CLASS__.'::getTableSchema() needs to be overridden in subclasses and return a TableSchema.'); | 
					 | 
					 | 
					 | 
							throw new InvalidConfigException(__CLASS__.'::getTableSchema() needs to be overridden in subclasses and return a TableSchema.'); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -173,9 +170,9 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									} | 
					 | 
					 | 
					 | 
									} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					//			} | 
					 | 
					 | 
					 | 
					//			} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								// save pk in a findall pool | 
					 | 
					 | 
					 | 
								// save pk in a findall pool | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$db->executeCommand('RPUSH', array(static::tableName(), implode('-', $pk))); // TODO escape PK glue | 
					 | 
					 | 
					 | 
								$db->executeCommand('RPUSH', array(static::tableName(), static::hashPk($pk))); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$key = static::tableName() . ':a:' . implode('-', $pk); // TODO escape PK glue | 
					 | 
					 | 
					 | 
								$key = static::tableName() . ':a:' . static::hashPk($pk); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								// save attributes | 
					 | 
					 | 
					 | 
								// save attributes | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$args = array($key); | 
					 | 
					 | 
					 | 
								$args = array($key); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								foreach($values as $attribute => $value) { | 
					 | 
					 | 
					 | 
								foreach($values as $attribute => $value) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -216,7 +213,7 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$n=0; | 
					 | 
					 | 
					 | 
							$n=0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							foreach($condition as $pk) { | 
					 | 
					 | 
					 | 
							foreach($condition as $pk) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$key = static::tableName() . ':a:' . (is_array($pk) ? implode('-', $pk) : $pk); // TODO escape PK glue | 
					 | 
					 | 
					 | 
								$key = static::tableName() . ':a:' . static::hashPk($pk); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								// save attributes | 
					 | 
					 | 
					 | 
								// save attributes | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$args = array($key); | 
					 | 
					 | 
					 | 
								$args = array($key); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								foreach($attributes as $attribute => $value) { | 
					 | 
					 | 
					 | 
								foreach($attributes as $attribute => $value) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -257,7 +254,7 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$n=0; | 
					 | 
					 | 
					 | 
							$n=0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							foreach($condition as $pk) { // TODO allow multiple pks as condition | 
					 | 
					 | 
					 | 
							foreach($condition as $pk) { // TODO allow multiple pks as condition | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$key = static::tableName() . ':a:' . (is_array($pk) ? implode('-', $pk) : $pk); // TODO escape PK glue | 
					 | 
					 | 
					 | 
								$key = static::tableName() . ':a:' . static::hashPk($pk); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								foreach($counters as $attribute => $value) { | 
					 | 
					 | 
					 | 
								foreach($counters as $attribute => $value) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									$db->executeCommand('HINCRBY', array($key, $attribute, $value)); | 
					 | 
					 | 
					 | 
									$db->executeCommand('HINCRBY', array($key, $attribute, $value)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								} | 
					 | 
					 | 
					 | 
								} | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -292,13 +289,11 @@ abstract class ActiveRecord extends \yii\db\ActiveRecord | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							$attributeKeys = array(); | 
					 | 
					 | 
					 | 
							$attributeKeys = array(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							foreach($condition as $pk) { | 
					 | 
					 | 
					 | 
							foreach($condition as $pk) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								if (is_array($pk)) { | 
					 | 
					 | 
					 | 
								$pk = static::hashPk($pk); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									$pk = implode('-', $pk); | 
					 | 
					 | 
					 | 
								$db->executeCommand('LREM', array(static::tableName(), 0, $pk)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								} | 
					 | 
					 | 
					 | 
								$attributeKeys[] = static::tableName() . ':a:' . $pk; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$db->executeCommand('LREM', array(static::tableName(), 0, $pk)); // TODO escape PK glue | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								$attributeKeys[] = static::tableName() . ':a:' . $pk; // TODO escape PK glue | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} | 
					 | 
					 | 
					 | 
							} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							return $db->executeCommand('DEL', $attributeKeys); | 
					 | 
					 | 
					 | 
							return $db->executeCommand('DEL', $attributeKeys);// TODO make this atomic or document as NOT | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						} | 
					 | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						/** | 
					 | 
					 | 
					 | 
						/** | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |