+ DI::keyValue()->set('post_update_version', 1427);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Fill the receivers of the post via the raw source
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function update1452()
+ {
+ // Was the script completed?
+ if (DI::keyValue()->get('post_update_version') >= 1452) {
+ return true;
+ }
+
+ if (!DBStructure::existsTable('conversation')) {
+ DI::keyValue()->set('post_update_version', 1452);
+ return true;
+ }
+
+ $id = DI::keyValue()->get('post_update_version_1452_id') ?? 0;
+
+ Logger::info('Start', ['uri-id' => $id]);
+
+ $rows = 0;
+ $received = '';
+
+ $conversations = DBA::p("SELECT `post-view`.`uri-id`, `conversation`.`source`, `conversation`.`received` FROM `conversation`
+ INNER JOIN `post-view` ON `post-view`.`uri` = `conversation`.`item-uri`
+ WHERE NOT `source` IS NULL AND `conversation`.`protocol` = ? AND `uri-id` > ? LIMIT ?",
+ Conversation::PARCEL_ACTIVITYPUB, $id, 1000);
+
+ if (DBA::errorNo() != 0) {
+ Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+ return false;
+ }
+
+ while ($conversation = DBA::fetch($conversations)) {
+ $id = $conversation['uri-id'];
+ $received = $conversation['received'];
+
+ $raw = json_decode($conversation['source'], true);
+ if (empty($raw)) {
+ continue;
+ }
+ $activity = JsonLD::compact($raw);
+
+ $urls = Receiver::getReceiverURL($activity);
+ Processor::storeReceivers($conversation['uri-id'], $urls);
+
+ if (!empty($activity['as:object'])) {
+ $urls = array_merge($urls, Receiver::getReceiverURL($activity['as:object']));
+ Processor::storeReceivers($conversation['uri-id'], $urls);
+ }
+ ++$rows;
+ }
+
+ DBA::close($conversations);
+
+ DI::keyValue()->set('post_update_version_1452_id', $id);
+
+ Logger::info('Processed', ['rows' => $rows, 'last' => $id, 'last-received' => $received]);
+
+ if ($rows <= 100) {
+ DI::keyValue()->set('post_update_version', 1452);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Correct the parent.
+ * This fixes a bug that was introduced in the development of version 2022.09
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function update1483()
+ {
+ // Was the script completed?
+ if (DI::keyValue()->get('post_update_version') >= 1483) {
+ return true;
+ }
+
+ Logger::info('Start');
+
+ $posts = DBA::select('post-view', ['uri-id'], ['conversation' => './']);
+ while ($post = DBA::fetch($posts)) {
+ $parent = Item::getParent($post['uri-id']);
+ if ($parent != 0) {
+ DBA::update('post', ['parent-uri-id' => $parent], ['uri-id' => $post['uri-id']]);
+ DBA::update('post-user', ['parent-uri-id' => $parent], ['uri-id' => $post['uri-id']]);
+ }
+ }
+ DBA::close($posts);
+
+ DI::keyValue()->set('post_update_version', 1483);
+ Logger::info('Done');
+ return true;
+ }
+
+ /**
+ * Handle duplicate contact entries
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function update1484()
+ {
+ // Was the script completed?
+ if (DI::keyValue()->get('post_update_version') >= 1484) {
+ return true;
+ }
+
+ $id = DI::keyValue()->get('post_update_version_1484_id') ?? 0;
+
+ Logger::info('Start', ['id' => $id]);
+
+ $rows = 0;
+
+ $contacts = DBA::select('contact', ['id', 'uid', 'uri-id', 'url'], ["`id` > ?", $id], ['order' => ['id'], 'limit' => 1000]);
+
+ if (DBA::errorNo() != 0) {
+ Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+ return false;
+ }
+
+ while ($contact = DBA::fetch($contacts)) {
+ $id = $contact['id'];
+ if (is_null($contact['uri-id'])) {
+ $contact['uri-id'] = ItemURI::getIdByURI($contact['url']);
+ DBA::update('contact', ['uri-id' => $contact['uri-id']], ['id' => $contact['id']]);
+ }
+ Contact::setAccountUser($contact['id'], $contact['uid'], $contact['uri-id'], $contact['url']);
+ ++$rows;
+ }
+ DBA::close($contacts);
+
+ DI::keyValue()->set('post_update_version_1484_id', $id);
+
+ Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
+
+ if ($rows <= 100) {
+ DI::keyValue()->set('post_update_version', 1484);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * update the "gsid" (global server id) field in the contact table
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function update1506()
+ {
+ // Was the script completed?
+ if (DI::keyValue()->get('post_update_version') >= 1506) {
+ return true;
+ }
+
+ $id = DI::keyValue()->get('post_update_version_1506_id') ?? 0;
+
+ Logger::info('Start', ['contact' => $id]);
+
+ $start_id = $id;
+ $rows = 0;
+ $condition = ["`id` > ? AND `gsid` IS NULL AND `network` = ?", $id, Protocol::DIASPORA];
+ $params = ['order' => ['id'], 'limit' => 10000];
+ $contacts = DBA::select('contact', ['id', 'url'], $condition, $params);
+
+ if (DBA::errorNo() != 0) {
+ Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+ return false;
+ }
+
+ while ($contact = DBA::fetch($contacts)) {
+ $id = $contact['id'];
+
+ $parts = parse_url($contact['url']);
+ unset($parts['path']);
+ $server = (string)Uri::fromParts($parts);
+
+ DBA::update('contact',
+ ['gsid' => GServer::getID($server, true), 'baseurl' => GServer::cleanURL($server)],
+ ['id' => $contact['id']]);
+
+ ++$rows;
+ }
+ DBA::close($contacts);
+
+ DI::keyValue()->set('post_update_version_1506_id', $id);
+
+ Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
+
+ if ($start_id == $id) {
+ DI::keyValue()->set('post_update_version', 1506);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * update the "gsid" (global server id) field in the inbox-status table
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function update1507()
+ {
+ // Was the script completed?
+ if (DI::keyValue()->get('post_update_version') >= 1507) {
+ return true;
+ }
+
+ $id = DI::keyValue()->get('post_update_version_1507_id') ?? '';
+
+ Logger::info('Start', ['apcontact' => $id]);
+
+ $start_id = $id;
+ $rows = 0;
+ $condition = ["`url` > ? AND NOT `gsid` IS NULL", $id];
+ $params = ['order' => ['url'], 'limit' => 10000];
+ $apcontacts = DBA::select('apcontact', ['url', 'gsid', 'sharedinbox', 'inbox'], $condition, $params);
+
+ if (DBA::errorNo() != 0) {
+ Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+ return false;
+ }
+
+ while ($apcontact = DBA::fetch($apcontacts)) {
+ $id = $apcontact['url'];
+
+ $inbox = [$apcontact['inbox']];
+ if (!empty($apcontact['sharedinbox'])) {
+ $inbox[] = $apcontact['sharedinbox'];
+ }
+ $condition = DBA::mergeConditions(['url' => $inbox], ["`gsid` IS NULL"]);
+ DBA::update('inbox-status', ['gsid' => $apcontact['gsid'], 'archive' => GServer::isDefunctById($apcontact['gsid'])], $condition);
+ ++$rows;
+ }
+ DBA::close($apcontacts);
+
+ DI::keyValue()->set('post_update_version_1507_id', $id);
+
+ Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
+
+ if ($start_id == $id) {
+ DI::keyValue()->set('post_update_version', 1507);