2013-02-26 01:09:40 +00:00
|
|
|
<?php /** @file */
|
|
|
|
|
2012-10-23 08:35:06 +00:00
|
|
|
require_once('boot.php');
|
2012-12-19 03:10:56 +00:00
|
|
|
require_once('include/zot.php');
|
2012-10-23 08:35:06 +00:00
|
|
|
require_once('include/cli_startup.php');
|
2012-12-20 03:51:52 +00:00
|
|
|
require_once('include/dir_fns.php');
|
2011-01-28 13:04:18 +00:00
|
|
|
|
2012-12-19 03:10:56 +00:00
|
|
|
|
2011-01-28 13:04:18 +00:00
|
|
|
function directory_run($argv, $argc){
|
2011-06-30 08:15:18 +00:00
|
|
|
|
2012-10-23 08:35:06 +00:00
|
|
|
cli_startup();
|
2010-08-19 11:59:31 +00:00
|
|
|
|
2014-02-11 04:38:26 +00:00
|
|
|
if($argc < 2)
|
2011-01-24 21:01:56 +00:00
|
|
|
return;
|
2010-08-19 11:59:31 +00:00
|
|
|
|
2014-02-11 22:19:20 +00:00
|
|
|
$force = false;
|
|
|
|
if(($argc > 2) && ($argv[2] === 'force'))
|
|
|
|
$force = true;
|
|
|
|
|
2013-02-20 07:21:23 +00:00
|
|
|
logger('directory update', LOGGER_DEBUG);
|
|
|
|
|
2012-12-19 03:10:56 +00:00
|
|
|
$dirmode = get_config('system','directory_mode');
|
|
|
|
if($dirmode === false)
|
|
|
|
$dirmode = DIRECTORY_MODE_NORMAL;
|
2010-08-19 11:59:31 +00:00
|
|
|
|
2012-12-19 03:10:56 +00:00
|
|
|
$x = q("select * from channel where channel_id = %d limit 1",
|
|
|
|
intval($argv[1])
|
|
|
|
);
|
|
|
|
if(! $x)
|
|
|
|
return;
|
2012-05-21 23:40:11 +00:00
|
|
|
|
2012-12-19 03:10:56 +00:00
|
|
|
$channel = $x[0];
|
2012-05-21 23:40:11 +00:00
|
|
|
|
2013-06-18 09:51:43 +00:00
|
|
|
|
|
|
|
if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) {
|
2014-02-11 22:19:20 +00:00
|
|
|
|
|
|
|
local_dir_update($argv[1],$force);
|
2013-06-18 09:51:43 +00:00
|
|
|
|
2013-10-28 07:11:44 +00:00
|
|
|
q("update channel set channel_dirdate = '%s' where channel_id = %d limit 1",
|
|
|
|
dbesc(datetime_convert()),
|
|
|
|
intval($channel['channel_id'])
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2013-06-18 09:51:43 +00:00
|
|
|
// Now update all the connections
|
|
|
|
proc_run('php','include/notifier.php','refresh_all',$channel['channel_id']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-19 03:10:56 +00:00
|
|
|
$directory = find_upstream_directory($dirmode);
|
|
|
|
|
|
|
|
if($directory) {
|
2013-08-06 03:08:35 +00:00
|
|
|
$url = $directory['url'] . '/post';
|
2012-12-19 03:10:56 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$url = DIRECTORY_FALLBACK_MASTER . '/post';
|
|
|
|
}
|
|
|
|
|
2013-06-14 23:54:58 +00:00
|
|
|
// ensure the upstream directory is updated
|
|
|
|
|
2014-02-11 22:19:20 +00:00
|
|
|
$packet = zot_build_packet($channel,(($force) ? 'force_refresh' : 'refresh'));
|
2012-12-19 03:10:56 +00:00
|
|
|
$z = zot_zot($url,$packet);
|
2013-10-25 02:38:50 +00:00
|
|
|
|
2012-12-19 03:10:56 +00:00
|
|
|
// re-queue if unsuccessful
|
2010-08-19 11:59:31 +00:00
|
|
|
|
2013-10-25 02:38:50 +00:00
|
|
|
if(! $z['success']) {
|
2013-10-28 07:11:44 +00:00
|
|
|
|
|
|
|
// FIXME - we aren't updating channel_dirdate if we have to queue
|
|
|
|
// the directory packet. That means we'll try again on the next poll run.
|
|
|
|
|
2013-10-25 02:38:50 +00:00
|
|
|
$hash = random_string();
|
|
|
|
q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg )
|
|
|
|
values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
|
|
|
|
dbesc($hash),
|
|
|
|
intval($channel['channel_account_id']),
|
|
|
|
intval($channel['channel_id']),
|
|
|
|
dbesc($url),
|
|
|
|
intval(1),
|
|
|
|
dbesc(datetime_convert()),
|
|
|
|
dbesc(datetime_convert()),
|
|
|
|
dbesc($packet),
|
|
|
|
dbesc('')
|
|
|
|
);
|
|
|
|
}
|
2013-10-28 07:11:44 +00:00
|
|
|
else {
|
|
|
|
q("update channel set channel_dirdate = '%s' where channel_id = %d limit 1",
|
|
|
|
dbesc(datetime_convert()),
|
|
|
|
intval($channel['channel_id'])
|
|
|
|
);
|
|
|
|
}
|
2013-10-25 02:38:50 +00:00
|
|
|
|
2013-06-14 23:54:58 +00:00
|
|
|
// Now update all the connections
|
|
|
|
|
2013-06-18 09:51:43 +00:00
|
|
|
proc_run('php','include/notifier.php','refresh_all',$channel['channel_id']);
|
2013-06-14 23:54:58 +00:00
|
|
|
|
2011-01-28 13:04:18 +00:00
|
|
|
}
|
2010-08-19 11:59:31 +00:00
|
|
|
|
2011-01-28 13:04:18 +00:00
|
|
|
if (array_search(__file__,get_included_files())===0){
|
|
|
|
directory_run($argv,$argc);
|
|
|
|
killme();
|
|
|
|
}
|