‪TYPO3CMS  ‪main
SysLogSerializationUpdate.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 
21 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
25 
30 #[UpgradeWizard('sysLogSerialization')]
32 {
33  use ‪LogDataTrait;
34  private const ‪TABLE_NAME = 'sys_log';
35 
36  public function ‪getTitle(): string
37  {
38  return 'Migrate sys_log entries to a JSON formatted value.';
39  }
40 
41  public function ‪getDescription(): string
42  {
43  return 'All sys_log_entries are now updated to contain JSON values in the "log_data" field.';
44  }
45 
46  public function ‪getPrerequisites(): array
47  {
48  return [
49  DatabaseUpdatedPrerequisite::class,
50  ];
51  }
52 
53  public function ‪updateNecessary(): bool
54  {
55  return $this->‪hasRecordsToUpdate();
56  }
57 
58  public function ‪executeUpdate(): bool
59  {
60  $connection = $this->‪getConnectionPool()->getConnectionForTable(self::TABLE_NAME);
61 
62  // Perform fast update of a:0:{}, since it evaluates to []
63  $connection->update(
64  self::TABLE_NAME,
65  ['log_data' => '[]'],
66  ['log_data' => 'a:0:{}']
67  );
68 
69  // Perform fast update of a:1:{i:0;s:0:"";}, since it evaluates to [""]
70  $connection->update(
71  self::TABLE_NAME,
72  ['log_data' => '[""]'],
73  ['log_data' => 'a:1:{i:0;s:0:"";}']
74  );
75 
76  $queryBuilder = $this->‪getPreparedQueryBuilder();
77  $result = $queryBuilder
78  ->select('uid', 'log_data')
79  ->where(
80  $queryBuilder->expr()->like('log_data', $queryBuilder->createNamedParameter('a:%'))
81  )
82  ->executeQuery();
83  while (‪$record = $result->fetchAssociative()) {
84  $logData = $this->unserializeLogData(‪$record['log_data'] ?? '');
85  $connection->update(
86  self::TABLE_NAME,
87  ['log_data' => json_encode($logData)],
88  ['uid' => (int)‪$record['uid']]
89  );
90  }
91 
92  return true;
93  }
94 
95  protected function ‪hasRecordsToUpdate(): bool
96  {
97  $queryBuilder = $this->‪getPreparedQueryBuilder();
98  return (bool)$queryBuilder
99  ->count('uid')
100  ->where(
101  $queryBuilder->expr()->like('log_data', $queryBuilder->createNamedParameter('a:%'))
102  )
103  ->executeQuery()
104  ->fetchOne();
105  }
106 
107  protected function ‪getPreparedQueryBuilder(): QueryBuilder
108  {
109  $queryBuilder = $this->‪getConnectionPool()->getQueryBuilderForTable(self::TABLE_NAME);
110  $queryBuilder->from(self::TABLE_NAME);
111  return $queryBuilder;
112  }
113 
115  {
116  return GeneralUtility::makeInstance(ConnectionPool::class);
117  }
118 }
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\getDescription
‪getDescription()
Definition: SysLogSerializationUpdate.php:41
‪TYPO3\CMS\Install\Attribute\UpgradeWizard
Definition: UpgradeWizard.php:25
‪TYPO3\CMS\Install\Updates
Definition: LegacyClassesForIde.php:22
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\executeUpdate
‪executeUpdate()
Definition: SysLogSerializationUpdate.php:58
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\getTitle
‪getTitle()
Definition: SysLogSerializationUpdate.php:36
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\TABLE_NAME
‪const TABLE_NAME
Definition: SysLogSerializationUpdate.php:34
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\getPrerequisites
‪getPrerequisites()
Definition: SysLogSerializationUpdate.php:46
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\getPreparedQueryBuilder
‪getPreparedQueryBuilder()
Definition: SysLogSerializationUpdate.php:107
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\updateNecessary
‪updateNecessary()
Definition: SysLogSerializationUpdate.php:53
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\getConnectionPool
‪getConnectionPool()
Definition: SysLogSerializationUpdate.php:114
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate
Definition: SysLogSerializationUpdate.php:32
‪TYPO3\CMS\Core\Log\LogDataTrait
Definition: LogDataTrait.php:25
‪TYPO3\CMS\Install\Updates\SysLogSerializationUpdate\hasRecordsToUpdate
‪hasRecordsToUpdate()
Definition: SysLogSerializationUpdate.php:95