| @@ -63,8 +63,13 @@ | ||
| 63 | 63 | if ( ! LP_Settings::is_created_tb_mcp_api_keys() ) { |
| 64 | 64 | $this->create_table_mcp_api_keys(); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | + // Runtime migration for Webhooks table. | |
| 68 | + if ( ! LP_Settings::is_created_tb_webhooks() ) { | |
| 69 | + $this->create_table_webhooks(); | |
| 70 | + } | |
| 71 | + | |
| 67 | 72 | // Set roles and capabilities. |
| 68 | 73 | learn_press_add_user_roles(); |
| 69 | 74 | |
| 70 | 75 | ini_set( 'max_execution_time', LearnPress::$time_limit_default_of_sever ); |
| @@ -139,8 +144,14 @@ | ||
| 139 | 144 | if ( ! LP_Settings::is_created_tb_mcp_api_keys() ) { |
| 140 | 145 | $this->create_table_mcp_api_keys(); |
| 141 | 146 | } |
| 142 | 147 | |
| 148 | + // Ensure Webhooks table exists for activation/upgrade flows. | |
| 149 | + // Keep this explicit guard in addition to tables-v4 config loading. | |
| 150 | + if ( ! LP_Settings::is_created_tb_webhooks() ) { | |
| 151 | + $this->create_table_webhooks(); | |
| 152 | + } | |
| 153 | + | |
| 143 | 154 | update_option( 'learn_press_check_tables', 'yes' ); |
| 144 | 155 | } catch ( Throwable $e ) { |
| 145 | 156 | error_log( $e->getMessage() ); |
| 146 | 157 | } |
| @@ -278,8 +289,41 @@ | ||
| 278 | 289 | updated_at datetime NULL DEFAULT NULL, |
| 279 | 290 | PRIMARY KEY (key_id), |
| 280 | 291 | UNIQUE KEY consumer_key (consumer_key), |
| 281 | 292 | KEY user_id (user_id) |
| 293 | + ) $collation"; | |
| 294 | + | |
| 295 | + $wpdb->query( $sql ); | |
| 296 | + } catch ( Throwable $e ) { | |
| 297 | + error_log( $e->getMessage() ); | |
| 298 | + } | |
| 299 | + } | |
| 300 | + | |
| 301 | + /** | |
| 302 | + * Create table learnpress_webhooks. | |
| 303 | + * | |
| 304 | + * @since 4.3.3 | |
| 305 | + * @return void | |
| 306 | + */ | |
| 307 | + public function create_table_webhooks() { | |
| 308 | + global $wpdb; | |
| 309 | + | |
| 310 | + try { | |
| 311 | + $collation = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'; | |
| 312 | + | |
| 313 | + $sql = "CREATE TABLE IF NOT EXISTS {$this->lp_db->tb_lp_webhooks} ( | |
| 314 | + webhook_id bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| 315 | + user_id bigint(20) unsigned NOT NULL DEFAULT 0, | |
| 316 | + status varchar(20) NOT NULL DEFAULT 'active', | |
| 317 | + name varchar(200) NOT NULL DEFAULT '', | |
| 318 | + delivery_url longtext NOT NULL, | |
| 319 | + secret text NOT NULL, | |
| 320 | + events longtext NOT NULL, | |
| 321 | + created_at datetime NOT NULL, | |
| 322 | + updated_at datetime NULL DEFAULT NULL, | |
| 323 | + PRIMARY KEY (webhook_id), | |
| 324 | + KEY user_id (user_id), | |
| 325 | + KEY status (status) | |
| 282 | 326 | ) $collation"; |
| 283 | 327 | |
| 284 | 328 | $wpdb->query( $sql ); |
| 285 | 329 | } catch ( Throwable $e ) { |