public function swapLocation(APILocation $location1, APILocation $location2)
{
$loadedLocation1 = $this->loadLocation($location1->id);
$loadedLocation2 = $this->loadLocation($location2->id);
if (!$this->repository->canUser('content', 'edit', $loadedLocation1->getContentInfo(), $loadedLocation1)) {
throw new UnauthorizedException('content', 'edit');
}
if (!$this->repository->canUser('content', 'edit', $loadedLocation2->getContentInfo(), $loadedLocation2)) {
throw new UnauthorizedException('content', 'edit');
}
$this->repository->beginTransaction();
try {
$this->persistenceHandler->locationHandler()->swap($loadedLocation1->id, $loadedLocation2->id);
$this->persistenceHandler->urlAliasHandler()->locationSwapped($location1->id, $location1->parentLocationId, $location2->id, $location2->parentLocationId);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}