PostConnectMiddleware.php
27 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Doctrine\Middlewares; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoetVendor\Doctrine\DBAL\Driver\Connection; |
| 9 | use MailPoetVendor\Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; |
| 10 | use Throwable; |
| 11 | |
| 12 | class PostConnectMiddleware extends AbstractDriverMiddleware { |
| 13 | public function connect(array $params): Connection { |
| 14 | $connection = parent::connect($params); |
| 15 | $connection->exec('SET time_zone = "+00:00"'); |
| 16 | // Lift the session MAX_JOIN_SIZE limit so large best-effort joins (e.g. the WP user |
| 17 | // synchronization on sites with many users/subscribers) don't fatal on hosts that |
| 18 | // enforce a low MAX_JOIN_SIZE. Best-effort: some hosts/engines may disallow it. |
| 19 | try { |
| 20 | $connection->exec('SET SESSION SQL_BIG_SELECTS=1'); |
| 21 | } catch (Throwable $e) { |
| 22 | // Ignore — keep the connection usable even if the host rejects this statement. |
| 23 | } |
| 24 | return $connection; |
| 25 | } |
| 26 | } |
| 27 |