‪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\Command\Command;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Output\OutputInterface;
23 use Symfony\Component\Console\Style\SymfonyStyle;
26 
30 class ‪CleanupPreviewLinksCommand extends Command
31 {
32  public function ‪__construct(private readonly ‪ConnectionPool $connectionPool)
33  {
34  parent::__construct();
35  }
36 
40  public function ‪configure()
41  {
42  $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.');
43  }
44 
48  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
49  {
50  $io = new SymfonyStyle($input, ‪$output);
51 
52  $queryBuilder = $this->connectionPool->getQueryBuilderForTable('sys_preview');
54  $affectedRows = $queryBuilder
55  ->delete('sys_preview')
56  ->where(
57  $queryBuilder->expr()->lt(
58  'endtime',
59  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], ‪Connection::PARAM_INT)
60  )
61  )
62  ->executeStatement();
63 
64  if ($affectedRows > 0) {
65  $io->success('Cleaned up ' . $affectedRows . ' preview links.');
66  } else {
67  $io->note('No expired preview links found. All done.');
68  }
69  return Command::SUCCESS;
70  }
71 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:50
‪TYPO3\CMS\Workspaces\Command
Definition: AutoPublishCommand.php:18
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:48