-- ------------------------------------------
-- Friendica 2021.12-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1438
+-- DB_UPDATE_VERSION 1439
-- ------------------------------------------
CREATE TABLE IF NOT EXISTS `intro` (
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
- `fid` int unsigned COMMENT '',
+ `fid` int unsigned COMMENT 'deprecated',
`contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
+ `suggest-cid` int unsigned COMMENT 'Suggested contact',
`knowyou` boolean NOT NULL DEFAULT '0' COMMENT '',
`duplex` boolean NOT NULL DEFAULT '0' COMMENT '',
`note` text COMMENT '',
INDEX `contact-id` (`contact-id`),
INDEX `uid` (`uid`),
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
- FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
+ FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
+ FOREIGN KEY (`suggest-cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
--
Fields
------
-| Field | Description | Type | Null | Key | Default | Extra |
-| ---------- | ------------- | ------------------ | ---- | --- | ------------------- | -------------- |
-| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
-| uid | User id | mediumint unsigned | NO | | 0 | |
-| fid | | int unsigned | YES | | NULL | |
-| contact-id | | int unsigned | NO | | 0 | |
-| knowyou | | boolean | NO | | 0 | |
-| duplex | | boolean | NO | | 0 | |
-| note | | text | YES | | NULL | |
-| hash | | varchar(255) | NO | | | |
-| datetime | | datetime | NO | | 0001-01-01 00:00:00 | |
-| blocked | | boolean | NO | | 1 | |
-| ignore | | boolean | NO | | 0 | |
+| Field | Description | Type | Null | Key | Default | Extra |
+| ----------- | ----------------- | ------------------ | ---- | --- | ------------------- | -------------- |
+| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
+| uid | User id | mediumint unsigned | NO | | 0 | |
+| fid | deprecated | int unsigned | YES | | NULL | |
+| contact-id | | int unsigned | NO | | 0 | |
+| suggest-cid | Suggested contact | int unsigned | YES | | NULL | |
+| knowyou | | boolean | NO | | 0 | |
+| duplex | | boolean | NO | | 0 | |
+| note | | text | YES | | NULL | |
+| hash | | varchar(255) | NO | | | |
+| datetime | | datetime | NO | | 0001-01-01 00:00:00 | |
+| blocked | | boolean | NO | | 1 | |
+| ignore | | boolean | NO | | 0 | |
Indexes
------------
|-------|--------------|--------------|
| uid | [user](help/database/db_user) | uid |
| contact-id | [contact](help/database/db_contact) | id |
+| suggest-cid | [contact](help/database/db_contact) | id |
Return to [database documentation](help/database)
$intros1 = DBA::toArray(DBA::p(
"SELECT `intro`.`id`, `intro`.`datetime`,
- `fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo`
- FROM `intro` INNER JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
+ `contact`.`name`, `contact`.`url`, `contact`.`photo`
+ FROM `intro` INNER JOIN `contact` ON `intro`.`suggest-cid` = `contact`.`id`
WHERE `intro`.`uid` = ? AND NOT `intro`.`blocked` AND NOT `intro`.`ignore` AND `intro`.`fid` != 0",
local_user()
));
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
-use Friendica\DI;
use Friendica\Network\Probe;
-use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
return null;
}
-
- /**
- * Suggest a given contact to a given user from a given contact
- *
- * @param integer $uid
- * @param integer $cid
- * @param integer $from_cid
- * @return bool Was the adding successful?
- */
- public static function addSuggestion(int $uid, int $cid, int $from_cid, string $note = '')
- {
- $owner = User::getOwnerDataById($uid);
- $contact = Contact::getById($cid);
- $from_contact = Contact::getById($from_cid);
-
- if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($contact['url']), 'uid' => $uid])) {
- return false;
- }
-
- $fcontact = self::getByURL($contact['url'], null, $contact['network']);
- if (empty($fcontact)) {
- Logger::warning('FContact had not been found', ['fcontact' => $contact['url']]);
- return false;
- }
-
- $fid = $fcontact['id'];
-
- // Quit if we already have an introduction for this person
- if (DBA::exists('intro', ['uid' => $uid, 'fid' => $fid])) {
- return false;
- }
-
- $suggest = [];
- $suggest['uid'] = $uid;
- $suggest['cid'] = $from_cid;
- $suggest['url'] = $contact['url'];
- $suggest['name'] = $contact['name'];
- $suggest['photo'] = $contact['photo'];
- $suggest['request'] = $contact['request'];
- $suggest['title'] = '';
- $suggest['body'] = $note;
-
- $hash = Strings::getRandomHex();
- $fields = ['uid' => $suggest['uid'], 'fid' => $fid, 'contact-id' => $suggest['cid'],
- 'note' => $suggest['body'], 'hash' => $hash, 'datetime' => DateTimeFormat::utcNow(), 'blocked' => false];
- DBA::insert('intro', $fields);
-
- notification([
- 'type' => Notification\Type::SUGGEST,
- 'otype' => Notification\ObjectType::INTRO,
- 'verb' => Activity::REQ_FRIEND,
- 'uid' => $owner['uid'],
- 'cid' => $from_contact['uid'],
- 'item' => $suggest,
- 'link' => DI::baseUrl().'/notifications/intros',
- ]);
-
- return true;
- }
}
$formattedIntroductions = [];
try {
- /// @todo Fetch contact details by "Contact::getByUrl" instead of queries to contact and fcontact
$stmtNotifications = $this->dba->p(
"SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
- `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
- `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`
+ `sugggest-contact`.`name` AS `fname`, `sugggest-contact`.`url` AS `furl`, `sugggest-contact`.`addr` AS `faddr`,
+ `sugggest-contact`.`photo` AS `fphoto`, `sugggest-contact`.`request` AS `frequest`
FROM `intro`
LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
- LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
+ LEFT JOIN `contact` AS `sugggest-contact` ON `intro`.`suggest-cid` = `sugggest-contact`.`id`
WHERE `intro`.`uid` = ? $sql_extra
LIMIT ?, ?",
$_SESSION['uid'],
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
// We have to distinguish between these two because they use different data.
// Contact suggestions
- if ($intro['fid'] ?? '') {
+ if ($intro['suggest-cid'] ?? '') {
if (empty($intro['furl'])) {
continue;
}
$cid = Contact::getIdForURL($url);
$note = $xpath->evaluate('string(dfrn:note[1]/text())', $suggestion);
- return FContact::addSuggestion($importer['importer_uid'], $cid, $importer['id'], $note);
+ return self::addSuggestion($importer['importer_uid'], $cid, $importer['id'], $note);
+ }
+
+ /**
+ * Suggest a given contact to a given user from a given contact
+ *
+ * @param integer $uid
+ * @param integer $cid
+ * @param integer $from_cid
+ * @return bool Was the adding successful?
+ */
+ private static function addSuggestion(int $uid, int $cid, int $from_cid, string $note = '')
+ {
+ $owner = User::getOwnerDataById($uid);
+ $contact = Contact::getById($cid);
+ $from_contact = Contact::getById($from_cid);
+
+ if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($contact['url']), 'uid' => $uid])) {
+ return false;
+ }
+
+ // Quit if we already have an introduction for this person
+ if (DBA::exists('intro', ['uid' => $uid, 'suggest-cid' => $cid])) {
+ return false;
+ }
+
+ $suggest = [];
+ $suggest['uid'] = $uid;
+ $suggest['cid'] = $from_cid;
+ $suggest['url'] = $contact['url'];
+ $suggest['name'] = $contact['name'];
+ $suggest['photo'] = $contact['photo'];
+ $suggest['request'] = $contact['request'];
+ $suggest['title'] = '';
+ $suggest['body'] = $note;
+
+ $hash = Strings::getRandomHex();
+ $fields = ['uid' => $suggest['uid'], 'suggest-cid' => $cid, 'contact-id' => $suggest['cid'],
+ 'note' => $suggest['body'], 'hash' => $hash, 'datetime' => DateTimeFormat::utcNow(), 'blocked' => false];
+ DBA::insert('intro', $fields);
+
+ notification([
+ 'type' => Notification\Type::SUGGEST,
+ 'otype' => Notification\ObjectType::INTRO,
+ 'verb' => Activity::REQ_FRIEND,
+ 'uid' => $owner['uid'],
+ 'cid' => $from_contact['uid'],
+ 'item' => $suggest,
+ 'link' => DI::baseUrl().'/notifications/intros',
+ ]);
+
+ return true;
}
/**
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1438);
+ define('DB_UPDATE_VERSION', 1439);
}
return [
"fields" => [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"],
- "fid" => ["type" => "int unsigned", "relation" => ["fcontact" => "id"], "comment" => ""],
+ "fid" => ["type" => "int unsigned", "relation" => ["fcontact" => "id"], "comment" => "deprecated"],
"contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => ""],
+ "suggest-cid" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "Suggested contact"],
"knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"note" => ["type" => "text", "comment" => ""],
DBA::update('photo', ['photo-type' => Photo::CONTACT_AVATAR], ["NOT `profile` AND NOT `contact-id` IS NULL AND `contact-id` != ?", 0]);
DBA::update('photo', ['photo-type' => Photo::DEFAULT], ["NOT `profile` AND (`contact-id` IS NULL OR `contact-id` = ?) AND `photo-type` IS NULL AND `album` != ?", 0, Photo::CONTACT_PHOTOS]);
}
+
+function update_1439()
+{
+ $intros = DBA::select('intro', ['id', 'fid'], ["NOT `fid` IS NULL AND `fid` != ?", 0]);
+ while ($intro = DBA::fetch($intros)) {
+ $fcontact = DBA::selectFirst('fcontact', ['url'], ['id' => $intro['fid']]);
+ if (!empty($fcontact['url'])) {
+ $id = Contact::getIdForURL($fcontact['url']);
+ if (!empty($id)) {
+ DBA::update('intro',['suggest-cid' => $id], ['id' => $intro['id']]);
+ }
+ }
+ }
+ DBA::close($intros);
+}