function unmark_for_death($contact) {
- $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND `term-date` > '%s'",
+ $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND (`term-date` > '%s' OR `archive`)",
intval($contact['id']),
dbesc('1000-00-00 00:00:00')
);
}
// It's a miracle. Our dead contact has inexplicably come back to life.
- q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
- dbesc(NULL_DATE),
- intval($contact['id'])
- );
+ $fields = array('term-date' => NULL_DATE, 'archive' => false);
+ dba::update('contact', $fields, array('id' => $contact['id']));
if ($contact['url'] != '') {
- q("UPDATE `contact` SET `term-date` = '%s' WHERE `nurl` = '%s'",
- dbesc(NULL_DATE),
- dbesc(normalise_link($contact['url']))
- );
+ dba::update('contact', $fields, array('nurl' => normalise_link($contact['url'])));
}
}
use Friendica\App;
use Friendica\Core\System;
+use Friendica\Network\Probe;
require_once 'include/probe.php';
require_once 'include/socgraph.php';
-function new_contact($uid,$url,$interactive = false) {
+function new_contact($uid, $url, $interactive = false, $network = '') {
$result = array('cid' => -1, 'success' => false,'message' => '');
if (x($arr['contact'],'name')) {
$ret = $arr['contact'];
+ } else {
+ $ret = Probe::uri($url, $network, $uid, false);
}
- else {
- $ret = probe_url($url);
+
+ if (($network != '') && ($ret['network'] != $network)) {
+ logger('Expected network '.$network.' does not match actual network '.$ret['network']);
+ return result;
}
if ($ret['network'] === NETWORK_DFRN) {
// Only update the contacts if it is an OStatus contact
if ($r && ($r['id'] > 0) && !$onlyfetch && ($contact["network"] == NETWORK_OSTATUS)) {
+ // This contact is vital, so we awake it from the dead
+ unmark_for_death($contact);
+
// Update contact data
$current = $contact;
return;
if ($r[0]["network"] == NETWORK_OSTATUS) {
- $result = new_contact($uid, $r[0]["url"], false);
+ $result = new_contact($uid, $r[0]["url"], false, $r[0]["network"]);
if ($result['success'])
$r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
$data = probe_url($url);
if ($data["network"] == NETWORK_OSTATUS) {
- $result = new_contact($uid,$url,true);
+ $result = new_contact($uid, $url, true, NETWORK_OSTATUS);
if ($result["success"]) {
$o .= " - ".t("success");
} else {