3 # Debian-specific script to register a new plugin into the SF database
9 use vars qw/$dbh @reqlist $plugin_name $plugin_desc $plugin_id/ ;
13 require ("/usr/share/gforge/lib/include.pl") ; # Include all the predefined functions
18 debug "Usage: register-plugin <plugin name> <plugin description>" ;
22 $plugin_name = $ARGV [0] ;
23 $plugin_desc = $ARGV [1] ;
25 if ($plugin_name =~ /[^a-z]/) {
26 debug "Error: the plugin name must contain only [a-z] characters" ;
30 $dbh->{AutoCommit} = 0;
31 $dbh->{RaiseError} = 1;
33 my ($query, $sth, @array, $version, $action) ;
35 $plugin_desc = $dbh->quote ($plugin_desc) ;
37 $query = "SELECT count(*) FROM plugins WHERE plugin_name = '$plugin_name'" ;
38 $sth = $dbh->prepare ($query) ;
40 @array = $sth->fetchrow_array () ;
44 $query = "SELECT plugin_id FROM plugins WHERE plugin_name = '$plugin_name'" ;
45 $sth = $dbh->prepare ($query) ;
47 @array = $sth->fetchrow_array () ;
50 $plugin_id = $array[0] ;
51 debug "Plugin '$plugin_name' already registered, skipping." ;
52 print "$plugin_id\n" ;
54 $query = "INSERT INTO plugins (plugin_name, plugin_desc) VALUES ('$plugin_name', $plugin_desc)" ;
58 $sth = $dbh->prepare ($query) ;
62 $query = "SELECT plugin_id FROM plugins WHERE plugin_name = '$plugin_name'" ;
63 $sth = $dbh->prepare ($query) ;
65 @array = $sth->fetchrow_array () ;
68 $plugin_id = $array[0] ;
69 debug "Plugin '$plugin_name' registered with id $plugin_id." ;
70 print "$plugin_id\n" ;
72 # debug "Committing." ;
76 # There should be a commit at the end of every block above.
77 # If there is not, then it might be symptomatic of a problem.
78 # For safety, we roll back.
83 warn "Transaction aborted because $@" ;
84 debug "Transaction aborted because $@" ;
86 debug "Please report this bug on the Debian bug-tracking system." ;
87 debug "Please include the previous messages as well to help debugging." ;
88 debug "You should not worry too much about this," ;
89 debug "your DB is still in a consistent state and should be usable." ;