Support » Plugin: WooCommerce Blocks » wc_reserved_stock creation failed with hyperdb multiple database wp multisite

  • Resolved alexxus

    (@alexxus)


    WooCommerce wp_xxxid_wc_reserved_stock table creation failed. Does the xxxuser user have CREATE privileges on the xxxdb database?

    i use multiple database (101 databases) for my wordpress multisite network

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi there @alexxus 👋.

    Thanks for reporting the issue. This error message will appear when the table creation for that table fails. This could be due to the db user for your WordPress install not having privileges to create tables (unlikely in this case because it being WPMU) but can also be something else.

    Is this only happening for a specific site in your network (whatever xxid is), or is it happening for multiple sites?

    Plugin Support Joey Ricketts

    (@jricketts4)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    – Joey

    Hi,
    I have the same problem too.

    So, is that after we repair the db user privileges it will create *_wc_reserved_stock table automatically or we need to create it manually ?

    regards

    I had this issue and noticed that my table prefix had capital letters in and the function maybe_create_table in wp-content\plugins\woocommerce\packages\woocommerce-blocks\src\Installer.php fails to identify that the table already exists in the if statement on line 93 at the time of writing this.

    if ( in_array( $table_name, $wpdb->get_col( ‘SHOW TABLES’, 0 ), true ) ) {
    return true;
    }

    Anyway, I just reverted to all lower case prefix letters which resolved the error.

    @dalingzaf
    Could you be more detailed how to solve the problem? I have the same problem I enter from phpmyadmin and I see that the table is created but from the wordpress desktop I still get the same error message.Thanks

    @danielamat34

    As stated, my issue was case sensitivity.

    Have a look in your wp-config.php file for the table prefix setting used with your database. Ensure that the letters are all lowercase.
    For example:

    Change
    $table_prefix = 'wp_OdcSA_';
    to
    $table_prefix = 'wp_odcsa_';

    Hope it helps.

    @dalingzaf
    Yes, apparently that is my problem, only now it does not allow me to enter the desktop and it marks the following error Sorry, I do not have permission to access this page. I already verified that the prefix of my bd is the same as in the wp-config but the same thing I keep with the same error. I am going to investigate what it can be, thank you very much for your help and sorry for my English, I am managing with the google translate haha ​​thanks

    I have the same error, if I change the table prefix (setting in lowercase), the admin page (desktop page) marks the error “Sorry, You do not have permission to access this page”

    @danielamat34 can you solve it? (pudiste corregirlo, por si hablas español :P)

    hello I have solved the problem… please change the code of the file installer.php located in …wp-content/plugins/woocommerce/packages/woocommerce-blocks/src with this lines

    
    <?php
    /**
     * Handles installation of Blocks plugin dependencies.
     *
     * @package WooCommerce/Blocks
     */
    
    namespace Automattic\WooCommerce\Blocks;
    
    defined( 'ABSPATH' ) || exit;
    
    /**
     * Installer class.
     */
    class Installer {
    	/**
    	 * Constructor
    	 */
    	public function __construct() {
    		$this->init();
    	}
    
    	/**
    	 * Installation tasks ran on admin_init callback.
    	 */
    	public function install() {
    		$this->maybe_create_tables();
    		$this->maybe_create_cronjobs();
    	}
    
    	/**
    	 * Initialize class features.
    	 */
    	protected function init() {
    		add_action( 'admin_init', array( $this, 'install' ) );
    	}
    
    	/**
    	 * Set up the database tables which the plugin needs to function.
    	 */
    	public function maybe_create_tables() {
    		global $wpdb;
    
    		$schema_version    = 260;
    		$db_schema_version = (int) get_option( 'wc_blocks_db_schema_version', 0 );
    
    		if ( $db_schema_version > $schema_version ) {
    			return;
    		}
    
    		$show_errors = $wpdb->hide_errors();
    		$table_name  = strtolower($wpdb->prefix . 'wc_reserved_stock');
    		$collate     = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : '';
    		$exists      = $this->maybe_create_table(
    			$wpdb->prefix . 'wc_reserved_stock',
    			"
    			CREATE TABLE $table_name (
    				<code>order_id</code> bigint(20) NOT NULL,
    				<code>product_id</code> bigint(20) NOT NULL,
    				<code>stock_quantity</code> double NOT NULL DEFAULT 0,
    				<code>timestamp</code> datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    				<code>expires</code> datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
    				PRIMARY KEY  (<code>order_id</code>, <code>product_id</code>)
    			) $collate;
    			"
    		);
    
    		if ( $show_errors ) {
    			$wpdb->show_errors();
    		}
    
    		if ( ! $exists ) {
    			return $this->add_create_table_notice( $table_name );
    		}
    
    		// Update succeeded. This is only updated when successful and validated.
    		// $schema_version should be incremented when changes to schema are made within this method.
    		update_option( 'wc_blocks_db_schema_version', $schema_version );
    	}
    
    	/**
    	 * Create database table, if it doesn't already exist.
    	 *
    	 * Based on admin/install-helper.php maybe_create_table function.
    	 *
    	 * @param string $table_name Database table name.
    	 * @param string $create_sql Create database table SQL.
    	 * @return bool False on error, true if already exists or success.
    	 */
    	protected function maybe_create_table( $table_name, $create_sql ) {
    		global $wpdb;
    
    		if ( in_array( strtolower($table_name), $wpdb->get_col( 'SHOW TABLES', 0 ), true ) ) {
    			return true;
    		}
    
    		$wpdb->query( $create_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    
    		return in_array( strtolower($table_name), $wpdb->get_col( 'SHOW TABLES', 0 ), true );
    	}
    
    	/**
    	 * Add a notice if table creation fails.
    	 *
    	 * @param string $table_name Name of the missing table.
    	 */
    	protected function add_create_table_notice( $table_name ) {
    		add_action(
    			'admin_notices',
    			function() use ( $table_name ) {
    				echo '<div class="error"><p>';
    				printf(
    					/* Translators: %1$s table name, %2$s database user, %3$s database name. */
    					esc_html__( 'WooCommerce %1$s table creation failed. Does the %2$s user have CREATE privileges on the %3$s database?', 'woocommerce' ),
    					'<code>' . esc_html( $table_name ) . '</code>',
    					'<code>' . esc_html( DB_USER ) . '</code>',
    					'<code>' . esc_html( DB_NAME ) . '</code>'
    				);
    				echo '</p></div>';
    			}
    		);
    	}
    
    	/**
    	 * Maybe create cron events.
    	 */
    	protected function maybe_create_cronjobs() {
    		if ( function_exists( 'as_next_scheduled_action' ) && false === as_next_scheduled_action( 'woocommerce_cleanup_draft_orders' ) ) {
    			as_schedule_recurring_action( strtotime( 'midnight tonight' ), DAY_IN_SECONDS, 'woocommerce_cleanup_draft_orders' );
    		}
    	}
    }
    
    

    Hi guys,

    I have just solved the problem following the indications of marco978 right above this post.

    my wordpress version is : 5.5
    my woocommerce version is : 4.3.2

    The problem was a message displayed in the dashboard talking about “wc_reserved_stock creation failed”

    What I did was;
    – Change the installer.php code with the code provided by marco978.
    – Upgrade the php version from 7.3 to 7.4.

    The message is now gone.

    Hi everyone,
    same problem here: solved with the solution of @marco978 .

    No issues!

    • This reply was modified 2 months, 3 weeks ago by andrea5586.

    Hi,

    I’ve tried :
    @marco978 Installer.php file,
    – upgrade my php 7.2 to php 7.4
    – make user dbuser can create table

    But it hasn’t work yet. This message :
    WooCommerce p31_wc_reserved_stock table creation failed. Does the userdb user have CREATE privileges on the dbname database?

    and this message :

    Verifying database… One or more tables are still missing: p31_wc_reserved_stock

    any suggestion ?

    regards,

    • This reply was modified 2 months, 3 weeks ago by toosa.

    @toosa the problem wc_reserved_stock was solved definitely in wp 5.5 (in my opinion). You have to check that the table is in your db and update every plugin to the last version not only php.

    I hvae solved thanks to @marco978 :))

Viewing 15 replies - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.