- while ($item = dba::fetch($items)) {
- if (!empty($item['plink'])) {
- $content_fields['plink'] = $item['plink'];
+ while ($item = DBA::fetch($items)) {
+
+ // This part here can safely be removed when the legacy fields in the item had been removed
+ if (empty($item['uri-hash']) && !empty($item['uri']) && !empty($item['created'])) {
+
+ // Fetch the uri-hash from an existing item entry if there is one
+ $item_condition = ["`uri` = ? AND `uri-hash` != ''", $item['uri']];
+ $existing = DBA::selectfirst('item', ['uri-hash'], $item_condition);
+ if (DBA::isResult($existing)) {
+ $item['uri-hash'] = $existing['uri-hash'];
+ } else {
+ $item['uri-hash'] = self::itemHash($item['uri'], $item['created']);
+ }
+
+ DBA::update('item', ['uri-hash' => $item['uri-hash']], ['id' => $item['id']]);
+ DBA::update('item-activity', ['uri-hash' => $item['uri-hash']], ["`uri` = ? AND `uri-hash` = ''", $item['uri']]);
+ DBA::update('item-content', ['uri-plink-hash' => $item['uri-hash']], ["`uri` = ? AND `uri-plink-hash` = ''", $item['uri']]);