provide a way to sync locations and get rid of bogus hublocs, now implemented
This commit is contained in:
		| @@ -142,6 +142,7 @@ function diaspora_process_outbound($arr) { | ||||
| 				'cmd' => $cmd, | ||||
| 				'expire' =>	$expire, | ||||
| 				'mail' => $mail, | ||||
| 				'location' => $location, | ||||
| 				'fsuggest' => $fsuggest, | ||||
| 				'normal_mode' => $normal_mode, | ||||
| 				'packet_type' => $packet_type, | ||||
| @@ -150,6 +151,10 @@ function diaspora_process_outbound($arr) { | ||||
| */ | ||||
|  | ||||
|  | ||||
| 	if($arr['location']) | ||||
| 		return; | ||||
|  | ||||
|  | ||||
| 	$target_item = $arr['target_item']; | ||||
|  | ||||
| 	if($target_item && array_key_exists('item_flags',$target_item) && ($target_item['item_flags'] & ITEM_OBSCURED)) { | ||||
| @@ -161,6 +166,7 @@ function diaspora_process_outbound($arr) { | ||||
| 	} | ||||
|  | ||||
|  | ||||
|  | ||||
| 	if($arr['env_recips']) { | ||||
| 		$hashes = array(); | ||||
|  | ||||
|   | ||||
| @@ -46,6 +46,8 @@ function prune_hub_reinstalls() { | ||||
|  | ||||
| function remove_obsolete_hublocs() { | ||||
|  | ||||
| 	logger('remove_obsolete_hublocs',LOGGER_DEBUG); | ||||
|  | ||||
| 	// Get rid of any hublocs which are ours but aren't valid anymore -  | ||||
| 	// e.g. they point to a different and perhaps transient URL that we aren't using. | ||||
|  | ||||
| @@ -66,7 +68,9 @@ function remove_obsolete_hublocs() { | ||||
| 	if((! $r) || (! count($r))) | ||||
| 		return; | ||||
|  | ||||
| 	// Good. We have at least one valid hubloc. | ||||
| 	$channels = array(); | ||||
|  | ||||
| 	// Good. We have at least one *valid* hubloc. | ||||
|  | ||||
| 	// Do we have any invalid ones? | ||||
|  | ||||
| @@ -74,25 +78,38 @@ function remove_obsolete_hublocs() { | ||||
| 		dbesc(get_config('system','pubkey')), | ||||
| 		dbesc(z_root()) | ||||
| 	); | ||||
| 	if(! $r) | ||||
| 		return; | ||||
|  | ||||
| 	logger('remove_obsolete_hublocs: removing ' . count($r) . ' hublocs.'); | ||||
|  | ||||
| 	// We've got invalid hublocs. Get rid of them. | ||||
|  | ||||
| 	$r = q("delete from hubloc where hubloc_sitekey = '%s' and hubloc_url != '%s'", | ||||
| 	$p = q("select hubloc_id from hubloc where hubloc_sitekey != '%s' and hubloc_url = '%s'", | ||||
| 		dbesc(get_config('system','pubkey')), | ||||
| 		dbesc(z_root()) | ||||
| 	); | ||||
| 	if(is_array($r) && is_array($p)) | ||||
| 		$r = array_merge($r,$p); | ||||
|  | ||||
| 	// We should probably tell everybody... But we don't have an easy way to do this | ||||
| 	// for the entire site. We'd have to do a channel at a time.  | ||||
| 	// They will find out anyway - it just might take a little while.  | ||||
| 	if(! $r) | ||||
| 		return; | ||||
|  | ||||
| 	// FIXME we probably also need to check that the sys channel has a valid hubloc | ||||
| 	// and re-create it if it doesn't.  | ||||
| 	// We've got invalid hublocs. Get rid of them. | ||||
|  | ||||
| 	logger('remove_obsolete_hublocs: removing ' . count($r) . ' hublocs.'); | ||||
|  | ||||
| 	$interval = ((get_config('system','delivery_interval') !== false)  | ||||
| 			? intval(get_config('system','delivery_interval')) : 2 ); | ||||
|  | ||||
| 	foreach($r as $rr) { | ||||
| 		q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d limit 1", | ||||
| 			intval(HUBLOC_FLAGS_DELETED), | ||||
| 			intval($rr['hubloc_id']) | ||||
| 		); | ||||
|  | ||||
| 		$x = q("select channel_id from channel where channel_hash = '%s' limit 1", | ||||
| 			dbesc($rr['hubloc_hash'])  | ||||
| 		); | ||||
| 		if($x) { | ||||
| //			proc_run('php','include/notifier.php','location',$x[0]['channel_id']); | ||||
| //			if($interval) | ||||
| //				@time_sleep_until(microtime(true) + (float) $interval); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -57,6 +57,7 @@ require_once('include/html2plain.php'); | ||||
|  *       purge_all              channel_id | ||||
|  *       expire                 channel_id | ||||
|  *       relay					item_id (item was relayed to owner, we will deliver it as owner) | ||||
|  *       location               channel_id | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| @@ -144,6 +145,7 @@ function notifier_run($argv, $argc){ | ||||
| 	$mail = false; | ||||
| 	$fsuggest = false; | ||||
| 	$top_level = false; | ||||
| 	$location  = false; | ||||
| 	$recipients = array(); | ||||
| 	$url_recipients = array(); | ||||
| 	$normal_mode = true; | ||||
| @@ -230,6 +232,30 @@ function notifier_run($argv, $argc){ | ||||
| 		$private = false; | ||||
| 		$packet_type = 'refresh'; | ||||
| 	} | ||||
| 	elseif($cmd === 'location') { | ||||
| 		logger('notifier: location: ' . $item_id); | ||||
| 		$s = q("select * from channel where channel_id = %d limit 1", | ||||
| 			intval($item_id) | ||||
| 		); | ||||
| 		if($s) | ||||
| 			$channel = $s[0]; | ||||
| 		$uid = $item_id; | ||||
| 		$recipients = array(); | ||||
| 		$r = q("select abook_xchan from abook where abook_channel = %d", | ||||
| 			intval($item_id) | ||||
| 		); | ||||
| 		if($r) { | ||||
| 			foreach($r as $rr) { | ||||
| 				$recipients[] = $rr['abook_xchan']; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		$encoded_item = array('locations' => zot_encode_locations($channel),'type' => 'location', 'encoding' => 'zot'); | ||||
| 		$target_item = array('aid' => $channel['channel_account_id'],'uid' => $channel['channel_id']); | ||||
| 		$private = false; | ||||
| 		$packet_type = 'location'; | ||||
| 		$location = true; | ||||
| 	} | ||||
| 	elseif($cmd === 'purge_all') { | ||||
| 		logger('notifier: purge_all: ' . $item_id); | ||||
| 		$s = q("select * from channel where channel_id = %d limit 1", | ||||
| @@ -516,6 +542,7 @@ function notifier_run($argv, $argc){ | ||||
| 				'cmd' => $cmd, | ||||
| 				'expire' =>	$expire, | ||||
| 				'mail' => $mail, | ||||
| 				'location' => $location, | ||||
| 				'fsuggest' => $fsuggest, | ||||
| 				'normal_mode' => $normal_mode, | ||||
| 				'packet_type' => $packet_type, | ||||
|   | ||||
| @@ -171,6 +171,9 @@ function poller_run($argv, $argc){ | ||||
| 		proc_run('php','include/expire.php'); | ||||
| 		proc_run('php','include/cli_suggest.php'); | ||||
|  | ||||
| 		require_once('include/hubloc.php'); | ||||
| 		remove_obsolete_hublocs(); | ||||
|  | ||||
| 		/** | ||||
| 		 * End Cron Daily | ||||
| 		 */ | ||||
|   | ||||
| @@ -1121,6 +1121,11 @@ function zot_import($arr, $sender_url) { | ||||
|  | ||||
| 				$deliveries = allowed_public_recips($i); | ||||
|  | ||||
| 				if($i['message'] && array_key_exists('type',$i['message']) && $i['message']['type'] === 'location') { | ||||
| 					$sys = get_sys_channel(); | ||||
| 					$deliveries = array(array('hash' => $sys['xchan_hash'])); | ||||
| 				} | ||||
|  | ||||
| 				// if the scope is anything but 'public' we're going to store it as private regardless | ||||
| 				// of the private flag on the post.  | ||||
|  | ||||
| @@ -1206,7 +1211,7 @@ function zot_import($arr, $sender_url) { | ||||
| 					$arr = $i['message']; | ||||
|  | ||||
| 					logger('Location message received: ' . print_r($arr,true), LOGGER_DATA); | ||||
| 					logger('Location messaeg recipients: ' . print_r($deliveries,true), LOGGER_DATA); | ||||
| 					logger('Location message recipients: ' . print_r($deliveries,true), LOGGER_DATA); | ||||
| 					 | ||||
| 					$result = process_location_delivery($i['notify']['sender'],$arr,$deliveries); | ||||
| 				} | ||||
| @@ -1665,7 +1670,8 @@ function process_location_delivery($sender,$arr,$deliveries) { | ||||
| 	if($r) | ||||
| 		$sender['key'] = $r[0]['xchan_pubkey']; | ||||
|  | ||||
| 	sync_locations($sender,$arr,true); | ||||
| 	$x = sync_locations($sender,$arr,true); | ||||
| 	logger('process_location_delivery: results: ' . print_r($x,true), LOGGER_DATA); | ||||
| } | ||||
|  | ||||
| // We need to merge this code with that in the import_xchan function so as to make it  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user