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