Skip to content

Commit 7f0ab37

Browse files
committed
fixup! Reconnect wpdb with a fresh SQLite connection
1 parent 7369f13 commit 7f0ab37

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class WP_SQLite_DB extends wpdb {
2020
*/
2121
protected $dbh;
2222

23+
/**
24+
* Whether the PDO instance was provided externally through the global connection hook.
25+
*
26+
* @var bool
27+
*/
28+
private $is_pdo_external;
29+
2330
/**
2431
* Backward compatibility, see wpdb::$allow_unsafe_unquoted_parameters.
2532
*
@@ -38,6 +45,8 @@ class WP_SQLite_DB extends wpdb {
3845
* @param string $dbname Database name.
3946
*/
4047
public function __construct( $dbname ) {
48+
$this->is_pdo_external = isset( $GLOBALS['@pdo'] );
49+
4150
/**
4251
* We need to initialize the "$wpdb" global early, so that the SQLite
4352
* driver can configure the database. The call stack goes like this:
@@ -193,8 +202,14 @@ public function close() {
193202
return false;
194203
}
195204

205+
/*
206+
* @TODO: Release injected PDO instances. Closing a PDO instance requires
207+
* unsetting every reference. At the moment, $GLOBALS['@pdo'] must be
208+
* kept for backward compatibility and to reconnect when injected.
209+
*/
196210
if (
197-
isset( $GLOBALS['@pdo'] )
211+
! $this->is_pdo_external
212+
&& isset( $GLOBALS['@pdo'] )
198213
&& $GLOBALS['@pdo'] === $this->dbh->get_connection()->get_pdo()
199214
) {
200215
unset( $GLOBALS['@pdo'] );

0 commit comments

Comments
 (0)