-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwc-bulk-ai.php
More file actions
117 lines (107 loc) · 3.58 KB
/
wc-bulk-ai.php
File metadata and controls
117 lines (107 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Plugin Name: WooCommerce Product Bulk Agent
* Description: Update your WooCommerce products in bulk with an AI agent that can work 24/7.
* Version: 0.0.0
* Requires PHP: 8.2
*
* @package EPICWP\WC_Bulk_AI
*/
define( 'WC_BULK_AI_VERSION', '0.0.0' );
require __DIR__ . '/vendor/autoload_packages.php';
/**
* This loads the main application module.
*
* We use the `xwp_load_app` function to do all the heavy lifting.
* You can also use `xwp_create_app` to create a new container immediately.
* However this has caveats.
*
* If you use the `jetpack-autloader` autoloading will be done on the `plugins_loaded` hook.
* Using `xwp_create_app` will immediately start autoloading the classes and dependencies, which will prevent latest module versions from being loaded.
*
* @see https://github.com/Automattic/jetpack-autoloader
*/
xwp_load_app(
app: array(
'app_file' => __FILE__,
'app_id' => 'wc-bulk-ai',
'app_module' => \EPICWP\WC_Bulk_AI\App::class,
'app_version' => WC_BULK_AI_VERSION,
'cache_app' => false,
'cache_defs' => false,
'cache_dir' => __DIR__ . '/cache',
'cache_hooks' => false,
'public' => true,
'use_attributes' => true,
'use_autowiring' => true,
),
hook: 'plugins_loaded',
priority: 0,
);
// Register activation hook
\register_activation_hook(
__FILE__,
static function () {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
// Ensure WordPress is loaded
if ( ! function_exists( 'dbDelta' ) ) {
include_once ABSPATH . 'wp-admin/includes/upgrade.php';
}
// Create jobs table
$table_name = $wpdb->prefix . 'wcbai_jobs';
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
status varchar(20) NOT NULL,
product_id int(11) NOT NULL,
run_id int(11) NOT NULL,
created_at datetime NOT NULL,
started_at datetime NOT NULL,
finished_at datetime NOT NULL,
feedback text NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
dbDelta( $sql );
// Create runs table
$table_name = $wpdb->prefix . 'wcbai_runs';
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
task TEXT NOT NULL,
status varchar(20) NOT NULL,
created_at datetime NOT NULL,
started_at datetime NOT NULL,
finished_at datetime NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
dbDelta( $sql );
// Create product rollbacks table
$table_name = $wpdb->prefix . 'wcbai_product_rollbacks';
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
job_id int(11) NOT NULL,
property varchar(255) NOT NULL,
previous_value text NOT NULL,
status varchar(20) NOT NULL,
created_at datetime NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
dbDelta( $sql );
},
);
// Register deactivation hook
\register_deactivation_hook(
__FILE__,
static function () {
global $wpdb;
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wcbai_jobs" );
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wcbai_runs" );
},
);
// \register_deactivation_hook(
// __FILE__,
// static function () {
// global $wpdb;
// $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wcbai_jobs" );
// $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wcbai_runs" );
// },
// );