$wpdb->prefix . 'aieo_product_requests', 'items' => $wpdb->prefix . 'aieo_product_request_items', 'views' => $wpdb->prefix . 'aieo_product_request_views', ); } function aieo_product_requests_install_schema() { global $wpdb; if ( ! function_exists( 'aieo_dbdelta' ) && defined( 'AIEO_DIR' ) ) { if ( file_exists( AIEO_DIR . 'includes/sql/sprocs.php' ) ) { require_once AIEO_DIR . 'includes/sql/sprocs.php'; } if ( ! function_exists( 'aieo_dbdelta' ) && file_exists( AIEO_DIR . 'includes/sql/sql-runtime-helpers.php' ) ) { require_once AIEO_DIR . 'includes/sql/sql-runtime-helpers.php'; } } $t = aieo_product_requests_tables(); $charset = aieo_get_charset_collate(); $sql_requests = "CREATE TABLE {$t['requests']} ( id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, request_type varchar(20) NOT NULL DEFAULT 'quote', status varchar(20) NOT NULL DEFAULT 'new', email varchar(255) NOT NULL, name varchar(190) NOT NULL DEFAULT '', phone varchar(64) NOT NULL DEFAULT '', message text NULL, user_id bigint(20) UNSIGNED NOT NULL DEFAULT 0, session_id varchar(64) NOT NULL DEFAULT '', token char(32) NOT NULL, token_expires datetime NOT NULL, page_url varchar(512) NOT NULL DEFAULT '', referrer varchar(512) NOT NULL DEFAULT '', attribution text NULL, seen_before text NULL, consent tinyint(1) NOT NULL DEFAULT 0, locale varchar(20) NOT NULL DEFAULT '', admin_note text NULL, notified_at datetime NULL DEFAULT NULL, summary_sent_at datetime NULL DEFAULT NULL, created_at datetime NOT NULL, handled_at datetime NULL DEFAULT NULL, handled_by bigint(20) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE KEY uk_token (token), KEY idx_status_created (status, created_at), KEY idx_email (email), KEY idx_type_created (request_type, created_at), KEY idx_session (session_id) ) {$charset};"; $sql_items = "CREATE TABLE {$t['items']} ( id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, request_id bigint(20) UNSIGNED NOT NULL, product_id bigint(20) UNSIGNED NOT NULL, variation_id bigint(20) UNSIGNED NOT NULL DEFAULT 0, qty int(10) UNSIGNED NOT NULL DEFAULT 1, source varchar(16) NOT NULL DEFAULT 'initial', added_at datetime NOT NULL, removed_at datetime NULL DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY uk_request_product (request_id, product_id, variation_id), KEY idx_product (product_id), KEY idx_request_added (request_id, added_at), KEY idx_request_removed (request_id, removed_at) ) {$charset};"; $sql_views = "CREATE TABLE {$t['views']} ( id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, request_id bigint(20) UNSIGNED NOT NULL, product_id bigint(20) UNSIGNED NOT NULL, viewed_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uk_request_product (request_id, product_id), KEY idx_request_viewed (request_id, viewed_at) ) {$charset};"; foreach ( array( $sql_requests, $sql_items, $sql_views ) as $sql ) { if ( function_exists( 'aieo_dbdelta' ) ) { aieo_dbdelta( $sql ); } else { if ( ! function_exists( 'dbDelta' ) ) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; } dbDelta( $sql ); } } }