PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.1
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.1
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / lib / action-scheduler / classes / schema / ActionScheduler_StoreSchema.php
sureforms / inc / lib / action-scheduler / classes / schema Last commit date
ActionScheduler_LoggerSchema.php 2 years ago ActionScheduler_StoreSchema.php 2 years ago
ActionScheduler_StoreSchema.php
129 lines
1 <?php
2
3 /**
4 * Class ActionScheduler_StoreSchema
5 *
6 * @codeCoverageIgnore
7 *
8 * Creates custom tables for storing scheduled actions
9 */
10 class ActionScheduler_StoreSchema extends ActionScheduler_Abstract_Schema {
11 const ACTIONS_TABLE = 'actionscheduler_actions';
12 const CLAIMS_TABLE = 'actionscheduler_claims';
13 const GROUPS_TABLE = 'actionscheduler_groups';
14 const DEFAULT_DATE = '0000-00-00 00:00:00';
15
16 /**
17 * @var int Increment this value to trigger a schema update.
18 */
19 protected $schema_version = 7;
20
21 public function __construct() {
22 $this->tables = [
23 self::ACTIONS_TABLE,
24 self::CLAIMS_TABLE,
25 self::GROUPS_TABLE,
26 ];
27 }
28
29 /**
30 * Performs additional setup work required to support this schema.
31 */
32 public function init() {
33 add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_5_0' ), 10, 2 );
34 }
35
36 protected function get_table_definition( $table ) {
37 global $wpdb;
38 $table_name = $wpdb->$table;
39 $charset_collate = $wpdb->get_charset_collate();
40 $max_index_length = 191; // @see wp_get_db_schema()
41 $hook_status_scheduled_date_gmt_max_index_length = $max_index_length - 20 - 8; // - status, - scheduled_date_gmt
42 $default_date = self::DEFAULT_DATE;
43 switch ( $table ) {
44
45 case self::ACTIONS_TABLE:
46 return "CREATE TABLE {$table_name} (
47 action_id bigint(20) unsigned NOT NULL auto_increment,
48 hook varchar(191) NOT NULL,
49 status varchar(20) NOT NULL,
50 scheduled_date_gmt datetime NULL default '{$default_date}',
51 scheduled_date_local datetime NULL default '{$default_date}',
52 priority tinyint unsigned NOT NULL default '10',
53 args varchar($max_index_length),
54 schedule longtext,
55 group_id bigint(20) unsigned NOT NULL default '0',
56 attempts int(11) NOT NULL default '0',
57 last_attempt_gmt datetime NULL default '{$default_date}',
58 last_attempt_local datetime NULL default '{$default_date}',
59 claim_id bigint(20) unsigned NOT NULL default '0',
60 extended_args varchar(8000) DEFAULT NULL,
61 PRIMARY KEY (action_id),
62 KEY hook_status_scheduled_date_gmt (hook($hook_status_scheduled_date_gmt_max_index_length), status, scheduled_date_gmt),
63 KEY status_scheduled_date_gmt (status, scheduled_date_gmt),
64 KEY scheduled_date_gmt (scheduled_date_gmt),
65 KEY args (args($max_index_length)),
66 KEY group_id (group_id),
67 KEY last_attempt_gmt (last_attempt_gmt),
68 KEY `claim_id_status_scheduled_date_gmt` (`claim_id`, `status`, `scheduled_date_gmt`)
69 ) $charset_collate";
70
71 case self::CLAIMS_TABLE:
72 return "CREATE TABLE {$table_name} (
73 claim_id bigint(20) unsigned NOT NULL auto_increment,
74 date_created_gmt datetime NULL default '{$default_date}',
75 PRIMARY KEY (claim_id),
76 KEY date_created_gmt (date_created_gmt)
77 ) $charset_collate";
78
79 case self::GROUPS_TABLE:
80 return "CREATE TABLE {$table_name} (
81 group_id bigint(20) unsigned NOT NULL auto_increment,
82 slug varchar(255) NOT NULL,
83 PRIMARY KEY (group_id),
84 KEY slug (slug($max_index_length))
85 ) $charset_collate";
86
87 default:
88 return '';
89 }
90 }
91
92 /**
93 * Update the actions table schema, allowing datetime fields to be NULL.
94 *
95 * This is needed because the NOT NULL constraint causes a conflict with some versions of MySQL
96 * configured with sql_mode=NO_ZERO_DATE, which can for instance lead to tables not being created.
97 *
98 * Most other schema updates happen via ActionScheduler_Abstract_Schema::update_table(), however
99 * that method relies on dbDelta() and this change is not possible when using that function.
100 *
101 * @param string $table Name of table being updated.
102 * @param string $db_version The existing schema version of the table.
103 */
104 public function update_schema_5_0( $table, $db_version ) {
105 global $wpdb;
106
107 if ( 'actionscheduler_actions' !== $table || version_compare( $db_version, '5', '>=' ) ) {
108 return;
109 }
110
111 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
112 $table_name = $wpdb->prefix . 'actionscheduler_actions';
113 $table_list = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" );
114 $default_date = self::DEFAULT_DATE;
115
116 if ( ! empty( $table_list ) ) {
117 $query = "
118 ALTER TABLE {$table_name}
119 MODIFY COLUMN scheduled_date_gmt datetime NULL default '{$default_date}',
120 MODIFY COLUMN scheduled_date_local datetime NULL default '{$default_date}',
121 MODIFY COLUMN last_attempt_gmt datetime NULL default '{$default_date}',
122 MODIFY COLUMN last_attempt_local datetime NULL default '{$default_date}'
123 ";
124 $wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
125 }
126 // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
127 }
128 }
129