aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-11-20 21:09:13 -0800
committerfriendica <info@friendica.com>2013-11-20 21:09:13 -0800
commit4791b2fd9c6dabc9ebb1f42a4993185d85493261 (patch)
tree4a63752ec22345dabc3e8d07c483046c91547a98
parenteb3d8e2cd7e2bd51035918b4106d1c29b6605505 (diff)
downloadvolse-hubzilla-4791b2fd9c6dabc9ebb1f42a4993185d85493261.tar.gz
volse-hubzilla-4791b2fd9c6dabc9ebb1f42a4993185d85493261.tar.bz2
volse-hubzilla-4791b2fd9c6dabc9ebb1f42a4993185d85493261.zip
add aid to notifiy table which we may need to supress duplicate notify emails across your channels
also try to handle the wretched mess of broken and duplicated hublocs that fred.cepheus.uberspace.de typically reports
-rwxr-xr-xboot.php2
-rw-r--r--include/enotify.php8
-rw-r--r--include/notifier.php12
-rw-r--r--include/zot.php16
-rw-r--r--install/database.sql4
-rw-r--r--install/update.php11
6 files changed, 40 insertions, 13 deletions
diff --git a/boot.php b/boot.php
index c84604dc1..3fabff55a 100755
--- a/boot.php
+++ b/boot.php
@@ -45,7 +45,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' );
define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 );
-define ( 'DB_UPDATE_VERSION', 1083 );
+define ( 'DB_UPDATE_VERSION', 1084 );
define ( 'EOL', '<br />' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
diff --git a/include/enotify.php b/include/enotify.php
index 67fe748d1..91b37a913 100644
--- a/include/enotify.php
+++ b/include/enotify.php
@@ -322,6 +322,7 @@ function notification($params) {
$datarray['url'] = $sender['xchan_url'];
$datarray['photo'] = $sender['xchan_photo_s'];
$datarray['date'] = datetime_convert();
+ $datarray['aid'] = $recip['channel_account_id'];
$datarray['uid'] = $recip['channel_id'];
$datarray['link'] = $itemlink;
$datarray['parent'] = $parent_id;
@@ -340,13 +341,14 @@ function notification($params) {
// create notification entry in DB
- $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype)
- values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')",
+ $r = q("insert into notify (hash,name,url,photo,date,aid,uid,link,parent,type,verb,otype)
+ values('%s','%s','%s','%s','%s',%d,%d,'%s',%d,%d,'%s','%s')",
dbesc($datarray['hash']),
dbesc($datarray['name']),
dbesc($datarray['url']),
dbesc($datarray['photo']),
dbesc($datarray['date']),
+ intval($datarray['aid']),
intval($datarray['uid']),
dbesc($datarray['link']),
intval($datarray['parent']),
@@ -559,7 +561,7 @@ class enotify {
// send the message
$res = mail(
- $params['toEmail'], // send to address
+ $params['toEmail'], // send to address
$messageSubject, // subject
$multipartMessageBody, // message body
$messageHeader // message headers
diff --git a/include/notifier.php b/include/notifier.php
index 1407be4b3..2ca3531d6 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -408,9 +408,9 @@ function notifier_run($argv, $argc){
// for public posts always include our own hub
- $sql_extra = (($private) ? "" : " or hubloc_url = '" . z_root() . "' ");
+ $sql_extra = (($private) ? "" : " or hubloc_url = '" . dbesc(z_root()) . "' ");
- $r = q("select distinct hubloc_sitekey, hubloc_flags, hubloc_callback, hubloc_host from hubloc
+ $r = q("select hubloc_sitekey, hubloc_flags, hubloc_callback, hubloc_host from hubloc
where hubloc_hash in (" . implode(',',$recipients) . ") $sql_extra group by hubloc_sitekey");
if(! $r) {
logger('notifier: no hubs');
@@ -419,10 +419,14 @@ function notifier_run($argv, $argc){
$hubs = $r;
$hublist = array();
+ $keys = array();
+
foreach($hubs as $hub) {
- // don't try to deliver to deleted hublocs
- if(! ($hub['hubloc_flags'] & HUBLOC_FLAGS_DELETED)) {
+ // don't try to deliver to deleted hublocs - and inexplicably SQL "distinct" and "group by"
+ // both return records with duplicate keys in rare circumstances
+ if((! ($hub['hubloc_flags'] & HUBLOC_FLAGS_DELETED)) && (! in_array($hub['hubloc_sitekey'],$keys))) {
$hublist[] = $hub['hubloc_host'];
+ $keys[] = $hub['hubloc_sitekey'];
}
}
diff --git a/include/zot.php b/include/zot.php
index a4a27ce9c..9906b7ec8 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -584,7 +584,7 @@ function import_xchan($arr,$ud_flags = 1) {
if($arr['locations']) {
- $xisting = q("select hubloc_id, hubloc_url from hubloc where hubloc_hash = '%s'",
+ $xisting = q("select hubloc_id, hubloc_url, hubloc_sitekey from hubloc where hubloc_hash = '%s'",
dbesc($xchan_hash)
);
@@ -596,14 +596,14 @@ function import_xchan($arr,$ud_flags = 1) {
}
for($x = 0; $x < count($xisting); $x ++) {
- if($xisting[$x]['hubloc_url'] == $location['url']) {
+ if(($xisting[$x]['hubloc_url'] === $location['url']) && ($xisting[$x]['hubloc_sitekey'] === $location['sitekey'])) {
$xisting[$x]['updated'] = true;
}
}
// match as many fields as possible in case anything at all changed.
- $r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' limit 1",
+ $r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",
dbesc($xchan_hash),
dbesc($arr['guid']),
dbesc($arr['guid_sig']),
@@ -624,6 +624,16 @@ function import_xchan($arr,$ud_flags = 1) {
intval($r[0]['hubloc_id'])
);
}
+
+ // Remove pure duplicates
+ if($count($r) > 1) {
+ for($h = 1; $h < count($r); $h ++) {
+ q("delete from hubloc where hubloc_id = %d limit 1",
+ intval($r[$h]['hubloc_id'])
+ );
+ }
+ }
+
if((($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && (! $location['primary']))
|| ((! ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY)) && ($location['primary']))) {
$r = q("update hubloc set hubloc_flags = (hubloc_flags ^ %d), hubloc_updated = '%s' where hubloc_id = %d limit 1",
diff --git a/install/database.sql b/install/database.sql
index 5496072a9..ef79862c3 100644
--- a/install/database.sql
+++ b/install/database.sql
@@ -563,6 +563,7 @@ CREATE TABLE IF NOT EXISTS `notify` (
`photo` char(255) NOT NULL,
`date` datetime NOT NULL,
`msg` mediumtext NOT NULL,
+ `aid` int(11) NOT NULL,
`uid` int(11) NOT NULL,
`link` char(255) NOT NULL,
`parent` int(11) NOT NULL,
@@ -578,7 +579,8 @@ CREATE TABLE IF NOT EXISTS `notify` (
KEY `hash` (`hash`),
KEY `parent` (`parent`),
KEY `link` (`link`),
- KEY `otype` (`otype`)
+ KEY `otype` (`otype`),
+ KEY `aid` (`aid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `obj` (
diff --git a/install/update.php b/install/update.php
index 31eac2963..f498ec042 100644
--- a/install/update.php
+++ b/install/update.php
@@ -1,6 +1,6 @@
<?php
-define( 'UPDATE_VERSION' , 1083 );
+define( 'UPDATE_VERSION' , 1084 );
/**
*
@@ -910,3 +910,12 @@ function update_r1082() {
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
+
+function update_r1083() {
+ $r = q("ALTER TABLE `notify` ADD `aid` INT NOT NULL AFTER `msg` ,
+ADD INDEX ( `aid` )");
+ if($r)
+ return UPDATE_SUCCESS;
+ return UPDATE_FAILED;
+}
+