-
Notifications
You must be signed in to change notification settings - Fork 3
[FEATURE] Allow other adapters for Phinx configuration #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ | |
| namespace Pagemachine\Phinx\Configuration; | ||
|
|
||
| use TYPO3\CMS\Core\Core\Environment; | ||
| use TYPO3\CMS\Core\Database\Connection; | ||
| use TYPO3\CMS\Core\Database\ConnectionPool; | ||
| use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
|
||
| final class PhinxConfiguration | ||
| { | ||
|
|
@@ -12,7 +15,8 @@ final class PhinxConfiguration | |
| public function toArray(): array | ||
| { | ||
| $extensionsPath = Environment::getExtensionsPath(); | ||
| $connectionParameters = $this->getConnectionParameters(); | ||
| $connection = GeneralUtility::makeInstance(ConnectionPool::class) | ||
| ->getConnectionForTable(self::MIGRATION_TABLE_NAME); | ||
|
|
||
| return [ | ||
| 'paths' => [ | ||
|
|
@@ -28,22 +32,49 @@ public function toArray(): array | |
| 'environments' => [ | ||
| 'default_migration_table' => self::MIGRATION_TABLE_NAME, | ||
| 'default_environment' => 'typo3', | ||
| 'typo3' => [ | ||
| 'adapter' => 'mysql', | ||
| 'host' => $connectionParameters['host'], | ||
| 'port' => $connectionParameters['port'], | ||
| 'user' => $connectionParameters['user'], | ||
| 'pass' => $connectionParameters['password'], | ||
| 'name' => $connectionParameters['dbname'], | ||
| 'unix_socket' => $connectionParameters['unix_socket'] ?? null, | ||
| 'charset' => $connectionParameters['charset'], | ||
| ], | ||
| 'typo3' => $this->getEnvironment($connection), | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| private function getConnectionParameters(): array | ||
| private function getEnvironment(Connection $connection): array | ||
| { | ||
| return $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']; | ||
| switch ($connection->getDatabasePlatform()->getName()) { | ||
| case 'sqlite': | ||
| $pathInfo = pathinfo($connection->getDatabase()); | ||
| $name = $pathInfo['dirname'] . '/' . $pathInfo['filename']; | ||
| $suffix = '.' . $pathInfo['extension']; | ||
|
Comment on lines
+44
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be a lot of magic / hidden knowledge going on here. Is there no Doctrine DBAL API for this? |
||
|
|
||
| return [ | ||
| 'adapter' => 'sqlite', | ||
| 'name' => $name, | ||
| 'suffix' => $suffix, | ||
| ]; | ||
| case 'mssql': | ||
| $adapter = 'sqlsrv'; | ||
| break; | ||
|
|
||
| case 'postgresql': | ||
| $adapter = 'pgsql'; | ||
| break; | ||
|
|
||
| case 'mysql': | ||
| $adapter = 'mysql'; | ||
| break; | ||
|
|
||
| default: | ||
| return []; | ||
| } | ||
|
|
||
| return [ | ||
| 'adapter' => $adapter, | ||
| 'host' => $connection->getParams()['host'] ?? null, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd at least call Finally |
||
| 'port' => $connection->getParams()['port'] ?? null, | ||
| 'user' => $connection->getParams()['user'] ?? null, | ||
| 'pass' => $connection->getParams()['password'] ?? null, | ||
| 'name' => $connection->getDatabase(), | ||
| 'unix_socket' => $connection->getParams()['unix_socket'] ?? null, | ||
| 'charset' => $connection->getParams()['charset'] ?? null, | ||
| ]; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we could put this directly in
$adapterinstead.Also what's the reason from using a connection instead of the raw TYPO3 config?