‪TYPO3CMS  10.4
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 {
38  public function ‪onSchemaAlterTable(SchemaAlterTableEventArgs $event)
39  {
41  $tableDiff = $event->getTableDiff();
42 
43  // Original Doctrine TableDiff without table options, continue default processing
44  if (!$tableDiff instanceof ‪TableDiff) {
45  return false;
46  }
47 
48  // Table options are only supported on MySQL, continue default processing
49  if (!$event->getPlatform() instanceof MySqlPlatform) {
50  return false;
51  }
52 
53  // No changes in table options, continue default processing
54  if (count($tableDiff->getTableOptions()) === 0) {
55  return false;
56  }
57 
58  $quotedTableName = $tableDiff->getName($event->getPlatform())->getQuotedName($event->getPlatform());
59 
60  // Add an ALTER TABLE statement to change the table engine to the list of statements.
61  if ($tableDiff->hasTableOption('engine')) {
62  $statement = 'ALTER TABLE ' . $quotedTableName . ' ENGINE = ' . $tableDiff->getTableOption('engine');
63  $event->addSql($statement);
64  }
65 
66  // continue default processing for all other changes.
67  return false;
68  }
69 }
‪TYPO3\CMS\Core\Database\Schema\EventListener\SchemaAlterTableListener\onSchemaAlterTable
‪bool onSchemaAlterTable(SchemaAlterTableEventArgs $event)
Definition: SchemaAlterTableListener.php:38
‪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