Merge pull request #1131 from fabrixxm/master

Bug fixes!
This commit is contained in:
Tobias Diekershoff 2014-09-07 17:52:52 +02:00
commit e767e2d750
9 changed files with 196 additions and 158 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.1754' ); define ( 'FRIENDICA_VERSION', '3.2.1754' );
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

@ -57,6 +57,7 @@ class Emailer {
); );
logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG); logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG); logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);
return $res;
} }
} }
?> ?>

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');
@ -14,12 +19,12 @@ require_once('include/datetime.php');
* *
* For debugging, insert 'dbg(1);' anywhere in the program flow. * For debugging, insert 'dbg(1);' anywhere in the program flow.
* dbg(0); will turn it off. Logging is performed at LOGGER_DATA level. * dbg(0); will turn it off. Logging is performed at LOGGER_DATA level.
* When logging, all binary info is converted to text and html entities are escaped so that * When logging, all binary info is converted to text and html entities are escaped so that
* the debugging stream is safe to view within both terminals and web pages. * the debugging stream is safe to view within both terminals and web pages.
* *
*/ */
if(! class_exists('dba')) { if(! class_exists('dba')) {
class dba { class dba {
private $debug = 0; private $debug = 0;
@ -227,7 +232,7 @@ class dba {
} }
function __destruct() { function __destruct() {
if ($this->db) if ($this->db)
if($this->mysqli) if($this->mysqli)
$this->db->close(); $this->db->close();
else else
@ -245,14 +250,14 @@ function printable($s) {
}} }}
// Procedural functions // Procedural functions
if(! function_exists('dbg')) { if(! function_exists('dbg')) {
function dbg($state) { function dbg($state) {
global $db; global $db;
if($db) if($db)
$db->dbg($state); $db->dbg($state);
}} }}
if(! function_exists('dbesc')) { if(! function_exists('dbesc')) {
function dbesc($str) { function dbesc($str) {
global $db; global $db;
if($db && $db->connected) if($db && $db->connected)
@ -268,7 +273,7 @@ function dbesc($str) {
// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", // Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
// 'user', 1); // 'user', 1);
if(! function_exists('q')) { if(! function_exists('q')) {
function q($sql) { function q($sql) {
global $db; global $db;
@ -285,12 +290,12 @@ function q($sql) {
/** /**
* *
* This will happen occasionally trying to store the * This will happen occasionally trying to store the
* session data after abnormal program termination * session data after abnormal program termination
* *
*/ */
logger('dba: no database: ' . print_r($args,true)); logger('dba: no database: ' . print_r($args,true));
return false; return false;
}} }}
@ -300,7 +305,7 @@ function q($sql) {
* *
*/ */
if(! function_exists('dbq')) { if(! function_exists('dbq')) {
function dbq($sql) { function dbq($sql) {
global $db; global $db;
@ -312,10 +317,10 @@ function dbq($sql) {
}} }}
// Caller is responsible for ensuring that any integer arguments to // Caller is responsible for ensuring that any integer arguments to
// dbesc_array are actually integers and not malformed strings containing // dbesc_array are actually integers and not malformed strings containing
// SQL injection vectors. All integer array elements should be specifically // SQL injection vectors. All integer array elements should be specifically
// cast to int to avoid trouble. // cast to int to avoid trouble.
if(! function_exists('dbesc_array_cb')) { if(! function_exists('dbesc_array_cb')) {

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
* *
@ -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

@ -595,7 +595,7 @@ function notification($params) {
// use the Emailer class to send the message // use the Emailer class to send the message
Emailer::send(array( return Emailer::send(array(
'fromName' => $sender_name, 'fromName' => $sender_name,
'fromEmail' => $sender_email, 'fromEmail' => $sender_email,
'replyTo' => $sender_email, 'replyTo' => $sender_email,
@ -605,7 +605,6 @@ function notification($params) {
'textVersion' => $email_text_body, 'textVersion' => $email_text_body,
'additionalMailHeader' => $datarray['headers'], 'additionalMailHeader' => $datarray['headers'],
)); ));
return True;
} }
return False; return False;

View File

@ -2,7 +2,7 @@
// curl wrapper. If binary flag is true, return binary // curl wrapper. If binary flag is true, return binary
// results. // results.
// Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt") // Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
// to preserve cookies from one request to the next. // to preserve cookies from one request to the next.
@ -24,7 +24,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
} }
// These settings aren't needed. We're following the location already. // These settings aren't needed. We're following the location already.
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5); // @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
@ -219,8 +219,8 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
}} }}
// Generic XML return // Generic XML return
// Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable // Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
// of $st and an optional text <message> of $message and terminates the current process. // of $st and an optional text <message> of $message and terminates the current process.
if(! function_exists('xml_status')) { if(! function_exists('xml_status')) {
function xml_status($st, $message = '') { function xml_status($st, $message = '') {
@ -246,7 +246,7 @@ function http_status_exit($val) {
if($val >= 200 && $val < 300) if($val >= 200 && $val < 300)
$err = 'OK'; $err = 'OK';
logger('http_status_exit ' . $val); logger('http_status_exit ' . $val);
header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err);
killme(); killme();
@ -298,16 +298,16 @@ function convert_xml_element_to_array($xml_element, &$recursion_depth=0) {
} }
}} }}
// Given an email style address, perform webfinger lookup and // Given an email style address, perform webfinger lookup and
// return the resulting DFRN profile URL, or if no DFRN profile URL // return the resulting DFRN profile URL, or if no DFRN profile URL
// is located, returns an OStatus subscription template (prefixed // is located, returns an OStatus subscription template (prefixed
// with the string 'stat:' to identify it as on OStatus template). // with the string 'stat:' to identify it as on OStatus template).
// If this isn't an email style address just return $s. // If this isn't an email style address just return $s.
// Return an empty string if email-style addresses but webfinger fails, // Return an empty string if email-style addresses but webfinger fails,
// or if the resultant personal XRD doesn't contain a supported // or if the resultant personal XRD doesn't contain a supported
// subscription/friend-request attribute. // subscription/friend-request attribute.
// amended 7/9/2011 to return an hcard which could save potentially loading // amended 7/9/2011 to return an hcard which could save potentially loading
// a lengthy content page to scrape dfrn attributes // a lengthy content page to scrape dfrn attributes
if(! function_exists('webfinger_dfrn')) { if(! function_exists('webfinger_dfrn')) {
@ -332,7 +332,7 @@ function webfinger_dfrn($s,&$hcard) {
return $profile_link; return $profile_link;
}} }}
// Given an email style address, perform webfinger lookup and // Given an email style address, perform webfinger lookup and
// return the array of link attributes from the personal XRD file. // return the array of link attributes from the personal XRD file.
// On error/failure return an empty array. // On error/failure return an empty array.
@ -374,7 +374,7 @@ function lrdd($uri, $debug = false) {
// All we have is an email address. Resource-priority is irrelevant // All we have is an email address. Resource-priority is irrelevant
// because our URI isn't directly resolvable. // because our URI isn't directly resolvable.
if(strstr($uri,'@')) { if(strstr($uri,'@')) {
return(webfinger($uri)); return(webfinger($uri));
} }
@ -418,7 +418,7 @@ function lrdd($uri, $debug = false) {
foreach($properties as $prop) foreach($properties as $prop)
if((string) $prop['@attributes'] === 'http://lrdd.net/priority/resource') if((string) $prop['@attributes'] === 'http://lrdd.net/priority/resource')
$priority = 'resource'; $priority = 'resource';
} }
// save the links in case we need them // save the links in case we need them
@ -449,7 +449,7 @@ function lrdd($uri, $debug = false) {
$tpl = ''; $tpl = '';
if($priority === 'host') { if($priority === 'host') {
if(strlen($tpl)) if(strlen($tpl))
$pxrd = str_replace('{uri}', urlencode($uri), $tpl); $pxrd = str_replace('{uri}', urlencode($uri), $tpl);
elseif(isset($href)) elseif(isset($href))
$pxrd = $href; $pxrd = $href;
@ -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;
@ -688,7 +691,7 @@ function allowed_url($url) {
foreach($allowed as $a) { foreach($allowed as $a) {
$pat = strtolower(trim($a)); $pat = strtolower(trim($a));
if(($fnmatch && fnmatch($pat,$host)) || ($pat == $host)) { if(($fnmatch && fnmatch($pat,$host)) || ($pat == $host)) {
$found = true; $found = true;
break; break;
} }
} }
@ -722,7 +725,7 @@ function allowed_email($email) {
foreach($allowed as $a) { foreach($allowed as $a) {
$pat = strtolower(trim($a)); $pat = strtolower(trim($a));
if(($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) { if(($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) {
$found = true; $found = true;
break; break;
} }
} }
@ -888,7 +891,7 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
$new_height = $ph->getHeight(); $new_height = $ph->getHeight();
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG); logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
$s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' $s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]'
. "\n" . (($include_link) . "\n" . (($include_link)
? '[url=' . $mtch[1] . ']' . t('view full size') . '[/url]' . "\n" ? '[url=' . $mtch[1] . ']' . t('view full size') . '[/url]' . "\n"
: ''),$s); : ''),$s);
logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG); logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG);
@ -928,8 +931,8 @@ function fix_contact_ssl_policy(&$contact,$new_policy) {
} }
if($ssl_changed) { if($ssl_changed) {
q("update contact set q("update contact set
url = '%s', url = '%s',
request = '%s', request = '%s',
notify = '%s', notify = '%s',
poll = '%s', poll = '%s',
@ -984,7 +987,7 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority =
return array(); return array();
} }
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
// http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss // http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);

View File

@ -382,7 +382,7 @@ function send_register_open_eml($email, $sitename, $siteurl, $username, $passwor
The login details are as follows: The login details are as follows:
Site Location: %3$s Site Location: %3$s
Login Name: %1$s Login Name: %1$s
Password: %5$ Password: %5$s
You may change your password from your account "Settings" page after logging You may change your password from your account "Settings" page after logging
in. in.
@ -407,7 +407,7 @@ function send_register_open_eml($email, $sitename, $siteurl, $username, $passwor
$preamble = sprintf($preamble, $username, $sitename); $preamble = sprintf($preamble, $username, $sitename);
$body = sprintf($body, $email, $sitename, $siteurl, $username, $password); $body = sprintf($body, $email, $sitename, $siteurl, $username, $password);
notification(array( return notification(array(
'type' => "SYSTEM_EMAIL", 'type' => "SYSTEM_EMAIL",
'to_email' => $email, 'to_email' => $email,
'subject'=> sprintf( t('Registration details for %s'), $sitename), 'subject'=> sprintf( t('Registration details for %s'), $sitename),

View File

@ -81,20 +81,25 @@ function register_post(&$a) {
set_pconfig($user['uid'],'system','invites_remaining',$num_invites); set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
} }
send_register_open_eml( $res = send_register_open_eml(
$user['email'], $user['email'],
$a->config['sitename'], $a->config['sitename'],
$a->get_baseurl(), $a->get_baseurl(),
$user['username'], $user['username'],
$result['password']); $result['password']);
if($res) { if($res) {
info( t('Registration successful. Please check your email for further instructions.') . EOL ) ; info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
goaway(z_root()); goaway(z_root());
} }
else { else {
notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL ); notice(
sprintf(
t('Failed to send email message. Here your accout details:<br> login: %s<br> password: %s<br><br>You can change your password after login.'),
$user['email'],
$result['password']
). EOL
);
} }
} }
elseif($a->config['register_policy'] == REGISTER_APPROVE) { elseif($a->config['register_policy'] == REGISTER_APPROVE) {

View File

@ -48,13 +48,13 @@ function update_1000() {
q("ALTER TABLE `intro` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `knowyou` "); q("ALTER TABLE `intro` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `knowyou` ");
q("ALTER TABLE `contact` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rel` "); q("ALTER TABLE `contact` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rel` ");
q("ALTER TABLE `contact` CHANGE `issued-pubkey` `issued-pubkey` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); q("ALTER TABLE `contact` CHANGE `issued-pubkey` `issued-pubkey` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
q("ALTER TABLE `contact` ADD `term-date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `avatar-date`"); q("ALTER TABLE `contact` ADD `term-date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `avatar-date`");
} }
function update_1001() { function update_1001() {
q("ALTER TABLE `item` ADD `wall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` "); q("ALTER TABLE `item` ADD `wall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
q("ALTER TABLE `item` ADD INDEX ( `wall` )"); q("ALTER TABLE `item` ADD INDEX ( `wall` )");
} }
function update_1002() { function update_1002() {
@ -65,7 +65,7 @@ function update_1003() {
q("ALTER TABLE `contact` DROP `issued-pubkey` , DROP `ret-id` , DROP `ret-pubkey` "); q("ALTER TABLE `contact` DROP `issued-pubkey` , DROP `ret-id` , DROP `ret-pubkey` ");
q("ALTER TABLE `contact` ADD `usehub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `ret-aes`"); q("ALTER TABLE `contact` ADD `usehub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `ret-aes`");
q("ALTER TABLE `contact` ADD `hub-verify` CHAR( 255 ) NOT NULL AFTER `usehub`"); q("ALTER TABLE `contact` ADD `hub-verify` CHAR( 255 ) NOT NULL AFTER `usehub`");
q("ALTER TABLE `contact` ADD INDEX ( `uid` ) , ADD INDEX ( `self` ), ADD INDEX ( `issued-id` ), ADD INDEX ( `dfrn-id` )"); q("ALTER TABLE `contact` ADD INDEX ( `uid` ) , ADD INDEX ( `self` ), ADD INDEX ( `issued-id` ), ADD INDEX ( `dfrn-id` )");
q("ALTER TABLE `contact` ADD INDEX ( `blocked` ), ADD INDEX ( `readonly` )"); q("ALTER TABLE `contact` ADD INDEX ( `blocked` ), ADD INDEX ( `readonly` )");
} }
@ -104,7 +104,7 @@ function update_1006() {
function update_1007() { function update_1007() {
q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`"); q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`");
q("ALTER TABLE `user` ADD INDEX ( `nickname` )"); q("ALTER TABLE `user` ADD INDEX ( `nickname` )");
} }
function update_1008() { function update_1008() {
@ -137,9 +137,9 @@ function update_1012() {
} }
function update_1013() { function update_1013() {
q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL
AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`"); AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`");
} }
function update_1014() { function update_1014() {
require_once('include/Photo.php'); require_once('include/Photo.php');
@ -156,7 +156,7 @@ function update_1014() {
} }
$r = q("SELECT * FROM `contact` WHERE 1"); $r = q("SELECT * FROM `contact` WHERE 1");
if(count($r)) { if(count($r)) {
foreach($r as $rr) { foreach($r as $rr) {
if(stristr($rr['thumb'],'avatar')) if(stristr($rr['thumb'],'avatar'))
q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d",
dbesc(str_replace('avatar','micro',$rr['thumb'])), dbesc(str_replace('avatar','micro',$rr['thumb'])),
@ -269,7 +269,7 @@ function update_1027() {
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` CHAR( 255 ) NOT NULL , `name` CHAR( 255 ) NOT NULL ,
`version` CHAR( 255 ) NOT NULL , `version` CHAR( 255 ) NOT NULL ,
`installed` TINYINT( 1 ) NOT NULL DEFAULT '0' `installed` TINYINT( 1 ) NOT NULL DEFAULT '0'
) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
} }
@ -319,7 +319,7 @@ function update_1031() {
} }
} }
} }
function update_1032() { function update_1032() {
q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` "); q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` ");
} }
@ -335,11 +335,11 @@ function update_1033() {
function update_1034() { function update_1034() {
// If you have any of these parent-less posts they can cause problems, and // If you have any of these parent-less posts they can cause problems, and
// we need to delete them. You can't see them anyway. // we need to delete them. You can't see them anyway.
// Legitimate items will usually get re-created on the next // Legitimate items will usually get re-created on the next
// pull from the hub. // pull from the hub.
// But don't get rid of a post that may have just come in // But don't get rid of a post that may have just come in
// and may not yet have the parent id set. // and may not yet have the parent id set.
q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
@ -557,7 +557,7 @@ function update_1068() {
`url` CHAR( 255 ) NOT NULL , `url` CHAR( 255 ) NOT NULL ,
`photo` CHAR( 255 ) NOT NULL , `photo` CHAR( 255 ) NOT NULL ,
`note` TEXT NOT NULL , `note` TEXT NOT NULL ,
`created` DATETIME NOT NULL `created` DATETIME NOT NULL
) ENGINE = MYISAM DEFAULT CHARSET=utf8"); ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
} }
@ -633,7 +633,7 @@ function update_1076() {
} }
// There was a typo in 1076 so we'll try again in 1077 to make sure // There was a typo in 1076 so we'll try again in 1077 to make sure
// We'll also make it big enough to allow for future growth, I seriously // We'll also make it big enough to allow for future growth, I seriously
// doubt Diaspora will be able to leave guids at 16 bytes, // doubt Diaspora will be able to leave guids at 16 bytes,
// and we can also use the same structure for our own larger guids // and we can also use the same structure for our own larger guids
@ -641,7 +641,7 @@ function update_1077() {
q("CREATE TABLE IF NOT EXISTS `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , q("CREATE TABLE IF NOT EXISTS `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM "); `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM ");
q("ALTER TABLE `guid` CHANGE `guid` `guid` CHAR( 64 ) NOT NULL"); q("ALTER TABLE `guid` CHANGE `guid` `guid` CHAR( 64 ) NOT NULL");
} }
function update_1078() { function update_1078() {
@ -667,7 +667,7 @@ function update_1079() {
ADD `network` CHAR( 32 ) NOT NULL , ADD `network` CHAR( 32 ) NOT NULL ,
ADD `alias` CHAR( 255 ) NOT NULL , ADD `alias` CHAR( 255 ) NOT NULL ,
ADD `pubkey` TEXT NOT NULL , ADD `pubkey` TEXT NOT NULL ,
ADD INDEX ( `addr` ) , ADD INDEX ( `addr` ) ,
ADD INDEX ( `network` ) "); ADD INDEX ( `network` ) ");
} }
@ -802,24 +802,24 @@ function update_1096() {
} }
function update_1097() { function update_1097() {
q("ALTER TABLE `queue` q("ALTER TABLE `queue`
ADD INDEX (`cid`), ADD INDEX (`cid`),
ADD INDEX (`created`), ADD INDEX (`created`),
ADD INDEX (`last`), ADD INDEX (`last`),
ADD INDEX (`network`), ADD INDEX (`network`),
ADD INDEX (`batch`) ADD INDEX (`batch`)
"); ");
} }
function update_1098() { function update_1098() {
q("ALTER TABLE `contact` q("ALTER TABLE `contact`
ADD INDEX (`network`), ADD INDEX (`network`),
ADD INDEX (`name`), ADD INDEX (`name`),
ADD INDEX (`nick`), ADD INDEX (`nick`),
ADD INDEX (`attag`), ADD INDEX (`attag`),
ADD INDEX (`url`), ADD INDEX (`url`),
ADD INDEX (`addr`), ADD INDEX (`addr`),
ADD INDEX (`batch`) ADD INDEX (`batch`)
"); ");
} }
@ -843,7 +843,7 @@ function update_1099() {
q("ALTER TABLE `gcontact` ADD INDEX (`nurl`) "); q("ALTER TABLE `gcontact` ADD INDEX (`nurl`) ");
q("ALTER TABLE `glink` ADD INDEX (`cid`), ADD INDEX (`uid`), ADD INDEX (`gcid`), ADD INDEX (`updated`) "); q("ALTER TABLE `glink` ADD INDEX (`cid`), ADD INDEX (`uid`), ADD INDEX (`gcid`), ADD INDEX (`updated`) ");
q("ALTER TABLE `contact` ADD `poco` TEXT NOT NULL AFTER `confirm` "); q("ALTER TABLE `contact` ADD `poco` TEXT NOT NULL AFTER `confirm` ");
} }
@ -859,7 +859,7 @@ function update_1100() {
q("update contact set nurl = '%s' where id = %d", q("update contact set nurl = '%s' where id = %d",
dbesc(normalise_link($rr['url'])), dbesc(normalise_link($rr['url'])),
intval($rr['id']) intval($rr['id'])
); );
} }
} }
} }
@ -876,18 +876,18 @@ function update_1101() {
} }
function update_1102() { function update_1102() {
q("ALTER TABLE `clients` ADD `name` TEXT NULL DEFAULT NULL AFTER `redirect_uri` "); q("ALTER TABLE `clients` ADD `name` TEXT NULL DEFAULT NULL AFTER `redirect_uri` ");
q("ALTER TABLE `clients` ADD `icon` TEXT NULL DEFAULT NULL AFTER `name` "); q("ALTER TABLE `clients` ADD `icon` TEXT NULL DEFAULT NULL AFTER `name` ");
q("ALTER TABLE `clients` ADD `uid` INT NOT NULL DEFAULT 0 AFTER `icon` "); q("ALTER TABLE `clients` ADD `uid` INT NOT NULL DEFAULT 0 AFTER `icon` ");
q("ALTER TABLE `tokens` ADD `secret` TEXT NOT NULL AFTER `id` "); q("ALTER TABLE `tokens` ADD `secret` TEXT NOT NULL AFTER `id` ");
q("ALTER TABLE `tokens` ADD `uid` INT NOT NULL AFTER `scope` "); q("ALTER TABLE `tokens` ADD `uid` INT NOT NULL AFTER `scope` ");
} }
function update_1103() { function update_1103() {
// q("ALTER TABLE `item` ADD INDEX ( `wall` ) "); // q("ALTER TABLE `item` ADD INDEX ( `wall` ) ");
q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) ");
q("ALTER TABLE `contact` ADD INDEX ( `pending` ) "); q("ALTER TABLE `contact` ADD INDEX ( `pending` ) ");
q("ALTER TABLE `user` ADD INDEX ( `hidewall` ) "); q("ALTER TABLE `user` ADD INDEX ( `hidewall` ) ");
q("ALTER TABLE `user` ADD INDEX ( `blockwall` ) "); q("ALTER TABLE `user` ADD INDEX ( `blockwall` ) ");
@ -924,7 +924,7 @@ function update_1107() {
} }
function update_1108() { function update_1108() {
q("ALTER TABLE `contact` ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` , q("ALTER TABLE `contact` ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` ,
ADD INDEX ( `hidden` ) "); ADD INDEX ( `hidden` ) ");
@ -993,8 +993,8 @@ INDEX ( `stat` )
} }
function update_1115() { function update_1115() {
q("ALTER TABLE `item` ADD `moderated` q("ALTER TABLE `item` ADD `moderated`
TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `pubmail`, TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `pubmail`,
ADD INDEX (`moderated`) "); ADD INDEX (`moderated`) ");
} }
@ -1149,16 +1149,16 @@ function update_1134() {
} }
function update_1135() { function update_1135() {
//there can't be indexes with more than 1000 bytes in mysql, //there can't be indexes with more than 1000 bytes in mysql,
//so change charset to be smaller //so change charset to be smaller
q("ALTER TABLE `config` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL , q("ALTER TABLE `config` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL"); CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
//same thing for pconfig //same thing for pconfig
q("ALTER TABLE `pconfig` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL , q("ALTER TABLE `pconfig` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL"); CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
// faulty update merged forward. Bad update in 1134 caused duplicate k,cat pairs // faulty update merged forward. Bad update in 1134 caused duplicate k,cat pairs
// these have to be cleared before the unique keys can be added. // these have to be cleared before the unique keys can be added.
} }
function update_1136() { function update_1136() {
@ -1184,7 +1184,7 @@ function update_1136() {
} }
} }
} }
$arr = array(); $arr = array();
$r = q("select * from pconfig where 1 order by id desc"); $r = q("select * from pconfig where 1 order by id desc");
if(count($r)) { if(count($r)) {
@ -1203,8 +1203,8 @@ function update_1136() {
} }
} }
} }
q("ALTER TABLE `config` ADD UNIQUE `access` ( `cat` , `k` ) "); q("ALTER TABLE `config` ADD UNIQUE `access` ( `cat` , `k` ) ");
q("ALTER TABLE `pconfig` ADD UNIQUE `access` ( `uid` , `cat` , `k` )"); q("ALTER TABLE `pconfig` ADD UNIQUE `access` ( `uid` , `cat` , `k` )");
} }
@ -1278,7 +1278,7 @@ function update_1146() {
function update_1147() { function update_1147() {
$r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'"); $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'");
$r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`"); $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`");
$r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )"); $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )");
if((! $r1) || (! $r2) || (! $r3)) if((! $r1) || (! $r2) || (! $r3))
return UPDATE_FAILED ; return UPDATE_FAILED ;
return UPDATE_SUCCESS ; return UPDATE_SUCCESS ;
@ -1327,7 +1327,7 @@ function update_1152() {
`otype` TINYINT( 3 ) UNSIGNED NOT NULL , `otype` TINYINT( 3 ) UNSIGNED NOT NULL ,
`type` TINYINT( 3 ) UNSIGNED NOT NULL , `type` TINYINT( 3 ) UNSIGNED NOT NULL ,
`term` CHAR( 255 ) NOT NULL , `term` CHAR( 255 ) NOT NULL ,
`url` CHAR( 255 ) NOT NULL, `url` CHAR( 255 ) NOT NULL,
KEY `oid` ( `oid` ), KEY `oid` ( `oid` ),
KEY `otype` ( `otype` ), KEY `otype` ( `otype` ),
KEY `type` ( `type` ), KEY `type` ( `type` ),
@ -1340,7 +1340,7 @@ function update_1152() {
function update_1153() { function update_1153() {
$r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'"); $r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'");
if(!$r) return UPDATE_FAILED; if(!$r) return UPDATE_FAILED;
return UPDATE_SUCCESS; return UPDATE_SUCCESS;
} }
@ -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;