Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1293 dpurdie 1
###############################################################################
2
# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
3
# sits@users.sourceforge.net
4
#
5
# This program is free software; you can redistribute it and modify it under
6
# the terms of the GPL.
7
 
8
# Flyspray connection class, for appending comments to a bug report.
9
 
10
package Codestriker::BugDB::FlysprayConnection;
11
 
12
use strict;
13
use DBI;
14
 
15
# Static method for building a database connection.
16
sub get_connection($) {
17
    my ($type) = @_;
18
 
19
    # Return a connection with the flyspray database.
20
    my $self = {};
21
    my $dbname = $Codestriker::flyspray_db_dbname;
22
    $dbname = "flyspray" if ($dbname eq "");
23
    $self->{dbh} =
24
	DBI->connect("DBI:mysql:dbname=$dbname;host=$Codestriker::flyspray_db_host",
25
		     $Codestriker::flyspray_db_name, $Codestriker::flyspray_db_password,
26
		     { RaiseError => 1, AutoCommit => 1 });
27
    bless $self, $type;
28
}
29
 
30
# Method for releasing a flyspray database connection.
31
sub release_connection($) {
32
    my ($self) = @_;
33
 
34
    $self->{dbh}->disconnect;
35
}
36
 
37
# Return true if the specified bugid exists in the bug database,
38
# false otherwise.
39
sub bugid_exists($$) {
40
    my ($self, $bugid) = @_;
41
 
42
    return $self->{dbh}->selectrow_array('SELECT COUNT(*) FROM flyspray_tasks ' .
43
					 'WHERE task_id = ?', {}, $bugid) != 0;
44
}
45
 
46
 
47
# Method for updating the bug with information that a code review has been
48
# created/closed/committed against this bug.
49
sub update_bug($$$$) {
50
    my ($self, $bugid, $comment) = @_;
51
 
52
    # Create the necessary prepared statements.
53
    my $insert_comment =
54
	$self->{dbh}->prepare_cached('INSERT INTO flyspray_comments ' .
55
				     '(task_id, user_id, date_added, comment_text) ' .
56
				     'VALUES (?, ?, ?, ?)');
57
    my $insert_history =
58
	$self->{dbh}->prepare_cached('INSERT INTO flyspray_history ' .
59
				     '(task_id, user_id, event_date, event_type, new_value) ' .
60
				     'VALUES (?, ?, ?, 4, 1)');
61
 
62
    # Execute the statement.
63
 
64
    $comment =~ s/(http:\S+)/<A HREF=\"$1\">$1<\/A>/g;
65
    $insert_comment->execute($bugid, $Codestriker::bug_db_user_id, time(), $comment) or die $insert_comment->errstr;
66
    $insert_history->execute($bugid, $Codestriker::bug_db_user_id, time()) or die $insert_history->errstr;
67
}
68
 
69
1;