updateAll() public method

{@inheritDoc}
public updateAll ( $fields, $conditions )
Esempio n. 1
0
 /**
  * Recursive method used to recover a single level of the tree
  *
  * @param int $counter The Last left column value that was assigned
  * @param mixed $parentId the parent id of the level to be recovered
  * @return int Ne next value to use for the left column
  */
 protected function _recoverTree($counter = 0, $parentId = null)
 {
     $config = $this->config();
     list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']];
     $pk = (array) $this->_table->primaryKey();
     $query = $this->_scope($this->_table->query())->select($pk)->where(function ($exp) use($parentId, $parent) {
         return $parentId === null ? $exp->isNull($parent) : $exp->eq($parent, $parentId);
     })->order($pk)->hydrate(false)->bufferResults(false);
     $leftCounter = $counter;
     foreach ($query as $row) {
         $counter++;
         $counter = $this->_recoverTree($counter, $row[$pk[0]]);
     }
     if ($parentId === null) {
         return $counter;
     }
     $this->_table->updateAll([$left => $leftCounter, $right => $counter + 1], [$pk[0] => $parentId]);
     return $counter + 1;
 }
Esempio n. 2
0
 /**
  * Test basic multi row updates.
  *
  * @return void
  */
 public function testUpdateAll()
 {
     $table = new Table(['table' => 'users', 'connection' => $this->connection]);
     $fields = ['username' => 'mark'];
     $result = $table->updateAll($fields, ['id <' => 4]);
     $this->assertSame(3, $result);
     $result = $table->find('all')->select(['username'])->order(['id' => 'asc'])->hydrate(false)->toArray();
     $expected = array_fill(0, 3, $fields);
     $expected[] = ['username' => 'garrett'];
     $this->assertEquals($expected, $result);
 }