Integrate snipContent more tightly into snip and cleanup old code
This commit is contained in:
@ -28,7 +28,7 @@ readonly class SnipContentService
|
||||
$this->em->persist($content);
|
||||
$this->em->flush();
|
||||
|
||||
$this->snip->setActiveCommit($content->getId());
|
||||
$this->snip->setActiveVersion($content->getId());
|
||||
$this->em->persist($this->snip);
|
||||
$this->em->flush();
|
||||
}
|
||||
@ -37,38 +37,18 @@ readonly class SnipContentService
|
||||
public function getActiveText(): string
|
||||
{
|
||||
$contentRepo = $this->em->getRepository(SnipContent::class);
|
||||
return $contentRepo->find($this->snip->getActiveCommit())->getText();
|
||||
return $contentRepo->find($this->snip->getActiveVersion())->getText();
|
||||
}
|
||||
|
||||
/** @return array{id: string, name: string} */
|
||||
public function getVersions(): array
|
||||
public function setVersion(SnipContent $version): void
|
||||
{
|
||||
// Return all snipContent entities (by parent)
|
||||
return array_map(fn(SnipContent $content) => [
|
||||
'id' => (string)$content->getId(),
|
||||
'name' => $content->getId()->getDateTime()->format('Y-m-d H:i:s'),
|
||||
], $this->snip->getSnipContents()->toArray());
|
||||
}
|
||||
|
||||
public function setVersion(string $version): void
|
||||
{
|
||||
$this->snip->setActiveCommit($version);
|
||||
$this->snip->setActiveVersion($version);
|
||||
$this->em->persist($this->snip);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
public function getActiveVersion(): string
|
||||
{
|
||||
return $this->snip->getActiveCommit();
|
||||
}
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
// Cleanup the versions
|
||||
}
|
||||
|
||||
public function getLatestVersion(): string
|
||||
{
|
||||
return $this->snip->getSnipContents()->last()->getId();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user