Ejemplo n.º 1
0
 public function testIfWillUpdateAll()
 {
     $model = new DocumentBaseAttributes();
     $model->bool = false;
     $model->string = 'Las Vegas';
     $model->save();
     $model = new DocumentBaseAttributes();
     $model->bool = true;
     $model->string = 'Las Palmas';
     $model->save();
     $model = new DocumentBaseAttributes();
     $model->bool = false;
     $model->string = 'Las Cruces';
     $model->save();
     $em = new EntityManager($model);
     // With true
     $modifier = new Modifier(['int' => ['set' => 1]]);
     $criteria = new Criteria();
     $criteria->bool = true;
     $ok = $em->updateAll($modifier, $criteria);
     $this->assertTrue($ok);
     $criteria = new Criteria();
     $criteria->int = 1;
     $finder = new Finder($model);
     $modified = $finder->count($criteria);
     $this->assertSame(1, $modified);
     $found = $finder->find($criteria);
     $this->assertSame(1, $found->int);
     // With false
     $modifier = new Modifier();
     $modifier->set('int', 2);
     $criteria = new Criteria();
     $criteria->bool = false;
     $ok = $em->updateAll($modifier, $criteria);
     $this->assertTrue($ok);
     $criteria = new Criteria();
     $criteria->int = 2;
     $finder = new Finder($model);
     $modified = $finder->count($criteria);
     $this->assertSame(2, $modified);
     $found = $finder->find($criteria);
     $this->assertSame(2, $found->int);
 }
Ejemplo n.º 2
0
 /**
  * Atomic, in-place update method.
  *
  * @since v1.3.6
  * @param Modifier $modifier updating rules to apply
  * @param CriteriaInterface $criteria condition to limit updating rules
  * @return boolean
  */
 public function updateAll(Modifier $modifier, CriteriaInterface $criteria = null)
 {
     if ($modifier->canApply()) {
         $criteria = $this->sm->apply($criteria);
         $result = $this->getCollection()->update($criteria->getConditions(), $modifier->getModifiers(), $this->options->getSaveOptions(['upsert' => false, 'multiple' => true]));
         return $this->_result($result);
     } else {
         return false;
     }
 }