#!/usr/bin/perl -w # # Debian-specific script to register a new theme into the Gforge database use DBI ; use strict ; use diagnostics ; use vars qw/$dbh @reqlist $thdir $thname/ ; sub debug ( $ ) ; require ("/usr/lib/gforge/lib/include.pl") ; # Include all the predefined functions &db_connect ; if ($#ARGV < 1) { debug "Usage: register-theme " ; debug "The theme must be in /usr/share/gforge/www/themes//" ; exit 1 ; } $thdir = $ARGV [0] ; $thname = $ARGV [1] ; unless (-d "/usr/share/gforge/www/themes/$thdir") { debug "The directory /usr/share/gforge/www/themes/$thdir does not exist" ; exit 1 ; } unless (-e "/usr/share/gforge/www/themes/$thdir/Theme.class") { debug "The file /usr/share/gforge/www/themes/$thdir/Theme.class does not exist" ; exit 1 ; } $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; eval { my ($query, $sth, @array, $version, $action) ; $thdir = $dbh->quote ($thdir) ; $thname = $dbh->quote ($thname) ; $query = "SELECT count(*) FROM themes WHERE dirname=$thdir" ; $sth = $dbh->prepare($query) ; $sth->execute() ; @array = $sth->fetchrow_array() ; $sth->finish() ; if ($array [0] != 0) { $query = "UPDATE themes SET enabled=true WHERE dirname=$thdir" ; } else { $query = "INSERT INTO themes (dirname, fullname) VALUES ($thdir, $thname)" ; } # debug $query ; $sth = $dbh->prepare ($query) ; $sth->execute () ; $sth->finish () ; # debug "Committing." ; $dbh->commit () ; # There should be a commit at the end of every block above. # If there is not, then it might be symptomatic of a problem. # For safety, we roll back. $dbh->rollback (); }; if ($@) { warn "Transaction aborted because $@" ; debug "Transaction aborted because $@" ; $dbh->rollback ; debug "Please report this bug on the Debian bug-tracking system." ; debug "Please include the previous messages as well to help debugging." ; debug "You should not worry too much about this," ; debug "your DB is still in a consistent state and should be usable." ; exit 1 ; } $dbh->rollback ; $dbh->disconnect ; sub debug ( $ ) { my $v = shift ; chomp $v ; print STDERR "$v\n" ; }