mailpoet
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
schema
/
ActionScheduler_StoreSchema.php
ActionScheduler_LoggerSchema.php
1 year ago
ActionScheduler_StoreSchema.php
1 year ago
index.php
3 years ago
ActionScheduler_StoreSchema.php
93 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | class ActionScheduler_StoreSchema extends ActionScheduler_Abstract_Schema { |
| 4 | const ACTIONS_TABLE = 'actionscheduler_actions'; |
| 5 | const CLAIMS_TABLE = 'actionscheduler_claims'; |
| 6 | const GROUPS_TABLE = 'actionscheduler_groups'; |
| 7 | const DEFAULT_DATE = '0000-00-00 00:00:00'; |
| 8 | protected $schema_version = 7; |
| 9 | public function __construct() { |
| 10 | $this->tables = array( |
| 11 | self::ACTIONS_TABLE, |
| 12 | self::CLAIMS_TABLE, |
| 13 | self::GROUPS_TABLE, |
| 14 | ); |
| 15 | } |
| 16 | public function init() { |
| 17 | add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_5_0' ), 10, 2 ); |
| 18 | } |
| 19 | protected function get_table_definition( $table ) { |
| 20 | global $wpdb; |
| 21 | $table_name = $wpdb->$table; |
| 22 | $charset_collate = $wpdb->get_charset_collate(); |
| 23 | $default_date = self::DEFAULT_DATE; |
| 24 | // phpcs:ignore Squiz.PHP.CommentedOutCode |
| 25 | $max_index_length = 191; // @see wp_get_db_schema() |
| 26 | $hook_status_scheduled_date_gmt_max_index_length = $max_index_length - 20 - 8; // - status, - scheduled_date_gmt |
| 27 | switch ( $table ) { |
| 28 | case self::ACTIONS_TABLE: |
| 29 | return "CREATE TABLE {$table_name} ( |
| 30 | action_id bigint(20) unsigned NOT NULL auto_increment, |
| 31 | hook varchar(191) NOT NULL, |
| 32 | status varchar(20) NOT NULL, |
| 33 | scheduled_date_gmt datetime NULL default '{$default_date}', |
| 34 | scheduled_date_local datetime NULL default '{$default_date}', |
| 35 | priority tinyint unsigned NOT NULL default '10', |
| 36 | args varchar($max_index_length), |
| 37 | schedule longtext, |
| 38 | group_id bigint(20) unsigned NOT NULL default '0', |
| 39 | attempts int(11) NOT NULL default '0', |
| 40 | last_attempt_gmt datetime NULL default '{$default_date}', |
| 41 | last_attempt_local datetime NULL default '{$default_date}', |
| 42 | claim_id bigint(20) unsigned NOT NULL default '0', |
| 43 | extended_args varchar(8000) DEFAULT NULL, |
| 44 | PRIMARY KEY (action_id), |
| 45 | KEY hook_status_scheduled_date_gmt (hook($hook_status_scheduled_date_gmt_max_index_length), status, scheduled_date_gmt), |
| 46 | KEY status_scheduled_date_gmt (status, scheduled_date_gmt), |
| 47 | KEY scheduled_date_gmt (scheduled_date_gmt), |
| 48 | KEY args (args($max_index_length)), |
| 49 | KEY group_id (group_id), |
| 50 | KEY last_attempt_gmt (last_attempt_gmt), |
| 51 | KEY `claim_id_status_scheduled_date_gmt` (`claim_id`, `status`, `scheduled_date_gmt`) |
| 52 | ) $charset_collate"; |
| 53 | case self::CLAIMS_TABLE: |
| 54 | return "CREATE TABLE {$table_name} ( |
| 55 | claim_id bigint(20) unsigned NOT NULL auto_increment, |
| 56 | date_created_gmt datetime NULL default '{$default_date}', |
| 57 | PRIMARY KEY (claim_id), |
| 58 | KEY date_created_gmt (date_created_gmt) |
| 59 | ) $charset_collate"; |
| 60 | case self::GROUPS_TABLE: |
| 61 | return "CREATE TABLE {$table_name} ( |
| 62 | group_id bigint(20) unsigned NOT NULL auto_increment, |
| 63 | slug varchar(255) NOT NULL, |
| 64 | PRIMARY KEY (group_id), |
| 65 | KEY slug (slug($max_index_length)) |
| 66 | ) $charset_collate"; |
| 67 | default: |
| 68 | return ''; |
| 69 | } |
| 70 | } |
| 71 | public function update_schema_5_0( $table, $db_version ) { |
| 72 | global $wpdb; |
| 73 | if ( 'actionscheduler_actions' !== $table || version_compare( $db_version, '5', '>=' ) ) { |
| 74 | return; |
| 75 | } |
| 76 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 77 | $table_name = $wpdb->prefix . 'actionscheduler_actions'; |
| 78 | $table_list = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" ); |
| 79 | $default_date = self::DEFAULT_DATE; |
| 80 | if ( ! empty( $table_list ) ) { |
| 81 | $query = " |
| 82 | ALTER TABLE {$table_name} |
| 83 | MODIFY COLUMN scheduled_date_gmt datetime NULL default '{$default_date}', |
| 84 | MODIFY COLUMN scheduled_date_local datetime NULL default '{$default_date}', |
| 85 | MODIFY COLUMN last_attempt_gmt datetime NULL default '{$default_date}', |
| 86 | MODIFY COLUMN last_attempt_local datetime NULL default '{$default_date}' |
| 87 | "; |
| 88 | $wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 89 | } |
| 90 | // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 91 | } |
| 92 | } |
| 93 |