[bugzilla-gnome-org-extensions] 4.4 migration: Mostly style fixes in WebService



commit 8f16f5e060fd00f8abe798f52086ef77c4906ede
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Tue Nov 18 13:23:39 2014 +0100

    4.4 migration: Mostly style fixes in WebService

 lib/WebService.pm |   56 +++++++++++++++++++++++++---------------------------
 1 files changed, 27 insertions(+), 29 deletions(-)
---
diff --git a/lib/WebService.pm b/lib/WebService.pm
index 024ca3d..855b5fc 100644
--- a/lib/WebService.pm
+++ b/lib/WebService.pm
@@ -51,23 +51,23 @@ sub publish_review {
     Bugzilla->login(LOGIN_REQUIRED);
 
     # Check parameters
-    defined $params->{attachment_id}
-        || ThrowCodeError('param_required', { param => 'attachment_id' });
-    my $review = $params->{review};
-    (defined $review && trim($review) ne '')
-        || ThrowCodeError('param_required', { param => 'review' });
-
-    my $attachment_status = $params->{attachment_status};
-    if (defined $attachment_status) {
+    defined $params->{'attachment_id'}
+        || ThrowCodeError('param_required', { 'param' => 'attachment_id' });
+    my $review = $params->{'review'};
+    (defined($review) && trim($review) ne '')
+        || ThrowCodeError('param_required', { 'param' => 'review' });
+
+    my $attachment_status = $params->{'attachment_status'};
+    if (defined($attachment_status)) {
         my $field_object = Bugzilla::Field->new({ name => 'attachments.status' });
-        my $legal_values = [map { $_->name } @{ $field_object->legal_values }];
-        check_field('attachments.status', $attachment_status, $legal_values);
+        my @legal_values = map { $_->name } @{ $field_object->legal_values() };
+        check_field('attachments.status', $attachment_status, \ legal_values);
     }
 
-    my $attachment = Bugzilla::Attachment->new($params->{attachment_id});
-    defined $attachment
-        || ThrowUserError("invalid_attach_id",
-                          { attach_id => $params->{attachment_id} });
+    my $attachment = Bugzilla::Attachment->new($params->{'attachment_id'});
+    defined($attachment)
+        || ThrowUserError('invalid_attach_id',
+                          { 'attach_id' => $params->{'attachment_id'} });
 
     # Publishing a review of an attachment you can't access doesn't leak
     # information about that attachment, but it seems like bad policy to
@@ -75,24 +75,22 @@ sub publish_review {
     check_can_access($attachment);
 
     my $bug = Bugzilla::Bug->new($attachment->bug_id);
+    my $user = Bugzilla->user();
 
-    Bugzilla->user->can_edit_product($bug->product_id)
-        || ThrowUserError("product_edit_denied", {product => $bug->product});
+    $user->can_edit_product($bug->product_id)
+        || ThrowUserError('product_edit_denied', {'product' => $bug->product()});
 
     # This is a "magic string" used to identify review comments
-    my $comment = "Review of attachment " . $attachment->id . ":\n\n" . $review;
-
-    my $dbh = Bugzilla->dbh;
-
+    my $comment = 'Review of attachment ' . $attachment->id() . ":\n\n" . $review;
+    my $dbh = Bugzilla->dbh();
     # Figure out when the changes were made.
     my ($timestamp) = $dbh->selectrow_array("SELECT NOW()");
 
     # Append review comment
     $bug->add_comment($comment);
-
     $dbh->bz_start_transaction();
 
-    if (defined $attachment_status && $attachment->status ne $attachment_status) {
+    if (defined($attachment_status) && $attachment->status() ne $attachment_status) {
         # Note that this file needs to load properly even if the installation
         # doesn't have attachment statuses (a bugzilla.gnome.org addition), so,
         # for example, we wouldn't want an explicit 'use Bugzilla::AttachmentStatus'
@@ -102,18 +100,19 @@ sub publish_review {
                   SET     status      = ?,
                           modification_time = ?
                   WHERE   attach_id   = ?",
-                  undef, ($attachment_status, $timestamp, $attachment->id));
+                  undef, ($attachment_status, $timestamp, $attachment->id()));
 
-        my $updated_attachment = Bugzilla::Attachment->new($attachment->id);
+        my $updated_attachment = Bugzilla::Attachment->new($attachment->id());
 
-        if ($attachment->status ne $updated_attachment->status) {
+        if ($attachment->status() ne $updated_attachment->status()) {
             my $fieldid = get_field_id('attachments.status');
+
             $dbh->do('INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when,
                                                fieldid, removed, added)
                            VALUES (?, ?, ?, ?, ?, ?, ?)',
-                     undef, ($bug->id, $attachment->id, Bugzilla->user->id,
+                     undef, ($bug->id(), $attachment->id, $user->id(),
                              $timestamp, $fieldid,
-                             $attachment->status, $updated_attachment->status));
+                             $attachment->status(), $updated_attachment->status()));
 
             # Adding the comment will update the bug's delta_ts, so we don't need to do it here
         }
@@ -121,11 +120,10 @@ sub publish_review {
 
     # This actually adds the comment
     $bug->update();
-
     $dbh->bz_commit_transaction();
 
     # Send mail.
-    Bugzilla::BugMail::Send($bug->bug_id, { changer => Bugzilla->user() });
+    Bugzilla::BugMail::Send($bug->bug_id(), { changer => $user });
 
     # Nothing very interesting to return on success, so just return an empty structure
     return {};


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]