Skip to content

Commit 989f13f

Browse files
fixed MysqlAdapter check in Utf8mb4Fix migration
1 parent 0d61cb1 commit 989f13f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

config/Migrations/20171013133145_Utf8mb4Fix.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
use Cake\Error\Debugger;
4+
use Phinx\Db\Adapter\AdapterInterface;
5+
use Phinx\Db\Adapter\AdapterWrapper;
46
use Phinx\Db\Adapter\MysqlAdapter;
57
use Phinx\Migration\AbstractMigration;
68

@@ -16,7 +18,7 @@ class Utf8mb4Fix extends AbstractMigration {
1618
*
1719
* @return void
1820
*/
19-
public function change() {
21+
public function change(): void {
2022
$table = $this->table('queue_processes');
2123
$table->changeColumn('pid', 'string', [
2224
'length' => 40,
@@ -64,9 +66,8 @@ public function change() {
6466
'collation' => 'utf8mb4_unicode_ci',
6567
]);
6668
$table->update();
67-
6869
//TODO: check adapter and skip for postgres, instead of try/catch
69-
if ($this->adapter instanceof MysqlAdapter) {
70+
if ($this->getUnwrappedAdapter() instanceof MysqlAdapter) {
7071
try {
7172
$table = $this->table('queued_jobs');
7273
$table->changeColumn('data', 'text', [
@@ -90,4 +91,19 @@ public function change() {
9091
}
9192
}
9293

94+
/**
95+
* Gets the unwrapped adapter
96+
*
97+
* @return \Phinx\Db\Adapter\AdapterInterface|null
98+
*/
99+
private function getUnwrappedAdapter(): ?AdapterInterface {
100+
$adapter = $this->adapter;
101+
102+
while ($adapter instanceof AdapterWrapper) {
103+
$adapter = $adapter->getAdapter();
104+
}
105+
106+
return $adapter;
107+
}
108+
93109
}

0 commit comments

Comments
 (0)