‪TYPO3CMS  11.5
SysLogChannel.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 Doctrine\DBAL\Schema\Column;
21 use Doctrine\DBAL\Schema\ColumnDiff;
22 use Doctrine\DBAL\Schema\TableDiff;
23 use Doctrine\DBAL\Types\StringType;
28 
30 {
32 
33  public function ‪__construct()
34  {
35  $this->sysLogTable = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_log');
36  }
37 
41  public function ‪getIdentifier(): string
42  {
43  return 'sysLogChannel';
44  }
45 
49  public function ‪getTitle(): string
50  {
51  return 'Populates a new channel column of the sys_log table.';
52  }
53 
57  public function ‪getDescription(): string
58  {
59  return <<<END
60 The logging system is migrating toward string-based channels rather than int-based types. This update populates the new column of existing log entries.
61 END;
62  }
63 
67  public function ‪executeUpdate(): bool
68  {
69  $statement = $this->sysLogTable->prepare('UPDATE sys_log SET channel = ? WHERE type = ?');
70  foreach (‪Type::channelMap() as $type => $channel) {
71  $statement->executeQuery([$channel, $type]);
72  }
73 
74  // Ensure the level field is a varchar, otherwise we are in trouble when logging into TYPO3 Backend.
75  $schema = $this->sysLogTable->createSchemaManager();
76  $table = $schema->listTableDetails('sys_log');
77  if (!$table->getColumn('level')->getType() instanceof StringType) {
78  $schema->alterTable(new TableDiff(
79  'sys_log',
80  [],
81  [new ColumnDiff('level', new Column('level', new StringType(), ['length' => 10, 'default' => 'info', 'notnull' => true]))],
82  [],
83  [],
84  [],
85  [],
86  $table
87  ));
88  }
89 
90  $statement = $this->sysLogTable->prepare('UPDATE sys_log SET level = ? WHERE type = ?');
91  foreach (‪Type::levelMap() as $type => $level) {
92  $statement->executeQuery([$level, $type]);
93  }
94 
95  return true;
96  }
97 
101  public function ‪updateNecessary(): bool
102  {
103  try {
104  $result = $this->sysLogTable->executeQuery('SELECT count(channel) FROM sys_log WHERE NOT channel="default"');
105  return !$result->fetchOne();
106  } catch (\Doctrine\DBAL\‪Exception\InvalidFieldNameException $e) {
107  return true;
108  }
109  }
110 
114  public function ‪getPrerequisites(): array
115  {
116  // we need to make sure the new DB column was already added.
117  return [
118  DatabaseUpdatedPrerequisite::class,
119  ];
120  }
121 }
‪TYPO3\CMS\Install\Updates\SysLogChannel\executeUpdate
‪executeUpdate()
Definition: SysLogChannel.php:67
‪TYPO3\CMS\Install\Updates\SysLogChannel\getPrerequisites
‪getPrerequisites()
Definition: SysLogChannel.php:114
‪TYPO3\CMS\Install\Updates\SysLogChannel\$sysLogTable
‪Connection $sysLogTable
Definition: SysLogChannel.php:31
‪TYPO3\CMS\Install\Updates\SysLogChannel\getTitle
‪getTitle()
Definition: SysLogChannel.php:49
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:16
‪TYPO3\CMS\Install\Updates\SysLogChannel\__construct
‪__construct()
Definition: SysLogChannel.php:33
‪TYPO3\CMS\Install\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Core\SysLog\Type\channelMap
‪static channelMap()
Definition: Type.php:71
‪TYPO3\CMS\Install\Updates\SysLogChannel\getDescription
‪getDescription()
Definition: SysLogChannel.php:57
‪TYPO3\CMS\Install\Updates\SysLogChannel\updateNecessary
‪updateNecessary()
Definition: SysLogChannel.php:101
‪TYPO3\CMS\Install\Updates\SysLogChannel\getIdentifier
‪getIdentifier()
Definition: SysLogChannel.php:41
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Install\Updates\SysLogChannel
Definition: SysLogChannel.php:30
‪TYPO3\CMS\Core\SysLog\Type\levelMap
‪static levelMap()
Definition: Type.php:63
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\SysLog\Type
Definition: Type.php:28