Start on property keeping track of git db content

This commit is contained in:
Tim
2023-12-16 01:26:47 +01:00
parent a9e740d018
commit 0fce8ee4fe
7 changed files with 219 additions and 27 deletions

View File

@ -5,17 +5,15 @@ namespace App\Service\SnipContent;
use App\Entity\Snip;
use App\Entity\SnipContent;
use App\Entity\User;
use App\Repository\SnipContentRepository;
use Doctrine\ORM\EntityManagerInterface;
class SnipContentDB implements SnipContentInterface
readonly class SnipContentDB implements SnipContentInterface
{
public function __construct(
private readonly Snip $snip,
private readonly User $user,
private readonly SnipContentRepository $repo,
)
{
}
private Snip $snip,
private User $user,
private EntityManagerInterface $em,
) {}
public function update(string $snipContents): void
{
@ -27,7 +25,12 @@ class SnipContentDB implements SnipContentInterface
$content->setParent($this->snip->getSnipContents()->last());
}
$this->repo->save($content);
$this->em->persist($content);
$this->em->flush();
$this->snip->setActiveCommit($content->getId());
$this->em->persist($this->snip);
$this->em->flush();
}
public function get(): string
@ -44,14 +47,14 @@ class SnipContentDB implements SnipContentInterface
public function setCommit(string $commit): void
{
// return to previous history commit
// maybe store the current commit in the snip content
$this->snip->setActiveCommit($commit);
$this->em->persist($this->snip);
$this->em->flush();
}
public function getCommit(): string
{
// return the current commit
return '';
return $this->snip->getActiveCommit();
}
public function delete(): void