Files
VITEC-website/packages/vitec/Classes/Command/SsrPurgeTargetsCommand.php
T
orascheandClaude Opus 5.5 e14f94ba63 SSR auto-purge: purge only the pages that show a saved record, megamenu purges everything
SsrPurgeTargetResolver finds the paths of a saved VITEC or news record: its detail URL, the pages that select it (sys_refindex), product lists by category or all products, list plugins of its type and the records embedding it one level deep. URL, visibility and timing changes, the newest news, events, unknown tables and more than 150 paths still purge everything. Megamenu records and the megamenu element now purge everything (before: only its storage page). New read-only command vitec:ssr-purge-targets shows what a save would purge. Reference index rebuilt (117 updates).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 12:16:44 +01:00

54 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Evomedien\Vitec\Command;
use Evomedien\Vitec\Service\SsrPurgeTargetResolver;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Read-only: shows which SSR paths the auto-purge would clear when the
* given record is saved (SsrPurgeTargetResolver). Purges nothing.
*
* vitec:ssr-purge-targets tx_vitec_domain_model_product 12
* vitec:ssr-purge-targets tx_news_domain_model_news 300 --fields=title,bodytext
*/
#[AsCommand(
name: 'vitec:ssr-purge-targets',
description: 'Show which SSR paths the auto-purge would clear for a saved record (read-only, purges nothing)'
)]
final class SsrPurgeTargetsCommand extends Command
{
protected function configure(): void
{
$this->addArgument('table', InputArgument::REQUIRED, 'Table, e.g. tx_vitec_domain_model_product');
$this->addArgument('uid', InputArgument::REQUIRED, 'Record uid');
$this->addOption('fields', null, InputOption::VALUE_REQUIRED, 'Changed fields, comma-separated', 'title');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$fields = GeneralUtility::trimExplode(',', (string)$input->getOption('fields'), true);
$paths = GeneralUtility::makeInstance(SsrPurgeTargetResolver::class)
->resolve((string)$input->getArgument('table'), (int)$input->getArgument('uid'), $fields);
if ($paths === []) {
$output->writeln('nothing to purge (record not rendered anywhere)');
} elseif ($paths === [SsrPurgeTargetResolver::ALL]) {
$output->writeln('<comment>* (everything)</comment>');
} else {
$output->writeln(count($paths) . ' path(s):');
foreach ($paths as $path) {
$output->writeln(' ' . $path);
}
}
return Command::SUCCESS;
}
}