Beispiel #1
0
 public function __construct($id = NULL)
 {
     parent::__construct($id);
     if (mt_rand(1, 100) === 1) {
         Jam::delete($this)->expired()->execute();
     }
 }
Beispiel #2
0
 public function test_expired()
 {
     $current_time = time();
     $expected_sql = "DELETE FROM `test_user_tokens` WHERE `test_user_tokens`.`expires` < {$current_time}";
     $sql = (string) Jam::delete('test_user_token')->expired(TRUE, $current_time);
     $this->assertEquals($expected_sql, $sql);
 }
Beispiel #3
0
 /**
  * Delete an item with a specific key from the database
  * @param  string $foreign_model
  * @param  string $key
  * @return Database_Result
  */
 protected function _delete_item($foreign_model, $key)
 {
     if (!$foreign_model) {
         return NULL;
     }
     return Jam::delete($foreign_model)->where_key($key)->execute();
 }
 public function erase_query(Jam_Model $model)
 {
     $descendant_ids = $this->descendants_query($model->id())->where($this->depth_key, '>', 0)->execute($model->meta()->db())->as_array(NULL, $this->descendant_key);
     return Jam::delete($this->foreign_model)->where_key($descendant_ids);
 }
Beispiel #5
0
 /**
  * Deletes a single record.
  *
  * @return  boolean
  **/
 public function delete()
 {
     $result = FALSE;
     // Are we loaded? Then we're just deleting this record
     if ($this->_loaded) {
         $key = $this->_original[$this->meta()->primary_key()];
         if (($result = $this->meta()->events()->trigger('model.before_delete', $this)) !== FALSE) {
             $result = Jam::delete($this)->where_key($key)->execute();
         }
     }
     // Trigger the after-delete
     $this->meta()->events()->trigger('model.after_delete', $this, array($result));
     // Clear the object so it appears deleted anyway
     $this->clear();
     // Set the flag indicatig the model has been successfully deleted
     $this->_deleted = $result;
     return $this->_deleted;
 }