‪TYPO3CMS  9.5
ClearTableService.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 
20 
27 {
31  protected ‪$tableList = [
32  [
33  'name' => 'be_sessions',
34  'description' => 'Backend user sessions'
35  ],
36  [
37  'name' => 'fe_sessions',
38  'description' => 'Frontend user sessions',
39  ],
40  [
41  'name' => 'sys_history',
42  'description' => 'Tracking of database record changes through TYPO3 backend forms',
43  ],
44  [
45  'name' => 'sys_lockedrecords',
46  'description' => 'Record locking of backend user editing',
47  ],
48  [
49  'name' => 'sys_log',
50  'description' => 'General log table',
51  ],
52  [
53  'name' => 'sys_preview',
54  'description' => 'Workspace preview links',
55  ],
56  [
57  'name' => 'tx_extensionmanager_domain_model_extension',
58  'description' => 'List of TER extensions',
59  ],
60  [
61  'name' => 'tx_rsaauth_keys',
62  'description' => 'Login process key storage'
63  ],
64  ];
65 
71  public function ‪getTableStatistics(): array
72  {
73  $tableStatistics = [];
74  foreach ($this->tableList as $table) {
75  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table['name']);
76  if ($connection->getSchemaManager()->tablesExist([$table['name']])) {
77  $table['rowCount'] = $connection->count(
78  '*',
79  $table['name'],
80  []
81  );
82  $tableStatistics[] = $table;
83  }
84  }
85  return $tableStatistics;
86  }
87 
94  public function ‪clearSelectedTable(string $tableName)
95  {
96  $tableFound = false;
97  foreach ($this->tableList as $table) {
98  if ($table['name'] === $tableName) {
99  $tableFound = true;
100  break;
101  }
102  }
103  if (!$tableFound) {
104  throw new \RuntimeException(
105  'Selected table ' . $tableName . ' can not be cleared',
106  1501942151
107  );
108  }
109  GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName)->truncate($tableName);
110  }
111 }
‪TYPO3\CMS\Install\Service\ClearTableService\getTableStatistics
‪array getTableStatistics()
Definition: ClearTableService.php:70
‪TYPO3\CMS\Install\Service\ClearTableService
Definition: ClearTableService.php:27
‪TYPO3\CMS\Install\Service\ClearTableService\$tableList
‪array $tableList
Definition: ClearTableService.php:30
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Service\ClearTableService\clearSelectedTable
‪clearSelectedTable(string $tableName)
Definition: ClearTableService.php:93
‪TYPO3\CMS\Install\Service
Definition: ClearCacheService.php:2