/** * Copies the content to a new location. If no version is given, * all versions are copied, otherwise only the given version. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location * * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null) { if (false === $this->repository->hasAccess('content', 'edit')) { throw new UnauthorizedExceptionStub('What error code should be used?'); } ++$this->contentNextId; $versionNo = $versionInfo ? $versionInfo->versionNo : null; $this->contentInfo[$this->contentNextId] = new ContentInfoStub(array('id' => $this->contentNextId, 'remoteId' => md5(uniqid($contentInfo->remoteId, true)), 'sectionId' => $contentInfo->sectionId, 'alwaysAvailable' => $contentInfo->alwaysAvailable, 'currentVersionNo' => $versionNo ? 1 : $contentInfo->currentVersionNo, 'mainLanguageCode' => $contentInfo->mainLanguageCode, 'modificationDate' => new \DateTime(), 'ownerId' => $contentInfo->ownerId, 'published' => $contentInfo->published, 'publishedDate' => new \DateTime(), 'mainLocationId' => $contentInfo->mainLocationId, 'contentTypeId' => $contentInfo->contentTypeId, 'repository' => $this->repository)); foreach ($this->versionInfo as $versionInfoStub) { if ($versionInfoStub->contentId !== $contentInfo->id) { continue; } if ($versionNo && $versionInfoStub->versionNo !== $versionNo) { continue; } ++$this->versionNextId; $this->versionInfo[$this->versionNextId] = new VersionInfoStub(array('id' => $this->versionNextId, 'status' => VersionInfo::STATUS_DRAFT, 'versionNo' => $versionNo ? 1 : $versionInfoStub->versionNo, 'creatorId' => $versionInfoStub->creatorId, 'creationDate' => new \DateTime(), 'modificationDate' => new \DateTime(), 'languageCodes' => $versionInfoStub->languageCodes, 'initialLanguageCode' => $versionInfoStub->initialLanguageCode, 'names' => $versionInfoStub->getNames(), 'contentId' => $this->contentNextId, 'repository' => $this->repository)); } foreach ($this->content as $content) { if ($content->id !== $contentInfo->id) { continue; } if ($versionNo && $content->versionNo !== $versionNo) { continue; } $this->content[] = $this->copyContentObject($content, array('id' => $this->contentNextId, 'versionNo' => $versionNo ? 1 : $content->versionNo)); } $locationService = $this->repository->getLocationService(); $location = $locationService->createLocation($this->contentInfo[$this->contentNextId], $destinationLocationCreateStruct); $this->repository->getUrlAliasService()->createAliasesForLocation($location); return $this->loadContent($this->contentNextId); }
/** * Internal helper method used to recover a location tree. * * @access private * * @internal * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentlocation * * @return \eZ\Publish\API\Repository\Values\Content\Location */ public function recoverLocation(Location $location, Location $newParentlocation = null) { if ($newParentlocation) { $location->setParentLocationId($newParentlocation->id); } $location->setDepth($this->locations[$location->parentLocationId]->depth + 1); $location->setPathString($this->locations[$location->parentLocationId]->pathString . $location->id . "/"); // If the main location of the restored content is also trashed / // deleted if (!isset($this->locations[$location->getContentInfo()->mainLocationId])) { $location->getContentInfo()->setMainLocationId($location->id); } $this->repository->getUrlAliasService()->createAliasesForLocation($location); return $this->locations[$location->id] = $location; }