Edit content in batches

The best way to edit page content in bulk is to do in directly in PHP.

Contents

Example

  1. Create a new Symfony Command

  2. Do what you want inside

Like stripping the word example from all h1


// src/Command/CleanContentCommand.php namespace App\Command; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; // the name of the command is what users type after "php bin/console" #[AsCommand(name: 'clean:content')] class CleanContentCommand extends Command { 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) { $h1Cleaned = str_replace('example', '', $page->getH1()); $page->setH1($h1cleaned); } $this->em->flush(); return Command::SUCCESS; } }
  1. Run it php bin/console clean