Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 42 additions & 71 deletions lib/Share/RoomShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,45 +353,31 @@ public function deleteFromSelf(IShare $share, $recipient): void {
$this->cleanSharesByIdCache();

// Check if there is a userroom share
$qb = $this->dbConnection->getQueryBuilder();
$stmt = $qb->select(['id', 'permissions'])
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM)))
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
))
->executeQuery();

$data = $stmt->fetch();
$stmt->closeCursor();

if ($data === false) {
// No userroom share yet. Create one.
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert('share')
->values([
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERROOM),
'share_with' => $qb->createNamedParameter($recipient),
'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
'parent' => $qb->createNamedParameter($share->getId()),
'item_type' => $qb->createNamedParameter($share->getNodeType()),
'item_source' => $qb->createNamedParameter($share->getNodeId()),
'file_source' => $qb->createNamedParameter($share->getNodeId()),
'file_target' => $qb->createNamedParameter($share->getTarget()),
'permissions' => $qb->createNamedParameter(0),
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
])->executeStatement();
} elseif ($data['permissions'] !== 0) {
$this->dbConnection->beginTransaction();
$inserted = $this->dbConnection->insertIfNotExist('*PREFIX*share', [
'share_type' => self::SHARE_TYPE_USERROOM,
'share_with' => $recipient,
'uid_owner' => $share->getShareOwner(),
'uid_initiator' => $share->getSharedBy(),
'parent' => $share->getId(),
'item_type' => $share->getNodeType(),
'item_source' => $share->getNodeId(),
'file_source' => $share->getNodeId(),
'file_target' => $share->getTarget(),
'permissions' => 0,
'stime' => $share->getShareTime()->getTimestamp(),
], ['share_type', 'share_with', 'parent']);
$this->dbConnection->commit();

if ($inserted === 0) {
Comment on lines +356 to +372
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately wrapping insertIfNotExists in a transaction does not give more atomicity

nextcloud/server#54041 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While that is sad, the reduced roundtrip time should help
And the change here in deleteFromSelf which updates ALL share_type+with+parent items instead of the first one found by ID should solve the issue we are facing at the moment:

  • After using "Unshare from self" and reloading the page, the share is visible again.
  • THat should be fixed, as now all items have permissions = 0 and are not mounted

// Already a userroom share. Update it.
$qb = $this->dbConnection->getQueryBuilder();
$qb->update('share')
->set('permissions', $qb->createNamedParameter(0))
->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
->executeStatement();
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM)))
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
$qb->executeStatement();
}
}

Expand Down Expand Up @@ -451,46 +437,31 @@ public function move(IShare $share, $recipient): IShare {
$this->cleanSharesByIdCache();

// Check if there is a userroom share
$qb = $this->dbConnection->getQueryBuilder();
$stmt = $qb->select('id')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM)))
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
))
->setMaxResults(1)
->executeQuery();

$data = $stmt->fetch();
$stmt->closeCursor();

if ($data === false) {
// No userroom share yet. Create one.
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert('share')
->values([
'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERROOM),
'share_with' => $qb->createNamedParameter($recipient),
'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
'parent' => $qb->createNamedParameter($share->getId()),
'item_type' => $qb->createNamedParameter($share->getNodeType()),
'item_source' => $qb->createNamedParameter($share->getNodeId()),
'file_source' => $qb->createNamedParameter($share->getNodeId()),
'file_target' => $qb->createNamedParameter($share->getTarget()),
'permissions' => $qb->createNamedParameter($share->getPermissions()),
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
])->executeStatement();
} else {
$this->dbConnection->beginTransaction();
$inserted = $this->dbConnection->insertIfNotExist('*PREFIX*share', [
'share_type' => self::SHARE_TYPE_USERROOM,
'share_with' => $recipient,
'uid_owner' => $share->getShareOwner(),
'uid_initiator' => $share->getSharedBy(),
'parent' => $share->getId(),
'item_type' => $share->getNodeType(),
'item_source' => $share->getNodeId(),
'file_source' => $share->getNodeId(),
'file_target' => $share->getTarget(),
'permissions' => $share->getPermissions(),
'stime' => $share->getShareTime()->getTimestamp(),
], ['share_type', 'share_with', 'parent']);
$this->dbConnection->commit();

if ($inserted === 0) {
// Already a userroom share. Update it.
$qb = $this->dbConnection->getQueryBuilder();
$qb->update('share')
->set('file_target', $qb->createNamedParameter($share->getTarget()))
->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
->executeStatement();
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM)))
->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
$qb->executeStatement();
}

return $share;
Expand Down
Loading