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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3