fix update routine to support update from 3.2

disable PDO support
This commit is contained in:
fabrixxm 2014-09-07 17:28:38 +02:00
parent a7302daf96
commit 6db73c0b6d
5 changed files with 185 additions and 152 deletions

105
boot.php
View File

@ -11,6 +11,9 @@ require_once('include/cache.php');
require_once('library/Mobile_Detect/Mobile_Detect.php'); require_once('library/Mobile_Detect/Mobile_Detect.php');
require_once('include/features.php'); require_once('include/features.php');
require_once('update.php');
require_once('include/dbstructure.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_VERSION', '3.2.1753' ); define ( 'FRIENDICA_VERSION', '3.2.1753' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
@ -1003,7 +1006,6 @@ if(! function_exists('check_url')) {
if(! function_exists('update_db')) { if(! function_exists('update_db')) {
function update_db(&$a) { function update_db(&$a) {
$build = get_config('system','build'); $build = get_config('system','build');
if(! x($build)) if(! x($build))
$build = set_config('system','build',DB_UPDATE_VERSION); $build = set_config('system','build',DB_UPDATE_VERSION);
@ -1011,21 +1013,17 @@ if(! function_exists('update_db')) {
if($build != DB_UPDATE_VERSION) { if($build != DB_UPDATE_VERSION) {
$stored = intval($build); $stored = intval($build);
$current = intval(DB_UPDATE_VERSION); $current = intval(DB_UPDATE_VERSION);
if(($stored < $current) && file_exists('update.php')) { if($stored < $current) {
load_config('database'); load_config('database');
// We're reporting a different version than what is currently installed. // We're reporting a different version than what is currently installed.
// Run any existing update scripts to bring the database up to current. // Run any existing update scripts to bring the database up to current.
require_once('update.php');
// make sure that boot.php and update.php are the same release, we might be // make sure that boot.php and update.php are the same release, we might be
// updating right this very second and the correct version of the update.php // updating right this very second and the correct version of the update.php
// file may not be here yet. This can happen on a very busy site. // file may not be here yet. This can happen on a very busy site.
if(DB_UPDATE_VERSION == UPDATE_VERSION) { if(DB_UPDATE_VERSION == UPDATE_VERSION) {
// Compare the current structure with the defined structure // Compare the current structure with the defined structure
$t = get_config('database','dbupdate_'.DB_UPDATE_VERSION); $t = get_config('database','dbupdate_'.DB_UPDATE_VERSION);
@ -1034,53 +1032,32 @@ if(! function_exists('update_db')) {
set_config('database','dbupdate_'.DB_UPDATE_VERSION, time()); set_config('database','dbupdate_'.DB_UPDATE_VERSION, time());
require_once("include/dbstructure.php"); // run old update routine (wich could modify the schema and
// conflits with new routine)
for ($x = $stored; $x < NEW_UPDATE_ROUTINE_VERSION; $x++) {
$r = run_update_function($x);
if (!$r) break;
}
if ($stored < NEW_UPDATE_ROUTINE_VERSION) $stored = NEW_UPDATE_ROUTINE_VERSION;
// run new update routine
// it update the structure in one call
$retval = update_structure(false, true); $retval = update_structure(false, true);
if($retval) { if($retval) {
update_fail( update_fail(
DB_UPDATE_VERSION, DB_UPDATE_VERSION,
sprintf(t('Update %s failed. See error logs.'), DB_UPDATE_VERSION) $retval
); );
break; return;
} else { } else {
set_config('database','dbupdate_'.DB_UPDATE_VERSION, 'success'); set_config('database','dbupdate_'.DB_UPDATE_VERSION, 'success');
} }
// run any left update_nnnn functions in update.php
for($x = $stored; $x < $current; $x ++) { for($x = $stored; $x < $current; $x ++) {
if(function_exists('update_' . $x)) { $r = run_update_function($x);
if (!$r) break;
// There could be a lot of processes running or about to run.
// We want exactly one process to run the update command.
// So store the fact that we're taking responsibility
// after first checking to see if somebody else already has.
// If the update fails or times-out completely you may need to
// delete the config entry to try again.
$t = get_config('database','update_' . $x);
if($t !== false)
break;
set_config('database','update_' . $x, time());
// call the specific update
$func = 'update_' . $x;
$retval = $func();
if($retval) {
//send the administrator an e-mail
update_fail(
$x,
sprintf(t('Update %s failed. See error logs.'), $x)
);
break;
} else {
set_config('database','update_' . $x, 'success');
set_config('system','build', $x + 1);
}
} else {
set_config('database','update_' . $x, 'success');
set_config('system','build', $x + 1);
}
} }
} }
} }
@ -1089,6 +1066,48 @@ if(! function_exists('update_db')) {
return; return;
} }
} }
if(!function_exists('run_update_function')){
function run_update_function($x) {
if(function_exists('update_' . $x)) {
// There could be a lot of processes running or about to run.
// We want exactly one process to run the update command.
// So store the fact that we're taking responsibility
// after first checking to see if somebody else already has.
// If the update fails or times-out completely you may need to
// delete the config entry to try again.
$t = get_config('database','update_' . $x);
if($t !== false)
return false;
set_config('database','update_' . $x, time());
// call the specific update
$func = 'update_' . $x;
$retval = $func();
if($retval) {
//send the administrator an e-mail
update_fail(
$x,
sprintf(t('Update %s failed. See error logs.'), $x)
);
return false;
} else {
set_config('database','update_' . $x, 'success');
set_config('system','build', $x + 1);
return true;
}
} else {
set_config('database','update_' . $x, 'success');
set_config('system','build', $x + 1);
return true;
}
return true;
}
}
if(! function_exists('check_plugins')) { if(! function_exists('check_plugins')) {

View File

@ -1,10 +1,15 @@
<?php <?php
# if PDO is avaible for mysql, use the new database abstraction # if PDO is avaible for mysql, use the new database abstraction
# TODO: PDO is disabled for release 3.3. We need to investigate why
# the update from 3.2 fails with pdo
/*
if(class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) { if(class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
require_once("library/dddbl2/dddbl.php"); require_once("library/dddbl2/dddbl.php");
require_once("include/dba_pdo.php"); require_once("include/dba_pdo.php");
} }
*/
require_once('include/datetime.php'); require_once('include/datetime.php');

View File

@ -1,6 +1,9 @@
<?php <?php
require_once("boot.php"); require_once("boot.php");
require_once("include/text.php"); require_once("include/text.php");
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/* /*
* send the email and do what is needed to do on update fails * send the email and do what is needed to do on update fails
* *
@ -24,7 +27,7 @@ function update_fail($update_id, $error_message){
The friendica developers released update %s recently, The friendica developers released update %s recently,
but when I tried to install it, something went terribly wrong. but when I tried to install it, something went terribly wrong.
This needs to be fixed soon and I can't do it alone. Please contact a This needs to be fixed soon and I can't do it alone. Please contact a
friendica developer if you can not help me on your own. My database might be invalid."); friendica developer if you can not help me on your own. My database might be invalid."));
$body = t("The error message is\n[pre]%s[/pre]"); $body = t("The error message is\n[pre]%s[/pre]");
$preamble = sprintf($preamble, $update_id); $preamble = sprintf($preamble, $update_id);
$body = sprintf($body, $error_message); $body = sprintf($body, $error_message);
@ -62,27 +65,6 @@ function update_fail($update_id, $error_message){
break; break;
} }
function dbstructure_run(&$argv, &$argc) {
global $a, $db;
if(is_null($a)){
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
}
update_structure(true, true);
}
if (array_search(__file__,get_included_files())===0){
dbstructure_run($argv,$argc);
killme();
}
function table_structure($table) { function table_structure($table) {
$structures = q("DESCRIBE `%s`", $table); $structures = q("DESCRIBE `%s`", $table);
@ -1334,3 +1316,29 @@ function db_definition() {
return($database); return($database);
} }
/*
* run from command line
*/
function dbstructure_run(&$argv, &$argc) {
global $a, $db;
if(is_null($a)){
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
}
update_structure(true, true);
}
if (array_search(__file__,get_included_files())===0){
dbstructure_run($argv,$argc);
killme();
}

View File

@ -623,6 +623,9 @@ function fetch_xrd_links($url) {
if(! function_exists('validate_url')) { if(! function_exists('validate_url')) {
function validate_url(&$url) { function validate_url(&$url) {
if(get_config('system','disable_url_validation'))
return true;
// no naked subdomains (allow localhost for tests) // no naked subdomains (allow localhost for tests)
if(strpos($url,'.') === false && strpos($url,'/localhost/') === false) if(strpos($url,'.') === false && strpos($url,'/localhost/') === false)
return false; return false;

View File

@ -1448,11 +1448,9 @@ function update_1162() {
function update_1163() { function update_1163() {
set_config('system', 'maintenance', 1); set_config('system', 'maintenance', 1);
$r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL, $r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL");
ADD INDEX (`network`)");
set_config('system', 'maintenance', 0); set_config('system', 'maintenance', 0);
if(!$r) if(!$r)
return UPDATE_FAILED; return UPDATE_FAILED;