Also update group in CrashReport::update
authorVincent Tondellier <tonton+hg@team1664.org>
Sun, 14 Feb 2016 20:18:39 +0100
changeset 96 716c0292967c
parent 95 fcf3a68002e6
child 97 f68abe1d7358
Also update group in CrashReport::update
lib/CrashTest/Command/update.pm
lib/CrashTest/Plugin/Storage/Sql/Model/CrashReport.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 <http://www.gnu.org/licenses/>.
+
+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 => <<EOF;
+Usage: APPLICATION update file ...
+EOF
+
+sub run {
+    my ($self, @args) = @_;
+
+    if(scalar @args < 1) {
+        say $self->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;
--- 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;