- // Update the thread table from the item table
- $r = q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
- SET `thread`.`author-id` = `item`.`author-id`,
- `thread`.`owner-id` = `item`.`owner-id`
- WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND
- (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
-
- logger("Updated threads", LOGGER_DEBUG);
- if (DBM::is_result($r)) {
- Config::set("system", "post_update_version", 1198);
- logger("Done", LOGGER_DEBUG);
- return true;
- }
- return false;
- }
-
- logger("Query done", LOGGER_DEBUG);
-
- $item_arr = [];
- foreach ($r as $item) {
- $index = $item["author-link"]."-".$item["owner-link"]."-".$item["uid"];
- $item_arr[$index] = ["author-link" => $item["author-link"],
- "owner-link" => $item["owner-link"],
- "uid" => $item["uid"]];
- }
-
- // Set the "author-id" and "owner-id" in the item table and add a new public contact entry if needed
- foreach ($item_arr as $item) {
- $default = ['url' => $item['author-link'], 'name' => $item['author-name'],
- 'photo' => $item['author-avatar'], 'network' => $item['network']];
- $author_id = Contact::getIdForURL($item["author-link"], 0, false, $default);
-
- $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
- 'photo' => $item['owner-avatar'], 'network' => $item['network']];
- $owner_id = Contact::getIdForURL($item["owner-link"], 0, false, $default);
-
- if ($author_id == 0) {
- $author_id = -1;
- }
- if ($owner_id == 0) {
- $owner_id = -1;
- }
- dba::update('item', ['author-id' => $author_id, 'owner-id' => $owner_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'owner-link' => $item['owner-link'], 'author-id' => 0, 'owner-id' => 0]);
- }
-
- logger("Updated items", LOGGER_DEBUG);
- return false;