‪TYPO3CMS  ‪main
SchemaAlterTableListener.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\Event\SchemaAlterTableEventArgs;
21 use Doctrine\DBAL\Platforms\MySQLPlatform;
23 
28 {
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:28
‪TYPO3\CMS\Core\Database\Schema\EventListener
Definition: SchemaAlterTableListener.php:18
‪TYPO3\CMS\Core\Database\Schema\TableDiff
Definition: TableDiff.php:27