installed plugin Easy Digital Downloads version 3.1.0.3

This commit is contained in:
2022-11-27 15:03:07 +00:00
committed by Gitium
parent 555673545b
commit c5dce2cec6
1200 changed files with 238970 additions and 0 deletions

View File

@ -0,0 +1,68 @@
<?php
/**
* Adjustment Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_adjustmentmeta" database table.
*
* @since 3.0
*/
final class Adjustment_Meta extends Table {
/**
* Table name.
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'adjustmentmeta';
/**
* Database version.
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201806142;
/**
* Array of upgrade versions and methods.
*
* @access protected
* @since 3.0
* @var array
*/
protected $upgrades = array();
/**
* Setup the database schema.
*
* @access protected
* @since 3.0
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_adjustment_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_adjustment_id (edd_adjustment_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,206 @@
<?php
/**
* Adjustments Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_adjustments" database table.
*
* @since 3.0
*/
final class Adjustments extends Table {
/**
* Table name.
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'adjustments';
/**
* Database version.
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202102161;
/**
* Array of upgrade versions and methods.
*
* @access protected
* @since 3.0
* @var array
*/
protected $upgrades = array(
'201906031' => 201906031,
'202002121' => 202002121,
'202102161' => 202102161
);
/**
* Setup the database schema.
*
* @access protected
* @since 3.0
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
parent bigint(20) unsigned NOT NULL default '0',
name varchar(200) NOT NULL default '',
code varchar(50) NOT NULL default '',
status varchar(20) NOT NULL default '',
type varchar(20) NOT NULL default '',
scope varchar(20) NOT NULL default 'all',
amount_type varchar(20) NOT NULL default '',
amount decimal(18,9) NOT NULL default '0',
description longtext NOT NULL default '',
max_uses bigint(20) unsigned NOT NULL default '0',
use_count bigint(20) unsigned NOT NULL default '0',
once_per_customer int(1) NOT NULL default '0',
min_charge_amount decimal(18,9) NOT NULL default '0',
start_date datetime default null,
end_date datetime default null,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY type_status (type(20), status(20)),
KEY code (code),
KEY date_created (date_created),
KEY date_start_end (start_date,end_date)";
}
/**
* Create the table
*
* @since 3.0
*
* @return bool
*/
public function create() {
$created = parent::create();
// After successful creation, we need to set the auto_increment for legacy orders.
if ( ! empty( $created ) ) {
$result = $this->get_db()->get_var( "SELECT ID FROM {$this->get_db()->prefix}posts WHERE post_type = 'edd_discount' ORDER BY ID DESC LIMIT 1;" );
if ( ! empty( $result ) ) {
$auto_increment = $result + 1;
$this->get_db()->query( "ALTER TABLE {$this->table_name} AUTO_INCREMENT = {$auto_increment};" );
}
}
return $created;
}
/**
* Upgrade to version 201906031
* - Drop the `product_condition` column.
*
* @since 3.0
*
* @return boolean True if upgrade was successful, false otherwise.
*/
protected function __201906031() {
// Look for column
$result = $this->column_exists( 'product_condition' );
// Maybe remove column
if ( true === $result ) {
// Try to remove it
$result = ! $this->get_db()->query( "
ALTER TABLE {$this->table_name} DROP COLUMN `product_condition`
" );
// Return success/fail
return $this->is_success( $result );
// Return true because column is already gone
} else {
return $this->is_success( true );
}
}
/**
* Upgrade to version 202002121
* - Change default value to `null` for columns `start_date` and `end_date`.
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @return bool
*/
protected function __202002121() {
// Update `start_date`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `start_date` datetime default null;
" );
if ( $this->is_success( $result ) ) {
$this->get_db()->query( "UPDATE {$this->table_name} SET `start_date` = NULL WHERE `start_date` = '0000-00-00 00:00:00'" );
}
// Update `end_date`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `end_date` datetime default null;
" );
if ( $this->is_success( $result ) ) {
$this->get_db()->query( "UPDATE {$this->table_name} SET `end_date` = NULL WHERE `end_date` = '0000-00-00 00:00:00'" );
}
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202102161
* - Drop old `code_status_type_scope_amount` index
* - Create new `status_type` index
* - Create new `code` index
*
* @since 3.0
* @return bool
*/
protected function __202102161() {
if ( $this->index_exists( 'code_status_type_scope_amount' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} DROP INDEX code_status_type_scope_amount" );
}
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX type_status (type(20), status(20))" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX code (code)" );
return true;
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
* Customer Addresses Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_customer_addresses" database table
*
* @since 3.0
*/
final class Customer_Addresses extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'customer_addresses';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202004051;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'201906251' => 201906251,
'202002141' => 202002141,
'202004051' => 202004051,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
customer_id bigint(20) unsigned NOT NULL default '0',
is_primary tinyint(1) signed NOT NULL default '0',
type varchar(20) NOT NULL default 'billing',
status varchar(20) NOT NULL default 'active',
name mediumtext NOT NULL,
address mediumtext NOT NULL,
address2 mediumtext NOT NULL,
city mediumtext NOT NULL,
region mediumtext NOT NULL,
postal_code varchar(32) NOT NULL default '',
country mediumtext NOT NULL,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY customer_is_primary (customer_id, is_primary),
KEY type (type(20)),
KEY status (status(20)),
KEY date_created (date_created)";
}
/**
* Upgrade to version 201906251
* - Add the `name` mediumtext column
*
* @since 3.0
*
* @return boolean
*/
protected function __201906251() {
$result = $this->column_exists( 'name' );
if ( false === $result ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN `name` mediumtext AFTER `status`;
" );
}
return $this->is_success( $result );
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202004051
* - Update the customer physical address table to have `is_primary`
*
* @since 3.0
* @return bool
*/
protected function __202004051() {
$result = $this->column_exists( 'is_primary' );
if ( false === $result ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN `is_primary` tinyint SIGNED NOT NULL default '0' AFTER `customer_id`;
" );
}
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* Customer Email Addresses Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_customer_email_addresses" database table
*
* @since 3.0
*/
final class Customer_Email_Addresses extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'customer_email_addresses';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202002141;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
customer_id bigint(20) unsigned NOT NULL default '0',
type varchar(20) NOT NULL default 'secondary',
status varchar(20) NOT NULL default 'active',
email varchar(100) NOT NULL default '',
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY customer (customer_id),
KEY email (email),
KEY type (type(20)),
KEY status (status(20)),
KEY date_created (date_created)";
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,131 @@
<?php
/**
* Customer Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_customermeta" database table
*
* @since 3.0
*/
final class Customer_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'customermeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201807111;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'201807111' => 201807111
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_customer_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_customer_id (edd_customer_id),
KEY meta_key (meta_key({$max_index_length}))";
}
/**
* Override the Base class `maybe_upgrade()` routine to do a very unique and
* special check against the old option.
*
* Maybe upgrades the database table from 2.x to 3.x standards. This method
* should be kept up-to-date with schema changes in `set_schema()` above.
*
* - Hooked to the "admin_init" action.
* - Calls the parent class `maybe_upgrade()` method
*
* @since 3.0
*/
public function maybe_upgrade() {
if ( $this->needs_initial_upgrade() ) {
// Delete old/irrelevant database options.
delete_option( $this->table_prefix . 'edd_customermeta_db_version' );
delete_option( 'wp_edd_customermeta_db_version' );
$this->get_db()->query( "ALTER TABLE {$this->table_name} CHANGE `customer_id` `edd_customer_id` bigint(20) unsigned NOT NULL default '0';" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} DROP INDEX customer_id" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX edd_customer_id (edd_customer_id)" );
}
parent::maybe_upgrade();
}
/**
* Whether the initial upgrade from the 1.0 database needs to be run.
*
* @since 3.0.3
* @return bool
*/
private function needs_initial_upgrade() {
return $this->exists() && $this->column_exists( 'customer_id' ) && ! $this->column_exists( 'edd_customer_id' );
}
/**
* Upgrade to version 201807111
* - Rename `customer_id` column to `edd_customer_id`
* - Add `status` column.
*
* @since 3.0
*
* @return bool
*/
protected function __201807111() {
// Alter the database with separate queries so indexes succeed
if ( $this->column_exists( 'customer_id' ) && ! $this->column_exists( 'edd_customer_id' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} CHANGE `customer_id` `edd_customer_id` bigint(20) unsigned NOT NULL default '0'" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} DROP INDEX customer_id" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX edd_customer_id (edd_customer_id)" );
}
// Return success/fail
return $this->is_success( true );
}
}

View File

@ -0,0 +1,182 @@
<?php
/**
* Customers Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_customers" database table
*
* @since 3.0
*/
final class Customers extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'customers';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202006101;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
'202006101' => 202006101,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
user_id bigint(20) unsigned NOT NULL default '0',
email varchar(100) NOT NULL default '',
name varchar(255) NOT NULL default '',
status varchar(20) NOT NULL default '',
purchase_value decimal(18,9) NOT NULL default '0',
purchase_count bigint(20) unsigned NOT NULL default '0',
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
UNIQUE KEY email (email),
KEY user (user_id),
KEY status (status(20)),
KEY date_created (date_created)";
}
/**
* Override the Base class `maybe_upgrade()` routine to do a very unique and
* special check against the old option.
*
* Maybe upgrades the database table from 2.x to 3.x standards. This method
* should be kept up-to-date with schema changes in `set_schema()` above.
*
* - Hooked to the "admin_init" action.
* - Calls the parent class `maybe_upgrade()` method
*
* @since 3.0
*/
public function maybe_upgrade() {
if ( $this->needs_initial_upgrade() ) {
// Delete old/irrelevant database options.
delete_option( $this->table_prefix . 'edd_customers_db_version' );
delete_option( 'wp_edd_customers_db_version' );
// Modify existing columns.
$this->get_db()->query( "ALTER TABLE {$this->table_name} MODIFY `email` varchar(100) NOT NULL default ''" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} MODIFY `name` varchar(255) NOT NULL default ''" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} MODIFY `user_id` bigint(20) unsigned NOT NULL default '0'" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} MODIFY `purchase_value` decimal(18,9) NOT NULL default '0'" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} MODIFY `purchase_count` bigint(20) unsigned NOT NULL default '0'" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} MODIFY `date_created` datetime NOT NULL default CURRENT_TIMESTAMP" );
if ( ! $this->column_exists( 'status' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD COLUMN `status` varchar(20) NOT NULL default 'active' AFTER `name`;" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX status (status(20))" );
}
if ( ! $this->column_exists( 'date_modified' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD COLUMN `date_modified` datetime DEFAULT CURRENT_TIMESTAMP AFTER `date_created`" );
$this->get_db()->query( "UPDATE {$this->table_name} SET `date_modified` = `date_created`" );
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX date_created (date_created)" );
}
if ( ! $this->column_exists( 'uuid' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD COLUMN `uuid` varchar(100) default '' AFTER `date_modified`;" );
}
}
parent::maybe_upgrade();
}
/**
* Whether the initial upgrade from the 1.0 database needs to be run.
*
* @since 3.0.3
* @return bool
*/
private function needs_initial_upgrade() {
return $this->exists() && ! $this->column_exists( 'status' ) && ! $this->column_exists( 'uuid' );
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202006101
* - Remove the payment_ids column if it still exists.
*
* @since 3.0
* @return bool
*/
protected function __202006101() {
$result = true;
// Remove the column.
if ( $this->column_exists( 'payment_ids' ) ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} DROP `payment_ids`
" );
}
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Log Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_logmeta" database table
*
* @since 3.0
*/
final class Log_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'logmeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201805221;
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_log_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_log_id (edd_log_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Log Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_logs_api_requestmeta" database table
*
* @since 3.0
*/
final class Logs_Api_Request_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'logs_api_requestmeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201907291;
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_logs_api_request_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_logs_api_request_id (edd_logs_api_request_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,102 @@
<?php
/**
* API Request Logs Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_logs_api_requests" database table
*
* @since 3.0
*/
final class Logs_Api_Requests extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'logs_api_requests';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202002141;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
user_id bigint(20) unsigned NOT NULL default '0',
api_key varchar(32) NOT NULL default 'public',
token varchar(32) NOT NULL default '',
version varchar(32) NOT NULL default '',
request longtext NOT NULL default '',
error longtext NOT NULL default '',
ip varchar(60) NOT NULL default '',
time varchar(60) NOT NULL default '',
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY user_id (user_id),
KEY date_created (date_created)";
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Log Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_logs_file_downloadmeta" database table
*
* @since 3.0
*/
final class Logs_File_Download_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'logs_file_downloadmeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201907291;
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_logs_file_download_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_logs_file_download_id (edd_logs_file_download_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,102 @@
<?php
/**
* File Download Logs Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_logs_file_downloads" database table
*
* @since 3.0
*/
final class Logs_File_Downloads extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'logs_file_downloads';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202002141;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
product_id bigint(20) unsigned NOT NULL default '0',
file_id bigint(20) unsigned NOT NULL default '0',
order_id bigint(20) unsigned NOT NULL default '0',
price_id bigint(20) unsigned NOT NULL default '0',
customer_id bigint(20) unsigned NOT NULL default '0',
ip varchar(60) NOT NULL default '',
user_agent varchar(200) NOT NULL default '',
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY customer_id (customer_id),
KEY product_id (product_id),
KEY date_created (date_created)";
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* Logs Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_logs" database table
*
* @since 3.0
*/
final class Logs extends Table {
/**
* Table name.
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'logs';
/**
* Database version.
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202002141;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
);
/**
* Setup the database schema.
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
object_id bigint(20) unsigned NOT NULL default '0',
object_type varchar(20) DEFAULT NULL,
user_id bigint(20) unsigned NOT NULL default '0',
type varchar(20) DEFAULT NULL,
title varchar(200) DEFAULT NULL,
content longtext DEFAULT NULL,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY object_id_type (object_id,object_type(20)),
KEY user_id (user_id),
KEY type (type(20)),
KEY date_created (date_created)";
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Note Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_notemeta" database table
*
* @since 3.0
*/
final class Note_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'notemeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201805221;
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_note_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_note_id (edd_note_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,99 @@
<?php
/**
* Notes Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_notes" database table
*
* @since 3.0
*/
final class Notes extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'notes';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202002141;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
object_id bigint(20) unsigned NOT NULL default '0',
object_type varchar(20) NOT NULL default '',
user_id bigint(20) unsigned NOT NULL default '0',
content longtext NOT NULL default '',
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY object_id_type (object_id,object_type(20)),
KEY user_id (user_id),
KEY date_created (date_created)";
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,174 @@
<?php
/**
* Order Addresses Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_order_addresses" database table
*
* @since 3.0
*/
final class Order_Addresses extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'order_addresses';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202002141;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'201906251' => 201906251,
'201906281' => 201906281,
'202002141' => 202002141,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
order_id bigint(20) unsigned NOT NULL default '0',
type varchar(20) NOT NULL default 'billing',
name mediumtext NOT NULL,
address mediumtext NOT NULL,
address2 mediumtext NOT NULL,
city mediumtext NOT NULL,
region mediumtext NOT NULL,
postal_code varchar(32) NOT NULL default '',
country mediumtext NOT NULL,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY order_id (order_id),
KEY city (city({$max_index_length})),
KEY region (region({$max_index_length})),
KEY postal_code (postal_code(32)),
KEY country (country({$max_index_length})),
KEY date_created (date_created)";
}
/**
* Upgrade to version 201906251
* - Adds the 'name' column
* - Combines the `first_name` and `last_name` columns to the `name` column.
* - Removes the `first_name` and `last_name` columns.
*
* @since 3.0
*
* @return boolean
*/
protected function __201906251() {
$success = true;
$column_exists = $this->column_exists( 'name' );
// Don't take any action if the column already exists.
if ( false === $column_exists ) {
$column_exists = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN `name` mediumtext NOT NULL AFTER `last_name`;
" );
}
$deprecated_columns_exist = ( $this->column_exists( 'first_name' ) && $this->column_exists( 'last_name' ) );
if ( $column_exists && $deprecated_columns_exist ) {
$data_merged = $this->get_db()->query( "
UPDATE {$this->table_name} SET name = CONCAT(first_name, ' ', last_name);
" );
if ( $data_merged ) {
$success = $this->get_db()->query( "
ALTER TABLE {$this->table_name} DROP first_name, DROP last_name;
" );
}
}
return $this->is_success( $success );
}
/**
* Upgrade to version 201906281
* - Add the `type` varchar column
*
* @since 3.0
*
* @return boolean
*/
protected function __201906281() {
// Look for column.
$result = $this->column_exists( 'type' );
// Maybe add column.
if ( false === $result ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN `type` varchar(20) default 'billing' AFTER `order_id`;
" );
}
// Return success/fail.
return $this->is_success( $result );
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Order Adjustment Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_order_adjustmentmeta" database table
*
* @since 3.0
*/
final class Order_Adjustment_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'order_adjustmentmeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201805221;
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_order_adjustment_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_order_adjustment_id (edd_order_adjustment_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,187 @@
<?php
/**
* Order Adjustments Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_order_adjustments" database table
*
* @since 3.0
*/
final class Order_Adjustments extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'order_adjustments';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202105221;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
'202011122' => 202011122,
'202103151' => 202103151,
'202105221' => 202105221,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
parent bigint(20) unsigned NOT NULL default '0',
object_id bigint(20) unsigned NOT NULL default '0',
object_type varchar(20) DEFAULT NULL,
type_id bigint(20) unsigned DEFAULT NULL,
type varchar(20) DEFAULT NULL,
type_key varchar(255) DEFAULT NULL,
description varchar(100) DEFAULT NULL,
subtotal decimal(18,9) NOT NULL default '0',
tax decimal(18,9) NOT NULL default '0',
total decimal(18,9) NOT NULL default '0',
rate decimal(10,5) NOT NULL DEFAULT 1.00000,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY object_id_type (object_id,object_type(20)),
KEY date_created (date_created),
KEY parent (parent)";
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202011122
* - Change default value to `NULL` for `type_id` column.
* - Add `type_key` column.
*
* @since 3.0
* @return bool
*/
protected function __202011122() {
// Update `type_id`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `type_id` bigint(20) default NULL;
" );
// Add `type_key`.
$column_exists = $this->column_exists( 'type_key' );
if ( false === $column_exists ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN `type_key` varchar(255) default NULL AFTER `type`;
" );
} else {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY `type_key` varchar(255) default NULL AFTER `type`
" );
}
// Change `type_id` with `0` value to `null` to support new default.
$this->get_db()->query( "UPDATE {$this->table_name} SET type_id = null WHERE type_id = 0;" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202103151
* - Add column `parent`
* - Add index on `parent` column.
*
* @since 3.0
* @return bool
*/
protected function __202103151() {
// Look for column
$result = $this->column_exists( 'parent' );
// Maybe add column
if ( false === $result ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN parent bigint(20) unsigned NOT NULL default '0' AFTER id;
" );
}
if ( ! $this->index_exists( 'parent' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX parent (parent)" );
}
// Return success/fail.
return $this->is_success( $result );
}
/**
* Upgrade to version 202105221
* - Add `rate` column.
*
* @since 3.0
* @return bool
*/
protected function __202105221() {
if ( ! $this->column_exists( 'rate' ) ) {
return $this->is_success(
$this->get_db()->query(
"ALTER TABLE {$this->table_name} ADD COLUMN rate decimal(10,5) NOT NULL DEFAULT 1.00000 AFTER total"
)
);
}
return true;
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Order Item Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_order_itemmeta" database table
*
* @since 3.0
*/
final class Order_Item_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'order_itemmeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201805221;
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_order_item_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_order_item_id (edd_order_item_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,209 @@
<?php
/**
* Order Items Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_order_items" database table
*
* @since 3.0
*/
final class Order_Items extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'order_items';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202110141;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'201906241' => 201906241,
'202002141' => 202002141,
'202102010' => 202102010,
'202103151' => 202103151,
'202105221' => 202105221,
'202110141' => 202110141,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
parent bigint(20) unsigned NOT NULL default '0',
order_id bigint(20) unsigned NOT NULL default '0',
product_id bigint(20) unsigned NOT NULL default '0',
product_name text NOT NULL default '',
price_id bigint(20) unsigned default null,
cart_index bigint(20) unsigned NOT NULL default '0',
type varchar(20) NOT NULL default 'download',
status varchar(20) NOT NULL default 'pending',
quantity int signed NOT NULL default '0',
amount decimal(18,9) NOT NULL default '0',
subtotal decimal(18,9) NOT NULL default '0',
discount decimal(18,9) NOT NULL default '0',
tax decimal(18,9) NOT NULL default '0',
total decimal(18,9) NOT NULL default '0',
rate decimal(10,5) NOT NULL DEFAULT 1.00000,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY order_product_price_id (order_id,product_id,price_id),
KEY type_status (type(20),status(20)),
KEY parent (parent)";
}
/**
* Upgrade to version 201906241
* - Make the quantity column signed so it can contain negative numbers.
* - Switch the quantity column from bigint to int for storage optimization.
*
* @since 3.0
*
* @return bool
*/
protected function __201906241() {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY `quantity` int signed NOT NULL default '0';
" );
// Return success/fail
return $this->is_success( $result );
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202102010.
* - Change default value for `status` column to 'pending'.
*
* @return bool
*/
protected function __202102010() {
// Update `status`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `status` varchar(20) NOT NULL default 'pending';
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202103151
* - Add column `parent`
* - Add index on `parent` column.
*
* @since 3.0
* @return bool
*/
protected function __202103151() {
// Look for column
$result = $this->column_exists( 'parent' );
// Maybe add column
if ( false === $result ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN parent bigint(20) unsigned NOT NULL default '0' AFTER id;
" );
}
if ( ! $this->index_exists( 'parent' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX parent (parent)" );
}
// Return success/fail.
return $this->is_success( $result );
}
/**
* Upgrade to version 202105221
* - Add `rate` column.
*
* @since 3.0
* @return bool
*/
protected function __202105221() {
if ( ! $this->column_exists( 'rate' ) ) {
return $this->is_success(
$this->get_db()->query(
"ALTER TABLE {$this->table_name} ADD COLUMN rate decimal(10,5) NOT NULL DEFAULT 1.00000 AFTER total"
)
);
}
return true;
}
/**
* Upgrade to version 202110141
* - Change default value for `price_id` to `null`.
*
* @since 3.0
* @return bool
*/
protected function __202110141() {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN price_id bigint(20) unsigned default null;
" );
return $this->is_success( $result );
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Order Meta Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_ordermeta" database table
*
* @since 3.0
*/
final class Order_Meta extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'ordermeta';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 201805221;
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
edd_order_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext DEFAULT NULL,
PRIMARY KEY (meta_id),
KEY edd_order_id (edd_order_id),
KEY meta_key (meta_key({$max_index_length}))";
}
}

View File

@ -0,0 +1,161 @@
<?php
/**
* Order Transactions Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_order_transactions" database table.
*
* @since 3.0
*/
final class Order_Transactions extends Table {
/**
* Table name
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'order_transactions';
/**
* Database version
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202205241;
/**
* Array of upgrade versions and methods
*
* @since 3.0
*
* @var array
*/
protected $upgrades = array(
'202002141' => 202002141,
'202005261' => 202005261,
'202105291' => 202105291,
'202205241' => 202205241,
);
/**
* Setup the database schema
*
* @access protected
* @since 3.0
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
object_id bigint(20) unsigned NOT NULL default '0',
object_type varchar(20) NOT NULL default '',
transaction_id varchar(256) NOT NULL default '',
gateway varchar(20) NOT NULL default '',
status varchar(20) NOT NULL default '',
total decimal(18,9) NOT NULL default '0',
rate decimal(10,5) NOT NULL DEFAULT 1.00000,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY transaction_id (transaction_id(64)),
KEY gateway (gateway(20)),
KEY status (status(20)),
KEY date_created (date_created),
KEY object_type_object_id (object_type, object_id)";
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202005261
* - Changed the column length from 64 to 256 in order to account for future updates to gateway data.
*
* @since 3.0
*
* @return bool
*/
protected function __202005261() {
// Increase the transaction_id column.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `transaction_id` varchar(256) NOT NULL default '';
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202105291
* - Add `rate` column.
*
* @since 3.0
* @return bool
*/
protected function __202105291() {
if ( ! $this->column_exists( 'rate' ) ) {
return $this->is_success(
$this->get_db()->query(
"ALTER TABLE {$this->table_name} ADD COLUMN rate decimal(10,5) NOT NULL DEFAULT 1.00000 AFTER total"
)
);
}
return true;
}
/**
* Upgrade to version 202205241
* - Add combined index for object_type, object_id.
*
* @since 3.0
* @return bool
*/
protected function __202205241() {
if ( $this->index_exists( 'object_type_object_id' ) ) {
return true;
}
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX object_type_object_id (object_type, object_id)" );
return true;
}
}

View File

@ -0,0 +1,283 @@
<?php
/**
* Orders Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2018, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.0
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the global "edd_orders" database table
*
* @since 3.0
*/
final class Orders extends Table {
/**
* Table name.
*
* @access protected
* @since 3.0
* @var string
*/
protected $name = 'orders';
/**
* Database version.
*
* @access protected
* @since 3.0
* @var int
*/
protected $version = 202108041;
/**
* Array of upgrade versions and methods.
*
* @access protected
* @since 3.0
* @var array
*/
protected $upgrades = array(
'201901111' => 201901111,
'202002141' => 202002141,
'202012041' => 202012041,
'202102161' => 202102161,
'202103261' => 202103261,
'202105221' => 202105221,
'202108041' => 202108041,
);
/**
* Setup the database schema.
*
* @access protected
* @since 3.0
*/
protected function set_schema() {
$max_index_length = 191;
$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
parent bigint(20) unsigned NOT NULL default '0',
order_number varchar(255) NOT NULL default '',
status varchar(20) NOT NULL default 'pending',
type varchar(20) NOT NULL default 'sale',
user_id bigint(20) unsigned NOT NULL default '0',
customer_id bigint(20) unsigned NOT NULL default '0',
email varchar(100) NOT NULL default '',
ip varchar(60) NOT NULL default '',
gateway varchar(100) NOT NULL default 'manual',
mode varchar(20) NOT NULL default '',
currency varchar(20) NOT NULL default '',
payment_key varchar(64) NOT NULL default '',
tax_rate_id bigint(20) DEFAULT NULL,
subtotal decimal(18,9) NOT NULL default '0',
discount decimal(18,9) NOT NULL default '0',
tax decimal(18,9) NOT NULL default '0',
total decimal(18,9) NOT NULL default '0',
rate decimal(10,5) NOT NULL DEFAULT 1.00000,
date_created datetime NOT NULL default CURRENT_TIMESTAMP,
date_modified datetime NOT NULL default CURRENT_TIMESTAMP,
date_completed datetime default null,
date_refundable datetime default null,
uuid varchar(100) NOT NULL default '',
PRIMARY KEY (id),
KEY order_number (order_number({$max_index_length})),
KEY status_type (status, type),
KEY user_id (user_id),
KEY customer_id (customer_id),
KEY email (email(100)),
KEY payment_key (payment_key(64)),
KEY date_created_completed (date_created,date_completed)";
}
/**
* Create the table
*
* @since 3.0
*
* @return bool
*/
public function create() {
$created = parent::create();
// After successful creation, we need to set the auto_increment for legacy orders.
if ( ! empty( $created ) ) {
$last_payment_id = $this->get_db()->get_var( "SELECT ID FROM {$this->get_db()->prefix}posts WHERE post_type = 'edd_payment' ORDER BY ID DESC LIMIT 1;" );
if ( ! empty( $last_payment_id ) ) {
update_option( 'edd_v3_migration_pending', $last_payment_id, false );
$auto_increment = $last_payment_id + 1;
$this->get_db()->query( "ALTER TABLE {$this->table_name} AUTO_INCREMENT = {$auto_increment};" );
}
}
return $created;
}
/**
* Upgrade to version 201901111
* - Set any 'publish' status items to 'complete'.
*
* @since 3.0
*
* @return boolean
*/
protected function __201901111() {
$this->get_db()->query( "
UPDATE {$this->table_name} set `status` = 'complete' WHERE `status` = 'publish';
" );
return $this->is_success( true );
}
/**
* Upgrade to version 202002141
* - Change default value to `CURRENT_TIMESTAMP` for columns `date_created` and `date_modified`.
* - Change default value to `null` for columns `date_completed` and `date_refundable`.
*
* @since 3.0
* @return bool
*/
protected function __202002141() {
// Update `date_created`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_created` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_modified`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_modified` datetime NOT NULL default CURRENT_TIMESTAMP;
" );
// Update `date_completed`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_completed` datetime default null;
" );
if ( $this->is_success( $result ) ) {
$this->get_db()->query( "UPDATE {$this->table_name} SET `date_completed` = NULL WHERE `date_completed` = '0000-00-00 00:00:00'" );
}
// Update `date_refundable`.
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `date_refundable` datetime default null;
" );
if ( $this->is_success( $result ) ) {
$this->get_db()->query( "UPDATE {$this->table_name} SET `date_refundable` = NULL WHERE `date_refundable` = '0000-00-00 00:00:00'" );
}
return $this->is_success( $result );
}
/**
* Upgrade to version 202012041
* - Add column `tax_rate_id`
*
* @since 3.0
* @return bool
*/
protected function __202012041() {
// Look for column
$result = $this->column_exists( 'tax_rate_id' );
// Maybe add column
if ( false === $result ) {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} ADD COLUMN tax_rate_id bigint(20) DEFAULT NULL AFTER payment_key;
" );
}
// Return success/fail.
return $this->is_success( $result );
}
/**
* Upgrade to version 202102161
* - Drop `status` index
* - Create new `status_type` index
*
* @since 3.0
* @return bool
*/
protected function __202102161() {
if ( $this->index_exists( 'status' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} DROP INDEX status" );
}
if ( ! $this->index_exists( 'status_type' ) ) {
$this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX status_type (status, type)" );
}
return true;
}
/**
* Upgrade to version 202103261
* - Change length of `gateway` column to `100`.
*
* @since 3.0
* @return bool
*/
protected function __202103261() {
$result = $this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `gateway` varchar(100) NOT NULL default '';
" );
return $this->is_success( $result );
}
/**
* Upgrade to version 202105221
* - Add `rate` column.
*
* @since 3.0
* @return bool
*/
protected function __202105221() {
if ( ! $this->column_exists( 'rate' ) ) {
return $this->is_success(
$this->get_db()->query(
"ALTER TABLE {$this->table_name} ADD COLUMN rate decimal(10,5) NOT NULL DEFAULT 1.00000 AFTER total"
)
);
}
return true;
}
/**
* Upgrade to version 202108041
* - Set any empty gateway items to 'manual'.
*
* @since 3.0
*
* @return boolean
*/
protected function __202108041() {
$this->get_db()->query( "
UPDATE {$this->table_name} set `gateway` = 'manual' WHERE `gateway` = '';
" );
$this->get_db()->query( "
ALTER TABLE {$this->table_name} MODIFY COLUMN `gateway` varchar(100) NOT NULL default 'manual';
" );
return true;
}
}