‪TYPO3CMS  9.5
CleanupPreviewLinksCommand.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Output\OutputInterface;
21 use Symfony\Component\Console\Style\SymfonyStyle;
24 
28 class ‪CleanupPreviewLinksCommand extends Command
29 {
30 
34  public function ‪configure()
35  {
36  $this
37  ->setDescription('Clean up expired preview links from shared workspace previews.')
38  ->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.');
39  }
40 
47  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
48  {
49  $io = new SymfonyStyle($input, ‪$output);
50 
51  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_preview');
52  $affectedRows = $queryBuilder
53  ->delete('sys_preview')
54  ->where(
55  $queryBuilder->expr()->lt(
56  'endtime',
57  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
58  )
59  )
60  ->execute();
61 
62  if ($affectedRows > 0) {
63  $io->success('Cleaned up ' . $affectedRows . ' preview links.');
64  } else {
65  $io->note('No expired preview links found. All done.');
66  }
67  }
68 }
‪TYPO3\CMS\Workspaces\Command
Definition: AutoPublishCommand.php:3
‪$output
‪$output
Definition: annotationChecker.php:113
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45