Change snipConent entitie property to public

This commit is contained in:
Tim
2025-07-24 15:03:20 +02:00
parent 074c1d8570
commit a1ecaf0189
8 changed files with 40 additions and 136 deletions

View File

@ -26,17 +26,16 @@ class SnipUpdateContentCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
// $io = new SymfonyStyle($input, $output);
$qb = $this->snipContentRepository->createQueryBuilder('s');
$qb->where('s.text IS NOT NULL');
$c = 0;
/** @var SnipContent $snipContent */
foreach ($qb->getQuery()->getResult() as $snipContent) {
$text = $snipContent->getText();
$text = $snipContent->text;
$text = Lexer::reconstruct(Lexer::tokenize($text));
$snipContent->setText($text);
$snipContent->text = $text;
$this->snipContentRepository->save($snipContent);
}

View File

@ -18,10 +18,10 @@ class SnipContentController extends AbstractController
#[Route('/compare/{to}/{from}', name: '_compare')]
public function compare(SnipContent $to, ?SnipContent $from = null): Response
{
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $to->getSnip());
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $to->snip);
if ($from === null) {
$from = $to->getParent();
$from = $to->parent;
}
$diff = MyersDiff::buildDiffLines(
@ -30,7 +30,7 @@ class SnipContentController extends AbstractController
);
return $this->render('content/compare.html.twig', [
'snip' => $to->getSnip(),
'snip' => $to->snip,
'diff' => $diff,
]);
}

View File

@ -33,7 +33,7 @@ class VersionController extends AbstractController
$this->denyAccessUnlessGranted(SnipVoter::EDIT, $snip);
$this->contentService->setVersion($snip, $version);
$this->addFlash('success', 'Snip version set to ' . $version->getId());
$this->addFlash('success', 'Snip version set to ' . $version->id);
return $this->redirectToRoute('snip_single', ['snip' => $snip->id]);
}
}

View File

@ -66,7 +66,7 @@ class Snip
{
if (!$this->snipContents->contains($snipContent)) {
$this->snipContents->add($snipContent);
$snipContent->setSnip($this);
$snipContent->snip = $this;
}
return $this;
@ -76,8 +76,8 @@ class Snip
{
if ($this->snipContents->removeElement($snipContent)) {
// set the owning side to null (unless already changed)
if ($snipContent->getSnip() === $this) {
$snipContent->setSnip(null);
if ($snipContent->snip === $this) {
$snipContent->snip = null;
}
}

View File

@ -17,124 +17,30 @@ class SnipContent
#[ORM\Column(type: UlidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')]
private ?Ulid $id = null;
public ?Ulid $id = null;
#[ORM\ManyToOne(inversedBy: 'snipContents')]
#[ORM\JoinColumn(nullable: false)]
private ?Snip $snip = null;
public ?Snip $snip = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
private ?self $parent = null;
public ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $children;
/** @var Collection<int, self> */
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
public Collection $children;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $text = null;
public ?string $text = null;
#[ORM\Column(nullable: true)]
private ?array $diff = null;
public ?array $diff = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
public ?string $name = null;
public function __construct()
{
$this->children = new ArrayCollection();
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getSnip(): ?Snip
{
return $this->snip;
}
public function setSnip(?Snip $snip): self
{
$this->snip = $snip;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children->add($child);
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(?string $text): self
{
$this->text = $text;
return $this;
}
public function getDiff(): ?array
{
return $this->diff;
}
public function setDiff(?array $diff): static
{
$this->diff = $diff;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
}

View File

@ -22,13 +22,12 @@ readonly class SnipContentService
// Create new snipContent entity with previous one as parent
$content = new SnipContent();
$content
->setText($contents)
->setSnip($snip)
->setName($contentName)
;
$content->text = $contents;
$content->snip = $snip;
$content->name = $contentName;
if ($parentContent !== null) {
$content->setParent($parentContent);
$content->parent = $parentContent;
$this->contentToRelative($parentContent);
}
@ -45,17 +44,17 @@ readonly class SnipContentService
if ($snipContent === null) {
return '';
}
if ($snipContent->getText()) {
return $snipContent->getText();
if ($snipContent->text) {
return $snipContent->text;
}
$parentContent = $snipContent->getParent();
if ($parentContent === null && $snipContent->getDiff() === null) {
$parentContent = $snipContent->parent;
if ($parentContent === null && $snipContent->diff === null) {
return '---Something went very wrong, cant rebuild the text---';
}
return MyersDiff::rebuildBFromCompact(
self::rebuildText($parentContent), $snipContent->getDiff()
self::rebuildText($parentContent), $snipContent->diff
);
}
@ -72,25 +71,25 @@ readonly class SnipContentService
public function contentToRelative(SnipContent $content): void
{
if ($content->getText() === null || $content->getParent() === null) {
if ($content->text === null || $content->parent === null) {
return;
}
$contentText = $content->getText();
$parentText = self::rebuildText($content->getParent());
$contentText = $content->text;
$parentText = self::rebuildText($content->parent);
$diff = MyersDiff::calculate($parentText, $contentText);
$content->setDiff($diff);
$content->setText(null);
$content->diff = $diff;
$content->text = null;
$this->em->persist($content);
$this->em->flush();
}
public function contentToAbsolute(SnipContent $content): void
{
if ($content->getDiff() === null) {
if ($content->diff === null) {
return;
}
$content->setText(self::rebuildText($content));
$content->setDiff(null);
$content->text = self::rebuildText($content);
$content->diff = null;
$this->em->persist($content);
$this->em->flush();
}

View File

@ -37,7 +37,7 @@ class IncludeReferenceStage implements StageInterface
$content = null;
}
if ($content) {
$snip = $content->getSnip();
$snip = $content->snip;
} else {
$snip = $this->snipRepository->find($id);
if ($snip) {

View File

@ -25,7 +25,7 @@ class SnipLoader implements LoaderInterface
public function getCacheKey(string $name): string
{
return $this->getFromKey($name)->activeVersion->getId();
return $this->getFromKey($name)->activeVersion->id;
}
public function isFresh(string $name, int $time): bool