- if ($start_id == $id) {
- // Set all deprecated fields to "null" if they contain an empty string
- $nullfields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'postopts', 'inform', 'type',
- 'bookmark', 'file', 'location', 'coord', 'tag', 'plink', 'title', 'content-warning',
- 'body', 'app', 'verb', 'object-type', 'object', 'target-type', 'target',
- 'author-name', 'author-link', 'author-avatar', 'owner-name', 'owner-link', 'owner-avatar',
- 'rendered-hash', 'rendered-html'];
- foreach ($nullfields as $field) {
- $fields = [$field => null];
- $condition = [$field => ''];
- Logger::log("Setting '" . $field . "' to null if empty.", Logger::DEBUG);
- // Important: This has to be a "DBA::update", not a "Item::update"
- DBA::update('item', $fields, $condition);
+ // When there are less than 1,000 items processed this means that we reached the end
+ // The other entries will then be processed with the regular functionality
+ if ($rows < 1000) {
+ DI::config()->set('system', 'post_update_version', 1341);
+ Logger::info('Done');
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Fill the "tag" table with tags and mentions from the "term" table
+ *
+ * @return bool "true" when the job is done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ private static function update1342()
+ {
+ // Was the script completed?
+ if (DI::config()->get('system', 'post_update_version') >= 1342) {
+ return true;
+ }
+
+ if (!DBStructure::existsTable('term') || !DBStructure::existsTable('item-content')) {
+ DI::config()->set('system', 'post_update_version', 1342);
+ return true;
+ }
+
+ $id = DI::config()->get('system', 'post_update_version_1342_id', 0);
+
+ Logger::info('Start', ['item' => $id]);
+
+ $rows = 0;
+
+ $terms = DBA::p("SELECT `term`.`tid`, `item`.`uri-id`, `term`.`type`, `term`.`term`, `term`.`url`, `item-content`.`body`
+ FROM `term`
+ INNER JOIN `item` ON `item`.`id` = `term`.`oid`
+ INNER JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`
+ WHERE term.type IN (?, ?, ?, ?) AND `tid` >= ? ORDER BY `tid` LIMIT 100000",
+ Tag::HASHTAG, Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION, $id);
+
+ if (DBA::errorNo() != 0) {
+ Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+ return false;
+ }
+
+ while ($term = DBA::fetch($terms)) {
+ if (($term['type'] == Tag::MENTION) && !empty($term['url']) && !strstr($term['body'], $term['url'])) {
+ $condition = ['nurl' => Strings::normaliseLink($term['url']), 'uid' => 0, 'deleted' => false];
+ $contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
+ if (!DBA::isResult($contact)) {
+ $ssl_url = str_replace('http://', 'https://', $term['url']);
+ $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $term['url'], Strings::normaliseLink($term['url']), $ssl_url, 0];
+ $contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
+ }
+
+ if (DBA::isResult($contact) && (!strstr($term['body'], $contact['url']) && (empty($contact['alias']) || !strstr($term['body'], $contact['alias'])))) {
+ $term['type'] = Tag::IMPLICIT_MENTION;
+ }
+ }
+
+ Tag::store($term['uri-id'], $term['type'], $term['term'], $term['url'], false);
+
+ $id = $term['tid'];
+ ++$rows;
+ if ($rows % 1000 == 0) {
+ DI::config()->set('system', 'post_update_version_1342_id', $id);