Exemplo n.º 1
0
	/**
	 * Delete this data object.
	 * $this->onBeforeDelete() gets called.
	 * Note that in Versioned objects, both Stage and Live will be deleted.
	 *  @uses DataObjectDecorator->augmentSQL()
	 */
	public function delete() {
		$this->brokenOnDelete = true;
		$this->onBeforeDelete();
		if($this->brokenOnDelete) {
			user_error("$this->class has a broken onBeforeDelete() function.  Make sure that you call parent::onBeforeDelete().", E_USER_ERROR);
		}
		
		foreach($this->getClassAncestry() as $ancestor) {
			if(self::has_own_table($ancestor)) {
				$sql = new SQLQuery();
				$sql->delete = true;
				$sql->from[$ancestor] = "`$ancestor`";
				$sql->where[] = "ID = $this->ID";
				$this->extend('augmentSQL', $sql);
				$sql->execute();
			}
		}
		
		$this->onAfterDelete();

		$this->OldID = $this->ID;
		$this->ID = 0;

		DataObjectLog::deletedObject($this);
	}
 /**
  * Delete this data object.
  * $this->onBeforeDelete() gets called.
  * Note that in Versioned objects, both Stage and Live will be deleted.
  *  @uses DataObjectDecorator->augmentSQL()
  */
 public function delete()
 {
     $this->brokenOnDelete = true;
     $this->onBeforeDelete();
     if ($this->brokenOnDelete) {
         user_error("{$this->class} has a broken onBeforeDelete() function.  Make sure that you call parent::onBeforeDelete().", E_USER_ERROR);
     }
     // Deleting a record without an ID shouldn't do anything
     if (!$this->ID) {
         throw new Exception("DataObject::delete() called on a DataObject without an ID");
     }
     foreach ($this->getClassAncestry() as $ancestor) {
         if (self::has_own_table($ancestor)) {
             $sql = new SQLQuery();
             $sql->delete = true;
             $sql->from[$ancestor] = "\"{$ancestor}\"";
             $sql->where[] = "\"ID\" = {$this->ID}";
             $this->extend('augmentSQL', $sql);
             $sql->execute();
         }
     }
     // Remove this item out of any caches
     $this->flushCache();
     $this->onAfterDelete();
     $this->OldID = $this->ID;
     $this->ID = 0;
     DataObjectLog::deletedObject($this);
 }