File: register-theme

package info (click to toggle)
gforge 4.5.14-22etch13
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,004 kB
  • ctags: 11,918
  • sloc: php: 36,047; sql: 29,050; sh: 10,538; perl: 6,496; xml: 3,810; makefile: 341; python: 263; ansic: 256
file content (88 lines) | stat: -rwxr-xr-x 2,262 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/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 <dirname> <theme name>" ;
    debug "The theme must be in /usr/share/gforge/www/themes/<dirname>/" ;
    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" ;
}