aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2017-01-29 20:02:34 -0500
committerAndrew Manning <tamanning@zoho.com>2017-01-29 20:02:34 -0500
commitb58d56826bf9fd74a70a25848113c80baeeb8dfc (patch)
tree17b98611cb4af1ffc0dc4b85c0d173b0231b9f9f
parente770768b790f2441ef5371910568ff3bf6680dab (diff)
parentdbf7ff979122ea0f8877e9ae4b16590f280593ef (diff)
downloadvolse-hubzilla-b58d56826bf9fd74a70a25848113c80baeeb8dfc.tar.gz
volse-hubzilla-b58d56826bf9fd74a70a25848113c80baeeb8dfc.tar.bz2
volse-hubzilla-b58d56826bf9fd74a70a25848113c80baeeb8dfc.zip
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev
-rw-r--r--Zotlabs/Daemon/Queue.php23
-rw-r--r--Zotlabs/Module/Import.php40
-rwxr-xr-xboot.php3
-rw-r--r--include/channel.php36
-rw-r--r--include/hubloc.php104
-rwxr-xr-xinclude/items.php34
-rw-r--r--include/network.php41
-rw-r--r--include/queue_fn.php46
-rw-r--r--include/security.php23
-rw-r--r--include/xchan.php139
-rw-r--r--include/zot.php44
-rw-r--r--install/schema_mysql.sql2
-rw-r--r--install/schema_postgres.sql2
-rw-r--r--install/update.php21
14 files changed, 324 insertions, 234 deletions
diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php
index 27306589d..11cbe4494 100644
--- a/Zotlabs/Daemon/Queue.php
+++ b/Zotlabs/Daemon/Queue.php
@@ -61,30 +61,15 @@ class Queue {
// the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once
// or twice a day.
- // FIXME: can we sort postgres on outq_priority and maintain the 'distinct' ?
- // The order by max(outq_priority) might be a dodgy query because of the group by.
- // The desired result is to return a sequence in the order most likely to be delivered in this run.
- // If a hub has already been sitting in the queue for a few days, they should be delivered last;
- // hence every failure should drop them further down the priority list.
-
- if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
- $prefix = 'DISTINCT ON (outq_posturl)';
- $suffix = 'ORDER BY outq_posturl';
- } else {
- $prefix = '';
- $suffix = 'GROUP BY outq_posturl ORDER BY max(outq_priority)';
- }
- $r = q("SELECT $prefix * FROM outq WHERE outq_delivered = 0 and (( outq_created > %s - INTERVAL %s and outq_updated < %s - INTERVAL %s ) OR ( outq_updated < %s - INTERVAL %s )) $suffix",
- db_utcnow(), db_quoteinterval('12 HOUR'),
- db_utcnow(), db_quoteinterval('15 MINUTE'),
- db_utcnow(), db_quoteinterval('1 HOUR')
+ $r = q("SELECT * FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s ",
+ db_utcnow()
);
}
if(! $r)
return;
- foreach($r as $rr) {
- queue_deliver($rr);
+ foreach($r as $rv) {
+ queue_deliver($rv);
}
}
}
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index b69daa2ff..6de7c85a2 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -247,25 +247,27 @@ class Import extends \Zotlabs\Web\Controller {
$r = q("delete from xchan where xchan_hash = '%s'",
dbesc($channel['channel_hash'])
);
-
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_hidden, xchan_orphan, xchan_censored, xchan_selfcensored, xchan_system, xchan_pubforum, xchan_deleted ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, %d )",
- dbesc($channel['channel_hash']),
- dbesc($channel['channel_guid']),
- dbesc($channel['channel_guid_sig']),
- dbesc($channel['channel_pubkey']),
- dbesc(z_root() . "/photo/profile/l/" . $channel['channel_id']),
- dbesc(z_root() . "/photo/profile/m/" . $channel['channel_id']),
- dbesc(z_root() . "/photo/profile/s/" . $channel['channel_id']),
- dbesc(channel_reddress($channel)),
- dbesc(z_root() . '/channel/' . $channel['channel_address']),
- dbesc(z_root() . '/follow?f=&url=%s'),
- dbesc(z_root() . '/poco/' . $channel['channel_address']),
- dbesc($channel['channel_name']),
- dbesc('zot'),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- 0,0,0,0,0,0,0
- );
+
+
+ $r = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $channel['channel_hash'],
+ 'xchan_guid' => $channel['channel_guid'],
+ 'xchan_guid_sig' => $channel['channel_guid_sig'],
+ 'xchan_pubkey' => $channel['channel_pubkey'],
+ 'xchan_photo_l' => z_root() . "/photo/profile/l/" . $channel['channel_id'],
+ 'xchan_photo_m' => z_root() . "/photo/profile/m/" . $channel['channel_id'],
+ 'xchan_photo_s' => z_root() . "/photo/profile/s/" . $channel['channel_id'],
+ 'xchan_addr' => channel_reddress($channel),
+ 'xchan_url' => z_root() . '/channel/' . $channel['channel_address'],
+ 'xchan_connurl' => z_root() . '/poco/' . $channel['channel_address'],
+ 'xchan_follow' => z_root() . '/follow?f=&url=%s',
+ 'xchan_name' => $channel['channel_name'],
+ 'xchan_network' => 'zot',
+ 'xchan_photo_date' => datetime_convert(),
+ 'xchan_name_date' => datetime_convert()
+ ]
+ );
}
logger('import step 6');
$_SESSION['import_step'] = 6;
diff --git a/boot.php b/boot.php
index 21862a227..69a08f0b3 100755
--- a/boot.php
+++ b/boot.php
@@ -45,13 +45,14 @@ require_once('include/channel.php');
require_once('include/connections.php');
require_once('include/account.php');
require_once('include/zid.php');
+require_once('include/xchan.php');
define ( 'PLATFORM_NAME', 'hubzilla' );
define ( 'STD_VERSION', '2.1' );
define ( 'ZOT_REVISION', '1.2' );
-define ( 'DB_UPDATE_VERSION', 1187 );
+define ( 'DB_UPDATE_VERSION', 1188 );
define ( 'PROJECT_BASE', __DIR__ );
diff --git a/include/channel.php b/include/channel.php
index d66ed7abe..d2ef89cc8 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -311,23 +311,25 @@ function create_identity($arr) {
$newuid = $ret['channel']['channel_id'];
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_system ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
- dbesc($hash),
- dbesc($guid),
- dbesc($sig),
- dbesc($key['pubkey']),
- dbesc(z_root() . "/photo/profile/l/{$newuid}"),
- dbesc(z_root() . "/photo/profile/m/{$newuid}"),
- dbesc(z_root() . "/photo/profile/s/{$newuid}"),
- dbesc(channel_reddress($ret['channel'])),
- dbesc(z_root() . '/channel/' . $ret['channel']['channel_address']),
- dbesc(z_root() . '/follow?f=&url=%s'),
- dbesc(z_root() . '/poco/' . $ret['channel']['channel_address']),
- dbesc($ret['channel']['channel_name']),
- dbesc('zot'),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- intval($system)
+ $r = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $hash,
+ 'xchan_guid' => $guid,
+ 'xchan_guid_sig' => $sig,
+ 'xchan_pubkey' => $key['pubkey'],
+ 'xchan_photo_l' => z_root() . "/photo/profile/l/{$newuid}",
+ 'xchan_photo_m' => z_root() . "/photo/profile/m/{$newuid}",
+ 'xchan_photo_s' => z_root() . "/photo/profile/s/{$newuid}",
+ 'xchan_addr' => channel_reddress($ret['channel']),
+ 'xchan_url' => z_root() . '/channel/' . $ret['channel']['channel_address'],
+ 'xchan_follow' => z_root() . '/follow?f=&url=%s',
+ 'xchan_connurl' => z_root() . '/poco/' . $ret['channel']['channel_address'],
+ 'xchan_name' => $ret['channel']['channel_name'],
+ 'xchan_network' => 'zot',
+ 'xchan_photo_date' => datetime_convert(),
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_system' => $system
+ ]
);
// Not checking return value.
diff --git a/include/hubloc.php b/include/hubloc.php
index 6f81ea31f..4da92ae72 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -176,110 +176,6 @@ function hubloc_mark_as_down($posturl) {
}
-function xchan_store($arr) {
-
- logger('xchan_store: ' . print_r($arr,true));
-
- if(! $arr['hash'])
- $arr['hash'] = $arr['guid'];
- if(! $arr['hash'])
- return false;
-
- $r = q("select * from xchan where xchan_hash = '%s' limit 1",
- dbesc($arr['hash'])
- );
- if($r)
- return true;
-
- if(! $arr['network'])
- $arr['network'] = 'unknown';
- if(! $arr['name'])
- $arr['name'] = 'unknown';
- if(! $arr['url'])
- $arr['url'] = z_root();
- if(! $arr['photo'])
- $arr['photo'] = z_root() . '/' . get_default_profile_photo();
-
-
- if($arr['network'] === 'zot') {
- if((! $arr['key']) || (! rsa_verify($arr['guid'],base64url_decode($arr['guid_sig']),$arr['key']))) {
- logger('Unable to verify signature for ' . $arr['hash']);
- return false;
- }
- }
-
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_instance_url, xchan_hidden, xchan_orphan, xchan_censored, xchan_selfcensored, xchan_system, xchan_pubforum, xchan_deleted, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s','%s',%d, %d, %d, %d, %d, %d, %d, '%s') ",
- dbesc($arr['hash']),
- dbesc($arr['guid']),
- dbesc($arr['guid_sig']),
- dbesc($arr['pubkey']),
- dbesc($arr['address']),
- dbesc($arr['url']),
- dbesc($arr['connurl']),
- dbesc($arr['follow']),
- dbesc($arr['connpage']),
- dbesc($arr['name']),
- dbesc($arr['network']),
- dbesc($arr['instance_url']),
- intval($arr['hidden']),
- intval($arr['orphan']),
- intval($arr['censored']),
- intval($arr['selfcensored']),
- intval($arr['system']),
- intval($arr['pubforum']),
- intval($arr['deleted']),
- dbesc(datetime_convert())
- );
- if(! $r)
- return $r;
-
- $photos = import_xchan_photo($arr['photo'],$arr['hash']);
- $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
- dbesc(datetime_convert()),
- dbesc($photos[0]),
- dbesc($photos[1]),
- dbesc($photos[2]),
- dbesc($photos[3]),
- dbesc($arr['hash'])
- );
- return $r;
-
-}
-
-
-function xchan_fetch($arr) {
-
- $key = '';
- if($arr['hash']) {
- $key = 'xchan_hash';
- $v = $arr['hash'];
- }
- elseif($arr['guid']) {
- $key = 'xchan_guid';
- $v = $arr['guid'];
- }
- elseif($arr['address']) {
- $key = 'xchan_addr';
- $v = $arr['address'];
- }
-
- if(! $key)
- return false;
-
- $r = q("select * from xchan where $key = '$v' limit 1");
- if(! $r)
- return false;
-
- $ret = array();
- foreach($r[0] as $k => $v) {
- if($k === 'xchan_addr')
- $ret['address'] = $v;
- else
- $ret[str_replace('xchan_','',$k)] = $v;
- }
- return $ret;
-}
-
function ping_site($url) {
diff --git a/include/items.php b/include/items.php
index 0d9fb02a4..559992b7f 100755
--- a/include/items.php
+++ b/include/items.php
@@ -833,13 +833,15 @@ function import_author_rss($x) {
}
$name = trim($x['name']);
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_url, xchan_name, xchan_network )
- values ( '%s', '%s', '%s', '%s', '%s' )",
- dbesc($x['guid']),
- dbesc($x['guid']),
- dbesc($x['url']),
- dbesc(($name) ? $name : t('(Unknown)')),
- dbesc('rss')
+ $r = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $x['guid'],
+ 'xchan_guid' => $x['guid'],
+ 'xchan_url' => $x['url'],
+ 'xchan_name' => (($name) ? $name : t('(Unknown)')),
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_network' => 'rss'
+ ]
);
if($r && $x['photo']) {
@@ -878,14 +880,17 @@ function import_author_unknown($x) {
$name = trim($x['name']);
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_url, xchan_name, xchan_network )
- values ( '%s', '%s', '%s', '%s', '%s' )",
- dbesc($x['url']),
- dbesc($x['url']),
- dbesc($x['url']),
- dbesc(($name) ? $name : t('(Unknown)')),
- dbesc('unknown')
+ $r = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $x['url'],
+ 'xchan_guid' => $x['url'],
+ 'xchan_url' => $x['url'],
+ 'xchan_name' => (($name) ? $name : t('(Unknown)')),
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_network' => 'unknown'
+ ]
);
+
if($r && $x['photo']) {
$photos = import_xchan_photo($x['photo']['src'],$x['url']);
@@ -1516,6 +1521,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
$arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
$arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
$arr['postopts'] = ((x($arr,'postopts')) ? trim($arr['postopts']) : '');
+ $arr['route'] = ((x($arr,'route')) ? trim($arr['route']) : '');
$arr['item_private'] = ((x($arr,'item_private')) ? intval($arr['item_private']) : 0 );
$arr['item_wall'] = ((x($arr,'item_wall')) ? intval($arr['item_wall']) : 0 );
$arr['item_type'] = ((x($arr,'item_type')) ? intval($arr['item_type']) : 0 );
diff --git a/include/network.php b/include/network.php
index 4391f1bfe..9049d016b 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1121,16 +1121,17 @@ function discover_by_url($url,$arr = null) {
if(! $photo)
$photo = z_root() . '/images/rss_icon.png';
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_instance_url, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
- dbesc($guid),
- dbesc($guid),
- dbesc($pubkey),
- dbesc($addr),
- dbesc($profile),
- dbesc($name),
- dbesc($network),
- dbesc(z_root()),
- dbesc(datetime_convert())
+ $r = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $guid,
+ 'xchan_guid' => $guid,
+ 'xchan_pubkey' => $pubkey,
+ 'xchan_addr' => $addr,
+ 'xchan_url' => $profile,
+ 'xchan_name' => $name,
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_network' => $network
+ ]
);
$photos = import_xchan_photo($photo,$guid);
@@ -1449,15 +1450,17 @@ function discover_by_webbie($webbie) {
);
}
else {
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
- dbesc($address),
- dbesc(($diaspora_guid) ? $diaspora_guid : $location),
- dbesc($pubkey),
- dbesc($address),
- dbesc($location),
- dbesc($fullname),
- dbesc($network),
- dbescdate(datetime_convert())
+ $r = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $address,
+ 'xchan_guid' => (($diaspora_guid) ? $diaspora_guid : $location),
+ 'xchan_pubkey' => $pubkey,
+ 'xchan_addr' => $address,
+ 'xchan_url' => $location,
+ 'xchan_name' => $fullname,
+ 'xchan_name_date' => datetime_convert(),
+ 'xchan_network' => $network
+ ]
);
}
diff --git a/include/queue_fn.php b/include/queue_fn.php
index 0950faf85..74dde5de2 100644
--- a/include/queue_fn.php
+++ b/include/queue_fn.php
@@ -2,9 +2,42 @@
function update_queue_item($id, $add_priority = 0) {
logger('queue: requeue item ' . $id,LOGGER_DEBUG);
- q("UPDATE outq SET outq_updated = '%s', outq_priority = outq_priority + %d WHERE outq_hash = '%s'",
+ $x = q("select outq_created, outq_posturl from outq where outq_hash = '%s' limit 1",
+ dbesc($id)
+ );
+ if(! $x)
+ return;
+
+ // Set all other records for this destination way into the future.
+ // The queue delivers by destination. We'll keep one queue item for
+ // this destination (this one) with a shorter delivery. If we succeed
+ // once, we'll try to deliver everything for that destination.
+ // The delivery will be set to at most once per hour, and if the
+ // queue item is less than 12 hours old, we'll schedule for fifteen
+ // minutes.
+
+ $r = q("UPDATE outq SET outq_scheduled = '%s' WHERE outq_posturl = '%s'",
+ dbesc(datetime_convert('UTC','UTC','now + 5 days')),
+ dbesc($x[0]['outq_posturl'])
+ );
+
+ $since = datetime_convert('UTC','UTC',$x[0]['outq_created']);
+
+ if($since < datetime_convert('UTC','UTC','now - 12 hour')) {
+ $next = datetime_convert('UTC','UTC','now + 1 hour');
+ }
+ else {
+ $next = datetime_convert('UTC','UTC','now + 15 minutes');
+ }
+
+ q("UPDATE outq SET outq_updated = '%s',
+ outq_priority = outq_priority + %d,
+ outq_scheduled = '%s'
+ WHERE outq_hash = '%s'",
+
dbesc(datetime_convert()),
intval($add_priority),
+ dbesc($next),
dbesc($id)
);
}
@@ -33,8 +66,12 @@ function queue_set_delivered($id,$channel = 0) {
logger('queue: set delivered ' . $id,LOGGER_DEBUG);
$sql_extra = (($channel_id) ? " and outq_channel = " . intval($channel_id) . " " : '');
- q("update outq set outq_delivered = 1, outq_updated = '%s' where outq_hash = '%s' $sql_extra ",
+ // Set the next scheduled run date so far in the future that it will be expired
+ // long before it ever makes it back into the delivery chain.
+
+ q("update outq set outq_delivered = 1, outq_updated = '%s', outq_scheduled = '%s' where outq_hash = '%s' $sql_extra ",
dbesc(datetime_convert()),
+ dbesc(datetime_convert('UTC','UTC','now + 5 days')),
dbesc($id)
);
}
@@ -44,8 +81,8 @@ function queue_set_delivered($id,$channel = 0) {
function queue_insert($arr) {
$x = q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_priority,
- outq_created, outq_updated, outq_notify, outq_msg )
- values ( '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' )",
+ outq_created, outq_updated, outq_scheduled, outq_notify, outq_msg )
+ values ( '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s' )",
dbesc($arr['hash']),
intval($arr['account_id']),
intval($arr['channel_id']),
@@ -55,6 +92,7 @@ function queue_insert($arr) {
intval(($arr['priority']) ? $arr['priority'] : 0),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
dbesc($arr['notify']),
dbesc(($arr['msg']) ? $arr['msg'] : '')
);
diff --git a/include/security.php b/include/security.php
index 2f5de54c7..57b33251f 100644
--- a/include/security.php
+++ b/include/security.php
@@ -171,19 +171,16 @@ function atoken_create_xchan($xchan) {
if($r)
return;
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_photo_mimetype, xchan_photo_l, xchan_photo_m, xchan_photo_s )
- values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ",
- dbesc($xchan['xchan_hash']),
- dbesc($xchan['xchan_hash']),
- dbesc($xchan['xchan_addr']),
- dbesc($xchan['xchan_url']),
- dbesc($xchan['xchan_name']),
- dbesc($xchan['xchan_network']),
- dbesc($xchan['xchan_photo_mimetype']),
- dbesc($xchan['xchan_photo_l']),
- dbesc($xchan['xchan_photo_m']),
- dbesc($xchan['xchan_photo_s'])
- );
+ $xchan['xchan_guid'] = $xchan['xchan_hash'];
+
+ $store = [];
+ foreach($xchan as $k => $v) {
+ if(strpos($k,'xchan_') === 0) {
+ $store[$k] = $v;
+ }
+ }
+
+ $r = xchan_store_lowlevel($store);
return true;
}
diff --git a/include/xchan.php b/include/xchan.php
new file mode 100644
index 000000000..12eb674fa
--- /dev/null
+++ b/include/xchan.php
@@ -0,0 +1,139 @@
+<?php
+
+
+function xchan_store_lowlevel($arr) {
+
+ $store = [
+ 'xchan_hash' => ((array_key_exists('xchan_hash',$arr)) ? $arr['xchan_hash'] : ''),
+ 'xchan_guid' => ((array_key_exists('xchan_guid',$arr)) ? $arr['xchan_guid'] : ''),
+ 'xchan_guid_sig' => ((array_key_exists('xchan_guid_sig',$arr)) ? $arr['xchan_guid_sig'] : ''),
+ 'xchan_pubkey' => ((array_key_exists('xchan_pubkey',$arr)) ? $arr['xchan_pubkey'] : ''),
+ 'xchan_photo_mimetype' => ((array_key_exists('xchan_photo_mimetype',$arr)) ? $arr['xchan_photo_mimetype'] : ''),
+ 'xchan_photo_l' => ((array_key_exists('xchan_photo_l',$arr)) ? $arr['xchan_photo_l'] : ''),
+ 'xchan_photo_m' => ((array_key_exists('xchan_photo_m',$arr)) ? $arr['xchan_photo_m'] : ''),
+ 'xchan_photo_s' => ((array_key_exists('xchan_photo_s',$arr)) ? $arr['xchan_photo_s'] : ''),
+ 'xchan_addr' => ((array_key_exists('xchan_addr',$arr)) ? $arr['xchan_addr'] : ''),
+ 'xchan_url' => ((array_key_exists('xchan_url',$arr)) ? $arr['xchan_url'] : ''),
+ 'xchan_connurl' => ((array_key_exists('xchan_connurl',$arr)) ? $arr['xchan_connurl'] : ''),
+ 'xchan_follow' => ((array_key_exists('xchan_follow',$arr)) ? $arr['xchan_follow'] : ''),
+ 'xchan_connpage' => ((array_key_exists('xchan_connpage',$arr)) ? $arr['xchan_connpage'] : ''),
+ 'xchan_name' => ((array_key_exists('xchan_name',$arr)) ? $arr['xchan_name'] : ''),
+ 'xchan_network' => ((array_key_exists('xchan_network',$arr)) ? $arr['xchan_network'] : ''),
+ 'xchan_instance_url' => ((array_key_exists('xchan_instance_url',$arr)) ? $arr['xchan_instance_url'] : ''),
+ 'xchan_flags' => ((array_key_exists('xchan_flags',$arr)) ? intval($arr['xchan_flags']) : 0),
+ 'xchan_photo_date' => ((array_key_exists('xchan_photo_date',$arr)) ? datetime_convert('UTC','UTC',$arr['xchan_photo_date']) : NULL_DATE),
+ 'xchan_name_date' => ((array_key_exists('xchan_name_date',$arr)) ? datetime_convert('UTC','UTC',$arr['xchan_name_date']) : NULL_DATE),
+ 'xchan_hidden' => ((array_key_exists('xchan_hidden',$arr)) ? intval($arr['xchan_hidden']) : 0),
+ 'xchan_orphan' => ((array_key_exists('xchan_orphan',$arr)) ? intval($arr['xchan_orphan']) : 0),
+ 'xchan_censored' => ((array_key_exists('xchan_censored',$arr)) ? intval($arr['xchan_censored']) : 0),
+ 'xchan_selfcensored' => ((array_key_exists('xchan_selfcensored',$arr)) ? intval($arr['xchan_selfcensored']) : 0),
+ 'xchan_system' => ((array_key_exists('xchan_system',$arr)) ? intval($arr['xchan_system']) : 0),
+ 'xchan_pubforum' => ((array_key_exists('xchan_pubforum',$arr)) ? intval($arr['xchan_pubforum']) : 0),
+ 'xchan_deleted' => ((array_key_exists('xchan_deleted',$arr)) ? intval($arr['xchan_deleted']) : 0)
+ ];
+
+ return create_table_from_array('xchan',$store);
+}
+
+
+
+function xchan_store($arr) {
+
+ logger('xchan_store: ' . print_r($arr,true));
+
+ if(! $arr['hash'])
+ $arr['hash'] = $arr['guid'];
+ if(! $arr['hash'])
+ return false;
+
+ $r = q("select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($arr['hash'])
+ );
+ if($r)
+ return true;
+
+ if(! $arr['network'])
+ $arr['network'] = 'unknown';
+ if(! $arr['name'])
+ $arr['name'] = 'unknown';
+ if(! $arr['url'])
+ $arr['url'] = z_root();
+ if(! $arr['photo'])
+ $arr['photo'] = z_root() . '/' . get_default_profile_photo();
+
+
+ if($arr['network'] === 'zot') {
+ if((! $arr['key']) || (! rsa_verify($arr['guid'],base64url_decode($arr['guid_sig']),$arr['key']))) {
+ logger('Unable to verify signature for ' . $arr['hash']);
+ return false;
+ }
+ }
+
+ $x = [];
+ foreach($arr as $k => $v) {
+ if($k === 'key') {
+ $x['xchan_pubkey'] = $v;
+ continue;
+ }
+ if($k === 'photo') {
+ continue;
+ }
+
+ $x['xchan_' . $k] = $v;
+ }
+
+ $x['xchan_name_date'] = datetime_convert();
+
+ $r = xchan_store_lowlevel($x);
+
+ if(! $r)
+ return $r;
+
+ $photos = import_xchan_photo($arr['photo'],$arr['hash']);
+ $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
+ dbesc(datetime_convert()),
+ dbesc($photos[0]),
+ dbesc($photos[1]),
+ dbesc($photos[2]),
+ dbesc($photos[3]),
+ dbesc($arr['hash'])
+ );
+ return $r;
+
+}
+
+
+function xchan_fetch($arr) {
+
+ $key = '';
+ if($arr['hash']) {
+ $key = 'xchan_hash';
+ $v = $arr['hash'];
+ }
+ elseif($arr['guid']) {
+ $key = 'xchan_guid';
+ $v = $arr['guid'];
+ }
+ elseif($arr['address']) {
+ $key = 'xchan_addr';
+ $v = $arr['address'];
+ }
+
+ if(! $key)
+ return false;
+
+ $r = q("select * from xchan where $key = '$v' limit 1");
+ if(! $r)
+ return false;
+
+ $ret = array();
+ foreach($r[0] as $k => $v) {
+ if($k === 'xchan_addr')
+ $ret['address'] = $v;
+ else
+ $ret[str_replace('xchan_','',$k)] = $v;
+ }
+ return $ret;
+}
+
+
diff --git a/include/zot.php b/include/zot.php
index 24b50cc12..1538e956e 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -759,28 +759,28 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) {
&& ($arr['site']['url'] != z_root()))
$arr['searchable'] = false;
- $x = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_mimetype,
- xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_hidden, xchan_selfcensored, xchan_deleted, xchan_pubforum )
- values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d) ",
- dbesc($xchan_hash),
- dbesc($arr['guid']),
- dbesc($arr['guid_sig']),
- dbesc($arr['key']),
- dbesc($arr['photo_mimetype']),
- dbesc($arr['photo']),
- dbesc($arr['address']),
- dbesc($arr['url']),
- dbesc($arr['connections_url']),
- dbesc($arr['follow_url']),
- dbesc($arr['connect_url']),
- dbesc(($arr['name']) ? $arr['name'] : '-'),
- dbesc('zot'),
- dbescdate($arr['photo_updated']),
- dbescdate($arr['name_updated']),
- intval(1 - intval($arr['searchable'])),
- intval($arr['adult_content']),
- intval($arr['deleted']),
- intval($arr['public_forum'])
+ $x = xchan_store_lowlevel(
+ [
+ 'xchan_hash' => $xchan_hash,
+ 'xchan_guid' => $arr['guid'],
+ 'xchan_guid_sig' => $arr['guid_sig'],
+ 'xchan_pubkey' => $arr['key'],
+ 'xchan_photo_mimetype' => $arr['photo_mimetype'],
+ 'xchan_photo_l' => $arr['photo'],
+ 'xchan_addr' => $arr['address'],
+ 'xchan_url' => $arr['url'],
+ 'xchan_connurl' => $arr['connections_url'],
+ 'xchan_follow' => $arr['follow_url'],
+ 'xchan_connpage' => $arr['connect_url'],
+ 'xchan_name' => (($arr['name']) ? $arr['name'] : '-'),
+ 'xchan_network' => 'zot',
+ 'xchan_photo_date' => $arr['photo_updated'],
+ 'xchan_name_date' => $arr['name_updated'],
+ 'xchan_hidden' => intval(1 - intval($arr['searchable'])),
+ 'xchan_selfcensored' => $arr['adult_content'],
+ 'xchan_deleted' => $arr['deleted'],
+ 'xchan_pubforum' => $arr['public_forum']
+ ]
);
$what .= 'new_xchan';
diff --git a/install/schema_mysql.sql b/install/schema_mysql.sql
index bd7d9d79c..be5317722 100644
--- a/install/schema_mysql.sql
+++ b/install/schema_mysql.sql
@@ -898,6 +898,7 @@ CREATE TABLE IF NOT EXISTS `outq` (
`outq_delivered` tinyint(1) NOT NULL DEFAULT '0',
`outq_created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`outq_updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
+ `outq_scheduled` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`outq_notify` mediumtext NOT NULL,
`outq_msg` mediumtext NOT NULL,
`outq_priority` smallint(6) NOT NULL DEFAULT '0',
@@ -907,6 +908,7 @@ CREATE TABLE IF NOT EXISTS `outq` (
KEY `outq_hub` (`outq_posturl`),
KEY `outq_created` (`outq_created`),
KEY `outq_updated` (`outq_updated`),
+ KEY `outq_scheduled` (`outq_scheduled`),
KEY `outq_async` (`outq_async`),
KEY `outq_delivered` (`outq_delivered`),
KEY `outq_priority` (`outq_priority`)
diff --git a/install/schema_postgres.sql b/install/schema_postgres.sql
index f8e4ecf5f..e78425828 100644
--- a/install/schema_postgres.sql
+++ b/install/schema_postgres.sql
@@ -884,6 +884,7 @@ CREATE TABLE "outq" (
"outq_delivered" numeric(1) NOT NULL DEFAULT '0',
"outq_created" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"outq_updated" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
+ "outq_scheduled" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"outq_notify" text NOT NULL,
"outq_msg" text NOT NULL,
"outq_priority" smallint NOT NULL DEFAULT '0',
@@ -894,6 +895,7 @@ create index "outq_channel" on outq ("outq_channel");
create index "outq_hub" on outq ("outq_posturl");
create index "outq_created" on outq ("outq_created");
create index "outq_updated" on outq ("outq_updated");
+create index "outq_scheduled" on outq ("outq_scheduled");
create index "outq_async" on outq ("outq_async");
create index "outq_delivered" on outq ("outq_delivered");
create index "outq_priority" on outq ("outq_priority");
diff --git a/install/update.php b/install/update.php
index 34f23b049..87cf4ba60 100644
--- a/install/update.php
+++ b/install/update.php
@@ -1,6 +1,6 @@
<?php
-define( 'UPDATE_VERSION' , 1187 );
+define( 'UPDATE_VERSION' , 1188 );
/**
*
@@ -2484,11 +2484,28 @@ function update_r1185() {
function update_r1186() {
- $r1 = q("alter table profile add profile_vcard text not null default '' ");
+ $r1 = q("alter table profile add profile_vcard text not null");
if($r1)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
+}
+
+function update_r1187() {
+
+ if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
+ $r1 = q("alter table outq add outq_scheduled timestamp not null default '0001-01-01 00:00:00' ");
+ }
+ else {
+ $r1 = q("alter table outq add outq_scheduled datetime not null default '0001-01-01 00:00:00' ");
+ }
+ $r2 = q("create index outq_scheduled_idx on outq (outq_scheduled)");
+
+ if($r1 && $r2)
+ return UPDATE_SUCCESS;
+ return UPDATE_FAILED;
+
+
} \ No newline at end of file