Esempio n. 1
0
 /**
  * Delete an attachment on an arbitrary object by its name.
  * If multiple attachments match the name (should not happen in reality), the
  * first match will be deleted.
  *
  * @param midcom_core_dbaobject $object The DBA object we're working on
  * @param string $name The name of the attachment to delete.
  * @return bool Indicating success.
  */
 public static function delete_attachment(midcom_core_dbaobject $object, $name)
 {
     $attachment = $object->get_attachment($name);
     if (!$attachment) {
         debug_add("Tried to delete the attachment {$name} at the object " . get_class($object) . " {$object->guid}, but it did not exist. Failing silently.");
         return false;
     }
     if (!$object->can_do('midgard:update') || !$object->can_do('midgard:attachments')) {
         debug_add("Failed to set parameters, midgard:update or midgard:attachments on the " . get_class($object) . " {$object->guid} not granted for the current user.", MIDCOM_LOG_ERROR);
         return false;
     }
     return $attachment->delete();
 }