‪TYPO3CMS  9.5
SchemaAlterTableListener.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Doctrine\DBAL\Event\SchemaAlterTableEventArgs;
20 use Doctrine\DBAL\Platforms\MySqlPlatform;
22 
27 {
37  public function ‪onSchemaAlterTable(SchemaAlterTableEventArgs $event)
38  {
40  $tableDiff = $event->getTableDiff();
41 
42  // Original Doctrine TableDiff without table options, continue default processing
43  if (!$tableDiff instanceof ‪TableDiff) {
44  return false;
45  }
46 
47  // Table options are only supported on MySQL, continue default processing
48  if (!$event->getPlatform() instanceof MySqlPlatform) {
49  return false;
50  }
51 
52  // No changes in table options, continue default processing
53  if (count($tableDiff->getTableOptions()) === 0) {
54  return false;
55  }
56 
57  $quotedTableName = $tableDiff->getName($event->getPlatform())->getQuotedName($event->getPlatform());
58 
59  // Add an ALTER TABLE statement to change the table engine to the list of statements.
60  if ($tableDiff->hasTableOption('engine')) {
61  $statement = 'ALTER TABLE ' . $quotedTableName . ' ENGINE = ' . $tableDiff->getTableOption('engine');
62  $event->addSql($statement);
63  }
64 
65  // continue default processing for all other changes.
66  return false;
67  }
68 }
‪TYPO3\CMS\Core\Database\Schema\EventListener\SchemaAlterTableListener\onSchemaAlterTable
‪bool onSchemaAlterTable(SchemaAlterTableEventArgs $event)
Definition: SchemaAlterTableListener.php:37
‪TYPO3\CMS\Core\Database\Schema\EventListener\SchemaAlterTableListener
Definition: SchemaAlterTableListener.php:27
‪TYPO3\CMS\Core\Database\Schema\EventListener
Definition: SchemaAlterTableListener.php:4
‪TYPO3\CMS\Core\Database\Schema\TableDiff
Definition: TableDiff.php:25