-- ------------------------------------------
-- Friendica 2021.09-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1428
+-- DB_UPDATE_VERSION 1429
-- ------------------------------------------
{
// Needed for the helper function to read from the legacy term table
const OBJECT_TYPE_POST = 1;
- const VERSION = 1400;
+
+ const VERSION = 1427;
/**
* Calls the post update functions
*/
public function createFromContactId(int $contactId, $uid = 0): \Friendica\Object\Api\Mastodon\Account
{
- $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
+ $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if (!empty($cdata)) {
$publicContact = Contact::getById($cdata['public']);
$userContact = Contact::getById($cdata['user']);
*/
public function createFromIntroduction(Introduction $introduction): \Friendica\Object\Api\Mastodon\FollowRequest
{
- $cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid);
+ $cdata = Contact::getPublicAndUserContactID($introduction->{'contact-id'}, $introduction->uid);
if (empty($cdata)) {
$this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);
*/
public function createFromContactId(int $contactId, int $uid): RelationshipEntity
{
- $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
+ $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if (!empty($cdata)) {
$cid = $cdata['user'];
} else {
*/
public function createFromContactId(int $contactId, $uid = 0, $skip_status = false, $include_user_entities = true)
{
- $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
+ $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if (!empty($cdata)) {
$publicContact = Contact::getById($cdata['public']);
$userContact = Contact::getById($cdata['user']);
return false;
}
- $cdata = self::getPublicAndUserContacID($cid, $uid);
+ $cdata = self::getPublicAndUserContactID($cid, $uid);
if (empty($cdata['user'])) {
return false;
}
return false;
}
- $cdata = self::getPublicAndUserContacID($cid, $uid);
+ $cdata = self::getPublicAndUserContactID($cid, $uid);
if (empty($cdata['user'])) {
return false;
}
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function getPublicAndUserContacID($cid, $uid)
+ public static function getPublicAndUserContactID($cid, $uid)
+ {
+ // We have to use the legacy function as long as the post update hasn't finished
+ if (DI::config()->get('system', 'post_update_version') < 1427) {
+ return self::legacyGetPublicAndUserContactID($cid, $uid);
+ }
+
+ if (empty($uid) || empty($cid)) {
+ return [];
+ }
+
+ $contact = DBA::selectFirst('account-user-view', ['id', 'uid', 'pid'], ['id' => $cid]);
+ if (!DBA::isResult($contact) || !in_array($contact['uid'], [0, $uid])) {
+ return [];
+ }
+
+ $pcid = $contact['pid'];
+ if ($contact['uid'] == $uid) {
+ $ucid = $contact['id'];
+ } else {
+ $contact = DBA::selectFirst('account-user-view', ['id', 'uid'], ['pid' => $cid, 'uid' => $uid]);
+ if (DBA::isResult($contact)) {
+ $ucid = $contact['id'];
+ } else {
+ $ucid = 0;
+ }
+ }
+
+ return ['public' => $pcid, 'user' => $ucid];
+ }
+
+ /**
+ * Helper function for "getPublicAndUserContactID"
+ *
+ * @param int $cid Either public contact id or user's contact id
+ * @param int $uid User ID
+ *
+ * @return array with public and user's contact id
+ * @throws HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function legacyGetPublicAndUserContactID($cid, $uid)
{
if (empty($uid) || empty($cid)) {
return [];
*/
public static function unfollow(int $cid, int $uid)
{
- $cdata = self::getPublicAndUserContacID($cid, $uid);
+ $cdata = self::getPublicAndUserContactID($cid, $uid);
if (empty($cdata['user'])) {
return false;
}
*/
public static function setBlocked($cid, $uid, $blocked)
{
- $cdata = Contact::getPublicAndUserContacID($cid, $uid);
+ $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return;
}
*/
public static function isBlocked($cid, $uid)
{
- $cdata = Contact::getPublicAndUserContacID($cid, $uid);
+ $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return false;
}
*/
public static function setIgnored($cid, $uid, $ignored)
{
- $cdata = Contact::getPublicAndUserContacID($cid, $uid);
+ $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return;
}
*/
public static function isIgnored($cid, $uid)
{
- $cdata = Contact::getPublicAndUserContacID($cid, $uid);
+ $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return false;
}
*/
public static function setCollapsed($cid, $uid, $collapsed)
{
- $cdata = Contact::getPublicAndUserContacID($cid, $uid);
+ $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return;
}
*/
public static function isCollapsed($cid, $uid)
{
- $cdata = Contact::getPublicAndUserContacID($cid, $uid);
+ $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return;
}
$lists = [];
- $cdata = Contact::getPublicAndUserContacID($id, $uid);
+ $cdata = Contact::getPublicAndUserContactID($id, $uid);
if (!empty($cdata['user'])) {
$groups = DBA::select('group_member', ['gid'], ['contact-id' => $cdata['user']]);
while ($group = DBA::fetch($groups)) {
'comment' => '',
]);
- $cdata = Contact::getPublicAndUserContacID($parameters['id'], $uid);
+ $cdata = Contact::getPublicAndUserContactID($parameters['id'], $uid);
if (empty($cdata['user'])) {
DI::mstdnError()->RecordNotFound();
}
DI::mstdnError()->InternalError();
}
- $cdata = Contact::getPublicAndUserContacID($self['id'], $uid);
+ $cdata = Contact::getPublicAndUserContactID($self['id'], $uid);
if (empty($cdata)) {
DI::mstdnError()->InternalError();
}
// Conversion to public contact ids
array_walk($ids, function (&$contactId) use ($uid, $stringify_ids) {
- $cdata = Contact::getPublicAndUserContacID($contactId, $uid);
+ $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if ($stringify_ids) {
$contactId = (string)$cdata['public'];
} else {
$contact_id = intval($a->argv[1]);
// Ensure to use the user contact when the public contact was provided
- $data = Model\Contact::getPublicAndUserContacID($contact_id, local_user());
+ $data = Model\Contact::getPublicAndUserContactID($contact_id, local_user());
if (!empty($data['user']) && ($contact_id == $data['public'])) {
$contact_id = $data['user'];
}
public static function getTabsHTML(array $contact, int $active_tab)
{
$cid = $pcid = $contact['id'];
- $data = Model\Contact::getPublicAndUserContacID($contact['id'], local_user());
+ $data = Model\Contact::getPublicAndUserContactID($contact['id'], local_user());
if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
$cid = $data['user'];
} elseif (!empty($data['public'])) {
}
if (!empty($owner['about'])) {
- $data['summary'] = BBCode::convertForUriId($owner['uri-id'], $owner['about'], BBCode::EXTERNAL);
+ $data['summary'] = BBCode::convertForUriId($owner['uri-id'] ?? 0, $owner['about'], BBCode::EXTERNAL);
}
$data['url'] = $owner['url'];
*/
public function selectByContactId($contact_id, $uid)
{
- $cdata = Model\Contact::getPublicAndUserContacID($contact_id, $uid);
+ $cdata = Model\Contact::getPublicAndUserContactID($contact_id, $uid);
if (!empty($cdata)) {
$public_contact_str = '<' . $cdata['public'] . '>';
$user_contact_str = '<' . $cdata['user'] . '>';
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1428);
+ define('DB_UPDATE_VERSION', 1429);
}
return [
// Insert a permissionset with id=0
// Inserting it without an ID and then changing the value to 0 tricks the auto increment
if (!DBA::exists('permissionset', ['id' => 0])) {
- DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
+ DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
$lastid = DBA::lastInsertId();
if ($lastid != 0) {
DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
function update_1399()
{
if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-user` ON `post-user`.`uid` = `post-thread-user`.`uid` AND `post-user`.`uri-id` = `post-thread-user`.`uri-id`
- SET `post-thread-user`.`contact-id` = `post-user`.`contact-id`, `post-thread-user`.`unseen` = `post-user`.`unseen`,
- `post-thread-user`.`hidden` = `post-user`.`hidden`, `post-thread-user`.`origin` = `post-user`.`origin`,
+ SET `post-thread-user`.`contact-id` = `post-user`.`contact-id`, `post-thread-user`.`unseen` = `post-user`.`unseen`,
+ `post-thread-user`.`hidden` = `post-user`.`hidden`, `post-thread-user`.`origin` = `post-user`.`origin`,
`post-thread-user`.`psid` = `post-user`.`psid`, `post-thread-user`.`post-user-id` = `post-user`.`id`")) {
return Update::FAILED;
}
{
if (!DBA::e("INSERT IGNORE INTO `post` (`uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`,
`created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global`)
- SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`,
+ SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`,
`gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global` FROM `item`")) {
return Update::FAILED;
}
$tasks = DBA::select('workerqueue', ['id', 'command', 'parameter'], ['command' => ['notifier', 'delivery', 'apdelivery', 'done' => false]]);
while ($task = DBA::fetch($tasks)) {
$parameters = json_decode($task['parameter'], true);
-
+
if (is_array($parameters) && count($parameters) && in_array($parameters[0], [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
continue;
}
-
+
switch (strtolower($task['command'])) {
case 'notifier':
if (count($parameters) == 3) {
if (!DBA::isResult($item)) {
continue 2;
}
-
+
$parameters[1] = $item['uri-id'];
$parameters[2] = $item['uid'];
break;
if (!DBA::isResult($item)) {
continue 2;
}
-
+
$parameters[1] = $item['uri-id'];
$parameters[3] = $item['uid'];
break;
if (count($parameters) == 6) {
continue 2;
}
-
+
if (empty($parameters[4])) {
$parameters[4] = [];
}
-
+
$item = DBA::selectFirst('item', ['uri-id'], ['id' => $parameters[1]]);
if (!DBA::isResult($item)) {
continue 2;
}
-
+
$parameters[5] = $item['uri-id'];
break;
default:
}
return Update::SUCCESS;
}
+
+function update_1429()
+{
+ if (!DBA::e("UPDATE `contact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
+ return Update::FAILED;
+ }
+
+ if (!DBA::e("UPDATE `fcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
+ return Update::FAILED;
+ }
+
+ if (!DBA::e("UPDATE `apcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
+ return Update::FAILED;
+ }
+
+ DI::config()->set("system", "post_update_version", 1423);
+
+ return Update::SUCCESS;
+}
\ No newline at end of file