3 # Debian-specific script to delete plugin-specific tables
4 # Roland Mas <lolando@debian.org>
13 use vars qw/$dbh @reqlist $query/ ;
14 use vars qw/$sys_default_domain $sys_cvs_host
15 $sys_shell_host $sys_users_host $sys_docs_host $sys_lists_host
16 $sys_dns1_host $sys_dns2_host $FTPINCOMING_DIR $FTPFILES_DIR
17 $sys_urlroot $sf_cache_dir $sys_name $sys_themeroot
18 $sys_news_group $sys_dbhost $sys_dbname $sys_dbuser $sys_dbpasswd
19 $sys_ldap_base_dn $sys_ldap_host $admin_login $admin_password
20 $server_admin $domain_name
22 use vars qw/$pluginname/ ;
24 sub is_lesser ( $$ ) ;
25 sub is_greater ( $$ ) ;
27 sub parse_sql_file ( $ ) ;
29 require ("/usr/share/gforge/lib/include.pl") ; # Include a few predefined functions
30 require ("/usr/share/gforge/lib/sqlparser.pm") ; # Our magic SQL parser
32 debug "You'll see some debugging info during this installation." ;
33 debug "Do not worry unless told otherwise." ;
37 # debug "Connected to the database OK." ;
39 $pluginname = "globaldashboard" ;
41 $dbh->{AutoCommit} = 0;
42 $dbh->{RaiseError} = 1;
44 my ($sth, @array, $version, $action, $path, $target, $rname) ;
46 my $pattern = "plugin_" . $pluginname . '_%' ;
48 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='v'" ;
49 $sth = $dbh->prepare ($query) ;
51 while (@array = $sth->fetchrow_array ()) {
53 &drop_view_if_exists ($rname) ;
57 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='r'" ;
58 $sth = $dbh->prepare ($query) ;
60 while (@array = $sth->fetchrow_array ()) {
62 &drop_table_if_exists ($rname) ;
66 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='i'" ;
67 $sth = $dbh->prepare ($query) ;
69 while (@array = $sth->fetchrow_array ()) {
71 &drop_index_if_exists ($rname) ;
75 $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='s'" ;
76 $sth = $dbh->prepare ($query) ;
78 while (@array = $sth->fetchrow_array ()) {
80 &drop_sequence_if_exists ($rname) ;
87 debug "It seems your database deletion went well and smoothly. That's cool." ;
88 debug "Please enjoy using Debian FusionForge." ;
90 # There should be a commit at the end of every block above.
91 # If there is not, then it might be symptomatic of a problem.
92 # For safety, we roll back.
97 warn "Transaction aborted because $@" ;
98 debug "Transaction aborted because $@" ;
99 debug "Last SQL query was:\n$query\n(end of query)" ;
101 debug "Please report this bug on the Debian bug-tracking system." ;
102 debug "Please include the previous messages as well to help debugging." ;
103 debug "You should not worry too much about this," ;
104 debug "your DB is still in a consistent state and should be usable." ;
114 print STDERR "$v\n" ;
117 sub drop_table_if_exists ( $ ) {
118 my $tname = shift or die "Not enough arguments" ;
119 $query = "SELECT count(*) FROM pg_class WHERE relname='$tname' AND relkind='r'" ;
120 my $sth = $dbh->prepare ($query) ;
122 my @array = $sth->fetchrow_array () ;
125 if ($array [0] != 0) {
126 # debug "Dropping table $tname" ;
127 $query = "DROP TABLE $tname" ;
129 $sth = $dbh->prepare ($query) ;
135 sub drop_sequence_if_exists ( $ ) {
136 my $sname = shift or die "Not enough arguments" ;
137 $query = "SELECT count(*) FROM pg_class WHERE relname='$sname' AND relkind='S'" ;
138 my $sth = $dbh->prepare ($query) ;
140 my @array = $sth->fetchrow_array () ;
143 if ($array [0] != 0) {
144 # debug "Dropping sequence $sname" ;
145 $query = "DROP SEQUENCE $sname" ;
147 $sth = $dbh->prepare ($query) ;
153 sub drop_index_if_exists ( $ ) {
154 my $iname = shift or die "Not enough arguments" ;
155 $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='i'" ;
156 my $sth = $dbh->prepare ($query) ;
158 my @array = $sth->fetchrow_array () ;
161 if ($array [0] != 0) {
162 # debug "Dropping index $iname" ;
163 $query = "DROP INDEX $iname" ;
165 $sth = $dbh->prepare ($query) ;
171 sub drop_view_if_exists ( $ ) {
172 my $iname = shift or die "Not enough arguments" ;
173 $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='v'" ;
174 my $sth = $dbh->prepare ($query) ;
176 my @array = $sth->fetchrow_array () ;
179 if ($array [0] != 0) {
180 # debug "Dropping view $iname" ;
181 $query = "DROP VIEW $iname" ;
183 $sth = $dbh->prepare ($query) ;