Example #1
0
File: CRUD.php Project: jasny/Q
 /**
  * Undelete a record. 
  */
 public function undelete()
 {
     if (empty($this->table)) {
         throw new Exception("No table argument specified");
     }
     if (!isset($id)) {
         list($id, $revision) = $this->getGetVars();
     }
     $id_col = $this->td->getFieldProperty('#role:id', 'name_db');
     if (isset($revision)) {
         if (DB::lookupValue("`_revision_-{$this->table}`", $id_col, $revision) != $id) {
             throw new Exception("Revision is not of the specified record.");
         }
     } else {
         $revision = DB::i()->query("SELECT `rv`.`_revision_previous` FROM `_revision_-{$this->table}` AS rv LEFT JOIN `_revision_-{$this->table}-_history_` AS h ON rv.id = h.id AND rv._revision_timestamp < h._revision_time_activate WHERE rv.`{$id_col}`=? AND rv.`_revision_action`='DELETE'", $id)->fetchValue();
         if (!isset($revision)) {
             throw new Exception("The record doesn't appear to be deleted.");
         }
     }
     DB::i()->store($this->table, array('_revision_' => $revision));
     $this->onactivate($id);
     echo 1;
 }
Example #2
0
 /**
  * Test the constraint exception when selecting multiple rows using conn->load() 
  */
 public function testLoad_Contraint()
 {
     $this->setExpectedException('Q\\DB_Constraint_Exception');
     $this->conn->lookupValue("test", "title", array('status' => 'ACTIVE'));
 }