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

@ -4,7 +4,7 @@
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.2",
"php": ">=8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"czproject/git-php": "^4.1",
@ -21,6 +21,7 @@
"symfony/runtime": "7.0.*",
"symfony/security-bundle": "7.0.*",
"symfony/twig-bundle": "7.0.*",
"symfony/uid": "7.0.*",
"symfony/validator": "7.0.*",
"symfony/yaml": "7.0.*",
"twig/extra-bundle": "^2.12|^3.0",

162
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "81c31aacf558fbbb42aaa93138c76e40",
"content-hash": "0d9cbf5f6f95b13006484d60ccb4d67c",
"packages": [
{
"name": "czproject/git-php",
@ -4097,6 +4097,88 @@
],
"time": "2023-08-16T06:22:46+00:00"
},
{
"name": "symfony/polyfill-uuid",
"version": "v1.28.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-uuid.git",
"reference": "9c44518a5aff8da565c8a55dbe85d2769e6f630e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-uuid/zipball/9c44518a5aff8da565c8a55dbe85d2769e6f630e",
"reference": "9c44518a5aff8da565c8a55dbe85d2769e6f630e",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-uuid": "*"
},
"suggest": {
"ext-uuid": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Uuid\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Grégoire Pineau",
"email": "lyrixx@lyrixx.info"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for uuid functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"uuid"
],
"support": {
"source": "https://github.com/symfony/polyfill-uuid/tree/v1.28.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-01-26T09:26:14+00:00"
},
{
"name": "symfony/property-access",
"version": "v7.0.0",
@ -5265,6 +5347,80 @@
],
"time": "2023-11-26T15:16:53+00:00"
},
{
"name": "symfony/uid",
"version": "v7.0.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/uid.git",
"reference": "9472fe6a4a2adcc9150106ebb9fde328828d312f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/uid/zipball/9472fe6a4a2adcc9150106ebb9fde328828d312f",
"reference": "9472fe6a4a2adcc9150106ebb9fde328828d312f",
"shasum": ""
},
"require": {
"php": ">=8.2",
"symfony/polyfill-uuid": "^1.15"
},
"require-dev": {
"symfony/console": "^6.4|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Uid\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Grégoire Pineau",
"email": "lyrixx@lyrixx.info"
},
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides an object-oriented API to generate and represent UIDs",
"homepage": "https://symfony.com",
"keywords": [
"UID",
"ulid",
"uuid"
],
"support": {
"source": "https://github.com/symfony/uid/tree/v7.0.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-10-31T08:22:02+00:00"
},
{
"name": "symfony/validator",
"version": "v7.0.0",
@ -6149,10 +6305,10 @@
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": ">=8.2",
"php": ">=8.3",
"ext-ctype": "*",
"ext-iconv": "*"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.3.0"
}

4
config/packages/uid.yaml Normal file
View File

@ -0,0 +1,4 @@
framework:
uid:
default_uuid_version: 7
time_based_uuid_version: 7

View File

@ -27,6 +27,9 @@ class Snip
#[ORM\OneToMany(mappedBy: 'snip', targetEntity: SnipContent::class, orphanRemoval: true)]
private Collection $snipContents;
#[ORM\Column(length: 255, nullable: true)]
private ?string $activeCommit = null;
public function __construct()
{
$this->snipContents = new ArrayCollection();
@ -95,4 +98,16 @@ class Snip
return $this;
}
public function getActiveCommit(): ?string
{
return $this->activeCommit;
}
public function setActiveCommit(?string $activeCommit): static
{
$this->activeCommit = $activeCommit;
return $this;
}
}

View File

@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Ulid;
#[ORM\Entity(repositoryClass: SnipContentRepository::class)]
class SnipContent
@ -14,27 +15,27 @@ class SnipContent
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
private ?Ulid $id = null;
#[ORM\ManyToOne(inversedBy: 'snipContents')]
#[ORM\JoinColumn(nullable: false)]
private ?Snip $snip = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'child')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $child;
private Collection $children;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $text = null;
public function __construct()
{
$this->child = new ArrayCollection();
$this->children = new ArrayCollection();
}
public function getId(): ?int
public function getId(): ?Ulid
{
return $this->id;
}
@ -66,15 +67,15 @@ class SnipContent
/**
* @return Collection<int, self>
*/
public function getChild(): Collection
public function getChildren(): Collection
{
return $this->child;
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->child->contains($child)) {
$this->child->add($child);
if (!$this->children->contains($child)) {
$this->children->add($child);
$child->setParent($this);
}
@ -83,7 +84,7 @@ class SnipContent
public function removeChild(self $child): self
{
if ($this->child->removeElement($child)) {
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);

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

View File

@ -140,6 +140,18 @@
"templates/base.html.twig"
]
},
"symfony/uid": {
"version": "7.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "6.2",
"ref": "d294ad4add3e15d7eb1bae0221588ca89b38e558"
},
"files": [
"config/packages/uid.yaml"
]
},
"symfony/validator": {
"version": "6.2",
"recipe": {