‪TYPO3CMS  10.4
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 
36  public function ‪configure()
37  {
38  $this
39  ->setDescription('Clean up expired preview links from shared workspace previews.')
40  ->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.');
41  }
42 
50  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
51  {
52  $io = new SymfonyStyle($input, ‪$output);
53 
54  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_preview');
56  $affectedRows = $queryBuilder
57  ->delete('sys_preview')
58  ->where(
59  $queryBuilder->expr()->lt(
60  'endtime',
61  $queryBuilder->createNamedParameter(‪$GLOBALS['EXEC_TIME'], \PDO::PARAM_INT)
62  )
63  )
64  ->execute();
65 
66  if ($affectedRows > 0) {
67  $io->success('Cleaned up ' . $affectedRows . ' preview links.');
68  } else {
69  $io->note('No expired preview links found. All done.');
70  }
71  return 0;
72  }
73 }
‪TYPO3\CMS\Workspaces\Command
Definition: AutoPublishCommand.php:18
‪$output
‪$output
Definition: annotationChecker.php:119
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46