Skip to content

Commit

Permalink
Fixed #100
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammaye committed Aug 15, 2013
1 parent 4b38c95 commit 7a875f9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions EMongoDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public function findAll($criteria=array(),$fields=array()){
* Finds all records based on $pk
* @param mixed $pk String, MongoID or array of strings or MongoID values (one can mix strings and MongoID in the array)
*/
public function findAllByPk($pk=array(),$fields=array()){
public function findAllByPk($pk,$fields=array()){
if(is_string($pk)||$pk instanceof MongoId){
return $this->find (array($this->primaryKey() => $this->getPrimaryKey($pk)),$fields);
}else if(is_array($pk)){
Expand Down Expand Up @@ -702,18 +702,28 @@ public function deleteAll($criteria=array(),$options=array()){
/**
* (non-PHPdoc)
* @see http://www.yiiframework.com/doc/api/1.1/CActiveRecord#saveCounters-detail
* @param $lower define a lower that the counter should not pass. IS NOT ATOMIC
*/
public function saveCounters(array $counters) {
public function saveCounters(array $counters,$lower=null,$upper=null) {
$this->trace(__FUNCTION__);

if ($this->getIsNewRecord())
throw new EMongoException(Yii::t('yii', 'The active record cannot be updated because it is new.'));

if(sizeof($counters)>0){
foreach($counters as $k => $v) $this->$k=$this->$k+$v;
return $this->updateByPk($this->{$this->primaryKey()}, array('$inc' => $counters));
foreach($counters as $k => $v){
if(
($lower!==null&&(($this->$k+$v)>$lower))||
($upper!==null&&(($this->$k+$v)<$upper))||
($lower===null&&$upper===null)
){
$this->$k=$this->$k+$v;
}else
unset($counters[$k]);
}
if(count($counters)>0)
return $this->updateByPk($this->{$this->primaryKey()}, array('$inc' => $counters));
}
return true; // Assume true since the action did run it just had nothing to update...
return true; // Assume true since the action did run it just had nothing to update...
}

/**
Expand Down

0 comments on commit 7a875f9

Please sign in to comment.