File "ActionScheduler_LoggerSchema.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php
File size: 1.98 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

class ActionScheduler_LoggerSchema extends ActionScheduler_Abstract_Schema
{
    const LOG_TABLE = 'actionscheduler_logs';
    protected $schema_version = 3;
    public function __construct()
    {
        $this->tables = [self::LOG_TABLE];
    }
    public function init()
    {
        add_action('action_scheduler_before_schema_update', array($this, 'update_schema_3_0'), 10, 2);
    }
    protected function get_table_definition($table)
    {
        global $wpdb;
        $table_name = $wpdb->{$table};
        $charset_collate = $wpdb->get_charset_collate();
        switch ($table) {
            case self::LOG_TABLE:
                $default_date = ActionScheduler_StoreSchema::DEFAULT_DATE;
                return "CREATE TABLE {$table_name} (\n\t\t\t\t        log_id bigint(20) unsigned NOT NULL auto_increment,\n\t\t\t\t        action_id bigint(20) unsigned NOT NULL,\n\t\t\t\t        message text NOT NULL,\n\t\t\t\t        log_date_gmt datetime NULL default '{$default_date}',\n\t\t\t\t        log_date_local datetime NULL default '{$default_date}',\n\t\t\t\t        PRIMARY KEY  (log_id),\n\t\t\t\t        KEY action_id (action_id),\n\t\t\t\t        KEY log_date_gmt (log_date_gmt)\n\t\t\t\t        ) {$charset_collate}";
            default:
                return '';
        }
    }
    public function update_schema_3_0($table, $db_version)
    {
        global $wpdb;
        if ('actionscheduler_logs' !== $table || version_compare($db_version, '3', '>=')) {
            return;
        }
        $table_name = $wpdb->prefix . 'actionscheduler_logs';
        $table_list = $wpdb->get_col("SHOW TABLES LIKE '{$table_name}'");
        $default_date = ActionScheduler_StoreSchema::DEFAULT_DATE;
        if (!empty($table_list)) {
            $query = "\n\t\t\t\tALTER TABLE {$table_name}\n\t\t\t\tMODIFY COLUMN log_date_gmt datetime NULL default '{$default_date}',\n\t\t\t\tMODIFY COLUMN log_date_local datetime NULL default '{$default_date}'\n\t\t\t";
            $wpdb->query($query);
        }
    }
}