diff --git a/codepot/codepot.spec.in b/codepot/codepot.spec.in index b8df60cb..0033b57a 100644 --- a/codepot/codepot.spec.in +++ b/codepot/codepot.spec.in @@ -17,6 +17,7 @@ Source0: %{name}-%{version}.tar.gz Requires: httpd %{php_package_name} %{php_package_name}-ldap %{php_package_name}-mysql %{php_package_name}-gd subversion subversion-perl mod_dav_svn mod_perl perl perl-LDAP perl-Config-Simple perl-URI perl-DBI perl-Digest-SHA1 # %{php_package_name}-pecl-svn > 1.2.0 +# %{php_package_name}-pgsql perl-DBD-Pg BuildRequires: subversion-devel neon-devel %{php_package_name}-devel BuildRoot: %{_tmppath}/%{name}-%{version}-root @@ -70,6 +71,7 @@ rm -rf $RPM_BUILD_ROOT %config(noreplace) /etc/codepot/codepot.ini /etc/codepot/codepot.mysql +/etc/codepot/codepot.pgsql /etc/codepot/codepot.a2ldap /etc/codepot/codepot.httpd /etc/codepot/start-commit diff --git a/codepot/etc/Makefile.am b/codepot/etc/Makefile.am index 0bd65bc1..bdee6a9f 100644 --- a/codepot/etc/Makefile.am +++ b/codepot/etc/Makefile.am @@ -1,6 +1,6 @@ cfgdir=$(CFGDIR) -cfg_DATA = codepot.ini codepot.mysql codepot.a2ldap codepot.httpd +cfg_DATA = codepot.ini codepot.mysql codepot.pgsql codepot.a2ldap codepot.httpd cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change cloc.pl perldir=$(CFGDIR)/perl/Codepot diff --git a/codepot/etc/Makefile.in b/codepot/etc/Makefile.in index 0df44bc6..72417061 100644 --- a/codepot/etc/Makefile.in +++ b/codepot/etc/Makefile.in @@ -207,7 +207,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwdir = @wwwdir@ -cfg_DATA = codepot.ini codepot.mysql codepot.a2ldap codepot.httpd +cfg_DATA = codepot.ini codepot.mysql codepot.pgsql codepot.a2ldap codepot.httpd cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change cloc.pl perldir = $(CFGDIR)/perl/Codepot perl_SCRIPTS = perl/Codepot/AccessHandler.pm perl/Codepot/AuthenHandler.pm diff --git a/codepot/etc/codepot.ini.in b/codepot/etc/codepot.ini.in index 793d5f88..c1ab8972 100644 --- a/codepot/etc/codepot.ini.in +++ b/codepot/etc/codepot.ini.in @@ -10,8 +10,11 @@ default_site_name = "@PACKAGE@" ;------------------------------------------------------------------------------ ; database settings +; +; database_driver: mysql for MySQL, postgre for PostgreSQL ;------------------------------------------------------------------------------ database_hostname = "localhost" +database_port = "" database_username = "" database_password = "" database_name = "" diff --git a/codepot/etc/codepot.mysql b/codepot/etc/codepot.mysql index 50ccde60..760566f7 100644 --- a/codepot/etc/codepot.mysql +++ b/codepot/etc/codepot.mysql @@ -173,12 +173,30 @@ CREATE TABLE file ( UNIQUE KEY file_id (projectid, name), UNIQUE KEY (encname), - INDEX tagged_file_id (projectid, tag, name), + INDEX file_tagged_name (projectid, tag, name), CONSTRAINT file_projectid FOREIGN KEY (projectid) REFERENCES project(id) ON DELETE RESTRICT ON UPDATE CASCADE ) charset=utf8 engine=InnoDB; +CREATE TABLE code_review ( + projectid VARCHAR(32) NOT NULL, + rev BIGINT NOT NULL, + sno BIGINT NOT NULL, + comment TEXT NOT NULL, + + createdon DATETIME NOT NULL, + createdby VARCHAR(32) NOT NULL, + + updatedon DATETIME NOT NULL, + updatedby VARCHAR(32) NOT NULL, + + UNIQUE KEY code_review_id (projectid, rev, sno), + + CONSTRAINT code_review_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE +) charset=utf8 engine=InnoDB; + CREATE TABLE log ( id BIGINT PRIMARY KEY AUTO_INCREMENT, projectid VARCHAR(32) NOT NULL, @@ -204,20 +222,3 @@ CREATE TABLE user ( enabled CHAR(1) NOT NULL DEFAULT 'N' CHECK(enabled in ('Y', 'N')) ) charset=utf8 engine=InnoDB; -CREATE TABLE code_review ( - projectid VARCHAR(32) NOT NULL, - rev BIGINT NOT NULL, - sno BIGINT NOT NULL, - comment TEXT NOT NULL, - - createdon DATETIME NOT NULL, - createdby VARCHAR(32) NOT NULL, - - updatedon DATETIME NOT NULL, - updatedby VARCHAR(32) NOT NULL, - - UNIQUE KEY code_review_id (projectid, rev, sno), - - CONSTRAINT code_review_projectid FOREIGN KEY (projectid) REFERENCES project(id) - ON DELETE RESTRICT ON UPDATE CASCADE -) charset=utf8 engine=InnoDB; diff --git a/codepot/etc/codepot.pgsql b/codepot/etc/codepot.pgsql new file mode 100644 index 00000000..f64b2cd5 --- /dev/null +++ b/codepot/etc/codepot.pgsql @@ -0,0 +1,245 @@ +-- ------------------------------------------------------------ +-- This file is the Codepot database schema file for PostreSQL. +-- Note this file doesn't mandate which database to use. +-- +-- Assumining "local all all password" in /var/lib/pgsql/data/pg_hba.conf +-- +-- $ sudo -u postgres psql +-- postgres=# CREATE USER codepot WITH PASSWORD 'codepot'; +-- postgres=# \du +-- postgres=# CREATE DATABASE codepot; +-- postgres=# \l +-- postgres=# ALTER DATABASE "codepot" OWNER TO codepot; +-- postgres=# \l +-- postgres=# \q +-- +-- $ psql -U codepot -W codepot +-- postgres=# \i codepot.pgsql +-- postgres=# \dt +-- postgres=# \q +-- ------------------------------------------------------------ + +CREATE TABLE site ( + id VARCHAR(32) PRIMARY KEY, + name VARCHAR(128) NOT NULL, + summary VARCHAR(255) NOT NULL, + text TEXT NOT NULL, + + createdon TIMESTAMP NOT NULL, + updatedon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL +); + +CREATE TABLE project ( + id VARCHAR(32) PRIMARY KEY, + name VARCHAR(255) UNIQUE NOT NULL, + summary VARCHAR(255) NOT NULL, + description TEXT NOT NULL, + commitable CHAR(1) NOT NULL DEFAULT 'Y', + public CHAR(1) NOT NULL DEFAULT 'Y', + + createdon TIMESTAMP NOT NULL, + updatedon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL + +); + +CREATE TABLE project_membership ( + projectid VARCHAR(32) NOT NULL, + userid VARCHAR(32) NOT NULL, + priority INTEGER NOT NULL, + UNIQUE (projectid, userid), + CONSTRAINT membership_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE wiki ( + projectid VARCHAR(32) NOT NULL, + name VARCHAR(255) NOT NULL, + text TEXT NOT NULL, + columns INT NOT NULL DEFAULT 1, + + createdon TIMESTAMP NOT NULL, + updatedon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, + + UNIQUE (projectid, name), + + CONSTRAINT wiki_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE TABLE wiki_attachment ( + projectid VARCHAR(32) NOT NULL, + wikiname VARCHAR(255) NOT NULL, + name VARCHAR(255) NOT NULL, + encname VARCHAR(255) NOT NULL, + + createdon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + + UNIQUE (projectid, wikiname, name), + + CONSTRAINT wiki_attachment_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE, + + CONSTRAINT wiki_attachment_wikiid FOREIGN KEY (projectid,wikiname) REFERENCES wiki(projectid,name) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE TABLE issue ( + projectid VARCHAR(32) NOT NULL, + id BIGINT NOT NULL, + summary VARCHAR(255) NOT NULL, + description TEXT NOT NULL, + + type VARCHAR(32) NOT NULL, + status VARCHAR(32) NOT NULL, + owner VARCHAR(255) NOT NULL, + priority VARCHAR(32) NOT NULL, + + createdon TIMESTAMP NOT NULL, + updatedon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, + + PRIMARY KEY (projectid, id), + + CONSTRAINT issue_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE INDEX issue_status_type_summary ON issue(projectid, status, type, summary); + +CREATE INDEX issue_summary ON issue(projectid, summary); + +CREATE TABLE issue_attachment ( + projectid VARCHAR(32) NOT NULL, + issueid BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + encname VARCHAR(255) NOT NULL, + + createdon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + + UNIQUE (projectid, issueid, name), + + CONSTRAINT issue_attachment_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE, + + CONSTRAINT issue_attachment_issueid FOREIGN KEY (projectid,issueid) REFERENCES issue(projectid,id) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE TABLE issue_change ( + projectid VARCHAR(32) NOT NULL, + id BIGINT NOT NULL, + sno BIGINT NOT NULL, + + type VARCHAR(32) NOT NULL, + status VARCHAR(32) NOT NULL, + owner VARCHAR(255) NOT NULL, + priority VARCHAR(32) NOT NULL, + comment TEXT NOT NULL, + + updatedon TIMESTAMP NOT NULL, + updatedby VARCHAR(32) NOT NULL, + + PRIMARY KEY (projectid, id, sno), + + CONSTRAINT issue_update_id FOREIGN KEY (projectid,id) REFERENCES issue(projectid,id) + ON DELETE RESTRICT ON UPDATE CASCADE + +); + +CREATE INDEX issue_update_time ON issue_change(projectid, id, updatedon); + +CREATE TABLE issue_change_attachment ( + projectid VARCHAR(32) NOT NULL, + issueid BIGINT NOT NULL, + issuesno BIGINT NOT NULL, + name VARCHAR(255) NOT NULL, + encname VARCHAR(255) NOT NULL, + + createdon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + + UNIQUE (projectid, issueid, name), + + CONSTRAINT issue_change_attachment_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE, + + CONSTRAINT issue_change_attachment_issueidsno FOREIGN KEY (projectid,issueid,issuesno) REFERENCES issue_change(projectid,id,sno) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE TABLE file ( + projectid VARCHAR(32) NOT NULL, + name VARCHAR(255) NOT NULL, + encname VARCHAR(255) NOT NULL, + tag VARCHAR(54) NOT NULL, + summary VARCHAR(255) NOT NULL, + md5sum CHAR(32) NOT NULL, + description TEXT NOT NULL, + + createdon TIMESTAMP NOT NULL, + updatedon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + updatedby VARCHAR(32) NOT NULL, + + UNIQUE (projectid, name), + UNIQUE (encname), + + CONSTRAINT file_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE INDEX file_tagged_name ON file(projectid, tag, name); + + +CREATE TABLE code_review ( + projectid VARCHAR(32) NOT NULL, + rev BIGINT NOT NULL, + sno BIGINT NOT NULL, + comment TEXT NOT NULL, + + createdon TIMESTAMP NOT NULL, + createdby VARCHAR(32) NOT NULL, + + updatedon TIMESTAMP NOT NULL, + updatedby VARCHAR(32) NOT NULL, + + UNIQUE (projectid, rev, sno), + + CONSTRAINT code_review_projectid FOREIGN KEY (projectid) REFERENCES project(id) + ON DELETE RESTRICT ON UPDATE CASCADE +); + +CREATE TABLE log ( + id BIGSERIAL PRIMARY KEY, + projectid VARCHAR(32) NOT NULL, + type VARCHAR(16) NOT NULL, + action VARCHAR(16) NOT NULL, + userid VARCHAR(32) NOT NULL, + message TEXT NOT NULL, + createdon TIMESTAMP NOT NULL +); + +CREATE INDEX log_timed_project_type_action ON log(createdon, projectid, type, action); + +CREATE TABLE user_settings ( + userid VARCHAR(32) PRIMARY KEY, + code_hide_line_num CHAR(1) NOT NULL, + code_hide_metadata CHAR(1) NOT NULL, + icon_name VARCHAR(255) UNIQUE NULL +); + +CREATE TABLE "user" ( + userid VARCHAR(32) PRIMARY KEY, + passwd VARCHAR(255) NOT NULL, + email VARCHAR(255), + enabled CHAR(1) NOT NULL DEFAULT 'N' CHECK(enabled in ('Y', 'N')) +); diff --git a/codepot/etc/post-commit.in b/codepot/etc/post-commit.in index c5221d50..731f0132 100644 --- a/codepot/etc/post-commit.in +++ b/codepot/etc/post-commit.in @@ -23,6 +23,7 @@ sub get_config my $config = { database_hostname => $cfg->param ("database_hostname"), + database_port => $cfg->param ("database_port"), database_username => $cfg->param ("database_username"), database_password => $cfg->param ("database_password"), database_name => $cfg->param ("database_name"), @@ -40,9 +41,16 @@ sub open_database my $dbtype = $cfg->{database_driver}; my $dbname = $cfg->{database_name}; my $dbhost = $cfg->{database_hostname}; + my $dbport = $cfg->{database_port}; + + if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + + my $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbh = DBI->connect( - "DBI:$dbtype:$dbname:$dbhost", + $dbstr, $cfg->{database_username}, $cfg->{database_password}, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } @@ -102,7 +110,7 @@ if (!defined($cfg)) my $dbh = open_database ($cfg); if (!defined($dbh)) { - print (STDERR "Cannot open database\n"); + printf (STDERR "Cannot open database - %s\n", $DBI::errstr); exit (1); } diff --git a/codepot/etc/post-revprop-change.in b/codepot/etc/post-revprop-change.in index bfeaa6ff..c28c11af 100644 --- a/codepot/etc/post-revprop-change.in +++ b/codepot/etc/post-revprop-change.in @@ -28,6 +28,7 @@ sub get_config my $config = { database_hostname => $cfg->param ("database_hostname"), + database_port => $cfg->param ("database_port"), database_username => $cfg->param ("database_username"), database_password => $cfg->param ("database_password"), database_name => $cfg->param ("database_name"), @@ -45,9 +46,16 @@ sub open_database my $dbtype = $cfg->{database_driver}; my $dbname = $cfg->{database_name}; my $dbhost = $cfg->{database_hostname}; + my $dbport = $cfg->{database_port}; + + if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + + my $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbh = DBI->connect( - "DBI:$dbtype:$dbname:$dbhost", + $dbstr, $cfg->{database_username}, $cfg->{database_password}, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } @@ -104,7 +112,7 @@ if (!defined($cfg)) my $dbh = open_database ($cfg); if (!defined($dbh)) { - print (STDERR "Cannot open database\n"); + printf (STDERR "Cannot open database - %s\n", $DBI::errstr); exit (1); } diff --git a/codepot/etc/pre-commit.in b/codepot/etc/pre-commit.in index 147cc5d1..781db783 100644 --- a/codepot/etc/pre-commit.in +++ b/codepot/etc/pre-commit.in @@ -43,6 +43,7 @@ sub get_config my $config = { database_hostname => $cfg->param ('database_hostname'), + database_port => $cfg->param ("database_port"), database_username => $cfg->param ('database_username'), database_password => $cfg->param ('database_password'), database_name => $cfg->param ('database_name'), @@ -65,9 +66,16 @@ sub open_database my $dbtype = $cfg->{database_driver}; my $dbname = $cfg->{database_name}; my $dbhost = $cfg->{database_hostname}; + my $dbport = $cfg->{database_port}; + + if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + + my $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbh = DBI->connect( - "DBI:$dbtype:$dbname:$dbhost", + $dbstr, $cfg->{database_username}, $cfg->{database_password}, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } @@ -510,7 +518,7 @@ if (defined($topdirs)) #my $dbh = open_database ($cfg); #if (!defined($dbh)) #{ -# print (STDERR "Cannot open database\n"); +# printf (STDERR "Cannot open database - %s\n", $DBI::errstr); # exit (1); #} # diff --git a/codepot/etc/pre-revprop-change.in b/codepot/etc/pre-revprop-change.in index 6644f8c8..397560a8 100644 --- a/codepot/etc/pre-revprop-change.in +++ b/codepot/etc/pre-revprop-change.in @@ -29,6 +29,7 @@ sub get_config my $config = { database_hostname => $cfg->param ("database_hostname"), + database_port => $cfg->param ("database_port"), database_username => $cfg->param ("database_username"), database_password => $cfg->param ("database_password"), database_name => $cfg->param ("database_name"), @@ -48,9 +49,16 @@ sub open_database my $dbtype = $cfg->{database_driver}; my $dbname = $cfg->{database_name}; my $dbhost = $cfg->{database_hostname}; + my $dbport = $cfg->{database_port}; + + if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + + my $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbh = DBI->connect( - "DBI:$dbtype:$dbname:$dbhost", + $dbstr, $cfg->{database_username}, $cfg->{database_password}, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } @@ -161,7 +169,7 @@ elsif ($ACTION eq 'M' || $ACTION eq 'A') my $dbh = open_database ($cfg); if (!defined($dbh)) { - print (STDERR "Cannot open database\n"); + printf (STDERR "Cannot open database - %s\n", $DBI::errstr); exit (1); } diff --git a/codepot/etc/start-commit.in b/codepot/etc/start-commit.in index 2d52edcc..a5a77119 100644 --- a/codepot/etc/start-commit.in +++ b/codepot/etc/start-commit.in @@ -21,6 +21,7 @@ sub get_config my $config = { database_hostname => $cfg->param ("database_hostname"), + database_port => $cfg->param ("database_port"), database_username => $cfg->param ("database_username"), database_password => $cfg->param ("database_password"), database_name => $cfg->param ("database_name"), @@ -38,9 +39,16 @@ sub open_database my $dbtype = $cfg->{database_driver}; my $dbname = $cfg->{database_name}; my $dbhost = $cfg->{database_hostname}; + my $dbport = $cfg->{database_port}; + + if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } + + my $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbh = DBI->connect( - "DBI:$dbtype:$dbname:$dbhost", + $dbstr, $cfg->{database_username}, $cfg->{database_password}, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } @@ -99,7 +107,7 @@ if (!defined($cfg)) my $dbh = open_database ($cfg); if (!defined($dbh)) { - print (STDERR "Cannot open database\n"); + printf (STDERR "Cannot open database - %s\n", $DBI::errstr); exit (1); } diff --git a/codepot/sbin/codepot-user.in b/codepot/sbin/codepot-user.in index 766f9290..e9cc0e67 100644 --- a/codepot/sbin/codepot-user.in +++ b/codepot/sbin/codepot-user.in @@ -12,28 +12,30 @@ use Digest::SHA1 qw (sha1_hex); my $CFG_FILE = '@CFGDIR@/codepot.ini'; +my $USER_TABLE_NAME = 'user'; sub get_config { - my $cfg = new Config::Simple(); + my $cfg = new Config::Simple(); - if (!$cfg->read ($CFG_FILE)) - { - return undef; - } + 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"), + my $config = { + database_hostname => $cfg->param ("database_hostname"), + database_port => $cfg->param ("database_port"), + 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"), codepot_user_executor => $cfg->param("codepot_user_executor") - }; + }; - return $config; + return $config; } sub open_database @@ -43,9 +45,24 @@ sub open_database my $dbtype = $cfg->{database_driver}; my $dbname = $cfg->{database_name}; my $dbhost = $cfg->{database_hostname}; + my $dbport = $cfg->{database_port}; + my $dbprefix = $cfg->{database_prefix}; + + if ($dbtype eq 'postgre') + { + $dbtype = 'Pg'; + + # in postgresql, 'user' is a reserved word. + # it requires quotes for the word to be used as a normal word + if (length($dbprefix) <= 0) { $USER_TABLE_NAME = '"user"'; } + } + + my $dbstr = "DBI:$dbtype:database=$dbname;"; + if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } + if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbh = DBI->connect( - "DBI:$dbtype:$dbname:$dbhost", + $dbstr, $cfg->{database_username}, $cfg->{database_password}, { RaiseError => 0, PrintError => 0, AutoCommit => 0 } @@ -87,7 +104,7 @@ sub authenticate_database { my ($dbh, $prefix, $userid, $password) = @_; - my $query = $dbh->prepare ("SELECT userid,passwd FROM ${prefix}user WHERE userid=? and enabled='N'"); + my $query = $dbh->prepare ("SELECT userid,passwd FROM ${prefix}${USER_TABLE_NAME}} WHERE userid=? and enabled='N'"); if (!$query || !$query->execute ($userid)) { return (-1, $dbh->errstr()); @@ -119,7 +136,7 @@ sub add_user $dbh->begin_work (); - my $query = $dbh->prepare ("INSERT INTO ${prefix}user (userid,passwd,email,enabled) VALUES (?, ?, ?, ?)"); + my $query = $dbh->prepare ("INSERT INTO ${prefix}${USER_TABLE_NAME} (userid,passwd,email,enabled) VALUES (?, ?, ?, ?)"); if (!$query || !$query->execute ($userid, $fmt_pw, $email, 'N')) { my $errstr = $dbh->errstr(); @@ -139,7 +156,7 @@ sub delete_user $dbh->begin_work (); - my $query = $dbh->prepare ("DELETE FROM ${prefix}user WHERE userid=?"); + my $query = $dbh->prepare ("DELETE FROM ${prefix}${USER_TABLE_NAME} WHERE userid=?"); if (!$query || !$query->execute ($userid) || $query->rows() <= 0) { my $errstr = $dbh->errstr(); @@ -159,7 +176,7 @@ sub toggle_user $dbh->begin_work (); - my $query = $dbh->prepare ("UPDATE ${prefix}user SET enabled=? WHERE userid=?"); + my $query = $dbh->prepare ("UPDATE ${prefix}${USER_TABLE_NAME} SET enabled=? WHERE userid=?"); if (!$query || !$query->execute ($enabled, $userid) || $query->rows() <= 0) { my $errstr = $dbh->errstr(); @@ -249,7 +266,7 @@ if (scalar(@executors) > 0) { for my $executor (@executors) { - my $uid = getpwnam ($executor); + my $uid = getpwnam ($executor); if (defined($uid) && $> == $uid) { $allowed_to_execute = 1; @@ -271,7 +288,7 @@ if ($allowed_to_execute == 0) my $dbh = open_database ($cfg); if (!defined($dbh)) { - print (STDERR "Cannot open database\n"); + printf (STDERR "Cannot open database - %s\n", $DBI::errstr); exit (1); } diff --git a/codepot/src/codepot/config/database.php b/codepot/src/codepot/config/database.php index ea7cf656..ee8171a9 100644 --- a/codepot/src/codepot/config/database.php +++ b/codepot/src/codepot/config/database.php @@ -38,6 +38,7 @@ $active_group = "default"; $active_record = TRUE; $db['default']['hostname'] = CODEPOT_DATABASE_HOSTNAME; +$db['default']['port'] = CODEPOT_DATABASE_PORT; $db['default']['username'] = CODEPOT_DATABASE_USERNAME; $db['default']['password'] = CODEPOT_DATABASE_PASSWORD; $db['default']['database'] = CODEPOT_DATABASE_NAME; @@ -51,6 +52,7 @@ $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; $db['auth-mysql']['hostname'] = CODEPOT_AUTH_MYSQL_HOSTNAME; +$db['auth-mysql']['port'] = CODEPOT_AUTH_MYSQL_PORT; $db['auth-mysql']['username'] = CODEPOT_AUTH_MYSQL_USERNAME; $db['auth-mysql']['password'] = CODEPOT_AUTH_MYSQL_PASSWORD; $db['auth-mysql']['database'] = CODEPOT_AUTH_MYSQL_NAME; diff --git a/codepot/src/codepot/models/issuemodel.php b/codepot/src/codepot/models/issuemodel.php index 3bc61527..466fac75 100644 --- a/codepot/src/codepot/models/issuemodel.php +++ b/codepot/src/codepot/models/issuemodel.php @@ -111,7 +111,11 @@ class IssueModel extends Model if ($hour_limit > 0) { - $this->db->where ("updatedon >= SYSDATE() - INTERVAL {$hour_limit} HOUR"); + //$this->db->where ("updatedon >= SYSDATE() - INTERVAL {$hour_limit} HOUR"); + if (CODEPOT_DATABASE_DRIVER == 'mysql') + $this->db->where ("updatedon >= CURRENT_TIMESTAMP - INTERVAL {$hour_limit} HOUR"); + else + $this->db->where ("updatedon >= CURRENT_TIMESTAMP - INTERVAL '{$hour_limit} HOUR'"); } if (strlen($userid) > 0) diff --git a/codepot/src/codepot/models/projectmodel.php b/codepot/src/codepot/models/projectmodel.php index 7fd21c1a..9acfeda3 100644 --- a/codepot/src/codepot/models/projectmodel.php +++ b/codepot/src/codepot/models/projectmodel.php @@ -57,7 +57,14 @@ class ProjectModel extends Model $this->db->trans_start (); $this->db->select ('count(id) as count'); - $this->db->order_by ('name', 'asc'); + // having this line to make it same as getEntries() + // causes postgresql to emit this error: + // column "project.name" must appear in the GROUP BY clause or + // be used in an aggregate function. + // + // let's just comment it out as counting without sorting + // is ok. + //$this->db->order_by ('name', 'asc'); if ($search->or == 'Y') { diff --git a/codepot/src/codepot/views/code_blame.php b/codepot/src/codepot/views/code_blame.php index 7570507f..543f23bd 100644 --- a/codepot/src/codepot/views/code_blame.php +++ b/codepot/src/codepot/views/code_blame.php @@ -147,6 +147,7 @@ $this->load->view ( $history_anchor_text = ' ' . $this->lang->line('History'); $download_anchor_text = ' ' . $this->lang->line('Download'); +$diff_anchor_text = ' ' . $this->lang->line('Difference'); $xpar = $this->converter->AsciiToHex ($headpath); @@ -158,7 +159,7 @@ if ($file['created_rev'] != $file['head_rev']) print anchor ("code/file/{$project->id}/${xpar}{$revreq}", $this->lang->line('Details')); print ' | '; -print anchor ("code/diff/{$project->id}/{$xpar}{$revreq}", $this->lang->line('Difference')); +print anchor ("code/diff/{$project->id}/{$xpar}{$revreq}", $diff_anchor_text); print ' | '; if ($revision > 0) diff --git a/codepot/src/codepot/views/code_diff.php b/codepot/src/codepot/views/code_diff.php index 7d51ceab..3f992ec4 100644 --- a/codepot/src/codepot/views/code_diff.php +++ b/codepot/src/codepot/views/code_diff.php @@ -99,33 +99,31 @@ $this->load->view (