/** * Factory method to get the current DbObjectRegistry */ public static function current() { if (!DbObjectRegistry::$instance) { DbObjectRegistry::$instance = new DbObjectRegistry(); } return DbObjectRegistry::$instance; }
/** * Add this object to a register to be deleted later * * This is used when you want to delete multiple items from the database at one time * and only one database query is performed. * * As an example, imagine that you have an array of authors and want to delete those * who have not written a book in the last year: * * <code> * $auth = new Author(); * $book = $auth->exclude('Book'); * $book->clause('release_date',date('Y-m-d',strtotime('1 year ago')),Clause::GT); * * if($authors = $auth->fetch()) * { * foreach($authors as $auth) * $auth->deleteLater(); * } * * $auth->purge(); * </code> * * The last method called ({@link purge()}) can be called on any object of that type. It * does not have to be an object that was deleted. * * @access public * @see purge,delete */ public function deleteLater($from_db_object = FALSE) { if (is_object($this->super_object) && !$from_db_object) { throw new Exception('You called deleteLater() on a DbObject that has a super object (a generalised object) present. Either don\'t call also(\'' . $this->superObject()->getClass() . '\') when building the query, or call deleteLater() on the super object. eg. $specialised->superObject()->deleteLater(). You will also need to call purge() on the super object (' . $this->super_object->getClass() . ') rather than ' . $this->getClass()); } DbObjectRegistry::current()->registerDelete($this); }