120 lines
3.0 KiB
Plaintext
120 lines
3.0 KiB
Plaintext
|
#!/usr/bin/perl
|
||
|
|
||
|
use strict;
|
||
|
|
||
|
use Config::Simple;
|
||
|
use DBI;
|
||
|
use File::Basename;
|
||
|
use POSIX qw(strftime);
|
||
|
|
||
|
my $CFG_FILE = '@CFGDIR@/codepot.ini';
|
||
|
my $REPO = $ARGV[0];
|
||
|
my $REPOBASE = basename($REPO);
|
||
|
my $REV = $ARGV[1];
|
||
|
my $USER = $ARGV[2];
|
||
|
my $PROPNAME = $ARGV[3];
|
||
|
my $ACTION = $ARGV[4];
|
||
|
|
||
|
REPOBASE="`basename "${1}"`"
|
||
|
REVISION="${2}"
|
||
|
USER="${3}"
|
||
|
PROPNAME="${4}"
|
||
|
ACTION="${5}"
|
||
|
|
||
|
# [STDIN] PROPVAL ** the old property value is passed via STDIN.
|
||
|
|
||
|
#wget -q -O- "%API%/logCodeRevpropChange/svn/${REPOBASE}/${REVISION}/${USER}/${PROPNAME}/${ACTION}" 2>/dev/null
|
||
|
#exit 0
|
||
|
|
||
|
sub get_config
|
||
|
{
|
||
|
my $cfg = new Config::Simple();
|
||
|
|
||
|
if (!$cfg->read ($CFG_FILE))
|
||
|
{
|
||
|
return undef;
|
||
|
}
|
||
|
|
||
|
my $config = {
|
||
|
database_hostname => $cfg->param ("database_hostname"),
|
||
|
database_username => $cfg->param ("database_username"),
|
||
|
database_password => $cfg->param ("database_password"),
|
||
|
database_name => $cfg->param ("database_name"),
|
||
|
database_driver => $cfg->param ("database_driver"),
|
||
|
database_prefix => $cfg->param ("database_prefix")
|
||
|
};
|
||
|
|
||
|
return $config;
|
||
|
}
|
||
|
|
||
|
sub open_database
|
||
|
{
|
||
|
my ($cfg) = @_;
|
||
|
|
||
|
my $dbtype = $cfg->{database_driver};
|
||
|
my $dbname = $cfg->{database_name};
|
||
|
my $dbhost = $cfg->{database_hostname};
|
||
|
|
||
|
my $dbh = DBI->connect(
|
||
|
"DBI:$dbtype:$dbname:$dbhost",
|
||
|
$cfg->{database_username},
|
||
|
$cfg->{database_password},
|
||
|
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 }
|
||
|
);
|
||
|
|
||
|
return $dbh;
|
||
|
}
|
||
|
|
||
|
sub close_database
|
||
|
{
|
||
|
my ($dbh) = @_;
|
||
|
$dbh->disconnect ();
|
||
|
}
|
||
|
|
||
|
sub write_revprop_change_log
|
||
|
{
|
||
|
my ($dbh, $prefix, $projectid, $revision, $userid, $propname, $action) = @_;
|
||
|
|
||
|
#+------+---------+-----------+---------------------------+---------------------+---------------+-----------------+
|
||
|
#| id | type | projectid | message | createdon | action | userid |
|
||
|
#+------+---------+-----------+---------------------------+---------------------+---------------+-----------------+
|
||
|
#| 1610 | code | codepot | svn,codepot,98,svn:log,M | 2014-05-16 22:27:36 | revpropchange | hyunghwan.chung |
|
||
|
|
||
|
my $message = "svn,$projectid,$revision,$propname,$action";
|
||
|
my $createdon = strftime ('%Y-%m-%d %H:%M:%S', localtime());
|
||
|
|
||
|
my $query = $dbh->prepare ("INSERT INTO ${prefix}log(type,projectid,message,createdon,action,userid) VALUES(?,?,?,?,?,?)");
|
||
|
if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'revpropchange', $userid))
|
||
|
{
|
||
|
$dbh->rollback ();
|
||
|
return (-1, $dbh->errstr());
|
||
|
}
|
||
|
|
||
|
$dbh->commit ();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
#------------------------------------------------------------
|
||
|
# MAIN
|
||
|
#------------------------------------------------------------
|
||
|
|
||
|
my $cfg = get_config ();
|
||
|
if (!defined($cfg))
|
||
|
{
|
||
|
print (STDERR "Cannot load codepot configuration file\n");
|
||
|
exit (1);
|
||
|
}
|
||
|
|
||
|
my $dbh = open_database ($cfg);
|
||
|
if (!defined($dbh))
|
||
|
{
|
||
|
print (STDERR "Cannot open database\n");
|
||
|
exit (1);
|
||
|
}
|
||
|
|
||
|
write_revprop_change_log ($dbh, $cfg->{database_prefix}, $REPOBASE, $REV, $USER, $PROPNAME, $ACTION);
|
||
|
close_database ($dbh);
|
||
|
|
||
|
exit (0);
|
||
|
|