BZ::Client::Bug::Attachment - Client side representation of an Attachment to a Bug in Bugzilla
version 4.4004
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 );
This section lists the class methods, which are available in this module.
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".
Added in Bugzilla 3.6.
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 (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 (array) - An array of integer attachment ID's.
A hash containing two items is returned:
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.
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.
If you specified an alias and there is no bug with that alias.
The bug_id you specified doesn't exist in the database.
bug_id
You do not have access to the bug_id you specified.
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.
This allows you to add an attachment to a bug in Bugzilla.
Actual Bugzilla API method is "add_attachment".
Added in Bugzilla 4.0.
The return value has changed in Bugzilla 4.4.
An instance of this package or a hash containing:
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 (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 (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 (string) Required - A short string describing the attachment.
content_type (string) Required - The MIME type of the attachment, like text/plain or image/png.
comment (string) - A comment to add along with this attachment.
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.
text/plain
Defaults to False if not specified.
is_private (boolean) - True if the attachment should be private (restricted to the "insidergroup"), False if the attachment should be public.
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.
status
type_id
name
name (string) - The name of the flag type.
type_id (int) - THe internal flag type ID.
status (string) - The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).
requestee (string) - The login of the requestee if the flag type is requestable to a specific user.
An array of the attachment ID's created.
The flag status is invalid.
You tried to request, grant, or deny a flag but only a user with the required permissions may make the change.
You can't ask a specific person for the flag.
The flag type specified matches several flag types. You must specify the type id value to update or add a flag.
The flag type is inactive and cannot be used to create new flags.
You tried to attach a file that was larger than Bugzilla will accept.
You specified a "content_type" argument that was blank, not a valid MIME type, or not a MIME type that Bugzilla accepts for attachments.
You did not specify a valid for the "file_name" argument.
You did not specify a value for the "summary" argument.
You set the data field to an empty string.
data
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.
Added in Bugzilla 5.0.
text (string) Required - Text comment text to render
id The ID of the bug to render the comment against.
The HTML rendering
This allows you to update attachment metadata in Bugzilla.
Actual Bugzilla API method is "update_attachments".
content_type (string) - The MIME type of the attachment, like text/plain or image/png.
image/png
is_obsolete (boolean) - True if the attachment is obsolete, False otherwise.
type_id (int) - THe internal flag type id.
id (int) - Use id to specify the flag to be updated. You will need to specify the id if more than one flag is set of the same name.
id
new (boolean) - Set to true if you specifically want a new flag to be created.
An array of hashes with the following fields:
id (int) The id of the attachment that was updated.
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 (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 (string) - The values that were added to this field. possibly a comma-and-space-separated list if multiple values were added.
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', }, }, }, ]
The flag type specified matches several flag types. You must specify the type ID value to update or add a flag.
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.
This section lists the modules instance methods.
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 (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.
base46
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.
raw()
base64()
my $data = $attachment->data(); my $file_content_base64_encoded = $data->base64(); my $original_file_content = $data->raw();
Required, Read and Write.
file_name (string) The "file name" that will be displayed in the UI for this attachment.
summary (string) A short string describing the attachment.
content_type (string) The MIME type of the attachment, like text/plain or image/png.
comment (string or hash) A comment to add along with this attachment. If comment is a hash, it has the following keys:
comment
Only useful when adding attachments.
body (string) The body of the comment.
is_markdown (boolean) If set to true, the comment has Markdown structures; otherwise, it is an ordinary text.
is_patch (boolean) True if the attachment should be private (restricted to the "insidergroup"), False if the attachment should be public.
is_private (boolean) True if the attachment is private (only visible to a certain group called the "insidergroup"), False otherwise.
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 (name) The ID of the flag.
name (string) The name flag type.
type_id (int) The internal flag type ID.
creation_date (DateTime) The timestamp when this flag was originally created.
Read only.
modification_date (DateTime) The timestamp when the flag was last modified.
status (string) The flags new status (i.e. "?", "+", "-" or "X" to clear a flag).
setter (string) The login name of the user who created or last modified the flag.
requestee (string) The login of the requestee if the flag type is requestable to a specific user.
size (int) The length (in bytes) of the attachment.
creation_time (DateTime) The time the attachment was created.
last_change_time (DateTime) The last time the attachment was modified.
attachment_id (int) The numeric id of the attachment.
creator (string) The login name of the user that created the attachment.
Dean Hamstead <dean@bytefoundry.com.au>
Jochen Wiedmann <jochen.wiedmann@gmail.com>
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.
To install BZ::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm BZ::Client
CPAN shell
perl -MCPAN -e shell install BZ::Client
For more information on module installation, please visit the detailed CPAN module installation guide.