depth ) { $wpdb->query( 'BEGIN' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching } ++$this->depth; } /** * Decrement the nesting depth and commit when the outermost caller is done. * * @return void */ public function commit(): void { global $wpdb, $blclog; if ( $this->depth <= 0 ) { return; } --$this->depth; if ( 0 === $this->depth ) { $blclog->debug( 'Committing transaction.' ); $wpdb->query( 'COMMIT' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching } } /** * Roll back the current transaction and reset the nesting depth. * * @return void */ public function rollback(): void { global $wpdb; $this->depth = 0; $wpdb->query( 'ROLLBACK' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching } /** * Return the singleton instance. * * @return TransactionManager */ public static function getInstance() { if ( ! self::$instance ) { self::$instance = new TransactionManager(); } return self::$instance; } }