<<

# Bugzilla::Attachment

- NAME
- SYNOPSIS
- DESCRIPTION
  - Instance Properties
  - Class Methods

# NAME

Bugzilla::Attachment - a file related to a bug that a user has uploaded to the Bugzilla server

# SYNOPSIS

      use Bugzilla::Attachment;

      # Get the attachment with the given ID.
      my $attachment = Bugzilla::Attachment->get($attach_id);

      # Get the attachments with the given IDs.
      my $attachments = Bugzilla::Attachment->get_list($attach_ids);

# DESCRIPTION

This module defines attachment objects, which represent files related to bugs that users upload to the Bugzilla server.

## Instance Properties

`id`

  the unique identifier for the attachment

`bug_id`

  the ID of the bug to which the attachment is attached

`description`

  user-provided text describing the attachment

`contenttype`

  the attachment's MIME media type

`attacher`

  the user who attached the attachment

`attached`

  the date and time on which the attacher attached the attachment

`modification_time`

  the date and time on which the attachment was last modified.

`filename`

  the name of the file the attacher attached

`ispatch`

  whether or not the attachment is a patch

`isurl`

  whether or not the attachment is a URL

`isobsolete`

  whether or not the attachment is obsolete

`isprivate`

  whether or not the attachment is private

`is_viewable`

  Returns 1 if the attachment has a content-type viewable in this browser. Note that we don't use $cgi->Accept()'s ability to check if a content-type matches, because this will return a value even if it's matched by the generic */* which most browsers add to the end of their Accept: headers.

`data`

  the content of the attachment

`datasize`

  the length (in characters) of the attachment content

`flags`

  flags that have been set on the attachment

## Class Methods

`get_attachments_by_bug($bug_id)`

  Description: retrieves and returns the attachments the currently logged in user can view for the given bug.

  Params: `$bug_id` - integer - the ID of the bug for which to retrieve and return attachments.

  Returns: a reference to an array of attachment objects.

`validate_is_patch()`

  Description: validates the "patch" flag passed in by CGI.

  Returns: 1 on success.

`validate_description()`

  Description: validates the description passed in by CGI.

  Returns: 1 on success.

`validate_content_type()`

  Description: validates the content type passed in by CGI.

  Returns: 1 on success.

`validate_can_edit($attachment, $product_id)`

  Description: validates if the user is allowed to view and edit the attachment. Only the submitter or someone with editbugs privs can edit it. Only the submitter and users in the insider group can view private attachments.

  Params: $attachment - the attachment object being edited. $product_id - the product ID the attachment belongs to.

  Returns: 1 on success. Else an error is thrown.

`validate_obsolete($bug)`

  Description: validates if attachments the user wants to mark as obsolete really belong to the given bug and are not already obsolete. Moreover, a user cannot mark an attachment as obsolete if he cannot view it (due to restrictions on it).

  Params: $bug - The bug object obsolete attachments should belong to.

  Returns: 1 on success. Else an error is thrown.

`insert_attachment_for_bug($throw_error, $bug, $user, $timestamp, $hr_vars)`

  Description: inserts an attachment from CGI input for the given bug.

  Params: `$bug` - Bugzilla::Bug object - the bug for which to insert the attachment. `$user` - Bugzilla::User object - the user we're inserting an attachment for. `$timestamp` - scalar - timestamp of the insert as returned by SELECT NOW(). `$hr_vars` - hash reference - reference to a hash of template variables.

  Returns: the ID of the new attachment.

`remove_from_db()`

  Description: removes an attachment from the DB.

  Params: none

  Returns: nothing

<<