‪TYPO3CMS  ‪main
OptimizeDatabaseTableTask.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Doctrine\DBAL\Exception as DBALException;
19 use Doctrine\DBAL\Platforms\MariaDBPlatform as DoctrineMariaDBPlatform;
20 use Doctrine\DBAL\Platforms\MySQLPlatform as DoctrineMySQLPlatform;
23 
33 {
40  public ‪$selectedTables = [];
41 
47  public function ‪execute()
48  {
49  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
50  foreach ($this->selectedTables as $tableName) {
51  $connection = $connectionPool->getConnectionForTable($tableName);
52  $platform = $connection->getDatabasePlatform();
53 
54  if ($platform instanceof DoctrineMariaDBPlatform || $platform instanceof DoctrineMySQLPlatform) {
55  try {
56  $connection->executeStatement('OPTIMIZE TABLE ' . $connection->quoteIdentifier($tableName));
57  } catch (DBALException $e) {
58  throw new \RuntimeException(
59  TableGarbageCollectionTask::class . ' failed for: ' . $tableName . ': ' .
60  $e->getPrevious()->getMessage(),
61  1441390263
62  );
63  }
64  }
65  }
66 
67  return true;
68  }
69 
75  public function ‪getAdditionalInformation()
76  {
77  return implode(', ', $this->selectedTables);
78  }
79 }
‪TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableTask\execute
‪bool execute()
Definition: OptimizeDatabaseTableTask.php:46
‪TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableTask\getAdditionalInformation
‪string getAdditionalInformation()
Definition: OptimizeDatabaseTableTask.php:74
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:16
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:33
‪TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableTask
Definition: OptimizeDatabaseTableTask.php:33
‪TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableTask\$selectedTables
‪array $selectedTables
Definition: OptimizeDatabaseTableTask.php:39
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52