| 1 |
<?php |
| 2 |
/** |
| 3 |
* AI Initialization Class. |
| 4 |
* |
| 5 |
* Handles AI-related module setup, including meta boxes, assets, and AJAX actions. |
| 6 |
* |
| 7 |
* @package RadiusTheme\SB |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace RadiusTheme\SB\AI\DB; |
| 11 |
|
| 12 |
use RadiusTheme\SB\AI\AIFns; |
| 13 |
use RadiusTheme\SB\Helpers\Fns; |
| 14 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 15 |
|
| 16 |
defined( 'ABSPATH' ) || exit(); |
| 17 |
|
| 18 |
/** |
| 19 |
* Initializes AI module components. |
| 20 |
*/ |
| 21 |
class CreateTableForAi { |
| 22 |
/** |
| 23 |
* Use Singleton trait. |
| 24 |
*/ |
| 25 |
use SingletonTrait; |
| 26 |
|
| 27 |
/** |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public function create_ai_embeddings_table() { |
| 31 |
global $wpdb; |
| 32 |
$is_table_exist = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . AIFns::$ai_embeddings_table ) ); //phpcs:ignore |
| 33 |
if ( ! empty( $is_table_exist ) ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
Fns::DB()::create( AIFns::$ai_embeddings_table )->column( 'id' )->bigInt( 20 )->unsigned()->autoIncrement()->primary()->required() |
| 37 |
->column( 'product_id' )->bigInt( 20 )->unsigned()->required() |
| 38 |
->column( 'title' )->text()->required() |
| 39 |
->column( 'embedding' )->longText()->required() |
| 40 |
->column( 'info' )->string()->nullable() |
| 41 |
->column( 'created_at' )->dateTime() |
| 42 |
->column( 'updated_at' )->dateTime() |
| 43 |
->index( [ 'product_id' ] ) |
| 44 |
->execute(); |
| 45 |
} |
| 46 |
} |
| 47 |
|