mailpoet
/
vendor
/
woocommerce
/
action-scheduler
/
classes
/
schema
/
ActionScheduler_LoggerSchema.php
ActionScheduler_LoggerSchema.php
1 year ago
ActionScheduler_StoreSchema.php
1 year ago
index.php
3 years ago
ActionScheduler_LoggerSchema.php
55 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | class ActionScheduler_LoggerSchema extends ActionScheduler_Abstract_Schema { |
| 4 | const LOG_TABLE = 'actionscheduler_logs'; |
| 5 | protected $schema_version = 3; |
| 6 | public function __construct() { |
| 7 | $this->tables = array( |
| 8 | self::LOG_TABLE, |
| 9 | ); |
| 10 | } |
| 11 | public function init() { |
| 12 | add_action( 'action_scheduler_before_schema_update', array( $this, 'update_schema_3_0' ), 10, 2 ); |
| 13 | } |
| 14 | protected function get_table_definition( $table ) { |
| 15 | global $wpdb; |
| 16 | $table_name = $wpdb->$table; |
| 17 | $charset_collate = $wpdb->get_charset_collate(); |
| 18 | switch ( $table ) { |
| 19 | case self::LOG_TABLE: |
| 20 | $default_date = ActionScheduler_StoreSchema::DEFAULT_DATE; |
| 21 | return "CREATE TABLE $table_name ( |
| 22 | log_id bigint(20) unsigned NOT NULL auto_increment, |
| 23 | action_id bigint(20) unsigned NOT NULL, |
| 24 | message text NOT NULL, |
| 25 | log_date_gmt datetime NULL default '{$default_date}', |
| 26 | log_date_local datetime NULL default '{$default_date}', |
| 27 | PRIMARY KEY (log_id), |
| 28 | KEY action_id (action_id), |
| 29 | KEY log_date_gmt (log_date_gmt) |
| 30 | ) $charset_collate"; |
| 31 | default: |
| 32 | return ''; |
| 33 | } |
| 34 | } |
| 35 | public function update_schema_3_0( $table, $db_version ) { |
| 36 | global $wpdb; |
| 37 | if ( 'actionscheduler_logs' !== $table || version_compare( $db_version, '3', '>=' ) ) { |
| 38 | return; |
| 39 | } |
| 40 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 41 | $table_name = $wpdb->prefix . 'actionscheduler_logs'; |
| 42 | $table_list = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" ); |
| 43 | $default_date = ActionScheduler_StoreSchema::DEFAULT_DATE; |
| 44 | if ( ! empty( $table_list ) ) { |
| 45 | $query = " |
| 46 | ALTER TABLE {$table_name} |
| 47 | MODIFY COLUMN log_date_gmt datetime NULL default '{$default_date}', |
| 48 | MODIFY COLUMN log_date_local datetime NULL default '{$default_date}' |
| 49 | "; |
| 50 | $wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 51 | } |
| 52 | // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 53 | } |
| 54 | } |
| 55 |