mirror of
https://github.com/netzbegruenung/circles.git
synced 2024-04-29 02:14:51 +02:00
remove child shares
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
parent
78856e193d
commit
e69d1605dd
|
@ -431,12 +431,57 @@ class ShareWrapperRequest extends ShareWrapperRequestBuilder {
|
|||
* @param string $initiator
|
||||
*/
|
||||
public function deleteSharesToCircle(string $circleId, string $initiator = ''): void {
|
||||
$qb = $this->getShareDeleteSql();
|
||||
$qb->andWhere($qb->exprLimit('share_with', $circleId));
|
||||
$qb = $this->getShareSelectSql();
|
||||
$qb->limit('share_with', $circleId);
|
||||
if ($initiator !== '') {
|
||||
$qb->limit('uid_initiator', $initiator);
|
||||
}
|
||||
|
||||
$ids = array_map(
|
||||
function (ShareWrapper $share): string {
|
||||
return $share->getId();
|
||||
},
|
||||
$this->getItemsFromRequest($qb)
|
||||
);
|
||||
|
||||
$this->deleteSharesAndChild($ids);
|
||||
}
|
||||
|
||||
|
||||
public function removeOrphanShares(): void {
|
||||
$qb = $this->getShareSelectSql();
|
||||
$expr = $qb->expr();
|
||||
$qb->leftJoin(
|
||||
CoreQueryBuilder::SHARE, CoreRequestBuilder::TABLE_SHARE, 'p',
|
||||
$expr->andX($expr->eq('p.id', CoreQueryBuilder::SHARE . '.parent'))
|
||||
);
|
||||
|
||||
$qb->filterNull('parent');
|
||||
$qb->limitNull('id', false, 'p');
|
||||
|
||||
$ids = [];
|
||||
$cursor = $qb->execute();
|
||||
while ($data = $cursor->fetch()) {
|
||||
$ids[] = $data['id'];
|
||||
}
|
||||
$cursor->closeCursor();
|
||||
|
||||
$this->deleteSharesAndChild($ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*/
|
||||
private function deleteSharesAndChild(array $ids): void {
|
||||
$qb = $this->getShareDeleteSql();
|
||||
$qb->andWhere(
|
||||
$qb->expr()->orX(
|
||||
$qb->exprLimitInArray('id', $ids),
|
||||
$qb->exprLimitInArray('parent', $ids)
|
||||
)
|
||||
);
|
||||
|
||||
$qb->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,6 @@ class DestroyingCircle implements IEventListener {
|
|||
}
|
||||
|
||||
$circle = $event->getCircle();
|
||||
$this->shareWrapperService->deleteSharesToCircle($circle->getSingleId(), '', true);
|
||||
$this->shareWrapperService->deleteAllSharesToCircle($circle->getSingleId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ class MembershipsRemoved implements IEventListener {
|
|||
$federatedUser = $this->circlesManager->getFederatedUser($membership->getSingleId());
|
||||
if ($federatedUser->getUserType() === Member::TYPE_USER
|
||||
&& $federatedUser->isLocal()) {
|
||||
$this->shareWrapperService->deleteSharesToCircle(
|
||||
$this->shareWrapperService->deleteUserSharesToCircle(
|
||||
$membership->getCircleId(),
|
||||
$federatedUser->getUserId()
|
||||
);
|
||||
|
|
|
@ -288,6 +288,13 @@ class MaintenanceService {
|
|||
// } catch (Exception $e) {
|
||||
// }
|
||||
|
||||
try {
|
||||
// Can be removed in NC27.
|
||||
$this->output('Remove orphan shares');
|
||||
$this->removeOrphanShares();
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
// Can be removed in NC27.
|
||||
$this->output('fix sub-circle display name');
|
||||
|
@ -331,6 +338,14 @@ class MaintenanceService {
|
|||
}
|
||||
|
||||
|
||||
private function removeOrphanShares(): void {
|
||||
$this->shareWrapperRequest->removeOrphanShares();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws RequestBuilderException
|
||||
*/
|
||||
private function removeDeprecatedShares(): void {
|
||||
$probe = new CircleProbe();
|
||||
$probe->includePersonalCircles()
|
||||
|
@ -353,7 +368,7 @@ class MaintenanceService {
|
|||
|
||||
foreach ($shares as $share) {
|
||||
if (!in_array($share, $circles)) {
|
||||
$this->shareWrapperService->deleteSharesToCircle($share, '', true);
|
||||
$this->shareWrapperService->deleteAllSharesToCircle($share);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,9 +126,9 @@ class ShareWrapperService {
|
|||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteSharesToCircle(string $circleId, string $initiator = '', bool $force = false): void {
|
||||
if ($initiator === '' && !$force) {
|
||||
throw new Exception('if initiator is empty, you need to set $force as true');
|
||||
public function deleteUserSharesToCircle(string $circleId, string $initiator): void {
|
||||
if ($initiator === '') {
|
||||
throw new Exception('$initiator cannot be empty');
|
||||
}
|
||||
|
||||
$this->cache->clear('');
|
||||
|
@ -136,6 +136,15 @@ class ShareWrapperService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $circleId
|
||||
*/
|
||||
public function deleteAllSharesToCircle(string $circleId): void {
|
||||
$this->cache->clear('');
|
||||
$this->shareWrapperRequest->deleteSharesToCircle($circleId, '');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $circleId
|
||||
* @param FederatedUser|null $shareRecipient
|
||||
|
|
Loading…
Reference in a new issue