diff --git a/lib/Doctrine/ConnectionFactory.php b/lib/Doctrine/ConnectionFactory.php index 53f52de0af..fe86e23f33 100644 --- a/lib/Doctrine/ConnectionFactory.php +++ b/lib/Doctrine/ConnectionFactory.php @@ -16,6 +16,7 @@ class ConnectionFactory { function createConnection() { $platform_class = self::PLATFORM_CLASS; $connection_params = [ + 'wrapperClass' => SerializableConnection::class, 'driver' => self::DRIVER, 'platform' => new $platform_class, 'host' => Env::$db_host, diff --git a/lib/Doctrine/SerializableConnection.php b/lib/Doctrine/SerializableConnection.php new file mode 100644 index 0000000000..b0a49d0e27 --- /dev/null +++ b/lib/Doctrine/SerializableConnection.php @@ -0,0 +1,31 @@ +params = $params; + $this->driver = $driver; + $this->config = $config; + $this->event_manager = $event_manager; + parent::__construct($params, $driver, $config, $event_manager); + } + + function __sleep() { + return ['params', 'driver', 'config', 'event_manager']; + } + + function __wakeup() { + parent::__construct($this->params, $this->driver, $this->config, $this->event_manager); + } +} diff --git a/tests/integration/Doctrine/ConnectionFactoryTest.php b/tests/integration/Doctrine/ConnectionFactoryTest.php index 6c9d623bee..abef1f7804 100644 --- a/tests/integration/Doctrine/ConnectionFactoryTest.php +++ b/tests/integration/Doctrine/ConnectionFactoryTest.php @@ -4,6 +4,7 @@ namespace MailPoet\Test\Config; use MailPoet\Config\Env; use MailPoet\Doctrine\ConnectionFactory; +use MailPoet\Doctrine\SerializableConnection; use MailPoetVendor\Doctrine\DBAL\Driver\PDOMySql; use MailPoetVendor\Doctrine\DBAL\Platforms\MySqlPlatform; use PDO; @@ -13,6 +14,7 @@ class ConnectionFactoryTest extends \MailPoetTest { $connection_factory = new ConnectionFactory(); $connection = $connection_factory->createConnection(); + expect($connection)->isInstanceOf(SerializableConnection::class); expect($connection->getWrappedConnection())->isInstanceOf(PDO::class); expect($connection->getDriver())->isInstanceOf(PDOMySql\Driver::class); expect($connection->getDatabasePlatform())->isInstanceOf(MySqlPlatform::class);