diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/expire.php | 44 | ||||
-rw-r--r-- | include/items.php | 46 | ||||
-rw-r--r-- | include/notifier.php | 34 | ||||
-rw-r--r-- | include/poller.php | 11 |
4 files changed, 124 insertions, 11 deletions
diff --git a/include/expire.php b/include/expire.php new file mode 100644 index 000000000..3c30e01c1 --- /dev/null +++ b/include/expire.php @@ -0,0 +1,44 @@ +<?php + +require_once("boot.php"); + +function expire_run($argv, $argc){ + global $a, $db; + + if(is_null($a)) { + $a = new App; + } + + if(is_null($db)) { + @include(".htconfig.php"); + require_once("dba.php"); + $db = new dba($db_host, $db_user, $db_pass, $db_data); + unset($db_host, $db_user, $db_pass, $db_data); + }; + + require_once('session.php'); + require_once('datetime.php'); + require_once('simplepie/simplepie.inc'); + require_once('include/items.php'); + require_once('include/Contact.php'); + + $a->set_baseurl(get_config('system','url')); + + + logger('expire: start'); + + $r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0"); + if(count($r)) { + foreach($r as $rr) { + logger('Expire: ' . $rr['username'] . ' interval: ' . $rr['expire'], LOGGER_DEBUG); + item_expire($rr['uid'],$rr['expire']); + } + } + + return; +} + +if (array_search(__file__,get_included_files())===0){ + expire_run($argv,$argc); + killme(); +} diff --git a/include/items.php b/include/items.php index 2294fe294..051659321 100644 --- a/include/items.php +++ b/include/items.php @@ -1507,3 +1507,49 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { return $o; } +function item_expire($uid,$days) { + + if((! $uid) || (! $days)) + return; + + $r = q("SELECT * FROM `item` + WHERE `uid` = %d + AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY + AND `id` = `parent` + AND `deleted` = 0", + intval($uid), + intval($days) + ); + + if(! count($r)) + return; + + logger('expire: # items=' . count($r) ); + + foreach($r as $item) { + + // Only expire posts, not photos and photo comments + + if(strlen($item['resource-id'])) + continue; + + $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1", + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($item['id']) + ); + + // kill the kids + + $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($item['parent-uri']), + intval($item['uid']) + ); + + } + + proc_run('php',"include/notifier.php","expire","$uid"); + +}
\ No newline at end of file diff --git a/include/notifier.php b/include/notifier.php index 648a07062..ca2304845 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -40,6 +40,7 @@ function notifier_run($argv, $argc){ break; } + $expire = false; $top_level = false; $recipients = array(); $url_recipients = array(); @@ -57,6 +58,17 @@ function notifier_run($argv, $argc){ $item = $message[0]; } + elseif($cmd === 'expire') { + $expire = true; + $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 + AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP - INTERVAL 10 MINUTE", + intval($item_id) + ); + $uid = $item_id; + $item_id = 0; + if(! count($items)) + return; + } else { // find ancestors @@ -76,11 +88,10 @@ function notifier_run($argv, $argc){ intval($parent_id) ); - if(! count($items)){ + if(! count($items)) { return; } - // avoid race condition with deleting entries if($items[0]['deleted']) { @@ -98,11 +109,11 @@ function notifier_run($argv, $argc){ intval($uid) ); - if(count($r)) - $owner = $r[0]; - else { + if(! count($r)) return; - } + + $owner = $r[0]; + $hub = get_config('system','huburl'); // If this is a public conversation, notify the feed hub @@ -117,7 +128,7 @@ function notifier_run($argv, $argc){ $parent = $items[0]; - if($parent['type'] === 'remote') { + if($parent['type'] === 'remote' && (! $expire)) { // local followup to remote post $followup = true; $notify_hub = false; // not public @@ -235,6 +246,7 @@ function notifier_run($argv, $argc){ } else { foreach($items as $item) { + if(! $item['parent']) continue; @@ -242,9 +254,9 @@ function notifier_run($argv, $argc){ if(! $contact) continue; - $atom .= atom_entry($item,'text',$contact,$owner,true); + $atom .= atom_entry($item,'text',$contact,$owner,true); - if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link'])) + if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link']) && (! $expire)) $slaps[] = atom_entry($item,'html',$contact,$owner,true); } } @@ -319,7 +331,7 @@ function notifier_run($argv, $argc){ // only send salmon if public - e.g. if it's ok to notify // a public hub, it's ok to send a salmon - if(count($slaps) && $notify_hub) { + if((count($slaps)) && ($notify_hub) && (! $expire)) { logger('notifier: slapdelivery: ' . $contact['name']); foreach($slaps as $slappy) { if($contact['notify']) { @@ -350,7 +362,7 @@ function notifier_run($argv, $argc){ // send additional slaps to mentioned remote tags (@foo@example.com) - if($slap && count($url_recipients) && $followup && $notify_hub) { + if($slap && count($url_recipients) && $followup && $notify_hub && (! $expire)) { foreach($url_recipients as $url) { if($url) { logger('notifier: urldelivery: ' . $url); diff --git a/include/poller.php b/include/poller.php index a093190a6..8619697d9 100644 --- a/include/poller.php +++ b/include/poller.php @@ -29,6 +29,17 @@ function poller_run($argv, $argc){ proc_run('php',"include/queue.php"); + // once daily run expire in background + + $d1 = get_config('system','last_expire_day'); + $d2 = intval(datetime_convert('UTC','UTC','now','d')); + + if($d2 != intval($d1)) { + set_config('system','last_expire_day',$d2); + proc_run('php','include/expire.php'); + } + + // clear old cache q("DELETE FROM `cache` WHERE `updated` < '%s'", dbesc(datetime_convert('UTC','UTC',"now - 30 days"))); |