mirror of
https://github.com/friendica/friendica
synced 2025-04-28 02:30:16 +00:00
Store the server transport protocol
This commit is contained in:
parent
ca8e4066fc
commit
bf563a1a39
6 changed files with 90 additions and 3 deletions
|
@ -23,6 +23,7 @@ namespace Friendica\Model;
|
|||
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use Exception;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
|
@ -1734,4 +1735,65 @@ class GServer
|
|||
|
||||
DI::config()->set('poco', 'last_federation_discovery', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the protocol for the given server
|
||||
*
|
||||
* @param int $gsid Server id
|
||||
* @param int $protocol Protocol id
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
static function setProtocol(int $gsid, int $protocol)
|
||||
{
|
||||
if (empty($gsid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', ['protocol', 'url'], ['id' => $gsid]);
|
||||
if (!DBA::isResult($gserver)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$old = $gserver['protocol'];
|
||||
|
||||
if (!is_null($old)) {
|
||||
/*
|
||||
The priority for the protocols is:
|
||||
1. ActivityPub
|
||||
2. DFRN via Diaspora
|
||||
3. Legacy DFRN
|
||||
4. Diaspora
|
||||
5. OStatus
|
||||
*/
|
||||
|
||||
// We don't need to change it when nothing is to be changed
|
||||
if ($old == $protocol) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We don't want to mark a server as OStatus when it had been marked with any other protocol before
|
||||
if ($protocol == Post\DeliveryData::OSTATUS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the server is marked as ActivityPub then we won't change it to anything different
|
||||
if ($old == Post\DeliveryData::ACTIVITYPUB) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't change it to anything lower than DFRN if the new one wasn't ActivityPub
|
||||
if (($old == Post\DeliveryData::DFRN) && ($protocol != Post\DeliveryData::ACTIVITYPUB)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't change it to Diaspora when it is a legacy DFRN server
|
||||
if (($old == Post\DeliveryData::LEGACY_DFRN) && ($protocol == Post\DeliveryData::DIASPORA)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url']]);
|
||||
DBA::update('gserver', ['protocol' => $protocol], ['id' => $gsid]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue