prune_hub_reinstalls() and add cron weekly as a side effect

This commit is contained in:
friendica 2014-03-19 19:53:14 -07:00
parent afca10a071
commit 68fc2a220e
3 changed files with 50 additions and 1 deletions

32
include/hubloc.php Normal file
View File

@ -0,0 +1,32 @@
<?php /** @file */
function prune_hub_reinstalls() {
$r = q("select site_url from site where true");
if($r) {
foreach($r as $rr) {
$x = q("select count(*) as t, hubloc_sitekey, max(hubloc_connected) as c from hubloc where hubloc_url = '%s' group by hubloc_sitekey order by c",
dbesc($rr['site_url'])
);
// see if this url has more than one sitekey, indicating it has been re-installed.
if(count($x) > 1) {
$d1 = datetime_convert('UTC','UTC',$x[0]['c']);
$d2 = datetime_convert('UTC','UTC','now - 3 days');
// allow some slop period, say 3 days - just in case this is a glitch or transient occurrence
if($d1 < $d2) {
logger('prune_hub_reinstalls: removing dead hublocs at ' . $rr['site_url']);
$y = q("delete from hubloc where hubloc_sitekey = '%s'",
dbesc($x[0]['hubloc_sitekey'])
);
}
}
}
}
}

View File

@ -105,6 +105,23 @@ function poller_run($argv, $argc){
if($d2 != intval($d1)) {
$d3 = intval(datetime_convert('UTC','UTC','now','N'));
if($d3 == 7) {
/**
* Cron Weekly
*
* Actions in the following block are executed once per day only on Sunday (once per week).
*
*/
require_once('include/hubloc.php');
prune_hub_reinstalls();
}
// expire any read notifications over a month old
q("delete from notify where seen = 1 and date < UTC_TIMESTAMP() - INTERVAL 30 DAY");

View File

@ -1 +1 @@
2014-03-18.620
2014-03-19.621