[bugzilla-gnome-org-extensions] Move the install-update_db hook into TraceParser::Hooks.



commit 1280aceaf6b45fb91109cf1ca96160101652639e
Author: Max Kanat-Alexander <mkanat everythingsolved com>
Date:   Tue Aug 4 23:45:32 2009 -0500

    Move the install-update_db hook into TraceParser::Hooks.

 code/install-update_db.pl |   46 +-------------------------------------------
 lib/TraceParser/Hooks.pm  |   45 ++++++++++++++++++++++++++++++++++++++++++++
 lib/TraceParser/Trace.pm  |    3 +-
 3 files changed, 48 insertions(+), 46 deletions(-)
---
diff --git a/code/install-update_db.pl b/code/install-update_db.pl
index 818ecc8..9fb4f5e 100644
--- a/code/install-update_db.pl
+++ b/code/install-update_db.pl
@@ -23,47 +23,5 @@
 use strict;
 use warnings;
 use Bugzilla;
-use Bugzilla::Install::Util qw(indicate_progress);
-
-use TraceParser::Trace;
-
-my $dbh = Bugzilla->dbh;
-my $has_traces = $dbh->selectrow_array('SELECT 1 FROM trace ' 
-                                        . $dbh->sql_limit('1'));
-if (!$has_traces) {
-    print "Parsing traces from comments...\n";
-    my $total = $dbh->selectrow_array('SELECT COUNT(*) FROM longdescs');
-
-    if ($dbh->isa('Bugzilla::DB::Mysql')) {
-        $dbh->{'mysql_use_result'} = 1;
-    }
-
-    my $sth = $dbh->prepare('SELECT bug_id, thetext FROM longdescs');
-    $sth->execute();
-    my $count = 0;
-    my @traces;
-    while (my ($bug_id, $text) = $sth->fetchrow_array) {
-        $count++;
-        my $trace = TraceParser::Trace->parse_from_text($text, $bug_id);
-        push(@traces, $trace) if $trace;
-        indicate_progress({ current => $count, total => $total, 
-                            every => 100 });
-    }
-
-    my $total_traces = scalar(@traces);
-    print "Parsed $total_traces traces.\n";
-
-    if ($dbh->isa('Bugzilla::DB::Mysql')) {
-        $dbh->{'mysql_use_result'} = 0;
-    }
-
-    print "Inserting parsed traces into DB...\n";
-    $count = 1;
-    $dbh->bz_start_transaction();
-    while (my $trace = shift @traces) {
-        TraceParser::Trace->create($trace);
-        indicate_progress({ current => $count++, total => $total_traces, 
-                            every => 100 });
-    }
-    $dbh->bz_commit_transaction();
-}
+use TraceParser::Hooks;
+install_update_db();
diff --git a/lib/TraceParser/Hooks.pm b/lib/TraceParser/Hooks.pm
index ae9e62d..17a6f75 100644
--- a/lib/TraceParser/Hooks.pm
+++ b/lib/TraceParser/Hooks.pm
@@ -22,13 +22,58 @@
 package TraceParser::Hooks;
 use strict;
 use base qw(Exporter);
+use Bugzilla::Install::Util qw(indicate_progress);
 use TraceParser::Trace;
 
 our @EXPORT = qw(
+    install_update_db
     linkify_comment
     page
 );
 
+sub install_update_db {
+    my $dbh = Bugzilla->dbh;
+    my $has_traces = $dbh->selectrow_array('SELECT 1 FROM trace '
+                                           . $dbh->sql_limit('1'));
+    return if !$has_traces;
+
+    print "Parsing traces from comments...\n";
+    my $total = $dbh->selectrow_array('SELECT COUNT(*) FROM longdescs');
+
+    if ($dbh->isa('Bugzilla::DB::Mysql')) {
+        $dbh->{'mysql_use_result'} = 1;
+    }
+
+    my $sth = $dbh->prepare('SELECT bug_id, thetext FROM longdescs');
+    $sth->execute();
+    my $count = 0;
+    my @traces;
+    while (my ($bug_id, $text) = $sth->fetchrow_array) {
+        $count++;
+        my $trace = TraceParser::Trace->parse_from_text($text, $bug_id);
+        push(@traces, $trace) if $trace;
+        indicate_progress({ current => $count, total => $total,
+                            every => 100 });
+    }
+
+    my $total_traces = scalar(@traces);
+    print "Parsed $total_traces traces.\n";
+
+    if ($dbh->isa('Bugzilla::DB::Mysql')) {
+        $dbh->{'mysql_use_result'} = 0;
+    }
+
+    print "Inserting parsed traces into DB...\n";
+    $count = 1;
+    $dbh->bz_start_transaction();
+    while (my $trace = shift @traces) {
+        TraceParser::Trace->create($trace);
+        indicate_progress({ current => $count++, total => $total_traces,
+                            every => 100 });
+    }
+    $dbh->bz_commit_transaction();
+}
+
 sub linkify_comment {
     my %params = @_;
     my ($text, $bug_id, $match, $replace) = @params{qw(text bug_id match replace)};
diff --git a/lib/TraceParser/Trace.pm b/lib/TraceParser/Trace.pm
index ae24244..af2b39f 100644
--- a/lib/TraceParser/Trace.pm
+++ b/lib/TraceParser/Trace.pm
@@ -87,7 +87,7 @@ use constant IGNORE_FUNCTIONS => qw(
 # Returns a hash suitable for passing to create(), or undef if there is no
 # trace in the comment.
 sub parse_from_text {
-    my ($class, $text, $bug_id) = @_;
+    my ($class, $text) = @_;
     my $trace = Parse::StackTrace->parse(types => TRACE_TYPES, 
                                          text => $text);
     return undef if !$trace;
@@ -114,7 +114,6 @@ sub parse_from_text {
     my $trace_hash = md5_base64($trace_text);
 
     return {
-        bug_id      => $bug_id,
         stack_hash  => $stack_hash,
         short_hash  => $short_hash,
         short_stack => join(', ', @short_stack),


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