openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit fd8952c4350a89053eb09449edde8ca96bf0fb73
parent 114e967ab091c2a409ac485823b2b3386febee49
Author: dankert <devnull@localhost>
Date:   Sat, 10 Nov 2007 14:06:41 +0100

Neue Einstellung "cmd" f?r Datenbank.

Diffstat:
config/database.ini.php | 13++++++++++---
db/db.class.php | 40+++++++++++++++++++++++++++++++---------
2 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/config/database.ini.php b/config/database.ini.php @@ -11,7 +11,7 @@ default=db1 ; Database configuration for connection 'db1 enabled = true -comment = "OpenRat Example DB" ; comment of this database +comment = "OpenRat Example" ; comment of this database type = mysql ; 'mysql' or 'postgresql' user = dbuser ; database user @@ -24,7 +24,15 @@ base64 = false ; store binary as BASE64 (in postgresql=true) prefix = or_ ; table praefix persistent = yes ; use persistent connections (try this, it's faster) +; System command for executing before connecting to the database. +; Maybe for installing an SSH-Tunnel. +; For background programs, you have to redirect stdin and stdout! (maybe to /dev/null) +; Example: "sudo -u u123 /usr/local/bin/sshtunnel-example.sh" +; Default: blank. +cmd = "" + + ; Add here more sections with other database connections. ;[another_db] -;...- \ No newline at end of file +;... diff --git a/db/db.class.php b/db/db.class.php @@ -80,7 +80,7 @@ class DB $this->available = false; $this->conf = $conf; - $this->available = $this->connect(); + $this->connect(); return $this->available; } @@ -92,23 +92,45 @@ class DB * @return Status */ function connect() - { + { + // Ausführen des Systemkommandos. + if ( !empty($this->conf['cmd'])) + { + $ausgabe = array(); + $rc = false; + + Logger::debug("Database command executing: ".$this->conf['cmd']); + exec( $this->conf['cmd'],$ausgabe,$rc ); + + foreach( $ausgabe as $zeile ) + Logger::debug("Database command output: ".$zeile); + + if ( $rc != 0 ) + { + $this->error = 'Command failed: '.implode("",$ausgabe); + $this->available = false; + return false; + } + } + $type = $this->conf['type']; $classname = 'db_'.$type; $this->client = & new $classname; - $ok = $this->client->connect( $this->conf ); + $ok = $this->client->connect( $this->conf ); if ( ! $ok ) { - $this->error = $this->client->error; - - if ( empty($this->error) ) - $this->error = 'Error while connecting to database.'; - } + $this->error = $this->client->error; + $this->available = false; + return false; +// if ( empty($this->error) ) +// $this->error = 'Error while connecting to database.'; + } - return $ok; + $this->available = true; + return true; }