/** * Return the object repository locator * * @return RepositoryLocatorInterface Object repository locator */ public function getRepositoryLocator() { // If the object has already been instantiated if ($this->object instanceof ObjectInterface) { return $this->object->getRepositoryLocator(); } return $this->getUrl()->getLocator(); }
/** * Publish an object in the repository * * @param ObjectInterface $object */ protected function publishObject(ObjectInterface $object) { $objectRepoLocator = $object->getRepositoryLocator(); // If the object had been persisted as a draft: Remove the draft resource $objectDraftLocator = $objectRepoLocator->setRevision($object->getRevision()->setDraft(true)); $absObjectDraftPath = $this->getAbsoluteResourcePath($objectDraftLocator); if (@file_exists($absObjectDraftPath)) { unlink($absObjectDraftPath); } // If it's not the first object revision: Rotate the previous revision resource $objectRevisionNumber = $object->getRevision()->getRevision(); if ($objectRevisionNumber > 1) { // Build the "current" object repository locator $currentRevision = Revision::current(); $curObjectResPath = $this->getAbsoluteResourcePath($objectRepoLocator->setRevision($currentRevision)); // Build the previous object repository locator /** @var Revision $previousRevision */ $previousRevision = Kernel::create(Revision::class, [$objectRevisionNumber - 1]); $prevObjectResPath = $this->getAbsoluteResourcePath($objectRepoLocator->setRevision($previousRevision)); // Rotate the previous revision's resource path if (file_exists($curObjectResPath)) { rename($curObjectResPath, $prevObjectResPath); } } }