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\Term;
34 use Friendica\Model\UserItem;
35 use Friendica\Model\Verb;
36 use Friendica\Util\Strings;
39 * These database-intensive post update routines are meant to be executed in the background by the cronjob.
41 * If there is a need for a intensive migration after a database structure change, update this file
42 * by adding a new method at the end with the number of the new DB_UPDATE_VERSION.
47 * Calls the post update functions
49 public static function update()
51 if (!self::update1194()) {
54 if (!self::update1206()) {
57 if (!self::update1279()) {
60 if (!self::update1281()) {
63 if (!self::update1297()) {
66 if (!self::update1322()) {
69 if (!self::update1329()) {
72 if (!self::update1341()) {
75 if (!self::update1342()) {
78 if (!self::update1345()) {
81 if (!self::update1346()) {
84 if (!self::update1347()) {
92 * Updates the "global" field in the item table
94 * @return bool "true" when the job is done
95 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
97 private static function update1194()
99 // Was the script completed?
100 if (DI::config()->get("system", "post_update_version") >= 1194) {
104 Logger::log("Start", Logger::DEBUG);
106 $end_id = DI::config()->get("system", "post_update_1194_end");
108 $r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
110 DI::config()->set("system", "post_update_1194_end", $r[0]["id"]);
111 $end_id = DI::config()->get("system", "post_update_1194_end");
115 Logger::log("End ID: ".$end_id, Logger::DEBUG);
117 $start_id = DI::config()->get("system", "post_update_1194_start");
119 $query1 = "SELECT `item`.`id` FROM `item` ";
121 $query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
123 $query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
124 AND `item`.`visible` AND NOT `item`.`private`
125 AND NOT `item`.`deleted` AND NOT `item`.`moderated`
126 AND `item`.`network` IN ('%s', '%s', '%s', '')
127 AND NOT `item`.`global`";
129 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
130 intval($start_id), intval($end_id),
131 DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
133 DI::config()->set("system", "post_update_version", 1194);
134 Logger::log("Update is done", Logger::DEBUG);
137 DI::config()->set("system", "post_update_1194_start", $r[0]["id"]);
138 $start_id = DI::config()->get("system", "post_update_1194_start");
141 Logger::log("Start ID: ".$start_id, Logger::DEBUG);
143 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1",
144 intval($start_id), intval($end_id),
145 DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
147 $pos_id = $r[0]["id"];
151 Logger::log("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, Logger::DEBUG);
153 q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
154 intval($start_id), intval($pos_id),
155 DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DIASPORA), DBA::escape(Protocol::OSTATUS));
157 Logger::log("Done", Logger::DEBUG);
161 * update the "last-item" field in the "self" contact
163 * This field avoids cost intensive calls in the admin panel and in "nodeinfo"
165 * @return bool "true" when the job is done
166 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
168 private static function update1206()
170 // Was the script completed?
171 if (DI::config()->get("system", "post_update_version") >= 1206) {
175 Logger::log("Start", Logger::DEBUG);
176 $r = q("SELECT `contact`.`id`, `contact`.`last-item`,
177 (SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`
179 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");
181 if (!DBA::isResult($r)) {
184 foreach ($r as $user) {
185 if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) {
186 DBA::update('contact', ['last-item' => $user['lastitem_date']], ['id' => $user['id']]);
190 DI::config()->set("system", "post_update_version", 1206);
191 Logger::log("Done", Logger::DEBUG);
196 * update the item related tables
198 * @return bool "true" when the job is done
199 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
200 * @throws \ImagickException
202 private static function update1279()
204 // Was the script completed?
205 if (DI::config()->get("system", "post_update_version") >= 1279) {
209 $id = DI::config()->get("system", "post_update_version_1279_id", 0);
211 Logger::log("Start from item " . $id, Logger::DEBUG);
213 $fields = array_merge(Item::MIXED_CONTENT_FIELDLIST, ['network', 'author-id', 'owner-id', 'tag', 'file',
214 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id',
215 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'psid', 'post-type', 'bookmark', 'type',
216 'inform', 'postopts', 'icid']);
220 $condition = ["`id` > ?", $id];
221 $params = ['order' => ['id'], 'limit' => 10000];
222 $items = Item::select($fields, $condition, $params);
224 if (DBA::errorNo() != 0) {
225 Logger::log('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
229 while ($item = Item::fetch($items)) {
232 if (empty($item['author-id'])) {
233 $default = ['url' => $item['author-link'], 'name' => $item['author-name'],
234 'photo' => $item['author-avatar'], 'network' => $item['network']];
236 $item['author-id'] = Contact::getIdForURL($item["author-link"], 0, false, $default);
239 if (empty($item['owner-id'])) {
240 $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
241 'photo' => $item['owner-avatar'], 'network' => $item['network']];
243 $item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, false, $default);
246 if (empty($item['psid'])) {
247 $item['psid'] = PermissionSet::getIdFromACL(
256 $item['allow_cid'] = null;
257 $item['allow_gid'] = null;
258 $item['deny_cid'] = null;
259 $item['deny_gid'] = null;
261 if ($item['post-type'] == 0) {
262 if (!empty($item['type']) && ($item['type'] == 'note')) {
263 $item['post-type'] = Item::PT_PERSONAL_NOTE;
264 } elseif (!empty($item['type']) && ($item['type'] == 'photo')) {
265 $item['post-type'] = Item::PT_IMAGE;
266 } elseif (!empty($item['bookmark']) && $item['bookmark']) {
267 $item['post-type'] = Item::PT_PAGE;
271 self::createLanguage($item);
273 if (!empty($item['icid']) && !empty($item['language'])) {
274 DBA::update('item-content', ['language' => $item['language']], ['id' => $item['icid']]);
276 unset($item['language']);
278 Item::update($item, ['id' => $id]);
284 DI::config()->set("system", "post_update_version_1279_id", $id);
286 Logger::log("Processed rows: " . $rows . " - last processed item: " . $id, Logger::DEBUG);
288 if ($start_id == $id) {
289 // Set all deprecated fields to "null" if they contain an empty string
290 $nullfields = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'postopts', 'inform', 'type',
291 'bookmark', 'file', 'location', 'coord', 'tag', 'plink', 'title', 'content-warning',
292 'body', 'app', 'verb', 'object-type', 'object', 'target-type', 'target',
293 'author-name', 'author-link', 'author-avatar', 'owner-name', 'owner-link', 'owner-avatar',
294 'rendered-hash', 'rendered-html'];
295 foreach ($nullfields as $field) {
296 $fields = [$field => null];
297 $condition = [$field => ''];
298 Logger::log("Setting '" . $field . "' to null if empty.", Logger::DEBUG);
299 // Important: This has to be a "DBA::update", not a "Item::update"
300 DBA::update('item', $fields, $condition);
303 DI::config()->set("system", "post_update_version", 1279);
304 Logger::log("Done", Logger::DEBUG);
311 private static function createLanguage(&$item)
313 if (empty($item['postopts'])) {
317 $opts = explode(',', $item['postopts']);
321 foreach ($opts as $opt) {
322 if (strstr($opt, 'lang=')) {
323 $language = substr($opt, 5);
329 if (empty($language)) {
333 if (!empty($postopts)) {
334 $item['postopts'] = implode(',', $postopts);
336 $item['postopts'] = null;
339 $lang_pairs = explode(':', $language);
343 foreach ($lang_pairs as $pair) {
344 $lang_pair_arr = explode(';', $pair);
345 if (count($lang_pair_arr) == 2) {
346 $lang_arr[$lang_pair_arr[0]] = $lang_pair_arr[1];
350 $item['language'] = json_encode($lang_arr);
354 * update item-uri data. Prerequisite for the next item structure update.
356 * @return bool "true" when the job is done
357 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
359 private static function update1281()
361 // Was the script completed?
362 if (DI::config()->get("system", "post_update_version") >= 1281) {
366 $id = DI::config()->get("system", "post_update_version_1281_id", 0);
368 Logger::log("Start from item " . $id, Logger::DEBUG);
370 $fields = ['id', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id', 'thr-parent', 'thr-parent-id'];
374 $condition = ["`id` > ?", $id];
375 $params = ['order' => ['id'], 'limit' => 10000];
376 $items = DBA::select('item', $fields, $condition, $params);
378 if (DBA::errorNo() != 0) {
379 Logger::log('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
383 while ($item = DBA::fetch($items)) {
386 if (empty($item['uri'])) {
389 } elseif (empty($item['uri-id'])) {
390 $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
393 if (empty($item['parent-uri'])) {
394 $item['parent-uri-id'] = $item['uri-id'];
395 } elseif (empty($item['parent-uri-id'])) {
396 $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
399 // Very old items don't have this field
400 if (empty($item['thr-parent'])) {
401 $item['thr-parent-id'] = $item['parent-uri-id'];
402 } elseif (empty($item['thr-parent-id'])) {
403 $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
407 unset($item['guid']);
409 unset($item['parent-uri']);
410 unset($item['thr-parent']);
412 DBA::update('item', $item, ['id' => $id]);
418 DI::config()->set("system", "post_update_version_1281_id", $id);
420 Logger::log("Processed rows: " . $rows . " - last processed item: " . $id, Logger::DEBUG);
422 if ($start_id == $id) {
423 Logger::log("Updating item-uri in item-activity", Logger::DEBUG);
424 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");
426 Logger::log("Updating item-uri in item-content", Logger::DEBUG);
427 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");
429 DI::config()->set("system", "post_update_version", 1281);
430 Logger::log("Done", Logger::DEBUG);
438 * Set the delivery queue count to a negative value for all items preceding the feature.
440 * @return bool "true" when the job is done
441 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
443 private static function update1297()
445 // Was the script completed?
446 if (DI::config()->get('system', 'post_update_version') >= 1297) {
450 $max_item_delivery_data = DBA::selectFirst('item-delivery-data', ['iid'], ['queue_count > 0 OR queue_done > 0'], ['order' => ['iid']]);
451 $max_iid = $max_item_delivery_data['iid'];
453 Logger::info('Start update1297 with max iid: ' . $max_iid);
455 $condition = ['`queue_count` = 0 AND `iid` < ?', $max_iid];
457 DBA::update('item-delivery-data', ['queue_count' => -1], $condition);
459 if (DBA::errorNo() != 0) {
460 Logger::error('Database error ' . DBA::errorNo() . ':' . DBA::errorMessage());
464 Logger::info('Processed rows: ' . DBA::affectedRows());
466 DI::config()->set('system', 'post_update_version', 1297);
468 Logger::info('Done');
473 * Remove contact duplicates
475 * @return bool "true" when the job is done
476 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
478 private static function update1322()
480 // Was the script completed?
481 if (DI::config()->get('system', 'post_update_version') >= 1322) {
485 Logger::info('Start');
487 $contacts = DBA::p("SELECT `nurl`, `uid` FROM `contact`
488 WHERE EXISTS (SELECT `nurl` FROM `contact` AS `c2`
489 WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` IN (?, ?, ?) AND NOT `deleted`)
490 AND (`network` IN (?, ?, ?) OR (`uid` = ?)) AND NOT `deleted` GROUP BY `nurl`, `uid`",
491 Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB,
492 Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, 0);
494 while ($contact = DBA::fetch($contacts)) {
495 Logger::info('Remove duplicates', ['nurl' => $contact['nurl'], 'uid' => $contact['uid']]);
496 Contact::removeDuplicates($contact['nurl'], $contact['uid']);
499 DBA::close($contact);
500 DI::config()->set('system', 'post_update_version', 1322);
502 Logger::info('Done');
508 * update user-item data with notifications
510 * @return bool "true" when the job is done
511 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
513 private static function update1329()
515 // Was the script completed?
516 if (DI::config()->get('system', 'post_update_version') >= 1329) {
520 $id = DI::config()->get('system', 'post_update_version_1329_id', 0);
522 Logger::info('Start', ['item' => $id]);
526 $condition = ["`id` > ?", $id];
527 $params = ['order' => ['id'], 'limit' => 10000];
528 $items = DBA::select('item', ['id'], $condition, $params);
530 if (DBA::errorNo() != 0) {
531 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
535 while ($item = DBA::fetch($items)) {
538 UserItem::setNotification($item['id']);
544 DI::config()->set('system', 'post_update_version_1329_id', $id);
546 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
548 if ($start_id == $id) {
549 DI::config()->set('system', 'post_update_version', 1329);
550 Logger::info('Done');
558 * Fill the "tag" table with tags and mentions from the body
560 * @return bool "true" when the job is done
561 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
563 private static function update1341()
565 // Was the script completed?
566 if (DI::config()->get('system', 'post_update_version') >= 1341) {
570 $id = DI::config()->get('system', 'post_update_version_1341_id', 0);
572 Logger::info('Start', ['item' => $id]);
576 $items = DBA::p("SELECT `uri-id`,`body` FROM `item-content` WHERE
577 (`body` LIKE ? OR `body` LIKE ? OR `body` LIKE ?) AND `uri-id` >= ?
578 ORDER BY `uri-id` LIMIT 100000", '%#%', '%@%', '%!%', $id);
580 if (DBA::errorNo() != 0) {
581 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
585 while ($item = DBA::fetch($items)) {
586 Tag::storeFromBody($item['uri-id'], $item['body'], '#!@', false);
587 $id = $item['uri-id'];
589 if ($rows % 1000 == 0) {
590 DI::config()->set('system', 'post_update_version_1341_id', $id);
595 DI::config()->set('system', 'post_update_version_1341_id', $id);
597 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
599 // When there are less than 1,000 items processed this means that we reached the end
600 // The other entries will then be processed with the regular functionality
602 DI::config()->set('system', 'post_update_version', 1341);
603 Logger::info('Done');
611 * Fill the "tag" table with tags and mentions from the "term" table
613 * @return bool "true" when the job is done
614 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
616 private static function update1342()
618 // Was the script completed?
619 if (DI::config()->get('system', 'post_update_version') >= 1342) {
623 $id = DI::config()->get('system', 'post_update_version_1342_id', 0);
625 Logger::info('Start', ['item' => $id]);
629 $terms = DBA::p("SELECT `term`.`tid`, `item`.`uri-id`, `term`.`type`, `term`.`term`, `term`.`url`, `item-content`.`body`
631 INNER JOIN `item` ON `item`.`id` = `term`.`oid`
632 INNER JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`
633 WHERE term.type IN (?, ?, ?, ?) AND `tid` >= ? ORDER BY `tid` LIMIT 100000",
634 Tag::HASHTAG, Tag::MENTION, Tag::EXCLUSIVE_MENTION, Tag::IMPLICIT_MENTION, $id);
636 if (DBA::errorNo() != 0) {
637 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
641 while ($term = DBA::fetch($terms)) {
642 if (($term['type'] == Tag::MENTION) && !empty($term['url']) && !strstr($term['body'], $term['url'])) {
643 $condition = ['nurl' => Strings::normaliseLink($term['url']), 'uid' => 0, 'deleted' => false];
644 $contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
645 if (!DBA::isResult($contact)) {
646 $ssl_url = str_replace('http://', 'https://', $term['url']);
647 $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $term['url'], Strings::normaliseLink($term['url']), $ssl_url, 0];
648 $contact = DBA::selectFirst('contact', ['url', 'alias'], $condition, ['order' => ['id']]);
651 if (DBA::isResult($contact) && (!strstr($term['body'], $contact['url']) && (empty($contact['alias']) || !strstr($term['body'], $contact['alias'])))) {
652 $term['type'] = Tag::IMPLICIT_MENTION;
656 Tag::store($term['uri-id'], $term['type'], $term['term'], $term['url'], false);
660 if ($rows % 1000 == 0) {
661 DI::config()->set('system', 'post_update_version_1342_id', $id);
666 DI::config()->set('system', 'post_update_version_1342_id', $id);
668 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
670 // When there are less than 1,000 items processed this means that we reached the end
671 // The other entries will then be processed with the regular functionality
673 DI::config()->set('system', 'post_update_version', 1342);
674 Logger::info('Done');
682 * Fill the "post-delivery-data" table with data from the "item-delivery-data" table
684 * @return bool "true" when the job is done
685 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
687 private static function update1345()
689 // Was the script completed?
690 if (DI::config()->get('system', 'post_update_version') >= 1345) {
694 $id = DI::config()->get('system', 'post_update_version_1345_id', 0);
696 Logger::info('Start', ['item' => $id]);
700 $deliveries = DBA::p("SELECT `uri-id`, `iid`, `item-delivery-data`.`postopts`, `item-delivery-data`.`inform`,
701 `queue_count`, `queue_done`, `activitypub`, `dfrn`, `diaspora`, `ostatus`, `legacy_dfrn`, `queue_failed`
702 FROM `item-delivery-data`
703 INNER JOIN `item` ON `item`.`id` = `item-delivery-data`.`iid`
704 WHERE `iid` >= ? ORDER BY `iid` LIMIT 10000", $id);
706 if (DBA::errorNo() != 0) {
707 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
711 while ($delivery = DBA::fetch($deliveries)) {
712 $id = $delivery['iid'];
713 unset($delivery['iid']);
714 DBA::insert('post-delivery-data', $delivery, true);
717 DBA::close($deliveries);
719 DI::config()->set('system', 'post_update_version_1345_id', $id);
721 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
723 // When there are less than 100 items processed this means that we reached the end
724 // The other entries will then be processed with the regular functionality
726 DI::config()->set('system', 'post_update_version', 1345);
727 Logger::info('Done');
735 * Fill the "tag" table with tags and mentions from the "term" table
737 * @return bool "true" when the job is done
738 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
740 private static function update1346()
742 // Was the script completed?
743 if (DI::config()->get('system', 'post_update_version') >= 1346) {
747 $id = DI::config()->get('system', 'post_update_version_1346_id', 0);
749 Logger::info('Start', ['item' => $id]);
753 $terms = DBA::select('term', ['oid'],
754 ["`type` IN (?, ?) AND `oid` >= ?", Category::CATEGORY, Category::FILE, $id],
755 ['order' => ['oid'], 'limit' => 1000, 'group_by' => ['oid']]);
757 if (DBA::errorNo() != 0) {
758 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
762 while ($term = DBA::fetch($terms)) {
763 $item = Item::selectFirst(['uri-id', 'uid'], ['id' => $term['oid']]);
764 if (!DBA::isResult($item)) {
768 $file = Term::fileTextFromItemId($term['oid']);
770 Category::storeTextByURIId($item['uri-id'], $item['uid'], $file);
775 if ($rows % 100 == 0) {
776 DI::config()->set('system', 'post_update_version_1346_id', $id);
781 DI::config()->set('system', 'post_update_version_1346_id', $id);
783 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
785 // When there are less than 10 items processed this means that we reached the end
786 // The other entries will then be processed with the regular functionality
788 DI::config()->set('system', 'post_update_version', 1346);
789 Logger::info('Done');
797 * update the "vid" (verb) field in the item table
799 * @return bool "true" when the job is done
800 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
801 * @throws \ImagickException
803 private static function update1347()
805 // Was the script completed?
806 if (DI::config()->get("system", "post_update_version") >= 1347) {
810 $id = DI::config()->get("system", "post_update_version_1347_id", 0);
812 Logger::info('Start', ['item' => $id]);
816 $condition = ["`id` > ? AND `vid` IS NULL", $id];
817 $params = ['order' => ['id'], 'limit' => 10000];
818 $items = Item::select(['id', 'verb'], $condition, $params);
820 if (DBA::errorNo() != 0) {
821 Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
825 while ($item = Item::fetch($items)) {
828 DBA::update('item', ['vid' => Verb::getID($item['verb'])], ['id' => $item['id']]);
834 DI::config()->set("system", "post_update_version_1347_id", $id);
836 Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
838 if ($start_id == $id) {
839 DI::config()->set("system", "post_update_version", 1347);
840 Logger::info('Done');