File "ActionScheduler_StoreSchema.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/packages/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php
File
size: 3.88 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
class ActionScheduler_StoreSchema extends ActionScheduler_Abstract_Schema
{
const ACTIONS_TABLE = 'actionscheduler_actions';
const CLAIMS_TABLE = 'actionscheduler_claims';
const GROUPS_TABLE = 'actionscheduler_groups';
const DEFAULT_DATE = '0000-00-00 00:00:00';
protected $schema_version = 5;
public function __construct()
{
$this->tables = [self::ACTIONS_TABLE, self::CLAIMS_TABLE, self::GROUPS_TABLE];
}
public function init()
{
add_action('action_scheduler_before_schema_update', array($this, 'update_schema_5_0'), 10, 2);
}
protected function get_table_definition($table)
{
global $wpdb;
$table_name = $wpdb->{$table};
$charset_collate = $wpdb->get_charset_collate();
$max_index_length = 191;
$default_date = self::DEFAULT_DATE;
switch ($table) {
case self::ACTIONS_TABLE:
return "CREATE TABLE {$table_name} (\n\t\t\t\t action_id bigint(20) unsigned NOT NULL auto_increment,\n\t\t\t\t hook varchar(191) NOT NULL,\n\t\t\t\t status varchar(20) NOT NULL,\n\t\t\t\t scheduled_date_gmt datetime NULL default '{$default_date}',\n\t\t\t\t scheduled_date_local datetime NULL default '{$default_date}',\n\t\t\t\t args varchar({$max_index_length}),\n\t\t\t\t schedule longtext,\n\t\t\t\t group_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t attempts int(11) NOT NULL default '0',\n\t\t\t\t last_attempt_gmt datetime NULL default '{$default_date}',\n\t\t\t\t last_attempt_local datetime NULL default '{$default_date}',\n\t\t\t\t claim_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t extended_args varchar(8000) DEFAULT NULL,\n\t\t\t\t PRIMARY KEY (action_id),\n\t\t\t\t KEY hook (hook({$max_index_length})),\n\t\t\t\t KEY status (status),\n\t\t\t\t KEY scheduled_date_gmt (scheduled_date_gmt),\n\t\t\t\t KEY args (args({$max_index_length})),\n\t\t\t\t KEY group_id (group_id),\n\t\t\t\t KEY last_attempt_gmt (last_attempt_gmt),\n\t\t\t\t KEY claim_id (claim_id),\n\t\t\t\t KEY `claim_id_status_scheduled_date_gmt` (`claim_id`, `status`, `scheduled_date_gmt`)\n\t\t\t\t ) {$charset_collate}";
case self::CLAIMS_TABLE:
return "CREATE TABLE {$table_name} (\n\t\t\t\t claim_id bigint(20) unsigned NOT NULL auto_increment,\n\t\t\t\t date_created_gmt datetime NULL default '{$default_date}',\n\t\t\t\t PRIMARY KEY (claim_id),\n\t\t\t\t KEY date_created_gmt (date_created_gmt)\n\t\t\t\t ) {$charset_collate}";
case self::GROUPS_TABLE:
return "CREATE TABLE {$table_name} (\n\t\t\t\t group_id bigint(20) unsigned NOT NULL auto_increment,\n\t\t\t\t slug varchar(255) NOT NULL,\n\t\t\t\t PRIMARY KEY (group_id),\n\t\t\t\t KEY slug (slug({$max_index_length}))\n\t\t\t\t ) {$charset_collate}";
default:
return '';
}
}
public function update_schema_5_0($table, $db_version)
{
global $wpdb;
if ('actionscheduler_actions' !== $table || version_compare($db_version, '5', '>=')) {
return;
}
$table_name = $wpdb->prefix . 'actionscheduler_actions';
$table_list = $wpdb->get_col("SHOW TABLES LIKE '{$table_name}'");
$default_date = self::DEFAULT_DATE;
if (!empty($table_list)) {
$query = "\n\t\t\t\tALTER TABLE {$table_name}\n\t\t\t\tMODIFY COLUMN scheduled_date_gmt datetime NULL default '{$default_date}',\n\t\t\t\tMODIFY COLUMN scheduled_date_local datetime NULL default '{$default_date}',\n\t\t\t\tMODIFY COLUMN last_attempt_gmt datetime NULL default '{$default_date}',\n\t\t\t\tMODIFY COLUMN last_attempt_local datetime NULL default '{$default_date}'\n\t\t";
$wpdb->query($query);
}
}
}