# HG changeset patch # User Vincent Tondellier # Date 1455477519 -3600 # Node ID 716c0292967c16b0411c0d255babd21ead3910a5 # Parent fcf3a68002e67491d075236d5e66e34705deb2e5 Also update group in CrashReport::update diff -r fcf3a68002e6 -r 716c0292967c lib/CrashTest/Command/update.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/CrashTest/Command/update.pm Sun Feb 14 20:18:39 2016 +0100 @@ -0,0 +1,56 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +package CrashTest::Command::update; +use Mojo::Base 'Mojolicious::Command'; +use Mojo::JSON::MaybeXS; +use Mojo::JSON qw/decode_json/; +use Mojo::Util qw/slurp/; +use File::Spec::Functions qw/catdir catfile/; +use File::Basename; + +# Short description +has description => 'Update crash'; + +# Short usage message +has usage => <usage; + exit 0; + } + + foreach my $jsonfile(@args) { + my ($uuid,$path,$suffix) = fileparse($jsonfile, qw/.json/); + + my $dmp = undef; + if(-e catfile($path, "$uuid.dmp")) { + $dmp = slurp(catfile($path, "$uuid.dmp")); + } + + eval { + my $pjson = decode_json(slurp(catfile($path, "$uuid.json"))); + $self->app->crash_reports->update($uuid, $pjson, $pjson->{client_info}, $dmp); + }; + warn $@ if $@; + + } + +} + +1; diff -r fcf3a68002e6 -r 716c0292967c lib/CrashTest/Plugin/Storage/Sql/Model/CrashReport.pm --- a/lib/CrashTest/Plugin/Storage/Sql/Model/CrashReport.pm Sun Feb 14 20:17:15 2016 +0100 +++ b/lib/CrashTest/Plugin/Storage/Sql/Model/CrashReport.pm Sun Feb 14 20:18:39 2016 +0100 @@ -196,12 +196,27 @@ } sub update { - my ($self, $uuid, $pjson, $dmp_content) = @_; + my ($self, $uuid, $pjson, $dmp_file) = @_; my $tx = $self->db->begin; my $dbcrash = $self->db->query("SELECT id FROM crash_reports WHERE uuid = ?", $uuid)->hash; - $self->db->query("UPDATE crash_report_datas SET processed = ? WHERE crash_report_id = ?", $pjson, $dbcrash->{id}); + + my $crash_group = $self->crash_groups->find_or_create($uuid, $pjson); + + $self->db->query(" + UPDATE crash_report_datas SET processed = ? + WHERE crash_report_id = ?", + encode_json($pjson), + $dbcrash->{id}, + ); + $self->db->query(" + UPDATE crash_reports SET crash_group_id = ?, crash_group_distance = ? + WHERE id = ?", + $crash_group ? $crash_group->{id} : undef, + $crash_group ? ($crash_group->{dist} || 0) : undef, + $dbcrash->{id}, + ); $tx->commit;