database = $database; } public function begin(): void { if ( $this->active ) { throw new StorageException( 'nested_transaction_denied' ); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared if ( false === $this->database->query( 'START TRANSACTION' ) ) { throw new StorageException( 'transaction_start_failed' ); } $this->active = true; } public function commit(): void { if ( ! $this->active ) { throw new StorageException( 'transaction_not_active' ); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared if ( false === $this->database->query( 'COMMIT' ) ) { $this->active = false; throw new StorageException( 'transaction_commit_failed' ); } $this->active = false; } public function rollback(): void { if ( ! $this->active ) { return; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared $this->database->query( 'ROLLBACK' ); $this->active = false; } }