]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 413222: Implement $attachment->remove_from_db - Patch by Frédéric Buclin <LpSol...
authorlpsolit%gmail.com <>
Sun, 20 Jan 2008 21:03:53 +0000 (21:03 +0000)
committerlpsolit%gmail.com <>
Sun, 20 Jan 2008 21:03:53 +0000 (21:03 +0000)
Bugzilla/Attachment.pm
attachment.cgi

index dafdf70ad54b127a12624030012f8b979a5359c4..954765f0327c3674888a5b9a6777fd9d7a2d6100 100644 (file)
@@ -758,8 +758,6 @@ Params:     C<$bug> - Bugzilla::Bug object - the bug for which to insert
 
 Returns:    the ID of the new attachment.
 
-=back
-
 =cut
 
 sub insert_attachment_for_bug {
@@ -932,4 +930,30 @@ sub insert_attachment_for_bug {
     return $attachment;
 }
 
+=pod
+
+=item C<remove_from_db()>
+
+Description: removes an attachment from the DB.
+
+Params:     none
+
+Returns:    nothing
+
+=back
+
+=cut
+
+sub remove_from_db {
+    my $self = shift;
+    my $dbh = Bugzilla->dbh;
+
+    $dbh->bz_start_transaction();
+    $dbh->do('DELETE FROM flags WHERE attach_id = ?', undef, $self->id);
+    $dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $self->id);
+    $dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isurl = ?, isobsolete = ?
+              WHERE attach_id = ?', undef, ('text/plain', 0, 0, 1, $self->id));
+    $dbh->bz_commit_transaction();
+}
+
 1;
index 6fd238c2f8690fb4bf6986e695280576cf0eb88b..529e0aa0d93e94a8fbd2d8bfc0361fbc2761eaaf 100755 (executable)
@@ -649,19 +649,11 @@ sub delete_attachment {
         $template->process("attachment/delete_reason.txt.tmpl", $vars, \$msg)
           || ThrowTemplateError($template->error());
 
-        $dbh->bz_start_transaction();
-        $dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $attachment->id);
-        $dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isurl = ?,
-                         isobsolete = ?
-                  WHERE attach_id = ?', undef,
-                 ('text/plain', 0, 0, 1, $attachment->id));
-        $dbh->do('DELETE FROM flags WHERE attach_id = ?', undef, $attachment->id);
-        $dbh->bz_commit_transaction();
-
         # If the attachment is stored locally, remove it.
         if (-e $attachment->_get_local_filename) {
             unlink $attachment->_get_local_filename;
         }
+        $attachment->remove_from_db();
 
         # Now delete the token.
         delete_token($token);