Rather than three levels of configuration, let's have two (define()'d values in config.php for system-level stuff, the web-editable config table for user-level stuff). Basically switches database_dsn from a global variable to a defined constant.

This commit is contained in:
Shish 2012-01-20 03:15:58 +00:00
parent 36e443e07d
commit 18e36f9b31
5 changed files with 30 additions and 26 deletions

View File

@ -40,10 +40,10 @@ Installation
Upgrade from 2.3.X
~~~~~~~~~~~~~~~~~~
The database connection setting in config.php has changed; now using
PDO DSN format [1] rather than ADODB URI [2]
PDO DSN format rather than ADODB URI:
[1] <proto>:user=<username>;password=<password>;host=<host>;dbname=<database>
[2] <proto>://<username>:<password>@<host>/<database>
OLD: $database_dsn = "<proto>://<username>:<password>@<host>/<database>";
NEW: define("DATABASE_DSN", "<proto>:user=<username>;password=<password>;host=<host>;dbname=<database>");
The rest should be automatic, just unzip into a clean folder and copy across
config.php, images and thumbs folders from the old version. This

View File

@ -274,8 +274,6 @@ class Database {
* stored in config.php in the root shimmie folder
*/
public function Database() {
global $database_dsn, $cache_dsn;
# FIXME: detect ADODB URI, automatically translate PDO DSN
/*
@ -285,10 +283,10 @@ class Database {
* http://stackoverflow.com/questions/237367
*/
$matches = array(); $db_user=null; $db_pass=null;
if(preg_match("/user=([^;]*)/", $database_dsn, $matches)) $db_user=$matches[1];
if(preg_match("/password=([^;]*)/", $database_dsn, $matches)) $db_pass=$matches[1];
if(preg_match("/user=([^;]*)/", DATABASE_DSN, $matches)) $db_user=$matches[1];
if(preg_match("/password=([^;]*)/", DATABASE_DSN, $matches)) $db_pass=$matches[1];
$this->db = new PDO($database_dsn, $db_user, $db_pass);
$this->db = new PDO(DATABASE_DSN, $db_user, $db_pass);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db_proto = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME);
@ -305,9 +303,8 @@ class Database {
die("Unknown PDO driver: $db_proto");
}
if(isset($cache_dsn) && !empty($cache_dsn)) {
$matches = array();
preg_match("#(memcache|apc)://(.*)#", $cache_dsn, $matches);
$matches = array();
if(CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) {
if($matches[1] == "memcache") {
$this->cache = new MemcacheCache($matches[2]);
}

View File

@ -204,7 +204,7 @@ function make_link($page=null, $query=null) {
if(is_null($page)) $page = $config->get_string('main_page');
if(FORCE_NICE_URLS || $config->get_bool('nice_urls', false)) {
if(NICE_URLS || $config->get_bool('nice_urls', false)) {
#$full = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"];
$full = $_SERVER["PHP_SELF"];
$base = str_replace("/index.php", "", $full);

View File

@ -57,18 +57,23 @@ if(empty($database_dsn) && !file_exists("config.php")) {
require_once "config.php";
// set up and purify the environment
if(!defined("DEBUG")) define("DEBUG", false);
if(!defined("COVERAGE")) define("COVERAGE", false);
if(!defined("CONTEXT")) define("CONTEXT", false);
if(!defined("CACHE_MEMCACHE")) define("CACHE_MEMCACHE", false);
if(!defined("CACHE_DIR")) define("CACHE_DIR", false);
if(!defined("CACHE_HTTP")) define("CACHE_HTTP", false);
if(!defined("VERSION")) define("VERSION", 'trunk');
if(!defined("SCORE_VERSION")) define("SCORE_VERSION", 's2hack/'.VERSION);
if(!defined("COOKIE_PREFIX")) define("COOKIE_PREFIX", 'shm');
if(!defined("SPEED_HAX")) define("SPEED_HAX", false);
if(!defined("FORCE_NICE_URLS")) define("FORCE_NICE_URLS", false);
if(!defined("WH_SPLITS")) define("WH_SPLITS", 1);
function _d($name, $value) {
if(!defined($name)) define($name, $value);
}
_d("DATABASE_DSN", null); // string PDO database connection details
_d("CACHE_DSN", null); // string cache connection details
_d("DEBUG", false); // boolean print various debugging details
_d("COVERAGE", false); // boolean activate xdebug coverage monitor
_d("CONTEXT", null); // string file to log performance data into
_d("CACHE_MEMCACHE", false); // boolean store complete rendered pages in memcache
_d("CACHE_DIR", false); // boolean store complete rendered pages on disk
_d("CACHE_HTTP", false); // boolean output explicit HTTP caching headers
_d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes
_d("SPEED_HAX", false); // boolean do some questionable things in the name of performance
_d("NICE_URLS", false); // boolean force niceurl mode
_d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse
_d("VERSION", 'trunk'); // string shimmie version
_d("SCORE_VERSION", 's2hack/'.VERSION); // string SCore version
require_once "core/util.inc.php";
require_once "lib/context.php";

View File

@ -52,7 +52,7 @@ if(is_readable("config.php")) {
<h1>Shimmie Repair Console</h1>
<?php
include "config.php";
if($_SESSION['dsn'] == $database_dsn || $_POST['dsn'] == $database_dsn) {
if($_SESSION['dsn'] == DATABASE_DSN || $_POST['dsn'] == DATABASE_DSN) {
if($_POST['dsn']) {$_SESSION['dsn'] = $_POST['dsn'];}
if(empty($_GET["action"])) {
@ -350,7 +350,9 @@ function build_dirs() { // {{{
} // }}}
function write_config() { // {{{
global $database_dsn;
$file_content = "<?php \$database_dsn='$database_dsn'; ?>";
$file_content = "<"+"?php\n"+
"define('DATABASE_DSN', '$database_dsn');\n"+
"?"+">";
if(is_writable("./") && file_put_contents("config.php", $file_content)) {
assert(file_exists("config.php"));