Automattic\WooCommerce\Database\Migrations\CustomOrderTable

PostsToOrdersMigrationController::maybe_start_transaction()privateWC 1.0

Start a database transaction if the configuration mandates so.

Метод класса: PostsToOrdersMigrationController{}

Хуков нет.

Возвращает

true|false|null. True if transaction started, false if transactions won't be used, null if transaction failed to start.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->maybe_start_transaction(): ?bool;

Код PostsToOrdersMigrationController::maybe_start_transaction() WC 9.0.2

private function maybe_start_transaction(): ?bool {

	$use_transactions = get_option( CustomOrdersTableController::USE_DB_TRANSACTIONS_OPTION, 'yes' );
	if ( 'yes' !== $use_transactions ) {
		return null;
	}

	$transaction_isolation_level        = get_option( CustomOrdersTableController::DB_TRANSACTIONS_ISOLATION_LEVEL_OPTION, CustomOrdersTableController::DEFAULT_DB_TRANSACTIONS_ISOLATION_LEVEL );
	$valid_transaction_isolation_levels = array( 'READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ', 'SERIALIZABLE' );
	if ( ! in_array( $transaction_isolation_level, $valid_transaction_isolation_levels, true ) ) {
		throw new \Exception( "Invalid database transaction isolation level name $transaction_isolation_level" );
	}

	$set_transaction_isolation_level_command = "SET TRANSACTION ISOLATION LEVEL $transaction_isolation_level";

	// We suppress errors in transaction isolation level setting because it's not supported by all DB engines, additionally, this might be executing in context of another transaction with a different isolation level.
	if ( ! $this->db_query( $set_transaction_isolation_level_command, true ) ) {
		return null;
	}

	return $this->db_query( 'START TRANSACTION' ) ? true : null;
}