/**
  * @brief Delete this element
  *
  * @note    This function overrides the same-named function from the parent class.
  *          This is required to delete the attachements of an element too.
  *
  * @param boolean $delete_files_from_hdd    @li if true, the attached files will be deleted from harddisc drive (!!)
  *                                              If some files are used for other elements, they won't be deleted.
  *                                          @li if false, the files will be deleted from database,
  *                                              but not from the harddisc drive.
  *
  * @throws Exception if there was an error
  */
 public function delete($delete_files_from_hdd = false)
 {
     try {
         $transaction_id = $this->database->begin_transaction();
         // start transaction
         // first, we will delete all files of this element
         $attachements = $this->get_attachements();
         $this->reset_attributes();
         // set $this->attachements to NULL
         foreach ($attachements as $attachement) {
             $attachement->delete($delete_files_from_hdd);
         }
         parent::delete();
         // now delete this element
         $this->database->commit($transaction_id);
         // commit transaction
     } catch (Exception $e) {
         $this->database->rollback();
         // rollback transaction
         // restore the settings from BEFORE the transaction
         $this->reset_attributes();
         throw new Exception("Das Element \"" . $this->get_name() . "\" konnte nicht gelöscht werden!\nGrund: " . $e->getMessage());
     }
 }
Esempio n. 2
0
 /**
  * @brief Create a new attachement
  *
  * @param Database  &$database          reference to the database object
  * @param User      &$current_user      reference to the user which is logged in
  * @param Log       &$log               reference to the Log-object
  * @param object    &$element           @li the element on which the file will be attached
  *                                      @li For supported elements see Attachement::check_values_validity()
  * @param integer   $type_id            the ID of the attachement type (see Attachement::set_type_id())
  * @param string    $filename           the filename of the new attachement (see Attachement::set_filename())
  * @param string    $name               the name of the new attachement (see Attachement::set_name())
  * @param boolean   $show_in_table      the "show_in_table" attribute of the new filename (see Attachement::set_show_in_table())
  *
  * @warning         You have to supply the full path from filesystem root in $filename!!
  *                  For more details see Attachement::set_filename().
  *
  * @retval Attachement  the new attachement
  *
  * @throws Exception    if (this combination of) values is not valid
  * @throws Exception    if there was an error
  *
  * @see DBElement::add()
  */
 public static function add(&$database, &$current_user, &$log, &$element, $type_id, $filename, $name = '', $show_in_table = false)
 {
     if (!is_object($element)) {
         throw new Exception('$element ist kein Objekt!');
     }
     return parent::add($database, $current_user, $log, 'attachements', array('name' => $name, 'class_name' => get_class($element), 'element_id' => $element->get_id(), 'type_id' => $type_id, 'filename' => $filename, 'show_in_table' => $show_in_table));
 }