+ // 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']]);
+ }
+
+ if (!empty($item['iaid']) || (!empty($content_fields['verb']) && (self::activityToIndex($content_fields['verb']) >= 0))) {
+ if (!empty($item['iaid'])) {
+ $update_condition = ['id' => $item['iaid']];
+ } else {
+ $update_condition = ['uri-hash' => $item['uri-hash']];
+ }
+ self::updateActivity($content_fields, $update_condition);
+
+ if (empty($item['iaid'])) {
+ $item_activity = DBA::selectFirst('item-activity', ['id'], ['uri-hash' => $item['uri-hash']]);
+ if (DBA::isResult($item_activity)) {
+ $item_fields = ['iaid' => $item_activity['id'], 'icid' => null];
+ foreach (self::MIXED_CONTENT_FIELDLIST as $field) {
+ if (self::isLegacyMode()) {
+ $item_fields[$field] = null;
+ } else {
+ unset($item_fields[$field]);
+ }
+ }
+ DBA::update('item', $item_fields, ['id' => $item['id']]);
+
+ if (!empty($item['icid']) && !DBA::exists('item', ['icid' => $item['icid']])) {
+ DBA::delete('item-content', ['id' => $item['icid']]);
+ }
+ }
+ } elseif (!empty($item['icid'])) {
+ DBA::update('item', ['icid' => null], ['id' => $item['id']]);
+
+ if (!DBA::exists('item', ['icid' => $item['icid']])) {
+ DBA::delete('item-content', ['id' => $item['icid']]);
+ }
+ }
+ } else {
+ if (!empty($item['icid'])) {
+ $update_condition = ['id' => $item['icid']];
+ } else {
+ $update_condition = ['uri-plink-hash' => $item['uri-hash']];
+ }
+ self::updateContent($content_fields, $update_condition);
+
+ if (empty($item['icid'])) {
+ $item_content = DBA::selectFirst('item-content', [], ['uri-plink-hash' => $item['uri-hash']]);
+ if (DBA::isResult($item_content)) {
+ $item_fields = ['icid' => $item_content['id']];
+ // Clear all fields in the item table that have a content in the item-content table
+ foreach ($item_content as $field => $content) {
+ if (in_array($field, self::MIXED_CONTENT_FIELDLIST) && !empty($item_content[$field])) {
+ if (self::isLegacyMode()) {
+ $item_fields[$field] = null;
+ } else {
+ unset($item_fields[$field]);
+ }
+ }
+ }
+ DBA::update('item', $item_fields, ['id' => $item['id']]);
+ }
+ }