use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
+use Friendica\Model\Contact;
+use Friendica\Model\PermissionSet;
+use Friendica\Model\ItemURI;
use Friendica\Object\Image;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
$fields['item'] = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid',
'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid',
- 'created', 'edited', 'commented', 'received', 'changed',
- 'resource-id', 'event-id', 'tag', 'attach', 'post-type',
- 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'psid',
+ 'created', 'edited', 'commented', 'received', 'changed', 'psid',
+ 'resource-id', 'event-id', 'tag', 'attach', 'post-type', 'file',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global',
'id' => 'item_id', 'network', 'icid', 'iaid', 'id' => 'internal-iid',
$fields['item-delivery-data'] = self::DELIVERY_DATA_FIELDLIST;
+ $fields['permissionset'] = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
+
$fields['author'] = ['url' => 'author-link', 'name' => 'author-name',
'thumb' => 'author-avatar', 'nick' => 'author-nick', 'network' => 'author-network'];
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = $master_table.`author-id` AND NOT `author`.`blocked`
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked`
LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d",
- CONTACT_IS_SHARING, CONTACT_IS_FRIEND, GRAVITY_PARENT, intval($uid));
+ Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid));
} else {
if (strpos($sql_commands, "`contact`.") !== false) {
$joins .= "LEFT JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`";
$joins .= " LEFT JOIN `item-delivery-data` ON `item-delivery-data`.`iid` = `item`.`id`";
}
+ if (strpos($sql_commands, "`permissionset`.") !== false) {
+ $joins .= " LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`";
+ }
+
if ((strpos($sql_commands, "`parent-item`.") !== false) || (strpos($sql_commands, "`parent-author`.") !== false)) {
$joins .= " STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`";
}
// 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);
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'], '');
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']], ['cascade' => false]);
+ }
+ if (!empty($item['icid']) && !DBA::exists('item', ['icid' => $item['icid'], 'deleted' => false])) {
+ DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]);
+ }
+ // 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']], ['cascade' => false]);
+ }
+
// 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);
$item['guid'] = self::guid($item, $notify);
$item['uri'] = notags(trim(defaults($item, 'uri', self::newURI($item['uid'], $item['guid']))));
+ // Store URI data
+ $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
+
// Store conversation data
$item = Conversation::insert($item);
$item['uri-hash'] = $existing['uri-hash'];
}
- self::addLanguageToItemArray($item);
-
$item['wall'] = intval(defaults($item, 'wall', 0));
$item['extid'] = trim(defaults($item, 'extid', ''));
$item['author-name'] = trim(defaults($item, 'author-name', ''));
return 0;
}
+ self::addLanguageToItemArray($item);
+
// Items cannot be stored before they happen ...
if ($item['created'] > DateTimeFormat::utcNow()) {
$item['created'] = DateTimeFormat::utcNow();
}
}
+ $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
+ $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
+
$condition = ["`uri` = ? AND `network` IN (?, ?) AND `uid` = ?",
$item['uri'], $item['network'], NETWORK_DFRN, $item['uid']];
if (self::exists($condition)) {
$files = '';
}
- // Creates the permission set
- // Currently we only store the data but don't using it
+ // Creates or assigns the permission set
$item['psid'] = PermissionSet::fetchIDForPost($item);
// We are doing this outside of the transaction to avoid timing problems
$users = [];
$condition = ["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)",
- $parent['owner-id'], CONTACT_IS_SHARING, CONTACT_IS_FRIEND];
+ $parent['owner-id'], Contact::SHARING, Contact::FRIEND];
+
$contacts = DBA::select('contact', ['uid'], $condition);
+
while ($contact = DBA::fetch($contacts)) {
$users[$contact['uid']] = $contact['uid'];
}
return;
}
- $community_page = (($user['page-flags'] == PAGE_COMMUNITY) ? true : false);
- $prvgroup = (($user['page-flags'] == PAGE_PRVGROUP) ? true : false);
+ $community_page = (($user['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
+ $prvgroup = (($user['page-flags'] == Contact::PAGE_PRVGROUP) ? true : false);
$item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id]);
if (!DBA::isResult($item)) {
$condition[] = $days;
}
- $items = self::select(['file', 'resource-id', 'starred', 'type', 'id'], $condition);
+ $items = self::select(['file', 'resource-id', 'starred', 'type', 'id', 'post-type'], $condition);
if (!DBA::isResult($items)) {
return;
continue;
} elseif (!$expire_starred && intval($item['starred'])) {
continue;
- } elseif (!$expire_notes && $item['type'] == 'note') {
+ } elseif (!$expire_notes && (($item['type'] == 'note') || ($item['post-type'] == Item::PT_PERSONAL_NOTE))) {
continue;
- } elseif (!$expire_items && $item['type'] != 'note') {
+ } elseif (!$expire_items && ($item['type'] != 'note') && ($item['post-type'] != Item::PT_PERSONAL_NOTE)) {
continue;
}
// If it exists, mark it as deleted
if (DBA::isResult($like_item)) {
- // Already voted, undo it
- $fields = ['deleted' => true, 'unseen' => true, 'changed' => DateTimeFormat::utcNow()];
- /// @todo Consider using self::update - but before doing so, check the side effects
- DBA::update('item', $fields, ['id' => $like_item['id']]);
-
- // Clean up the Diaspora signatures for this like
- DBA::delete('sign', ['iid' => $like_item['id']]);
-
- Worker::add(PRIORITY_HIGH, "Notifier", "like", $like_item['id']);
+ self::deleteById($like_item['id']);
if (!$event_verb_flag || $like_item['verb'] == $activity) {
return true;