Пример #1
0
 /** 
  * This function provides basic delete functionality.  It gets rid of the
  * artefact's row in the artefact table, and the tables that reference the
  * artefact table.  It also recursively deletes child artefacts.
  *
  * If your artefact has additional data in another table, you should
  * override this function, but you MUST call parent::delete() after you
  * have done your own thing.
  */
 public function delete()
 {
     if (empty($this->id)) {
         $this->dirty = false;
         return;
     }
     db_begin();
     // Call delete() on children (if there are any)
     if ($children = $this->get_children_instances()) {
         foreach ($children as $child) {
             $child->delete();
         }
     }
     artefact_watchlist_notification($this->id);
     // Delete any references to this artefact from non-artefact places.
     delete_records_select('artefact_parent_cache', 'artefact = ? OR parent = ?', array($this->id, $this->id));
     // Make sure that the artefact is removed from any view blockinstances that have it
     if ($records = get_column('view_artefact', 'block', 'artefact', $this->id)) {
         foreach ($records as $blockid) {
             require_once get_config('docroot') . 'blocktype/lib.php';
             $bi = new BlockInstance($blockid);
             $bi->delete_artefact($this->id);
         }
     }
     delete_records('view_artefact', 'artefact', $this->id);
     delete_records('artefact_feedback', 'artefact', $this->id);
     delete_records('artefact_tag', 'artefact', $this->id);
     delete_records('artefact_access_role', 'artefact', $this->id);
     delete_records('artefact_access_usr', 'artefact', $this->id);
     if ($this->can_be_logged()) {
         $this->log('deleted');
     }
     // Delete the record itself.
     delete_records('artefact', 'id', $this->id);
     handle_event('deleteartefact', $this);
     // Set flags.
     $this->dirty = false;
     $this->parentdirty = true;
     $this->deleted = true;
     db_commit();
 }