Merge pull request #588 from fermionic/20130118-update-db-error-on-fresh-install

insidious set_config bug
This commit is contained in:
friendica 2013-01-19 03:59:49 -08:00
commit 759f36e7e8
4 changed files with 26 additions and 9 deletions

View file

@ -808,7 +808,7 @@ function check_db() {
$build = get_config('system','build'); $build = get_config('system','build');
if(! x($build)) { if(! x($build)) {
set_config('system','build',DB_UPDATE_VERSION); set_config('system','build',DB_UPDATE_VERSION);
$buid = DB_UPDATE_VERSION; $build = DB_UPDATE_VERSION;
} }
if($build != DB_UPDATE_VERSION) if($build != DB_UPDATE_VERSION)
proc_run('php', 'include/dbupdate.php'); proc_run('php', 'include/dbupdate.php');
@ -818,13 +818,11 @@ function check_db() {
// Primarily involved with database upgrade, but also sets the // Sets the base url for use in cmdline programs which don't have
// base url for use in cmdline programs which don't have
// $_SERVER variables // $_SERVER variables
if(! function_exists('check_url')) {
if(! function_exists('check_config')) { function check_url(&$a) {
function check_config(&$a) {
$url = get_config('system','url'); $url = get_config('system','url');
@ -839,6 +837,15 @@ if(! function_exists('check_config')) {
if((! link_compare($url,$a->get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname))) if((! link_compare($url,$a->get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname)))
$url = set_config('system','url',$a->get_baseurl()); $url = set_config('system','url',$a->get_baseurl());
return;
}
}
// Automatic database updates
if(! function_exists('update_db')) {
function update_db(&$a) {
$build = get_config('system','build'); $build = get_config('system','build');
if(! x($build)) if(! x($build))

View file

@ -85,6 +85,15 @@ function get_config($family, $key, $instore = false) {
if(! function_exists('set_config')) { if(! function_exists('set_config')) {
function set_config($family,$key,$value) { function set_config($family,$key,$value) {
global $a; global $a;
// If $a->config[$family] has been previously set to '!<unset>!', then
// $a->config[$family][$key] will evaluate to $a->config[$family][0], and
// $a->config[$family][$key] = $value will be equivalent to
// $a->config[$family][0] = $value[0] (this causes infuriating bugs),
// so unset the family before assigning a value to a family's key
if($a->config[$family] === '!<unset>!')
unset($a->config[$family]);
// manage array value // manage array value
$dbvalue = (is_array($value)?serialize($value):$value); $dbvalue = (is_array($value)?serialize($value):$value);
$dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue); $dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue);

View file

@ -19,7 +19,7 @@ function dbupdate_run(&$argv, &$argc) {
load_config('config'); load_config('config');
load_config('system'); load_config('system');
check_config($a); update_db($a);
} }
if (array_search(__file__,get_included_files())===0){ if (array_search(__file__,get_included_files())===0){

View file

@ -58,9 +58,9 @@ if(!$install) {
require_once("include/session.php"); require_once("include/session.php");
load_hooks(); load_hooks();
call_hooks('init_1'); call_hooks('init_1');
}
$maintenance = get_config('system', 'maintenance'); $maintenance = get_config('system', 'maintenance');
}
/** /**
@ -141,6 +141,7 @@ if($install)
elseif($maintenance) elseif($maintenance)
$a->module = 'maintenance'; $a->module = 'maintenance';
else { else {
check_url($a);
check_db(); check_db();
check_plugins($a); check_plugins($a);
} }