NAME
BZ::Client::Bug::Attachment - Client side representation of an Attachment to a Bug in Bugzilla
VERSION
version 4.4004
SYNOPSIS
This class provides methods for accessing and managing attachments in Bugzilla. Instances of this class are returned by BZ::Client::Bug::Attachment::get.
my $client = BZ::Client->new(
url => $url,
user => $user,
password => $password
);
my $comments = BZ::Client::Bug::Attachment->get( $client, $ids );
CLASS METHODS
This section lists the class methods, which are available in this module.
get
It allows you to get data about attachments, given a list of bugs and/or attachment ids.
Note: Private attachments will only be returned if you are in the insidergroup or if you are the submitter of the attachment.
Actual Bugzilla API method is "attachments".
History
Added in Bugzilla 3.6.
Parameters
Note: At least one of "ids" or "attachment_ids" is required.
In addition to the parameters below, this method also accepts the standard "include_fields" in BZ::Client::Bug and "exclude_fields" in BZ::Client::Bug arguments.
- ids
-
ids (array) - An array that can contain both bug IDs and bug aliases. All of the attachments (that are visible to you) will be returned for the specified bugs.
- attachment_ids
-
attachment_ids (array) - An array of integer attachment ID's.
Returns
A hash containing two items is returned:
- bugs
-
This is used for bugs specified in "ids". This is a hash, where the keys are the numeric ID's of the bugs and the value is an array of attachment obejcts.
Note that any individual bug will only be returned once, so if you specify an ID multiple times in "ids", it will still only be returned once.
- attachments
-
Each individual attachment requested in "attachment_ids" is returned here, in a hash where the numeric "attachment_id" is the key, and the value is the attachment object.
The return value looks like this:
{
bugs => {
1345 => [
{ (attachment) },
{ (attachment) }
],
9874 => [
{ (attachment) },
{ (attachment) }
],
},
attachments => {
234 => { (attachment) },
123 => { (attachment) },
},
}
An "attachment" as shown above is an object instance of this package.
Errors
- 100 - Invalid Bug Alias
-
If you specified an alias and there is no bug with that alias.
- 101 - Invalid Bug ID
-
The
bug_id
you specified doesn't exist in the database. - 102 - Access Denied
-
You do not have access to the
bug_id
you specified. - 304 - Auth Failure, Attachment is Private
-
You specified the ID of a private attachment in the "attachment_ids" argument, and you are not in the "insidergroup" that can see private attachments.
add
This allows you to add an attachment to a bug in Bugzilla.
Actual Bugzilla API method is "add_attachment".
History
Added in Bugzilla 4.0.
The return value has changed in Bugzilla 4.4.
Parameters
An instance of this package or a hash containing:
- ids
-
ids (array) Required - An array of ints and/or strings - the ID's or aliases of bugs that you want to add this attachment to. The same attachment and comment will be added to all these bugs.
- data
-
data (string or base64) Mostly Required - The content of the attachment.
The content will be base64 encoded. Of you can do it yourself by providing this option as a BZ::Client::XMPRPC::base64 object.
What is "Mostly Required" you ask? If you provide "file_name" only, this module will attempt to slurp it to provide this data parameter. See "file_name" options for more details.
- file_name
-
file_name (string) Required - The "file name" that will be displayed in the UI for this attachment.
If no /data parameter is provided, this module will attempt to open, slurp the contents of a file with path file_name, base64 encod that data, placed it into the /data parameter, then file_name is truncted to just the files basename.
Failures to open the file (for anyreason) will be silently ignored and the file_name parameter will not be touched.
- summary
-
summary (string) Required - A short string describing the attachment.
- content_type
-
content_type (string) Required - The MIME type of the attachment, like text/plain or image/png.
- comment
-
comment (string) - A comment to add along with this attachment.
- is_patch
-
is_patch (boolean) - True if Bugzilla should treat this attachment as a patch. If you specify this, you do not need to specify a "content_type". The "content_type" of the attachment will be forced to
text/plain
.Defaults to False if not specified.
- is_private
-
is_private (boolean) - True if the attachment should be private (restricted to the "insidergroup"), False if the attachment should be public.
Defaults to False if not specified.
- flags
-
An array of hashes with flags to add to the attachment. to create a flag, at least the
status
and thetype_id
orname
must be provided. An optional requestee can be passed if the flag type is requestable to a specific user.- name
-
name (string) - The name of the flag type.
- type_id
-
type_id (int) - THe internal flag type ID.
- status
-
status (string) - The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).
- requestee
-
requestee (string) - The login of the requestee if the flag type is requestable to a specific user.
Returns
An array of the attachment ID's created.
Errors
- 100 - Invalid Bug Alias
-
If you specified an alias and there is no bug with that alias.
- 101 - Invalid Bug ID
-
The
bug_id
you specified doesn't exist in the database. - 102 - Access Denied
-
You do not have access to the
bug_id
you specified. - 129 - Flag Status Invalid
-
The flag status is invalid.
- 130 - Flag Modification Denied
-
You tried to request, grant, or deny a flag but only a user with the required permissions may make the change.
- 131 - Flag not Requestable from Specific Person
-
You can't ask a specific person for the flag.
- 133 - Flag Type not Unique
-
The flag type specified matches several flag types. You must specify the type id value to update or add a flag.
- 134 - Inactive Flag Type
-
The flag type is inactive and cannot be used to create new flags.
- 600 - Attachment Too Large
-
You tried to attach a file that was larger than Bugzilla will accept.
- 601 - Invalid MIME Type
-
You specified a "content_type" argument that was blank, not a valid MIME type, or not a MIME type that Bugzilla accepts for attachments.
- 603 - File Name Not Specified
-
You did not specify a valid for the "file_name" argument.
- 604 - Summary Required
-
You did not specify a value for the "summary" argument.
- 606 - Empty Data
-
You set the
data
field to an empty string.
render
Returns the HTML rendering of the provided comment text.
Actual Bugzilla API method is "render_comment".
Note: this all takes place on your Bugzilla server.
History
Added in Bugzilla 5.0.
Parameters
- text
-
text (string) Required - Text comment text to render
- id
-
id The ID of the bug to render the comment against.
Returns
The HTML rendering
Errors
- 100 - Invalid Bug Alias
-
If you specified an alias and there is no bug with that alias.
- 101 - Invalid Bug ID
-
The
bug_id
you specified doesn't exist in the database. - 102 - Access Denied
-
You do not have access to the
bug_id
you specified.
update
This allows you to update attachment metadata in Bugzilla.
Actual Bugzilla API method is "update_attachments".
History
Added in Bugzilla 5.0.
Parameters
- ids
-
ids (array) - An array that can contain both bug IDs and bug aliases. All of the attachments (that are visible to you) will be returned for the specified bugs.
- file_name
-
file_name (string) Required - The "file name" that will be displayed in the UI for this attachment.
- summary
-
summary (string) Required - A short string describing the attachment.
- comment
-
comment (string) - A comment to add along with this attachment.
- content_type
-
content_type (string) - The MIME type of the attachment, like
text/plain
orimage/png
. - is_patch
-
is_patch (boolean) - True if Bugzilla should treat this attachment as a patch. If you specify this, you do not need to specify a "content_type". The "content_type" of the attachment will be forced to
text/plain
. - is_private
-
is_private (boolean) - True if the attachment should be private (restricted to the "insidergroup"), False if the attachment should be public.
- is_obsolete
-
is_obsolete (boolean) - True if the attachment is obsolete, False otherwise.
- flags
-
An array of hashes with flags to add to the attachment. to create a flag, at least the status and the type_id or name must be provided. An optional requestee can be passed if the flag type is requestable to a specific user.
- name
-
name (string) - The name of the flag type.
- type_id
-
type_id (int) - THe internal flag type id.
- status
-
status (string) - The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).
- requestee
-
requestee (string) - The login of the requestee if the flag type is requestable to a specific user.
- id
-
id (int) - Use
id
to specify the flag to be updated. You will need to specify theid
if more than one flag is set of the same name. - new
-
new (boolean) - Set to true if you specifically want a new flag to be created.
Returns
An array of hashes with the following fields:
- id
-
id (int) The id of the attachment that was updated.
- last_change_time
-
last_change_time (DateTime) - The exact time that this update was done at, for this attachment. If no update was done (that is, no fields had their values changed and no comment was added) then this will instead be the last time the attachment was updated.
- changes
-
changes (hash) - The changes that were actually done on this bug. The keys are the names of the fields that were changed, and the values are a hash with two keys:
- added
-
added (string) - The values that were added to this field. possibly a comma-and-space-separated list if multiple values were added.
- removed
-
removed (string) - The values that were removed from this field.
Here is an example of what a return value might look like:
[
{
id => 123,
last_change_time => '2010-01-01T12:34:56',
changes => {
summary => {
removed => 'Sample ptach',
added => 'Sample patch'
},
is_obsolete => {
removed => '0',
added => '1',
},
},
},
]
Errors
- 100 - Invalid Bug Alias
-
If you specified an alias and there is no bug with that alias.
- 101 - Invalid Bug ID
-
The bug_id you specified doesn't exist in the database.
- 102 - Access Denied
-
You do not have access to the
bug_id
you specified. - 129 - Flag Status Invalid
-
The flag status is invalid.
- 130 - Flag Modification Denied
-
You tried to request, grant, or deny a flag but only a user with the required permissions may make the change.
- 131 - Flag not Requestable from Specific Person
-
You can't ask a specific person for the flag.
- 133 - Flag Type not Unique
-
The flag type specified matches several flag types. You must specify the type ID value to update or add a flag.
- 134 - Inactive Flag Type
-
The flag type is inactive and cannot be used to create new flags.
- 601 - Invalid MIME Type
-
You specified a "content_type" argument that was blank, not a valid MIME type, or not a MIME type that Bugzilla accepts for attachments.
- 603 - File Name Not Specified
-
You did not specify a valid for the "file_name" argument.
- 604 - Summary Required
-
You did not specify a value for the "summary" argument.
new
my $comment = BZ::Client::Bug::Comment->new(
id => $bug_id,
comment => $comment,
is_private => 1 || 0,
work_time => 3.5
);
Creates a new instance with the given details. Doesn't actually touch your Bugzilla Server - see "add" for that.
INSTANCE METHODS
This section lists the modules instance methods.
bug_id
bug_id (int) - The ID of the bug that this attachment is on when reading
bug_id (int or string) - The ID or alias of the bug to append a attachment to when writing. Required.
data
data (base64 or string) The content of the attachment.
When writing, either provide a string (which will be base46
encoded for you) or a BZ::Client::XMLRPC::base64 object if you'd like to DIY.
When reading, a BZ::Client::XMLRPC::base64 object will be returned. To save you the trip, this object has a raw()
and a base64()
method. Here is an example.
my $data = $attachment->data();
my $file_content_base64_encoded = $data->base64();
my $original_file_content = $data->raw();
Required, Read and Write.
file_name
file_name (string) The "file name" that will be displayed in the UI for this attachment.
Required, Read and Write.
summary
summary (string) A short string describing the attachment.
Required, Read and Write.
content_type
content_type (string) The MIME type of the attachment, like text/plain
or image/png
.
Required, Read and Write.
comment
comment (string or hash) A comment to add along with this attachment. If comment
is a hash, it has the following keys:
Only useful when adding attachments.
- body
-
body (string) The body of the comment.
- is_markdown
-
is_markdown (boolean) If set to true, the comment has Markdown structures; otherwise, it is an ordinary text.
is_patch
is_patch (boolean) True if the attachment should be private (restricted to the "insidergroup"), False if the attachment should be public.
is_private
is_private (boolean) True if the attachment is private (only visible to a certain group called the "insidergroup"), False otherwise.
is_obsolete
is_obsolete (boolean) - True if the attachment is obsolete, False otherwise.
flags
flags (array) An array of hashes with flags to add to the attachment. to create a flag, at least the status and the type_id or name must be provided. An optional requestee can be passed if the flag type is requestable to a specific user.
Read and Write.
- id
-
id (name) The ID of the flag.
- name
-
name (string) The name flag type.
Read and Write.
- type_id
-
type_id (int) The internal flag type ID.
Read and Write.
- creation_date
-
creation_date (DateTime) The timestamp when this flag was originally created.
Read only.
- modification_date
-
modification_date (DateTime) The timestamp when the flag was last modified.
Read only.
- status
-
status (string) The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).
Read and Write.
- setter
-
setter (string) The login name of the user who created or last modified the flag.
Read only.
- requestee
-
requestee (string) The login of the requestee if the flag type is requestable to a specific user.
size
size (int) The length (in bytes) of the attachment.
Read only.
creation_time
creation_time (DateTime) The time the attachment was created.
Read only.
last_change_time
last_change_time (DateTime) The last time the attachment was modified.
attachment_id
attachment_id (int) The numeric id of the attachment.
creator
creator (string) The login name of the user that created the attachment.
AUTHORS
Dean Hamstead <dean@bytefoundry.com.au>
Jochen Wiedmann <jochen.wiedmann@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by Dean Hamstad.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.