diff options
author | Dylan Hardison <dylan@mozilla.com> | 2016-01-20 04:57:54 +0100 |
---|---|---|
committer | Dylan Hardison <dylan@mozilla.com> | 2016-01-20 04:57:54 +0100 |
commit | ace6728970b520f219907887cd7a90010239c2a1 (patch) | |
tree | 0c22ab3cb3b621d7090562653ef862cdab0726b6 /scripts | |
parent | 050d08d5c76745bb7ef7f63a931908b0842e4026 (diff) | |
download | bugzilla-ace6728970b520f219907887cd7a90010239c2a1.tar.gz bugzilla-ace6728970b520f219907887cd7a90010239c2a1.tar.xz |
Bug 1236161 - when converting a BMP attachment to PNG fails a zero byte attachment is created
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/fix-attachment-sizes.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/fix-attachment-sizes.pl b/scripts/fix-attachment-sizes.pl new file mode 100644 index 000000000..a50e241ce --- /dev/null +++ b/scripts/fix-attachment-sizes.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +use strict; +use feature 'say'; + +use FindBin qw( $RealBin ); +use lib "$RealBin/.."; +use lib "$RealBin/../lib"; + +use Bugzilla; +use Bugzilla::Constants; + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +my $dbh = Bugzilla->dbh; + +$dbh->bz_start_transaction(); +my $attachment_sizes = $dbh->selectall_arrayref(q{ + SELECT attachments.attach_id, length(thedata) + FROM attach_data + INNER JOIN attachments ON attachments.attach_id = attach_data.id + WHERE attachments.attach_size != 0 + AND attachments.mimetype = 'image/png' + AND length(thedata) != attachments.attach_size }); +say "Found ", scalar @$attachment_sizes, " attachments to fix"; + +foreach my $attachment_size (@$attachment_sizes) { + say "Setting size for $attachment_size->[0] to $attachment_size->[1]"; + + $dbh->do("UPDATE attachments SET attach_size = ? WHERE attach_id = ?", undef, + $attachment_size->[1], + $attachment_size->[0]); +} + +$dbh->bz_commit_transaction();
\ No newline at end of file |