3 # Debian-specific script to unregister a plugin from 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: unregister-plugin <plugin name>" ;
22 $plugin_name = $ARGV [0] ;
24 if ($plugin_name =~ /[^a-z]/) {
25 debug "Error: the plugin name must contain only [a-z] characters" ;
29 $dbh->{AutoCommit} = 0;
30 $dbh->{RaiseError} = 1;
32 my ($query, $query2, $query3, $sth, @array, @array2, @array3, $version, $action) ;
34 $query = "SELECT count(*) FROM plugins WHERE plugin_name = '$plugin_name'" ;
35 $sth = $dbh->prepare ($query) ;
37 @array = $sth->fetchrow_array () ;
44 # Looking if this plugin is already referenced by a group
45 $query2="SELECT group_plugin.plugin_id FROM group_plugin,plugins WHERE group_plugin.plugin_id=plugins.plugin_id AND plugin_name = '$plugin_name'";
46 $sth = $dbh->prepare ($query2) ;
48 @array2 = $sth->fetchrow_array () ;
50 if ($array2[0] && $array2[0] >= 1) {
51 print "WARNING: This plugin is already used by one or more groups, can't unregister\n"
53 $query3="SELECT user_plugin.plugin_id FROM user_plugin,plugins WHERE user_plugin.plugin_id=plugins.plugin_id AND plugin_name = '$plugin_name'";
54 $sth = $dbh->prepare ($query3) ;
56 @array3 = $sth->fetchrow_array () ;
58 if ($array3[0] && $array3[0] >= 1) {
59 print "WARNING: This plugin is already used by one or more users, can't unregister\n"
61 $query = "DELETE FROM plugins WHERE plugin_name = '$plugin_name'" ;
62 $sth = $dbh->prepare ($query) ;
66 $plugin_id = $array[0] ;
67 debug "Plugin '$plugin_name' successfully unregistered." ;
69 # debug "Committing." ;
74 debug "No plugin '$plugin_name' found, skipping." ;
77 # There should be a commit at the end of every block above.
78 # If there is not, then it might be symptomatic of a problem.
79 # For safety, we roll back.
84 warn "Transaction aborted because $@" ;
85 debug "Transaction aborted because $@" ;
87 debug "Please report this bug on the Debian bug-tracking system." ;
88 debug "Please include the previous messages as well to help debugging." ;
89 debug "You should not worry too much about this," ;
90 debug "your DB is still in a consistent state and should be usable." ;
100 print STDERR "$v\n" ;