deleteAll() public method

{@inheritDoc}
public deleteAll ( $conditions )
 /**
  * Also deletes the nodes in the subtree of the entity to be delete
  *
  * @param \Cake\Event\Event the beforeDelete event that was fired
  * @param \Cake\ORM\Entity the entity that is going to be saved
  * @return void
  */
 public function beforeDelete(Event $event, Entity $entity)
 {
     $config = $this->config();
     $this->_ensureFields($entity);
     $left = $entity->get($config['left']);
     $right = $entity->get($config['right']);
     $diff = $right - $left + 1;
     if ($diff > 2) {
         $this->_table->deleteAll(["{$config['left']} >=" => $left + 1, "{$config['left']} <=" => $right - 1]);
     }
     $this->_sync($diff, '-', "> {$right}");
 }
Beispiel #2
0
 /**
  * Test deleting many records with conditions using the alias
  *
  * @return void
  */
 public function testDeleteAllAliasedConditions()
 {
     $table = new Table(['table' => 'users', 'alias' => 'Managers', 'connection' => $this->connection]);
     $result = $table->deleteAll(['Managers.id <' => 4]);
     $this->assertSame(3, $result);
     $result = $table->find('all')->toArray();
     $this->assertCount(1, $result, 'Only one record should remain');
     $this->assertEquals(4, $result[0]['id']);
 }
Beispiel #3
0
 /**
  * Helper function called on gc for database sessions.
  *
  * @param string $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed.
  * @return bool True on success, false on failure.
  */
 public function gc($maxlifetime)
 {
     $this->_table->deleteAll(['expires <' => time()]);
     return true;
 }
 /**
  * Delete all draft entries in database
  * 
  * @param \Cake\ORM\Table $table Table instance
  * 
  * @return bool
  */
 public function cleanDrafts(Table $table)
 {
     return $table->deleteAll(['online' => -1]);
 }
 /**
  * Helper function called on gc for database sessions.
  *
  * @param string $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed.
  * @return bool True on success, false on failure.
  */
 public function gc($maxlifetime)
 {
     return $this->_table->deleteAll(['expires <' => time() - $maxlifetime]);
 }