[Bio] / FortyEight / Mantis.pm Repository:
ViewVC logotype

Diff of /FortyEight/Mantis.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Thu Oct 4 22:07:31 2007 UTC revision 1.3, Fri Feb 15 19:17:39 2008 UTC
# Line 5  Line 5 
5  use Data::Dumper;  use Data::Dumper;
6  use POSIX;  use POSIX;
7  use LWP::UserAgent;  use LWP::UserAgent;
8    use File::Basename;
9    
10  use base 'Class::Accessor';  use base 'Class::Accessor';
11  use DBI;  use DBI;
# Line 66  Line 67 
67      # Bug description.      # Bug description.
68      #      #
69    
70        my $sys = $self->info->{system};
71        my $summary = "$sys error detected in job $opts{job_id} stage $opts{stage}";
72    
73      my $descr = "Error reported in job $opts{job_id} in $opts{job_dir}\n";      my $descr = "Error reported in job $opts{job_id} in $opts{job_dir}\n";
74      $descr .= $opts{msg};      $descr .= $opts{msg};
75    
# Line 83  Line 87 
87      my $text_id = $dbh->{mysql_insertid};      my $text_id = $dbh->{mysql_insertid};
88      print "inserted: '$text_id'\n";      print "inserted: '$text_id'\n";
89    
90      $dbh->do(qq(INSERT INTO mantis_bug_table (project_id, reporter_id, date_submitted, last_updated, bug_text_id)      #
91                  VALUES (?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?)), undef,      # Determine if there is an auto-assigned handler for this project & category.
92               $project, $reporter, $text_id);      #
93    
94        my $res = $dbh->selectall_arrayref(qq(SELECT user_id
95                                              FROM mantis_project_category_table
96                                              WHERE project_id = ? AND category = ?), undef,
97                                           $project, $self->info->{bug_category});
98        # print Dumper($res);
99        my $handler = 0;
100        if (@$res)
101        {
102            $handler = $res->[0]->[0];
103        }
104    
105        $dbh->do(qq(INSERT INTO mantis_bug_table (project_id, reporter_id, handler_id, date_submitted, last_updated,
106                                                  bug_text_id, summary, category)
107                    VALUES (?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?, ?)), undef,
108                 $project, $reporter, $handler, $text_id, $summary, $self->info->{bug_category});
109      my $bug_id = $dbh->{mysql_insertid};      my $bug_id = $dbh->{mysql_insertid};
110    
111        {
112      my $b = $meta->get_metadata('mantis.bug');      my $b = $meta->get_metadata('mantis.bug');
113      if (ref($b))      if (ref($b))
114      {      {
# Line 98  Line 119 
119          $b = [$bug_id];          $b = [$bug_id];
120      }      }
121      $meta->set_metadata('mantis.bug', $b);      $meta->set_metadata('mantis.bug', $b);
122        }
123    
124      #      #
125      # custom field.      # custom field.
# Line 148  Line 170 
170          rmdir($tmp);          rmdir($tmp);
171      }      }
172    
173        #
174        # Insert a note for each error file.
175        #
176    
177        my @err_files = <$opts{job_dir}/rp.errors/*>;
178        @err_files = map { my @s = stat($_); [$_, @s] } @err_files;
179    
180        my @empty;
181        for my $err_file (sort { $b->[10] <=> $a->[10] } @err_files)
182        {
183            my $path = $err_file->[0];
184    
185            if ($err_file->[8] == 0)
186            {
187                push(@empty, $path);
188                next;
189            }
190    
191            eval {
192                my $txt = "Last ten lines of error file $path:\n";
193                $txt .= `ls -l $path`;
194                $txt .= "\n";
195                $txt .= `tail -10 $path`;
196    
197                insert_note($dbh, $bug_id, $reporter, $txt);
198            };
199            if ($@)
200            {
201                warn "Error inserting bug note about $path: $@\n";
202            }
203        }
204    
205        if (@empty)
206        {
207            my $txt = "Empty error files:\n" . join("\n", @empty), "\n";
208            insert_note($dbh, $bug_id, $reporter, $txt);
209        }
210    
211        my $bug_url = $self->info->{public_url} . "/view.php?id=$bug_id";
212        return($bug_id, $bug_url);
213  }  }
214    
215    
216    sub insert_note
217    {
218        my($dbh, $bug_id, $reporter, $txt) = @_;
219    
220        $dbh->do(qq(INSERT INTO mantis_bugnote_text_table(note) VALUES (?)),
221                 undef, $txt);
222        my $tid = $dbh->{mysql_insertid};
223        $dbh->do(qq(INSERT INTO mantis_bugnote_table (bug_id, reporter_id, bugnote_text_id, view_state,  date_submitted, last_modified)
224                    VALUES (?, ?, ?, 10, NOW(), NOW())), undef, $bug_id, $reporter, $tid);
225    }
226    
227  sub check_for_reporter  sub check_for_reporter
228  {  {
229      my($self, $email) = @_;      my($self, $email) = @_;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3