Skip to content

Commit

Permalink
Add page:clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed May 8, 2023
1 parent ffb08d8 commit a039bac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/core/src/Command/CleanPageCommand.php
@@ -0,0 +1,36 @@
<?php

namespace Pushword\Core\Command;

use Doctrine\ORM\EntityManagerInterface;
use Pushword\Core\Repository\PageRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class CleanPageCommand extends Command
{
/**
* @var string|null
*/
protected static $defaultName = 'pushword:page:clean';

public function __construct(
private readonly EntityManagerInterface $em,
private readonly PageRepository $pageRepo,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$pages = $this->pageRepo->findAll();
foreach ($pages as $page) {
$page->setMainContent($page->getMainContent());
}

$this->em->flush();

return 0;
}
}
3 changes: 3 additions & 0 deletions packages/core/src/Entity/PageTrait/PageTrait.php
Expand Up @@ -4,6 +4,7 @@

use Cocur\Slugify\Slugify;
use Doctrine\ORM\Mapping as ORM;
use Pushword\Core\Utils\F;

trait PageTrait
{
Expand Down Expand Up @@ -76,6 +77,8 @@ public function getMainContent(): string
public function setMainContent(?string $mainContent): self
{
$this->mainContent = (string) $mainContent;
// clean empty link added by editor.js
$this->mainContent = F::preg_replace_str('@<a[^>]+"></a>@U', '', $this->mainContent);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Service/PageOpenGraphImageGenerator.php
Expand Up @@ -23,7 +23,7 @@ class PageOpenGraphImageGenerator
{
private ?RGB $rgb = null;

private ?ImagineInterface $imagine = null;
public ?ImagineInterface $imagine = null;

public PageInterface $page;

Expand Down

0 comments on commit a039bac

Please sign in to comment.