streams/include/onepoll.php

116 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2012-12-31 00:14:29 +00:00
require_once('boot.php');
require_once('include/cli_startup.php');
2012-12-31 00:14:29 +00:00
function onepoll_run($argv, $argc){
2012-12-31 00:14:29 +00:00
cli_startup();
$a = get_app();
logger('onepoll: start');
$manual_id = 0;
$generation = 0;
2012-08-31 01:47:07 +00:00
$force = false;
$restart = false;
if(($argc > 1) && (intval($argv[1])))
$contact_id = intval($argv[1]);
if(! $contact_id) {
logger('onepoll: no contact');
return;
}
$d = datetime_convert();
2012-12-31 06:41:53 +00:00
$contacts = q("SELECT abook.*, xchan.*, account.*
FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_hash
where abook_id = %d
2012-12-31 00:14:29 +00:00
AND not ( abook_flags & %d ) AND not ( abook_flags & %d )
AND not ( abook_flags & %d ) AND not ( abook_flags & %d )
AND not ( abook_flags & %d ) AND ( account_flags & %d ) $abandon_sql ORDER BY RAND()",
intval($contact_id),
intval(ABOOK_FLAG_BLOCKED),
intval(ABOOK_FLAG_IGNORED),
intval(ABOOK_FLAG_PENDING),
intval(ABOOK_FLAG_ARCHIVED),
intval(ABOOK_FLAG_SELF),
intval(ACCOUNT_OK)
);
2012-12-31 00:14:29 +00:00
if(! $contacts) {
return;
}
2012-12-31 00:14:29 +00:00
if(! $contacts)
return;
$contact = $contacts[0];
2012-12-31 00:14:29 +00:00
$t = $contact['abook_updated'];
2012-12-31 06:41:53 +00:00
$importer_uid = $contact['abook_channel'];
2012-12-31 06:41:53 +00:00
$r = q("SELECT * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
intval($importer_uid)
);
2012-12-31 06:41:53 +00:00
if(! $r)
return;
$importer = $r[0];
2012-12-31 06:41:53 +00:00
logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}");
2012-08-31 01:47:07 +00:00
$last_update = (($contact['last_update'] === '0000-00-00 00:00:00')
2012-12-31 06:41:53 +00:00
? datetime_convert('UTC','UTC','now - 7 days')
: datetime_convert('UTC','UTC',$contact['abook_updated'])
);
2012-12-31 06:41:53 +00:00
// update permissions
2012-06-14 23:56:46 +00:00
2012-12-31 06:41:53 +00:00
$x = zot_refresh($contact,$importer);
2012-12-31 06:41:53 +00:00
if(! $x) {
// mark for death
}
2012-12-31 06:41:53 +00:00
else {
2012-12-31 06:41:53 +00:00
// if marked for death, reset
2012-08-31 01:47:07 +00:00
}
2012-12-31 06:41:53 +00:00
// fetch some items
// set last updated timestamp
2012-12-31 06:41:53 +00:00
/*
if($contact['poco']) {
$r = q("SELECT count(*) as total from glink
where `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
intval($contact['id'])
);
}
if(count($r)) {
if(! $r[0]['total']) {
2012-05-01 08:16:47 +00:00
poco_load($contact['id'],$importer_uid,0,$contact['poco']);
}
}
2012-12-31 06:41:53 +00:00
*/
return;
}
if (array_search(__file__,get_included_files())===0){
onepoll_run($argv,$argc);
killme();
}