‪TYPO3CMS  ‪main
CleanupPreviewLinksCommand.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\Console\Attribute\AsCommand;
21 use Symfony\Component\Console\Command\Command;
22 use Symfony\Component\Console\Input\InputInterface;
23 use Symfony\Component\Console\Output\OutputInterface;
24 use Symfony\Component\Console\Style\SymfonyStyle;
27 
33 #[AsCommand('cleanup:previewlinks', 'Find all versioned records and possibly cleans up invalid records in the database.')]
34 class ‪CleanupPreviewLinksCommand extends Command
35 {
36  public function ‪__construct(private readonly ‪ConnectionPool $connectionPool)
37  {
38  parent::__construct();
39  }
40 
44  public function ‪configure()
45  {
46  $this->setHelp('Look for preview links within the database table "sys_preview" that have been expired and and remove them. This command should be called regularly when working with workspaces.');
47  }
48 
52  protected function ‪execute(InputInterface $input, OutputInterface $output): int
53  {
54  $io = new SymfonyStyle($input, $output);
55 
56  $queryBuilder = $this->connectionPool->getQueryBuilderForTable('sys_preview');
58  $affectedRows = $queryBuilder
59  ->delete('sys_preview')
60  ->where(
61  $queryBuilder->expr()->lt(
62  'endtime',
63  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], ‪Connection::PARAM_INT)
64  )
65  )
66  ->executeStatement();
67 
68  if ($affectedRows > 0) {
69  $io->success('Cleaned up ' . $affectedRows . ' preview links.');
70  } else {
71  $io->note('No expired preview links found. All done.');
72  }
73  return Command::SUCCESS;
74  }
75 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Workspaces\Command
Definition: AutoPublishCommand.php:18
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46