eZ\Publish\Core\Repository\LocationService::swapLocation PHP Method

swapLocation() public method

Swaps the contents held by $location1 and $location2.
public swapLocation ( eZ\Publish\API\Repository\Values\Content\Location $location1, eZ\Publish\API\Repository\Values\Content\Location $location2 )
$location1 eZ\Publish\API\Repository\Values\Content\Location
$location2 eZ\Publish\API\Repository\Values\Content\Location
    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;
        }
    }