We now only store the content in item-content

This commit is contained in:
Michael 2018-06-24 23:09:13 +00:00
parent 58d61810ea
commit 941bab1096

View file

@ -72,7 +72,7 @@ class Item extends BaseObject
// Fetch data from the item-content table whenever there is content there // Fetch data from the item-content table whenever there is content there
foreach (self::CONTENT_FIELDLIST as $field) { foreach (self::CONTENT_FIELDLIST as $field) {
if (isset($row[$field]) && !empty($row['item-content-' . $field])) { if (!empty($row['item-content-' . $field])) {
$row[$field] = $row['item-content-' . $field]; $row[$field] = $row['item-content-' . $field];
unset($row['item-content-' . $field]); unset($row['item-content-' . $field]);
} }
@ -557,6 +557,15 @@ class Item extends BaseObject
// And we have to execute this query before the update to ensure to fetch the same data. // And we have to execute this query before the update to ensure to fetch the same data.
$items = dba::select('item', ['id', 'origin', 'uri'], $condition); $items = dba::select('item', ['id', 'origin', 'uri'], $condition);
$content_fields = [];
foreach (self::CONTENT_FIELDLIST as $field) {
if (isset($fields[$field])) {
$content_fields[$field] = $fields[$field];
unset($fields[$field]);
}
}
if (!empty($fields)) {
$success = dba::update('item', $fields, $condition); $success = dba::update('item', $fields, $condition);
if (!$success) { if (!$success) {
@ -564,11 +573,13 @@ class Item extends BaseObject
dba::rollback(); dba::rollback();
return false; return false;
} }
}
// When there is no content for the "old" item table, this will count the fetched items
$rows = dba::affected_rows(); $rows = dba::affected_rows();
while ($item = dba::fetch($items)) { while ($item = dba::fetch($items)) {
self::updateContent($fields, ['uri' => $item['uri']]); self::updateContent($content_fields, ['uri' => $item['uri']]);
Term::insertFromTagFieldByItemId($item['id']); Term::insertFromTagFieldByItemId($item['id']);
Term::insertFromFileFieldByItemId($item['id']); Term::insertFromFileFieldByItemId($item['id']);
self::updateThread($item['id']); self::updateThread($item['id']);
@ -1437,17 +1448,16 @@ class Item extends BaseObject
{ {
logger('Insert content for URI '.$item['uri']); logger('Insert content for URI '.$item['uri']);
$fields = ['uri' => $item['uri'], 'title' => $item['title'], $fields = ['uri' => $item['uri'], 'plink' => $item['plink'],
'content-warning' => $item['content-warning'],
'body' => $item['body'], 'location' => $item['location'],
'coord' => $item['coord'], 'app' => $item['app'],
'rendered-hash' => $item['rendered-hash'],
'rendered-html' => $item['rendered-html'],
'object-type' => $item['object-type'],
'object' => $item['object'], 'target-type' => $item['target-type'],
'target' => $item['target'], 'plink' => $item['plink'],
'uri-plink-hash' => hash('sha1', $item['plink']).hash('sha1', $item['uri'])]; 'uri-plink-hash' => hash('sha1', $item['plink']).hash('sha1', $item['uri'])];
foreach (self::CONTENT_FIELDLIST as $field) {
if (isset($item[$field])) {
$fields[$field] = $item[$field];
unset($item[$field]);
}
}
dba::insert('item-content', $fields, true); dba::insert('item-content', $fields, true);
} }