Skip to content

Commit 809a59a

Browse files
grnd-altbackportbot[bot]
authored andcommitted
chore: wrap share updates in transaction
Signed-off-by: grnd-alt <git@belakkaf.net>
1 parent e208882 commit 809a59a

File tree

1 file changed

+65
-58
lines changed

1 file changed

+65
-58
lines changed

lib/Sharing/DeckShareProvider.php

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -289,55 +289,62 @@ private function applyBoardPermission($share, $permissions, $userId) {
289289
* @inheritDoc
290290
*/
291291
public function update(IShare $share) {
292-
$qb = $this->dbConnection->getQueryBuilder();
293-
$qb->update('share')
294-
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
295-
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
296-
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
297-
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
298-
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
299-
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
300-
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE));
301-
302-
$shareAttributes = $this->formatShareAttributes($share->getAttributes());
303-
if ($shareAttributes !== null) {
304-
$qb->set('attributes', $qb->createNamedParameter($shareAttributes));
305-
}
292+
$this->dbConnection->beginTransaction();
293+
try {
294+
$qb = $this->dbConnection->getQueryBuilder();
295+
$qb->update('share')
296+
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
297+
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
298+
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
299+
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
300+
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
301+
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
302+
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE));
303+
304+
$shareAttributes = $this->formatShareAttributes($share->getAttributes());
305+
if ($shareAttributes !== null) {
306+
$qb->set('attributes', $qb->createNamedParameter($shareAttributes));
307+
}
306308

307-
$qb->executeStatement();
309+
$qb->executeStatement();
308310

309-
/*
310-
* Update all user defined group shares
311-
*/
312-
$qb = $this->dbConnection->getQueryBuilder();
313-
$qb->update('share')
314-
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
315-
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
316-
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
317-
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
318-
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
319-
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE));
320-
321-
if ($shareAttributes !== null) {
322-
$qb->set('attributes', $qb->createNamedParameter($shareAttributes));
323-
}
311+
/*
312+
* Update all user defined group shares
313+
*/
314+
$qb = $this->dbConnection->getQueryBuilder();
315+
$qb->update('share')
316+
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
317+
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
318+
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
319+
->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
320+
->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
321+
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE));
322+
323+
if ($shareAttributes !== null) {
324+
$qb->set('attributes', $qb->createNamedParameter($shareAttributes));
325+
}
324326

325-
$qb->executeStatement();
327+
$qb->executeStatement();
326328

327-
/*
328-
* Now update the permissions for all children that have not set it to 0
329-
*/
330-
$qb = $this->dbConnection->getQueryBuilder();
331-
$qb->update('share')
332-
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
333-
->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
334-
->set('permissions', $qb->createNamedParameter($share->getPermissions()));
329+
/*
330+
* Now update the permissions for all children that have not set it to 0
331+
*/
332+
$qb = $this->dbConnection->getQueryBuilder();
333+
$qb->update('share')
334+
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
335+
->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
336+
->set('permissions', $qb->createNamedParameter($share->getPermissions()));
335337

336-
if ($shareAttributes !== null) {
337-
$qb->set('attributes', $qb->createNamedParameter($shareAttributes));
338-
}
338+
if ($shareAttributes !== null) {
339+
$qb->set('attributes', $qb->createNamedParameter($shareAttributes));
340+
}
339341

340-
$qb->executeStatement();
342+
$qb->executeStatement();
343+
} catch (\Exception $e) {
344+
$this->dbConnection->rollBack();
345+
throw $e;
346+
}
347+
$this->dbConnection->commit();
341348

342349
return $share;
343350
}
@@ -1134,22 +1141,22 @@ public function getAllShares(): iterable {
11341141
}
11351142

11361143
protected function updateShareAttributes(IShare $share, ?string $data): IShare {
1137-
if ($data !== null && $data !== '') {
1138-
$attributes = $share->getAttributes() ?? $share->newAttributes();
1139-
$compressedAttributes = \json_decode($data, true);
1140-
if ($compressedAttributes === false || $compressedAttributes === null) {
1141-
return $share;
1142-
}
1143-
foreach ($compressedAttributes as $compressedAttribute) {
1144-
$attributes->setAttribute(
1145-
$compressedAttribute[0],
1146-
$compressedAttribute[1],
1147-
$compressedAttribute[2]
1148-
);
1149-
}
1150-
$share->setAttributes($attributes);
1144+
if ($data === null || $data === '') {
1145+
return $share;
11511146
}
1152-
1147+
$attributes = $share->getAttributes() ?? $share->newAttributes();
1148+
$compressedAttributes = \json_decode($data, true);
1149+
if ($compressedAttributes === false || $compressedAttributes === null) {
1150+
return $share;
1151+
}
1152+
foreach ($compressedAttributes as $compressedAttribute) {
1153+
$attributes->setAttribute(
1154+
$compressedAttribute[0],
1155+
$compressedAttribute[1],
1156+
$compressedAttribute[2]
1157+
);
1158+
}
1159+
$share->setAttributes($attributes);
11531160
return $share;
11541161
}
11551162

0 commit comments

Comments
 (0)