PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.5.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.5.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / vendor / woocommerce / action-scheduler / classes / schema / ActionScheduler_StoreSchema.php

ActionScheduler_StoreSchema.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.5.4, at vendor/woocommerce/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php

141 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
22 * Construct.
23 */
24 public function __construct() {
25 $this->tables = [
26 self::ACTIONS_TABLE,
27 self::CLAIMS_TABLE,
28 self::GROUPS_TABLE,
29 ];
30 }
31
32 /**
33 * Performs additional setup work required to support this schema.
34 */
35 public function init() {
36 add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_5_0' ), 10, 2 );
37 }
38
39 /**
40 * Get table definition.
41 *
42 * @param string $table Table name.
43 */
44 protected function get_table_definition( $table ) {
45 global $wpdb;
46 $table_name = $wpdb->$table;
47 $charset_collate = $wpdb->get_charset_collate();
48 // phpcs:ignore Squiz.PHP.CommentedOutCode
49 $max_index_length = 191; // @see wp_get_db_schema()
50 $hook_status_scheduled_date_gmt_max_index_length = $max_index_length - 20 - 8; // - status, - scheduled_date_gmt
51 $default_date = self::DEFAULT_DATE;
52 switch ( $table ) {
53
54 case self::ACTIONS_TABLE:
55
56 return "CREATE TABLE {$table_name} (
57 action_id bigint(20) unsigned NOT NULL auto_increment,
58 hook varchar(191) NOT NULL,
59 status varchar(20) NOT NULL,
60 scheduled_date_gmt datetime NULL default '{$default_date}',
61 scheduled_date_local datetime NULL default '{$default_date}',
62 priority tinyint unsigned NOT NULL default '10',
63 args varchar($max_index_length),
64 schedule longtext,
65 group_id bigint(20) unsigned NOT NULL default '0',
66 attempts int(11) NOT NULL default '0',
67 last_attempt_gmt datetime NULL default '{$default_date}',
68 last_attempt_local datetime NULL default '{$default_date}',
69 claim_id bigint(20) unsigned NOT NULL default '0',
70 extended_args varchar(8000) DEFAULT NULL,
71 PRIMARY KEY (action_id),
72 KEY hook_status_scheduled_date_gmt (hook($hook_status_scheduled_date_gmt_max_index_length), status, scheduled_date_gmt),
73 KEY status_scheduled_date_gmt (status, scheduled_date_gmt),
74 KEY scheduled_date_gmt (scheduled_date_gmt),
75 KEY args (args($max_index_length)),
76 KEY group_id (group_id),
77 KEY last_attempt_gmt (last_attempt_gmt),
78 KEY `claim_id_status_scheduled_date_gmt` (`claim_id`, `status`, `scheduled_date_gmt`)
79 ) $charset_collate";
80
81 case self::CLAIMS_TABLE:
82
83 return "CREATE TABLE {$table_name} (
84 claim_id bigint(20) unsigned NOT NULL auto_increment,
85 date_created_gmt datetime NULL default '{$default_date}',
86 PRIMARY KEY (claim_id),
87 KEY date_created_gmt (date_created_gmt)
88 ) $charset_collate";
89
90 case self::GROUPS_TABLE:
91
92 return "CREATE TABLE {$table_name} (
93 group_id bigint(20) unsigned NOT NULL auto_increment,
94 slug varchar(255) NOT NULL,
95 PRIMARY KEY (group_id),
96 KEY slug (slug($max_index_length))
97 ) $charset_collate";
98
99 default:
100 return '';
101 }
102 }
103
104 /**
105 * Update the actions table schema, allowing datetime fields to be NULL.
106 *
107 * This is needed because the NOT NULL constraint causes a conflict with some versions of MySQL
108 * configured with sql_mode=NO_ZERO_DATE, which can for instance lead to tables not being created.
109 *
110 * Most other schema updates happen via ActionScheduler_Abstract_Schema::update_table(), however
111 * that method relies on dbDelta() and this change is not possible when using that function.
112 *
113 * @param string $table Name of table being updated.
114 * @param string $db_version The existing schema version of the table.
115 */
116 public function update_schema_5_0( $table, $db_version ) {
117 global $wpdb;
118
119 if ( 'actionscheduler_actions' !== $table || version_compare( $db_version, '5', '>=' ) ) {
120 return;
121 }
122
123 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
124 $table_name = $wpdb->prefix . 'actionscheduler_actions';
125 $table_list = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" );
126 $default_date = self::DEFAULT_DATE;
127
128 if ( ! empty( $table_list ) ) {
129 $query = "
130 ALTER TABLE {$table_name}
131 MODIFY COLUMN scheduled_date_gmt datetime NULL default '{$default_date}',
132 MODIFY COLUMN scheduled_date_local datetime NULL default '{$default_date}',
133 MODIFY COLUMN last_attempt_gmt datetime NULL default '{$default_date}',
134 MODIFY COLUMN last_attempt_local datetime NULL default '{$default_date}'
135 ";
136 $wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
137 }
138 // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
139 }
140 }
141