lockName( $orderId ); $wpdb = $this->wpdb; // Only a successful claim may write a refund. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Named lock, nothing to cache. $acquired = $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, %d)', $name, self::TIMEOUT_SECONDS ) ); if ( '1' !== (string) $acquired ) { throw new RefundLockException( 'Could not acquire the per-order refund lock; another refund is in progress.' ); } try { return $callback(); } finally { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Named lock, nothing to cache. $wpdb->query( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $name ) ); } } /** * Build a server-wide MySQL lock name for this site and order. * * @since 1.0.0 * * @param int $orderId The order id. * @return string The lock name. */ private function lockName( int $orderId ): string { $scope = md5( (string) $this->wpdb->dbname . '|' . (string) $this->wpdb->prefix ); return substr( 'releasecart_refund_' . $orderId . '_' . $scope, 0, 64 ); } }