Dont make new version if content didnt change

This commit is contained in:
Tim 2023-12-24 01:06:30 +01:00
parent 6f64f29177
commit b2bc519e26
4 changed files with 14 additions and 11 deletions

View File

@ -15,14 +15,17 @@ readonly class SnipContentService
public function update(string $snipContents): void
{
if ($this->snip->getActiveVersion()?->getText() === $snipContents) {
return;
}
// Create new snipContent entity with previous one as parent
$content = new SnipContent();
$content
->setText($snipContents)
->setSnip($this->snip)
;
if ($this->snip->getSnipContents()->count() > 0) {
$content->setParent($this->snip->getSnipContents()->last());
if ($this->snip->getActiveVersion() !== null) {
$content->setParent($this->snip->getActiveVersion());
}
$this->em->persist($content);

View File

@ -4,12 +4,12 @@ namespace App\Service\SnipParser\Stages;
use League\Pipeline\StageInterface;
class ReplaceStage implements StageInterface
readonly class ReplaceStage implements StageInterface
{
// replaces a string with another string
public function __construct(
public readonly string $search,
public readonly string $replace,
public string $search,
public string $replace,
) {}
public function __invoke(mixed $payload): string

View File

@ -9,12 +9,12 @@ use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class UrlReferenceStage implements StageInterface
readonly class UrlReferenceStage implements StageInterface
{
public function __construct(
#[Autowire(lazy: true)] private readonly UrlGeneratorInterface $router,
#[Autowire(lazy: true)] private readonly Security $security,
#[Autowire(lazy: true)] private readonly SnipRepository $snipRepository,
#[Autowire(lazy: true)] private UrlGeneratorInterface $router,
#[Autowire(lazy: true)] private Security $security,
#[Autowire(lazy: true)] private SnipRepository $snipRepository,
) {}
public function __invoke(mixed $payload): string

View File

@ -6,10 +6,10 @@ use App\Entity\Snip;
use App\Service\SnipContent\SnipContentService;
use Doctrine\ORM\EntityManagerInterface;
class SnipServiceFactory
readonly class SnipServiceFactory
{
public function __construct(
private readonly EntityManagerInterface $em,
private EntityManagerInterface $em,
) {}
public function create(Snip $snip): SnipContentService