Merge pull request #5028 from annando/probe-insert
Insert a gcontact on probing, but not insert a contact
This commit is contained in:
commit
a2dbf17a3d
|
@ -20,7 +20,7 @@ use Friendica\Protocol\Feed;
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
use Friendica\Util\DateTimeFormat;
|
||||||
use dba;
|
use dba;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
|
@ -357,11 +357,11 @@ class Probe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::$baseurl != "") {
|
if (!empty(self::$baseurl)) {
|
||||||
$data["baseurl"] = self::$baseurl;
|
$data["baseurl"] = self::$baseurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($data["network"])) {
|
if (empty($data["network"])) {
|
||||||
$data["network"] = NETWORK_PHANTOM;
|
$data["network"] = NETWORK_PHANTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,6 +395,12 @@ class Probe
|
||||||
'network' => $data['network'],
|
'network' => $data['network'],
|
||||||
'server_url' => $data['baseurl']];
|
'server_url' => $data['baseurl']];
|
||||||
|
|
||||||
|
// This doesn't cover the case when a community isn't a community anymore
|
||||||
|
if (!empty($data['community']) && $data['community']) {
|
||||||
|
$fields['community'] = $data['community'];
|
||||||
|
$fields['contact-type'] = ACCOUNT_TYPE_COMMUNITY;
|
||||||
|
}
|
||||||
|
|
||||||
$fieldnames = [];
|
$fieldnames = [];
|
||||||
|
|
||||||
foreach ($fields as $key => $val) {
|
foreach ($fields as $key => $val) {
|
||||||
|
@ -411,6 +417,17 @@ class Probe
|
||||||
|
|
||||||
$old_fields = dba::selectFirst('gcontact', $fieldnames, $condition);
|
$old_fields = dba::selectFirst('gcontact', $fieldnames, $condition);
|
||||||
|
|
||||||
|
// When the gcontact doesn't exist, the value "true" will trigger an insert.
|
||||||
|
// In difference to the public contacts we want to have every contact
|
||||||
|
// in the world in our global contacts.
|
||||||
|
if (!$old_fields) {
|
||||||
|
$old_fields = true;
|
||||||
|
|
||||||
|
// These values have to be set only on insert
|
||||||
|
$fields['photo'] = $data['photo'];
|
||||||
|
$fields['created'] = DateTimeFormat::utcNow();
|
||||||
|
}
|
||||||
|
|
||||||
dba::update('gcontact', $fields, $condition, $old_fields);
|
dba::update('gcontact', $fields, $condition, $old_fields);
|
||||||
|
|
||||||
$fields = ['name' => $data['name'],
|
$fields = ['name' => $data['name'],
|
||||||
|
@ -428,7 +445,10 @@ class Probe
|
||||||
'confirm' => $data['confirm'],
|
'confirm' => $data['confirm'],
|
||||||
'poco' => $data['poco'],
|
'poco' => $data['poco'],
|
||||||
'network' => $data['network'],
|
'network' => $data['network'],
|
||||||
'success_update' => DBM::date()];
|
'pubkey' => $data['pubkey'],
|
||||||
|
'priority' => $data['priority'],
|
||||||
|
'writable' => true,
|
||||||
|
'rel' => CONTACT_IS_SHARING];
|
||||||
|
|
||||||
$fieldnames = [];
|
$fieldnames = [];
|
||||||
|
|
||||||
|
@ -442,14 +462,15 @@ class Probe
|
||||||
|
|
||||||
$condition = ['nurl' => normalise_link($data["url"]), 'self' => false, 'uid' => 0];
|
$condition = ['nurl' => normalise_link($data["url"]), 'self' => false, 'uid' => 0];
|
||||||
|
|
||||||
|
// "$old_fields" will return a "false" when the contact doesn't exist.
|
||||||
|
// This won't trigger an insert. This is intended, since we only need
|
||||||
|
// public contacts for everyone we store items from.
|
||||||
|
// We don't need to store every contact on the planet.
|
||||||
$old_fields = dba::selectFirst('contact', $fieldnames, $condition);
|
$old_fields = dba::selectFirst('contact', $fieldnames, $condition);
|
||||||
|
|
||||||
// When the contact doesn't exist, the value "true" will trigger an insert
|
$fields['name-date'] = DateTimeFormat::utcNow();
|
||||||
if (!$old_fields) {
|
$fields['uri-date'] = DateTimeFormat::utcNow();
|
||||||
$old_fields = true;
|
$fields['success_update'] = DateTimeFormat::utcNow();
|
||||||
$fields['blocked'] = false;
|
|
||||||
$fields['pending'] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
dba::update('contact', $fields, $condition, $old_fields);
|
dba::update('contact', $fields, $condition, $old_fields);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue