class ZoneOwnershipGuard (View source)

The last-owner rule: a zone keeps at least one owner of a kind the ownership mode allows. Every writer removes owners through here, so the check and the delete share one transaction and two concurrent removals cannot both pass.

Methods

__construct(ZoneOwnershipRepositoryInterface $zoneRepository, ZoneGroupRepositoryInterface $zoneGroupRepository, ZoneOwnershipModeService $ownershipMode, TransactionInterface $transaction)

No description

removeUserOwner(int $zoneId, int $userId)

Removes a user owner, deciding and deleting inside one transaction.

removeGroup(int $zoneId, int $groupId)

Removes a group owner, deciding and deleting inside one transaction.

bool
refusesNewGrants(int $zoneId)

Whether new owners or groups would be granted nothing on this zone id, because two zones share it (see ZoneOwnershipRepositoryInterface::isSharedZoneId()).

refuseUserOwnerRemoval(int $zoneId, int $userId)

Null when the user may be removed; a refusal otherwise. A user who is not an owner is never refused, so the caller's own not-found path still runs.

refuseGroupRemoval(int $zoneId, int $groupId)

Null when the group may be removed; a refusal otherwise. A group that does not own the zone is never refused.

array
zonesOrphanedByGroupDeletion(int $groupId)

Zones that would be left without an allowed owner if the group were deleted, because deleting it drops its zones_groups rows.

array|bool
deleteGroup(int $groupId, callable $delete)

Deletes a group, deciding and writing under the same locks the single-zone removals take, so a concurrent removal of the other owner cannot slip in between the check and the delete and leave a zone with nobody.

Details

__construct(ZoneOwnershipRepositoryInterface $zoneRepository, ZoneGroupRepositoryInterface $zoneGroupRepository, ZoneOwnershipModeService $ownershipMode, TransactionInterface $transaction)

No description

Parameters

ZoneOwnershipRepositoryInterface $zoneRepository
ZoneGroupRepositoryInterface $zoneGroupRepository
ZoneOwnershipModeService $ownershipMode
TransactionInterface $transaction

ZoneOwnershipRefusal|bool removeUserOwner(int $zoneId, int $userId)

Removes a user owner, deciding and deleting inside one transaction.

Returns the refusal when the rule forbids it, otherwise whether a row went.

Parameters

int $zoneId
int $userId

Return Value

ZoneOwnershipRefusal|bool

ZoneOwnershipRefusal|bool removeGroup(int $zoneId, int $groupId)

Removes a group owner, deciding and deleting inside one transaction.

Returns the refusal when the rule forbids it, otherwise whether a row went.

Parameters

int $zoneId
int $groupId

Return Value

ZoneOwnershipRefusal|bool

bool refusesNewGrants(int $zoneId)

Whether new owners or groups would be granted nothing on this zone id, because two zones share it (see ZoneOwnershipRepositoryInterface::isSharedZoneId()).

Parameters

int $zoneId

Return Value

bool

ZoneOwnershipRefusal|null refuseUserOwnerRemoval(int $zoneId, int $userId)

Null when the user may be removed; a refusal otherwise. A user who is not an owner is never refused, so the caller's own not-found path still runs.

Parameters

int $zoneId
int $userId

Return Value

ZoneOwnershipRefusal|null

ZoneOwnershipRefusal|null refuseGroupRemoval(int $zoneId, int $groupId)

Null when the group may be removed; a refusal otherwise. A group that does not own the zone is never refused.

Parameters

int $zoneId
int $groupId

Return Value

ZoneOwnershipRefusal|null

array zonesOrphanedByGroupDeletion(int $groupId)

Zones that would be left without an allowed owner if the group were deleted, because deleting it drops its zones_groups rows.

Parameters

int $groupId

Return Value

array

Zone id => zone name, empty when the group may go

array|bool deleteGroup(int $groupId, callable $delete)

Deletes a group, deciding and writing under the same locks the single-zone removals take, so a concurrent removal of the other owner cannot slip in between the check and the delete and leave a zone with nobody.

Parameters

int $groupId
callable $delete

Deletes the group and reports whether a row went

Return Value

array|bool

Zone id => name when the deletion is refused, otherwise what $delete reported