Dont make new version if content didnt change
This commit is contained in:
parent
6f64f29177
commit
b2bc519e26
@ -15,14 +15,17 @@ readonly class SnipContentService
|
|||||||
|
|
||||||
public function update(string $snipContents): void
|
public function update(string $snipContents): void
|
||||||
{
|
{
|
||||||
|
if ($this->snip->getActiveVersion()?->getText() === $snipContents) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Create new snipContent entity with previous one as parent
|
// Create new snipContent entity with previous one as parent
|
||||||
$content = new SnipContent();
|
$content = new SnipContent();
|
||||||
$content
|
$content
|
||||||
->setText($snipContents)
|
->setText($snipContents)
|
||||||
->setSnip($this->snip)
|
->setSnip($this->snip)
|
||||||
;
|
;
|
||||||
if ($this->snip->getSnipContents()->count() > 0) {
|
if ($this->snip->getActiveVersion() !== null) {
|
||||||
$content->setParent($this->snip->getSnipContents()->last());
|
$content->setParent($this->snip->getActiveVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->em->persist($content);
|
$this->em->persist($content);
|
||||||
|
@ -4,12 +4,12 @@ namespace App\Service\SnipParser\Stages;
|
|||||||
|
|
||||||
use League\Pipeline\StageInterface;
|
use League\Pipeline\StageInterface;
|
||||||
|
|
||||||
class ReplaceStage implements StageInterface
|
readonly class ReplaceStage implements StageInterface
|
||||||
{
|
{
|
||||||
// replaces a string with another string
|
// replaces a string with another string
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public readonly string $search,
|
public string $search,
|
||||||
public readonly string $replace,
|
public string $replace,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function __invoke(mixed $payload): string
|
public function __invoke(mixed $payload): string
|
||||||
|
@ -9,12 +9,12 @@ use Symfony\Bundle\SecurityBundle\Security;
|
|||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
|
||||||
class UrlReferenceStage implements StageInterface
|
readonly class UrlReferenceStage implements StageInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire(lazy: true)] private readonly UrlGeneratorInterface $router,
|
#[Autowire(lazy: true)] private UrlGeneratorInterface $router,
|
||||||
#[Autowire(lazy: true)] private readonly Security $security,
|
#[Autowire(lazy: true)] private Security $security,
|
||||||
#[Autowire(lazy: true)] private readonly SnipRepository $snipRepository,
|
#[Autowire(lazy: true)] private SnipRepository $snipRepository,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function __invoke(mixed $payload): string
|
public function __invoke(mixed $payload): string
|
||||||
|
@ -6,10 +6,10 @@ use App\Entity\Snip;
|
|||||||
use App\Service\SnipContent\SnipContentService;
|
use App\Service\SnipContent\SnipContentService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
class SnipServiceFactory
|
readonly class SnipServiceFactory
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityManagerInterface $em,
|
private EntityManagerInterface $em,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function create(Snip $snip): SnipContentService
|
public function create(Snip $snip): SnipContentService
|
||||||
|
Loading…
Reference in New Issue
Block a user