1
1
Fork 0

Moved expiring of item content

This commit is contained in:
Michael 2018-07-29 03:54:34 +00:00
parent 489d3daa94
commit dc9b10fb09
2 changed files with 16 additions and 18 deletions

View file

@ -979,7 +979,8 @@ class Item extends BaseObject
// locate item to be deleted
$fields = ['id', 'uri', 'uid', 'parent', 'parent-uri', 'origin',
'deleted', 'file', 'resource-id', 'event-id', 'attach',
'verb', 'object-type', 'object', 'target', 'contact-id'];
'verb', 'object-type', 'object', 'target', 'contact-id',
'icid', 'iaid', 'psid'];
$item = self::selectFirst($fields, ['id' => $item_id]);
if (!DBA::isResult($item)) {
logger('Item with ID ' . $item_id . " hasn't been found.", LOGGER_DEBUG);
@ -1042,11 +1043,7 @@ class Item extends BaseObject
self::deleteTagsFromItem($item);
// Set the item to "deleted"
// This erasing of item content is superfluous for items with a matching item-content.
// But for the next time we will still have old content in the item table.
$item_fields = ['deleted' => true, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow(),
'body' => '', 'title' => '', 'content-warning' => '', 'rendered-hash' => '', 'rendered-html' => '',
'object' => '', 'target' => '', 'tag' => '', 'postopts' => '', 'attach' => '', 'file' => ''];
$item_fields = ['deleted' => true, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
DBA::update('item', $item_fields, ['id' => $item['id']]);
Term::insertFromTagFieldByItemId($item['id'], '');
@ -1059,6 +1056,18 @@ class Item extends BaseObject
DBA::delete('item-delivery-data', ['iid' => $item['id']]);
if (!empty($item['iaid']) && !DBA::exists('item', ['iaid' => $item['iaid'], 'deleted' => false])) {
DBA::delete('item-activity', ['id' => $item['iaid']]);
}
if (!empty($item['icid']) && !DBA::exists('item', ['icid' => $item['icid'], 'deleted' => false])) {
DBA::delete('item-content', ['id' => $item['icid']]);
}
// When the permission set will be used in photo and events as well,
// this query here needs to be extended.
if (!empty($item['psid']) && !DBA::exists('item', ['psid' => $item['psid'], 'deleted' => false])) {
DBA::delete('permissionset', ['id' => $item['psid']]);
}
// If it's the parent of a comment thread, kill all the kids
if ($item['id'] == $item['parent']) {
self::delete(['parent' => $item['parent'], 'deleted' => false], $priority);

View file

@ -29,20 +29,9 @@ class Expire
logger('Delete expired items', LOGGER_DEBUG);
// physically remove anything that has been deleted for more than two months
$condition = ["`deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY"];
$rows = DBA::select('item', ['id', 'iaid', 'icid', 'psid'], $condition);
$rows = DBA::select('item', ['id'], $condition);
while ($row = DBA::fetch($rows)) {
DBA::delete('item', ['id' => $row['id']]);
if (!empty($row['iaid']) && !DBA::exists('item', ['iaid' => $row['iaid']])) {
DBA::delete('item-activity', ['id' => $row['iaid']]);
}
if (!empty($row['icid']) && !DBA::exists('item', ['icid' => $row['icid']])) {
DBA::delete('item-content', ['id' => $row['icid']]);
}
// When the permission set will be used in photo and events as well.
// this query here needs to be extended.
if (!empty($row['psid']) && !DBA::exists('item', ['psid' => $row['psid']])) {
DBA::delete('permissionset', ['id' => $row['psid']]);
}
}
DBA::close($rows);