3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Database;
24 use Friendica\Core\Logger;
25 use Friendica\Core\Protocol;
27 use Friendica\Model\Contact;
28 use Friendica\Model\Item;
29 use Friendica\Model\ItemURI;
30 use Friendica\Model\PermissionSet;
31 use Friendica\Model\Post\Category;
32 use Friendica\Model\Tag;
33 use Friendica\Model\UserItem;
34 use Friendica\Model\Verb;
35 use Friendica\Util\Strings;
38 * These database-intensive post update routines are meant to be executed in the background by the cronjob.
40 * If there is a need for a intensive migration after a database structure change, update this file
41 * by adding a new method at the end with the number of the new DB_UPDATE_VERSION.
45 // Needed for the helper function to read from the legacy term table
46 const OBJECT_TYPE_POST = 1;
49 * Calls the post update functions
51 public static function update()
53 if (!self::update1194()) {
56 if (!self::update1206()) {
59 if (!self::update1279()) {
62 if (!self::update1281()) {
65 if (!self::update1297()) {
68 if (!self::update1322()) {
71 if (!self::update1329()) {
74 if (!self::update1341()) {
77 if (!self::update1342()) {
80 if (!self::update1345()) {
83 if (!self::update1346()) {
86 if (!self::update1347()) {
94 * Updates the "global" field in the item table
96 * @return bool "true" when the job is done
97 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
99 private static function update1194()
101 // Was the script completed?
102 if (DI::config()->get("system", "post_update_version") >= 1194) {
106 Logger::log("Start", Logger::DEBUG);
108 $end_id = DI::config()->get("system", "post_update_1194_end");
110 $r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
112 DI::config()->set("system", "post_update_1194_end", $r[0]["id"]);
113 $end_id = DI::config()->get("system", "post_update_1194_end");
117 Logger::log("End ID: ".$end_id, Logger::DEBUG);
119 $start_id = DI::config()->get("system", "post_update_1194_start");
121 $query1 = "SELECT `item`.`id` FROM `item` ";
123 $query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
125 $query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
126 AND `item`.`visible` AND NOT `item`.`private`
127 AND NOT `item`.`deleted` AND NOT `item`.`moderated`
128 AND `item`.`network` IN ('%s', '%s', '%s', '')
129 AND NOT `item`.`global`";
131 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
132 intval($start_id), intval($end_id),
133 DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
135 DI::config()->set("system", "post_update_version", 1194);
136 Logger::log("Update is done", Logger::DEBUG);
139 DI::config()->set("system", "post_update_1194_start", $r[0]["id"]);
140 $start_id = DI::config()->get("system", "post_update_1194_start");
143 Logger::log("Start ID: ".$start_id, Logger::DEBUG);
145 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1",
146 intval($start_id), intval($end_id),
147 DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
149 $pos_id = $r[0]["id"];
153 Logger::log("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, Logger::DEBUG);
155 q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
156 intval($start_id), intval($pos_id),
157 DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
159 Logger::log("Done", Logger::DEBUG);
163 * update the "last-item" field in the "self" contact
165 * This field avoids cost intensive calls in the admin panel and in "nodeinfo"
167 * @return bool "true" when the job is done
168 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
170 private static function update1206()
172 // Was the script completed?
173 if (DI::config()->get("system", "post_update_version") >= 1206) {
177 Logger::log("Start", Logger::DEBUG);
178 $r = q("SELECT `contact`.`id`, `contact`.`last-item`,
179 (SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`
181 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");
183 if (!DBA::isResult($r)) {
186 foreach ($r as $user) {
187 if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) {
188 DBA::update('contact', ['last-item' => $user['lastitem_date']], ['id' => $user['id']]);
192 DI::config()->set("system", "post_update_version", 1206);
193 Logger::log("Done", Logger::DEBUG);
198 * update the item related tables
200 * @return bool "true" when the job is done
201 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
202 * @throws \ImagickException
204 private static function update1279()
206 // Was the script completed?
207 if (DI::config()->get("system", "post_update_version") >= 1279) {
211 $id = DI::config()->get("system", "post_update_version_1279_id", 0);
213 Logger::log("Start from item " . $id, Logger::DEBUG);
215 $fields = array_merge(Item::MIXED_CONTENT_FIELDLIST, ['network', 'author-id', 'owner-id', 'tag', 'file',
216 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id',
217 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'psid', 'post-type', 'bookmark', 'type',
218 'inform', 'postopts', 'icid']);
222 $condition = ["`id` > ?", $id];
223 $params = ['order' => ['id'], 'limit' => 10000];
224 $items = Item::select($fields, $condition, $params);
226 if (DBA::errorNo() != 0) {
227 Logger::log('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
231 while ($item = Item::fetch($items)) {
234 if (empty($item['author-id'])) {
235 $default = ['url' => $item['author-link'], 'name' => $item['author-name'],
236 'photo' => $item['author-avatar'], 'network' => $item['network']];
238 $item['author-id'] = Contact::getIdForURL($item["author-link"], 0, false, $default);
241 if (empty($item['owner-id'])) {
242 $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
243 'photo' => $item['owner-avatar'], 'network' => $item['network']];
245 $item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, false, $default);
248 if (empty($item['psid'])) {
249 $item['psid'] = PermissionSet::getIdFromACL(
258 $item['allow_cid'] = null;
259 $item['allow_gid'] = null;
260 $item['deny_cid'] = null;
261 $item['deny_gid'] = null;
263 if ($item['post-type'] == 0) {
264 if (!empty($item['type']) && ($item['type'] == 'note')) {
265 $item['post-type'] = Item::PT_PERSONAL_NOTE;
266 } elseif (!empty($item['type']) && ($item['type'] == 'photo')) {
267 $item['post-type'] = Item::PT_IMAGE;
268 } elseif (!empty($item['bookmark']) && $item['bookmark']) {
269 $item['post-type'] = Item::PT_PAGE;
273 self::createLanguage($item);
275 if (!empty($item['icid']) && !empty($item['language'])) {
276 DBA::update('item-content', ['language' => $item['language']], ['id' => $item['icid']]);
278 unset($item['language']);
280 Item::update($item, ['id' => $id]);
286 DI::config()->set("system", "post_update_version_1279_id", $id);
288 Logger::log("Processed rows: " . $rows . " - last processed item: " . $id, Logger::DEBUG);
290 if ($start_id == $id) {
291 // Set all deprecated fields to "null" if they contain an empty string
292 $nullfields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'postopts', 'inform', 'type',
293 'bookmark', 'file', 'location', 'coord', 'tag', 'plink', 'title', 'content-warning',
294 'body', 'app', 'verb', 'object-type', 'object', 'target-type', 'target',
295 'author-name', 'author-link', 'author-avatar', 'owner-name', 'owner-link', 'owner-avatar',
296 'rendered-hash', 'rendered-html'];
297 foreach ($nullfields as $field) {
298 $fields = [$field => null];
299 $condition = [$field => ''];
300 Logger::log("Setting '" . $field . "' to null if empty.", Logger::DEBUG);
301 // Important: This has to be a "DBA::update", not a "Item::update"
302 DBA::update('item', $fields, $condition);
305 DI::config()->set("system", "post_update_version", 1279);
306 Logger::log("Done", Logger::DEBUG);
313 private static function createLanguage(&$item)
315 if (empty($item['postopts'])) {
319 $opts = explode(',', $item['postopts']);
323 foreach ($opts as $opt) {
324 if (strstr($opt, 'lang=')) {
325 $language = substr($opt, 5);
331 if (empty($language)) {
335 if (!empty($postopts)) {
336 $item['postopts'] = implode(',', $postopts);
338 $item['postopts'] = null;
341 $lang_pairs = explode(':', $language);
345 foreach ($lang_pairs as $pair) {
346 $lang_pair_arr = explode(';', $pair);
347 if (count($lang_pair_arr) == 2) {
348 $lang_arr[$lang_pair_arr[0]] = $lang_pair_arr[1];
352 $item['language'] = json_encode($lang_arr);
356 * update item-uri data. Prerequisite for the next item structure update.
358 * @return bool "true" when the job is done
359 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
361 private static function update1281()
363 // Was the script completed?
364 if (DI::config()->get("system", "post_update_version") >= 1281) {
368 $id = DI::config()->get("system", "post_update_version_1281_id", 0);
370 Logger::log("Start from item " . $id, Logger::DEBUG);
372 $fields = ['id', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id', 'thr-parent', 'thr-parent-id'];
376 $condition = ["`id` > ?", $id];
377 $params = ['order' => ['id'], 'limit' => 10000];
378 $items = DBA::select('item', $fields, $condition, $params);
380 if (DBA::errorNo() != 0) {
381 Logger::log('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
385 while ($item = DBA::fetch($items)) {
388 if (empty($item['uri'])) {
391 } elseif (empty($item['uri-id'])) {
392 $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
395 if (empty($item['parent-uri'])) {
396 $item['parent-uri-id'] = $item['uri-id'];
397 } elseif (empty($item['parent-uri-id'])) {
398 $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
401 // Very old items don't have this field
402 if (empty($item['thr-parent'])) {
403 $item['thr-parent-id'] = $item['parent-uri-id'];
404 } elseif (empty($item['thr-parent-id'])) {
405 $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
409 unset($item['guid']);
411 unset($item['parent-uri']);
412 unset($item['thr-parent']);
414 DBA::update('item', $item, ['id' => $id]);
420 DI::config()->set("system", "post_update_version_1281_id", $id);
422 Logger::log("Processed rows: " . $rows . " - last processed item: " . $id, Logger::DEBUG);
424 if ($start_id == $id) {
425 Logger::log("Updating item-uri in item-activity", Logger::DEBUG);
426 DBA::e("UPDATE `item-activity` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item-activity`.`uri` SET `item-activity`.`uri-id` = `item-uri`.`id` WHERE `item-activity`.`uri-id` IS NULL");
428 Logger::log("Updating item-uri in item-content", Logger::DEBUG);
429 DBA::e("UPDATE `item-content` INNER JOIN `item-uri` ON `item-uri`.`uri` = `item-content`.`uri` SET `item-content`.`uri-id` = `item-uri`.`id` WHERE `item-content`.`uri-id` IS NULL");
431 DI::config()->set("system", "post_update_version", 1281);
432 Logger::log("Done", Logger::DEBUG);
440 * Set the delivery queue count to a negative value for all items preceding the feature.
442 * @return bool "true" when the job is done
443 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
445 private static function update1297()
447 // Was the script completed?
448 if (DI::config()->get('system', 'post_update_version') >= 1297) {
452 $max_item_delivery_data = DBA::selectFirst('item-delivery-data', ['iid'], ['queue_count > 0 OR queue_done > 0'], ['order' => ['iid']]);
453 $max_iid = $max_item_delivery_data['iid'];
455 Logger::info('Start update1297 with max iid: ' . $max_iid);
457 $condition = ['`queue_count` = 0 AND `iid` < ?', $max_iid];
459 DBA::update('item-delivery-data', ['queue_count' => -1], $condition);
461 if (DBA::errorNo() != 0) {
462 Logger::error('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
466 Logger::info('Processed rows: ' . DBA::affectedRows());
468 DI::config()->set('system', 'post_update_version', 1297);
470 Logger::info('Done');
475 * Remove contact duplicates
477 * @return bool "true" when the job is done
478 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
480 private static function update1322()
482 // Was the script completed?
483 if (DI::config()->get('system', 'post_update_version') >= 1322) {
487 Logger::info('Start');
489 $contacts = DBA::p("SELECT `nurl`, `uid` FROM `contact`
490 WHERE EXISTS (SELECT `nurl` FROM `contact` AS `c2`
491 WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` IN (?, ?, ?) AND NOT `deleted`)
492 AND (`network` IN (?, ?, ?) OR (`uid` = ?)) AND NOT `deleted` GROUP BY `nurl`, `uid`",
493 Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB,
494 Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, 0);
496 while ($contact = DBA::fetch($contacts)) {
497 Logger::info('Remove duplicates', ['nurl' => $contact['nurl'], 'uid' => $contact['uid']]);
498 Contact::removeDuplicates($contact['nurl'], $contact['uid']);
501 DBA::close($contact);
502 DI::config()->set('system', 'post_update_version', 1322);
504 Logger::info('Done');
510 * update user-item data with notifications
512 * @return bool "true" when the job is done
513 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
515 private static function update1329()
517 // Was the script completed?
518 if (DI::config()->get('system', 'post_update_version') >= 1329) {
522 $id = DI::config()->get('system', 'post_update_version_1329_id', 0);
524 Logger::info('Start', ['item' => $id]);
528 $condition = ["`id` > ?", $id];
529 $params = ['order' => ['id'], 'limit' => 10000];
530 $items = DBA::select('item', ['id'], $condition, $params);
532 if (DBA::errorNo() != 0) {
533 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
537 while ($item = DBA::fetch($items)) {
540 UserItem::setNotification($item['id']);
546 DI::config()->set('system', 'post_update_version_1329_id', $id);
548 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
550 if ($start_id == $id) {
551 DI::config()->set('system', 'post_update_version', 1329);
552 Logger::info('Done');
560 * Fill the "tag" table with tags and mentions from the body
562 * @return bool "true" when the job is done
563 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
565 private static function update1341()
567 // Was the script completed?
568 if (DI::config()->get('system', 'post_update_version') >= 1341) {
572 $id = DI::config()->get('system', 'post_update_version_1341_id', 0);
574 Logger::info('Start', ['item' => $id]);
578 $items = DBA::p("SELECT `uri-id`,`body` FROM `item-content` WHERE
579 (`body` LIKE ? OR `body` LIKE ? OR `body` LIKE ?) AND `uri-id` >= ?
580 ORDER BY `uri-id` LIMIT 100000", '%#%', '%@%', '%!%', $id);
582 if (DBA::errorNo() != 0) {
583 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
587 while ($item = DBA::fetch($items)) {
588 Tag::storeFromBody($item['uri-id'], $item['body'], '#!@', false);
589 $id = $item['uri-id'];
591 if ($rows % 1000 == 0) {
592 DI::config()->set('system', 'post_update_version_1341_id', $id);
597 DI::config()->set('system', 'post_update_version_1341_id', $id);
599 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
601 // When there are less than 1,000 items processed this means that we reached the end
602 // The other entries will then be processed with the regular functionality
604 DI::config()->set('system', 'post_update_version', 1341);
605 Logger::info('Done');
613 * Fill the "tag" table with tags and mentions from the "term" table
615 * @return bool "true" when the job is done
616 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
618 private static function update1342()
620 // Was the script completed?
621 if (DI::config()->get('system', 'post_update_version') >= 1342) {
625 $id = DI::config()->get('system', 'post_update_version_1342_id', 0);
627 Logger::info('Start', ['item' => $id]);
631 $terms = DBA::p("SELECT `term`.`tid`, `item`.`uri-id`, `term`.`type`, `term`.`term`, `term`.`url`, `item-content`.`body`
633 INNER JOIN `item` ON `item`.`id` = `term`.`oid`
634 INNER JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`
635 WHERE term.type IN (?, ?, ?, ?) AND `tid` >= ? ORDER BY `tid` LIMIT 100000",
636 Tag::HASHTAG, Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION, $id);
638 if (DBA::errorNo() != 0) {
639 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
643 while ($term = DBA::fetch($terms)) {
644 if (($term['type'] == Tag::MENTION) && !empty($term['url']) && !strstr($term['body'], $term['url'])) {
645 $condition = ['nurl' => Strings::normaliseLink($term['url']), 'uid' => 0, 'deleted' => false];
646 $contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
647 if (!DBA::isResult($contact)) {
648 $ssl_url = str_replace('http://', 'https://', $term['url']);
649 $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $term['url'], Strings::normaliseLink($term['url']), $ssl_url, 0];
650 $contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
653 if (DBA::isResult($contact) && (!strstr($term['body'], $contact['url']) && (empty($contact['alias']) || !strstr($term['body'], $contact['alias'])))) {
654 $term['type'] = Tag::IMPLICIT_MENTION;
658 Tag::store($term['uri-id'], $term['type'], $term['term'], $term['url'], false);
662 if ($rows % 1000 == 0) {
663 DI::config()->set('system', 'post_update_version_1342_id', $id);
668 DI::config()->set('system', 'post_update_version_1342_id', $id);
670 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
672 // When there are less than 1,000 items processed this means that we reached the end
673 // The other entries will then be processed with the regular functionality
675 DI::config()->set('system', 'post_update_version', 1342);
676 Logger::info('Done');
684 * Fill the "post-delivery-data" table with data from the "item-delivery-data" table
686 * @return bool "true" when the job is done
687 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
689 private static function update1345()
691 // Was the script completed?
692 if (DI::config()->get('system', 'post_update_version') >= 1345) {
696 $id = DI::config()->get('system', 'post_update_version_1345_id', 0);
698 Logger::info('Start', ['item' => $id]);
702 $deliveries = DBA::p("SELECT `uri-id`, `iid`, `item-delivery-data`.`postopts`, `item-delivery-data`.`inform`,
703 `queue_count`, `queue_done`, `activitypub`, `dfrn`, `diaspora`, `ostatus`, `legacy_dfrn`, `queue_failed`
704 FROM `item-delivery-data`
705 INNER JOIN `item` ON `item`.`id` = `item-delivery-data`.`iid`
706 WHERE `iid` >= ? ORDER BY `iid` LIMIT 10000", $id);
708 if (DBA::errorNo() != 0) {
709 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
713 while ($delivery = DBA::fetch($deliveries)) {
714 $id = $delivery['iid'];
715 unset($delivery['iid']);
716 DBA::insert('post-delivery-data', $delivery, true);
719 DBA::close($deliveries);
721 DI::config()->set('system', 'post_update_version_1345_id', $id);
723 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
725 // When there are less than 100 items processed this means that we reached the end
726 // The other entries will then be processed with the regular functionality
728 DI::config()->set('system', 'post_update_version', 1345);
729 Logger::info('Done');
737 * Generates the legacy item.file field string from an item ID.
738 * Includes only file and category terms.
740 * @param int $item_id
744 private static function fileTextFromItemId($item_id)
748 $condition = ['otype' => self::OBJECT_TYPE_POST, 'oid' => $item_id, 'type' => [Category::FILE, Category::CATEGORY]];
749 $tags = DBA::selectToArray('term', ['type', 'term', 'url'], $condition);
750 foreach ($tags as $tag) {
751 if ($tag['type'] == Category::CATEGORY) {
752 $file_text .= '<' . $tag['term'] . '>';
754 $file_text .= '[' . $tag['term'] . ']';
762 * Fill the "tag" table with tags and mentions from the "term" table
764 * @return bool "true" when the job is done
765 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
767 private static function update1346()
769 // Was the script completed?
770 if (DI::config()->get('system', 'post_update_version') >= 1346) {
774 $id = DI::config()->get('system', 'post_update_version_1346_id', 0);
776 Logger::info('Start', ['item' => $id]);
780 $terms = DBA::select('term', ['oid'],
781 ["`type` IN (?, ?) AND `oid` >= ?", Category::CATEGORY, Category::FILE, $id],
782 ['order' => ['oid'], 'limit' => 1000, 'group_by' => ['oid']]);
784 if (DBA::errorNo() != 0) {
785 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
789 while ($term = DBA::fetch($terms)) {
790 $item = Item::selectFirst(['uri-id', 'uid'], ['id' => $term['oid']]);
791 if (!DBA::isResult($item)) {
795 $file = self::fileTextFromItemId($term['oid']);
797 Category::storeTextByURIId($item['uri-id'], $item['uid'], $file);
802 if ($rows % 100 == 0) {
803 DI::config()->set('system', 'post_update_version_1346_id', $id);
808 DI::config()->set('system', 'post_update_version_1346_id', $id);
810 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
812 // When there are less than 10 items processed this means that we reached the end
813 // The other entries will then be processed with the regular functionality
815 DI::config()->set('system', 'post_update_version', 1346);
816 Logger::info('Done');
824 * update the "vid" (verb) field in the item table
826 * @return bool "true" when the job is done
827 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
828 * @throws \ImagickException
830 private static function update1347()
832 // Was the script completed?
833 if (DI::config()->get("system", "post_update_version") >= 1347) {
837 $id = DI::config()->get("system", "post_update_version_1347_id", 0);
839 Logger::info('Start', ['item' => $id]);
843 $condition = ["`id` > ? AND `vid` IS NULL", $id];
844 $params = ['order' => ['id'], 'limit' => 10000];
845 $items = Item::select(['id', 'verb'], $condition, $params);
847 if (DBA::errorNo() != 0) {
848 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
852 while ($item = Item::fetch($items)) {
855 DBA::update('item', ['vid' => Verb::getID($item['verb'])], ['id' => $item['id']]);
861 DI::config()->set("system", "post_update_version_1347_id", $id);
863 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
865 if ($start_id == $id) {
866 DI::config()->set("system", "post_update_version", 1347);
867 Logger::info('Done');