move db_upgrade to zlib
This commit is contained in:
parent
dea4879938
commit
5f0004b416
105
Zotlabs/Lib/DB_Upgrade.php
Normal file
105
Zotlabs/Lib/DB_Upgrade.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Lib;
|
||||||
|
|
||||||
|
|
||||||
|
class DB_Upgrade {
|
||||||
|
|
||||||
|
|
||||||
|
function __construct($db_revision) {
|
||||||
|
|
||||||
|
$build = get_config('system','db_version',0);
|
||||||
|
if(! intval($build))
|
||||||
|
$build = set_config('system','db_version',$db_revision);
|
||||||
|
|
||||||
|
if($build == $db_revision) {
|
||||||
|
// Nothing to be done.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$stored = intval($build);
|
||||||
|
if(! $stored) {
|
||||||
|
logger('Critical: check_config unable to determine database schema version');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = intval($db_revision);
|
||||||
|
if(($stored < $current) && file_exists('install/update.php')) {
|
||||||
|
|
||||||
|
Config::Load('database');
|
||||||
|
|
||||||
|
// We're reporting a different version than what is currently installed.
|
||||||
|
// Run any existing update scripts to bring the database up to current.
|
||||||
|
|
||||||
|
require_once('install/update.php');
|
||||||
|
|
||||||
|
// make sure that boot.php and update.php are the same release, we might be
|
||||||
|
// updating from git 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.
|
||||||
|
|
||||||
|
if($db_revision == UPDATE_VERSION) {
|
||||||
|
for($x = $stored; $x < $current; $x ++) {
|
||||||
|
if(function_exists('update_r' . $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.
|
||||||
|
|
||||||
|
if(get_config('database','update_r' . $x))
|
||||||
|
break;
|
||||||
|
set_config('database','update_r' . $x, '1');
|
||||||
|
// call the specific update
|
||||||
|
|
||||||
|
$func = 'update_r' . $x;
|
||||||
|
$retval = $func();
|
||||||
|
if($retval) {
|
||||||
|
|
||||||
|
// Prevent sending hundreds of thousands of emails by creating
|
||||||
|
// a lockfile.
|
||||||
|
|
||||||
|
$lockfile = 'store/[data]/mailsent';
|
||||||
|
|
||||||
|
if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400)))
|
||||||
|
return;
|
||||||
|
@unlink($lockfile);
|
||||||
|
//send the administrator an e-mail
|
||||||
|
file_put_contents($lockfile, $x);
|
||||||
|
|
||||||
|
$r = q("select account_language from account where account_email = '%s' limit 1",
|
||||||
|
dbesc(App::$config['system']['admin_email'])
|
||||||
|
);
|
||||||
|
push_lang(($r) ? $r[0]['account_language'] : 'en');
|
||||||
|
|
||||||
|
z_mail(
|
||||||
|
[
|
||||||
|
'toEmail' => \App::$config['system']['admin_email'],
|
||||||
|
'messageSubject' => sprintf( t('Update Error at %s'), z_root()),
|
||||||
|
'textVersion' => replace_macros(get_intltext_template('update_fail_eml.tpl'),
|
||||||
|
[
|
||||||
|
'$sitename' => \App::$config['system']['sitename'],
|
||||||
|
'$siteurl' => z_root(),
|
||||||
|
'$update' => $x,
|
||||||
|
'$error' => sprintf( t('Update %s failed. See error logs.'), $x)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
//try the logger
|
||||||
|
logger('CRITICAL: Update Failed: ' . $x);
|
||||||
|
pop_lang();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
set_config('database','update_r' . $x, 'success');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set_config('system','db_version', $db_revision);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -338,7 +338,6 @@ class ThreadItem {
|
|||||||
'profile_url' => $profile_link,
|
'profile_url' => $profile_link,
|
||||||
'thread_action_menu' => thread_action_menu($item,$conv->get_mode()),
|
'thread_action_menu' => thread_action_menu($item,$conv->get_mode()),
|
||||||
'thread_author_menu' => thread_author_menu($item,$conv->get_mode()),
|
'thread_author_menu' => thread_author_menu($item,$conv->get_mode()),
|
||||||
'item_photo_menu' => item_photo_menu($item),
|
|
||||||
'dreport' => $dreport,
|
'dreport' => $dreport,
|
||||||
'name' => $profile_name,
|
'name' => $profile_name,
|
||||||
'thumb' => $profile_avatar,
|
'thumb' => $profile_avatar,
|
||||||
|
@ -79,11 +79,6 @@ class WebServer {
|
|||||||
if(! x($_SESSION, 'sysmsg_info'))
|
if(! x($_SESSION, 'sysmsg_info'))
|
||||||
$_SESSION['sysmsg_info'] = array();
|
$_SESSION['sysmsg_info'] = array();
|
||||||
|
|
||||||
/*
|
|
||||||
* check_config() is responsible for running update scripts. These automatically
|
|
||||||
* update the DB schema whenever we push a new one out. It also checks to see if
|
|
||||||
* any plugins have been added or removed and reacts accordingly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
if(\App::$install) {
|
if(\App::$install) {
|
||||||
@ -91,8 +86,16 @@ class WebServer {
|
|||||||
if(\App::$module != 'view')
|
if(\App::$module != 'view')
|
||||||
\App::$module = 'setup';
|
\App::$module = 'setup';
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
check_config($a);
|
|
||||||
|
/*
|
||||||
|
* check_config() is responsible for running update scripts. These automatically
|
||||||
|
* update the DB schema whenever we push a new one out. It also checks to see if
|
||||||
|
* any plugins have been added or removed and reacts accordingly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
check_config();
|
||||||
|
}
|
||||||
|
|
||||||
nav_set_selected('nothing');
|
nav_set_selected('nothing');
|
||||||
|
|
||||||
|
88
boot.php
88
boot.php
@ -1394,11 +1394,7 @@ function is_ajax() {
|
|||||||
// base url for use in cmdline programs which don't have
|
// base url for use in cmdline programs which don't have
|
||||||
// $_SERVER variables, and synchronising the state of installed plugins.
|
// $_SERVER variables, and synchronising the state of installed plugins.
|
||||||
|
|
||||||
function check_config(&$a) {
|
function check_config() {
|
||||||
|
|
||||||
$build = get_config('system','db_version');
|
|
||||||
if(! intval($build))
|
|
||||||
$build = set_config('system','db_version',DB_UPDATE_VERSION);
|
|
||||||
|
|
||||||
$saved = get_config('system','urlverify');
|
$saved = get_config('system','urlverify');
|
||||||
if(! $saved)
|
if(! $saved)
|
||||||
@ -1436,88 +1432,8 @@ function check_config(&$a) {
|
|||||||
if (! $syschan_exists)
|
if (! $syschan_exists)
|
||||||
create_sys_channel();
|
create_sys_channel();
|
||||||
|
|
||||||
if($build != DB_UPDATE_VERSION) {
|
$x = new \Zotlabs\Lib\DB_Upgrade(DB_UPDATE_VERSION);
|
||||||
$stored = intval($build);
|
|
||||||
if(! $stored) {
|
|
||||||
logger('Critical: check_config unable to determine database schema version');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$current = intval(DB_UPDATE_VERSION);
|
|
||||||
if(($stored < $current) && file_exists('install/update.php')) {
|
|
||||||
|
|
||||||
load_config('database');
|
|
||||||
|
|
||||||
// We're reporting a different version than what is currently installed.
|
|
||||||
// Run any existing update scripts to bring the database up to current.
|
|
||||||
require_once('install/update.php');
|
|
||||||
|
|
||||||
// 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
|
|
||||||
// file may not be here yet. This can happen on a very busy site.
|
|
||||||
|
|
||||||
if(DB_UPDATE_VERSION == UPDATE_VERSION) {
|
|
||||||
for($x = $stored; $x < $current; $x ++) {
|
|
||||||
if(function_exists('update_r' . $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.
|
|
||||||
|
|
||||||
if(get_config('database','update_r' . $x))
|
|
||||||
break;
|
|
||||||
set_config('database','update_r' . $x, '1');
|
|
||||||
// call the specific update
|
|
||||||
|
|
||||||
$func = 'update_r' . $x;
|
|
||||||
$retval = $func();
|
|
||||||
if($retval) {
|
|
||||||
|
|
||||||
// Prevent sending hundreds of thousands of emails by creating
|
|
||||||
// a lockfile.
|
|
||||||
|
|
||||||
$lockfile = 'store/[data]/mailsent';
|
|
||||||
|
|
||||||
if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400)))
|
|
||||||
return;
|
|
||||||
@unlink($lockfile);
|
|
||||||
//send the administrator an e-mail
|
|
||||||
file_put_contents($lockfile, $x);
|
|
||||||
|
|
||||||
$r = q("select account_language from account where account_email = '%s' limit 1",
|
|
||||||
dbesc(App::$config['system']['admin_email'])
|
|
||||||
);
|
|
||||||
push_lang(($r) ? $r[0]['account_language'] : 'en');
|
|
||||||
|
|
||||||
|
|
||||||
$email_tpl = get_intltext_template("update_fail_eml.tpl");
|
|
||||||
$email_msg = replace_macros($email_tpl, array(
|
|
||||||
'$sitename' => App::$config['system']['sitename'],
|
|
||||||
'$siteurl' => z_root(),
|
|
||||||
'$update' => $x,
|
|
||||||
'$error' => sprintf( t('Update %s failed. See error logs.'), $x)
|
|
||||||
));
|
|
||||||
|
|
||||||
$subject = email_header_encode(sprintf(t('Update Error at %s'), z_root()));
|
|
||||||
|
|
||||||
mail(App::$config['system']['admin_email'], $subject, $email_msg,
|
|
||||||
'From: Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
|
|
||||||
. 'Content-type: text/plain; charset=UTF-8' . "\n"
|
|
||||||
. 'Content-transfer-encoding: 8bit' );
|
|
||||||
//try the logger
|
|
||||||
logger('CRITICAL: Update Failed: ' . $x);
|
|
||||||
pop_lang();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
set_config('database','update_r' . $x, 'success');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set_config('system','db_version', DB_UPDATE_VERSION);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
require_once('include/items.php');
|
require_once('include/items.php');
|
||||||
|
|
||||||
// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
|
|
||||||
// is identical to the code in mod/message.php for 'item_extract_images' and
|
|
||||||
// 'item_redir_and_replace_images'
|
|
||||||
|
|
||||||
|
|
||||||
function item_extract_images($body) {
|
function item_extract_images($body) {
|
||||||
|
|
||||||
@ -375,13 +371,14 @@ function localize_item(&$item){
|
|||||||
* * \e array \b children
|
* * \e array \b children
|
||||||
* @return number
|
* @return number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function count_descendants($item) {
|
function count_descendants($item) {
|
||||||
|
|
||||||
$total = count($item['children']);
|
$total = count($item['children']);
|
||||||
|
|
||||||
if ($total > 0) {
|
if($total > 0) {
|
||||||
foreach ($item['children'] as $child) {
|
foreach($item['children'] as $child) {
|
||||||
if (! visible_activity($child))
|
if(! visible_activity($child))
|
||||||
$total --;
|
$total --;
|
||||||
|
|
||||||
$total += count_descendants($child);
|
$total += count_descendants($child);
|
||||||
@ -408,8 +405,8 @@ function visible_activity($item) {
|
|||||||
if(intval($item['item_notshown']))
|
if(intval($item['item_notshown']))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
foreach ($hidden_activities as $act) {
|
foreach($hidden_activities as $act) {
|
||||||
if ((activity_match($item['verb'], $act)) && ($item['mid'] != $item['parent_mid'])) {
|
if((activity_match($item['verb'], $act)) && ($item['mid'] != $item['parent_mid'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -875,98 +872,6 @@ function best_link_url($item) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function item_photo_menu($item){
|
|
||||||
|
|
||||||
$contact = null;
|
|
||||||
|
|
||||||
$ssl_state = false;
|
|
||||||
|
|
||||||
$sub_link="";
|
|
||||||
$poke_link="";
|
|
||||||
$contact_url="";
|
|
||||||
$pm_url="";
|
|
||||||
$vsrc_link = "";
|
|
||||||
$follow_url = "";
|
|
||||||
|
|
||||||
$local_channel = local_channel();
|
|
||||||
|
|
||||||
if($local_channel) {
|
|
||||||
$ssl_state = true;
|
|
||||||
if(! count(App::$contacts))
|
|
||||||
load_contact_links($local_channel);
|
|
||||||
$channel = App::get_channel();
|
|
||||||
$channel_hash = (($channel) ? $channel['channel_hash'] : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($local_channel) && $local_channel == $item['uid']) {
|
|
||||||
$vsrc_link = 'javascript:viewsrc(' . $item['id'] . '); return false;';
|
|
||||||
if($item['parent'] == $item['id'] && $channel && ($channel_hash != $item['author_xchan'])) {
|
|
||||||
$sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
|
|
||||||
}
|
|
||||||
if($channel) {
|
|
||||||
$unsub_link = 'javascript:dounsubthread(' . $item['id'] . '); return false;';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile_link = chanlink_hash($item['author_xchan']);
|
|
||||||
if($item['uid'] > 0)
|
|
||||||
$pm_url = z_root() . '/mail/new/?f=&hash=' . $item['author_xchan'];
|
|
||||||
|
|
||||||
if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts))
|
|
||||||
$contact = App::$contacts[$item['author_xchan']];
|
|
||||||
else
|
|
||||||
if($local_channel && $item['author']['xchan_addr'])
|
|
||||||
$follow_url = z_root() . '/follow/?f=&url=' . $item['author']['xchan_addr'];
|
|
||||||
|
|
||||||
if($contact) {
|
|
||||||
$poke_link = z_root() . '/poke/?f=&c=' . $contact['abook_id'];
|
|
||||||
if (! intval($contact['abook_self']))
|
|
||||||
$contact_url = z_root() . '/connedit/' . $contact['abook_id'];
|
|
||||||
$posts_link = z_root() . '/network/?cid=' . $contact['abook_id'];
|
|
||||||
|
|
||||||
$clean_url = normalise_link($item['author-link']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$rating_enabled = get_config('system','rating_enabled');
|
|
||||||
|
|
||||||
$ratings_url = (($rating_enabled) ? z_root() . '/ratings/' . urlencode($item['author_xchan']) : '');
|
|
||||||
|
|
||||||
$post_menu = Array(
|
|
||||||
t("View Source") => $vsrc_link,
|
|
||||||
t("Follow Thread") => $sub_link,
|
|
||||||
t("Unfollow Thread") => $unsub_link,
|
|
||||||
);
|
|
||||||
|
|
||||||
$author_menu = array(
|
|
||||||
t("View Profile") => $profile_link,
|
|
||||||
t("Activity/Posts") => $posts_link,
|
|
||||||
t("Connect") => $follow_url,
|
|
||||||
t("Edit Connection") => $contact_url,
|
|
||||||
t("Message") => $pm_url,
|
|
||||||
t('Ratings') => $ratings_url,
|
|
||||||
t("Poke") => $poke_link
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$args = array('item' => $item, 'post_menu' => $post_menu, 'author_menu' => $author_menu);
|
|
||||||
|
|
||||||
call_hooks('item_photo_menu', $args);
|
|
||||||
|
|
||||||
$menu = array_merge($args['post_menu'],$args['author_menu']);
|
|
||||||
|
|
||||||
$o = "";
|
|
||||||
foreach($menu as $k=>$v){
|
|
||||||
if(strpos($v,'javascript:') === 0) {
|
|
||||||
$v = substr($v,11);
|
|
||||||
$o .= "<li><a href=\"#\" onclick=\"$v\">$k</a></li>\n";
|
|
||||||
}
|
|
||||||
elseif ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $o;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function thread_action_menu($item,$mode = '') {
|
function thread_action_menu($item,$mode = '') {
|
||||||
|
|
||||||
$menu = [];
|
$menu = [];
|
||||||
@ -1026,14 +931,15 @@ function thread_author_menu($item, $mode = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$profile_link = chanlink_hash($item['author_xchan']);
|
$profile_link = chanlink_hash($item['author_xchan']);
|
||||||
|
|
||||||
if($item['uid'] > 0)
|
if($item['uid'] > 0)
|
||||||
$pm_url = z_root() . '/mail/new/?f=&hash=' . $item['author_xchan'];
|
$pm_url = z_root() . '/mail/new/?f=&hash=' . urlencode($item['author_xchan']);
|
||||||
|
|
||||||
if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts))
|
if(App::$contacts && array_key_exists($item['author_xchan'],App::$contacts))
|
||||||
$contact = App::$contacts[$item['author_xchan']];
|
$contact = App::$contacts[$item['author_xchan']];
|
||||||
else
|
else
|
||||||
if($local_channel && $item['author']['xchan_addr'])
|
if($local_channel && $item['author']['xchan_addr'])
|
||||||
$follow_url = z_root() . '/follow/?f=&url=' . $item['author']['xchan_addr'];
|
$follow_url = z_root() . '/follow/?f=&url=' . urlencode($item['author']['xchan_addr']);
|
||||||
|
|
||||||
if($contact) {
|
if($contact) {
|
||||||
$poke_link = z_root() . '/poke/?f=&c=' . $contact['abook_id'];
|
$poke_link = z_root() . '/poke/?f=&c=' . $contact['abook_id'];
|
||||||
|
@ -9,6 +9,7 @@ require_once('boot.php');
|
|||||||
require_once('include/cli_startup.php');
|
require_once('include/cli_startup.php');
|
||||||
|
|
||||||
cli_startup();
|
cli_startup();
|
||||||
|
$build = get_config('system','db_version');
|
||||||
|
|
||||||
echo "Old DB VERSION: " . $build . "\n";
|
echo "Old DB VERSION: " . $build . "\n";
|
||||||
echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n";
|
echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n";
|
||||||
@ -16,7 +17,7 @@ echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n";
|
|||||||
|
|
||||||
if($build != DB_UPDATE_VERSION) {
|
if($build != DB_UPDATE_VERSION) {
|
||||||
echo "Updating database...";
|
echo "Updating database...";
|
||||||
check_config($a);
|
check_config();
|
||||||
echo "Done\n";
|
echo "Done\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user