lockName( (string) $key ); $wpdb = $this->wpdb; // 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 ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML output here; escaped where printed. throw new AdvisoryLockException( sprintf( 'Could not acquire the %s advisory lock for key %s.', $this->lockSpace, (string) $key ) ); } 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 tenant-specific MySQL lock name. * * @since 1.0.0 * * @param string $key The entity key. * @return string The lock name. */ private function lockName( string $key ): string { $scope = md5( (string) $this->wpdb->dbname . '|' . (string) $this->wpdb->prefix ); return substr( 'releasecart_' . $this->lockSpace . '_' . $key . '_' . $scope, 0, 64 ); } }