-- ------------------------------------------
-- Friendica 2025.02-dev (Interrupted Fern)
--- DB_UPDATE_VERSION 1577
+-- DB_UPDATE_VERSION 1578
-- ------------------------------------------
`blocked` boolean COMMENT 'Server is blocked',
`failed` boolean COMMENT 'Connection failed',
`next_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Next connection request',
+ `redirect-gsid` int unsigned COMMENT 'Target Gserver id in case of a redirect',
PRIMARY KEY(`id`),
UNIQUE INDEX `nurl` (`nurl`(190)),
INDEX `next_contact` (`next_contact`),
- INDEX `network` (`network`)
+ INDEX `network` (`network`),
+ FOREIGN KEY (`redirect-gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Global servers';
--
| blocked | Server is blocked | boolean | YES | | NULL | |
| failed | Connection failed | boolean | YES | | NULL | |
| next_contact | Next connection request | datetime | YES | | 0001-01-01 00:00:00 | |
+| redirect-gsid | Target Gserver id in case of a redirect | int unsigned | YES | | NULL | |
Indexes
------------
| next_contact | next_contact |
| network | network |
+Foreign Keys
+------------
+
+| Field | Target Table | Target Field |
+|-------|--------------|--------------|
+| redirect-gsid | [gserver](help/database/db_gserver) | id |
Return to [database documentation](help/database)
DBA::update(
'contact',
- ['gsid' => GServer::getID($contact['baseurl'], true), 'baseurl' => GServer::cleanURL($contact['baseurl'])],
+ ['gsid' => GServer::getRealID($contact['baseurl'], true), 'baseurl' => GServer::cleanURL($contact['baseurl'])],
['id' => $contact['id']]
);
DBA::update(
'apcontact',
- ['gsid' => GServer::getID($apcontact['baseurl'], true), 'baseurl' => GServer::cleanURL($apcontact['baseurl'])],
+ ['gsid' => GServer::getRealID($apcontact['baseurl'], true), 'baseurl' => GServer::cleanURL($apcontact['baseurl'])],
['url' => $apcontact['url']]
);
DBA::update(
'contact',
- ['gsid' => GServer::getID($server, true), 'baseurl' => GServer::cleanURL($server)],
+ ['gsid' => GServer::getRealID($server, true), 'baseurl' => GServer::cleanURL($server)],
['id' => $contact['id']]
);
}
if (!empty($apcontact['baseurl']) && empty($fetched_contact['gsid'])) {
- $apcontact['gsid'] = GServer::getID($apcontact['baseurl']);
+ $apcontact['gsid'] = GServer::getRealID($apcontact['baseurl']);
} elseif (!empty($fetched_contact['gsid'])) {
$apcontact['gsid'] = $fetched_contact['gsid'];
} else {
public static function insert(array $fields, int $duplicate_mode = Database::INSERT_DEFAULT): int
{
if (!empty($fields['baseurl']) && empty($fields['gsid'])) {
- $fields['gsid'] = GServer::getID($fields['baseurl'], true);
+ $fields['gsid'] = GServer::getRealID($fields['baseurl'], true);
}
$fields['uri-id'] = ItemURI::getIdByURI($fields['url']);
$fields['unsearchable'] = !$profile['net-publish'];
$fields['manually-approve'] = in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP, User::PAGE_FLAGS_COMM_MAN]);
$fields['baseurl'] = DI::baseUrl();
- $fields['gsid'] = GServer::getID($fields['baseurl'], true);
+ $fields['gsid'] = GServer::getRealID($fields['baseurl'], true);
$update = false;
return self::getID($url, true);
}
+
+ /**
+ * Get the real ID for the given server URL, follows redirects.
+ *
+ * @param string $url
+ * @param boolean $no_check Don't check if the server hadn't been found
+ *
+ * @return int|null gserver id or NULL on empty URL or failed check
+ */
+ public static function getRealID(string $url, bool $no_check = false): ?int
+ {
+ $gsid = self::getID($url, $no_check);
+ if (empty($gsid)) {
+ return $gsid;
+ }
+
+ $gserver = DBA::selectFirst('gserver', ['redirect-gsid'], ['id' => $gsid]);
+ if (!empty($gserver['redirect-gsid'])) {
+ $redirect = DBA::selectFirst('gserver', ['failed'], ['id' => $gserver['redirect-gsid']]);
+ if (isset($redirect['failed']) && !$redirect['failed']) {
+ return $gserver['redirect-gsid'];
+ }
+ }
+ return $gsid;
+ }
+
/**
* Retrieves all the servers which base domain are matching the provided domain pattern
*
(((parse_url($url, PHP_URL_HOST) != parse_url($valid_url, PHP_URL_HOST)) || (parse_url($url, PHP_URL_PATH) != parse_url($valid_url, PHP_URL_PATH))) && empty(parse_url($valid_url, PHP_URL_PATH)))) {
DI::logger()->debug('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $valid_url]);
self::setFailureByUrl($url);
- if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
+ $target_id = self::getID($valid_url, true);
+ if (!$target_id && !Network::isUrlBlocked($valid_url)) {
self::detect($valid_url, $network, $only_nodeinfo);
+ $target_id = self::getID($valid_url, true);
+ }
+ if ($target_id) {
+ self::update(['redirect-gsid' => $target_id], ['nurl' => Strings::normaliseLink($url)]);
}
return false;
}
$system['thumb'] = Contact::getDefaultAvatar($system, Proxy::SIZE_THUMB);
$system['micro'] = Contact::getDefaultAvatar($system, Proxy::SIZE_MICRO);
$system['nurl'] = Strings::normaliseLink($system['url']);
- $system['gsid'] = GServer::getID($system['baseurl']);
+ $system['gsid'] = GServer::getRealID($system['baseurl']);
Contact::insert($system);
}
$newdata['baseurl'] = $data['networks'][$network]['baseurl'];
}
if (!empty($newdata['baseurl'])) {
- $newdata['gsid'] = $data['networks'][$network]['gsid'] = GServer::getID($newdata['baseurl']);
+ $newdata['gsid'] = $data['networks'][$network]['gsid'] = GServer::getRealID($newdata['baseurl']);
} else {
$newdata['gsid'] = $data['networks'][$network]['gsid'] = null;
}
}
if (!empty($data['baseurl']) && empty($data['gsid'])) {
- $data['gsid'] = GServer::getID($data['baseurl']);
+ $data['gsid'] = GServer::getRealID($data['baseurl']);
}
// Ensure that local connections always are DFRN
$split_name = Diaspora::splitName($owner['name']);
if (empty($owner['gsid'])) {
- $owner['gsid'] = GServer::getID($approfile['generator']['url']);
+ $owner['gsid'] = GServer::getRealID($approfile['generator']['url']);
}
$data = [
if (!empty($fields['baseurl'])) {
GServer::check($fields['baseurl'], Protocol::BLUESKY);
- $fields['gsid'] = GServer::getID($fields['baseurl'], true);
+ $fields['gsid'] = GServer::getRealID($fields['baseurl'], true);
}
foreach ($directory->verificationMethod as $method) {
// This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1577);
+ define('DB_UPDATE_VERSION', 1578);
}
return [
"blocked" => ["type" => "boolean", "comment" => "Server is blocked"],
"failed" => ["type" => "boolean", "comment" => "Connection failed"],
"next_contact" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => "Next connection request"],
+ "redirect-gsid" => ["type" => "int unsigned", "foreign" => ["gserver" => "id"], "comment" => "Target Gserver id in case of a redirect"],
],
"indexes" => [
"PRIMARY" => ["id"],