-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.php
91 lines (74 loc) · 2.27 KB
/
bootstrap.php
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
<?php
use NewfoldLabs\WP\Module\Tasks\Tasks;
use NewfoldLabs\WP\ModuleLoader\Container;
use function NewfoldLabs\WP\ModuleLoader\register;
/**
* Add the tables
*/
function nfd_tasks_setup_tables() {
global $wpdb;
// Maybe create the table
if ( ! function_exists( 'maybe_create_table' ) ) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
}
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE `{$wpdb->prefix}nfd_tasks` (
task_id bigint(20) NOT NULL AUTO_INCREMENT,
task_name varchar(63) NOT NULL,
task_execute varchar(125),
args longtext,
num_retries int(2) UNSIGNED,
task_interval int(2) UNSIGNED,
task_priority int(2) UNSIGNED,
task_status varchar(12),
updated TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,
enabled tinyint(1),
PRIMARY KEY (task_id)
) $charset_collate;";
maybe_create_table( "{$wpdb->prefix}nfd_tasks", $sql );
$sql = "CREATE TABLE `{$wpdb->prefix}nfd_task_results` (
task_result_id bigint(20) NOT NULL AUTO_INCREMENT,
task_name varchar(63) NOT NULL,
stacktrace longtext,
success tinyint(1),
updated TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (task_result_id)
) $charset_collate;";
maybe_create_table( "{$wpdb->prefix}nfd_task_results", $sql );
}
/**
* Drop the tables on plugin deactivation
*/
function nfd_tasks_purge_tables() {
global $wpdb;
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}nfd_tasks`" );
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}nfd_task_results`" );
}
if ( function_exists( 'add_action' ) ) {
add_action(
'plugins_loaded',
function () {
// Set Global Constants
if ( ! defined( 'NFD_MODULE_TASKS_DIR' ) ) {
define( 'NFD_MODULE_TASKS_DIR', __DIR__ );
}
if ( ! defined( 'NFD_MODULE_TASKS_TASK_TABLE_NAME' ) ) {
define( 'NFD_MODULE_TASKS_TASK_TABLE_NAME', 'nfd_tasks' );
}
if ( ! defined( 'NFD_MODULE_TASKS_TASK_RESULTS_TABLE_NAME' ) ) {
define( 'NFD_MODULE_TASKS_TASK_RESULTS_TABLE_NAME', 'nfd_task_results' );
}
register(
[
'name' => 'tasks',
'label' => __( 'Tasks', 'newfold-tasks-module' ),
'callback' => function ( Container $container ) {
new Tasks( $container );
},
'isActive' => true,
'isHidden' => true,
]
);
}
);
}