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,258 @@
<?php
/**
* Notifications Database
*
* @package easy-digital-downloads
* @copyright Copyright (c) 2021, Easy Digital Downloads
* @license GPL2+
* @since 2.11.4
*/
namespace EDD\Database;
use EDD\Models\Notification;
use EDD\Utils\EnvironmentChecker;
use EDD\Utils\NotificationImporter;
class NotificationsDB extends \EDD_DB {
/**
* Constructor
*/
public function __construct() {
global $wpdb;
$this->table_name = $wpdb->prefix . 'edd_notifications';
$this->primary_key = 'id';
$this->version = '1.0';
add_action( 'edd_daily_scheduled_events', array( $this, 'schedule_daily_notification_checks' ) );
$db_version = get_option( "{$this->table_name}_db_version" );
if ( version_compare( $db_version, $this->version, '>=' ) ) {
return;
}
$this->create_table();
}
/**
* Add a cron event to check for new notifications.
*
* @since 2.11.4
*/
public static function schedule_daily_notification_checks() {
$importer = new NotificationImporter();
$importer->run();
}
/**
* Columns and their formats.
*
* @since 2.11.4
*
* @return string[]
*/
public function get_columns() {
return array(
'id' => '%d',
'remote_id' => '%d',
'title' => '%s',
'content' => '%s',
'buttons' => '%s',
'type' => '%s',
'conditions' => '%s',
'start' => '%s',
'end' => '%s',
'dismissed' => '%d',
'date_created' => '%s',
'date_updated' => '%s',
);
}
/**
* Let MySQL handle most of the defaults.
* We just set the dates here to ensure they get saved in UTC.
*
* @since 2.11.4
*
* @return array
*/
public function get_column_defaults() {
return array(
'date_created' => gmdate( 'Y-m-d H:i:s' ),
'date_updated' => gmdate( 'Y-m-d H:i:s' ),
);
}
/**
* JSON-encodes any relevant columns.
*
* @since 2.11.4
*
* @param array $data
*
* @return array
*/
protected function maybeJsonEncode( $data ) {
$jsonColumns = array( 'buttons', 'conditions' );
foreach ( $jsonColumns as $column ) {
if ( ! empty( $data[ $column ] ) && is_array( $data[ $column ] ) ) {
$data[ $column ] = json_encode( $data[ $column ] );
}
}
return $data;
}
/**
* Inserts a new notification.
*
* @since 2.11.4
*
* @param array $data
* @param string $type
*
* @return int
*/
public function insert( $data, $type = 'notification' ) {
$result = parent::insert( $this->maybeJsonEncode( $data ), $type );
wp_cache_delete( 'edd_active_notification_count', 'edd_notifications' );
return $result;
}
/**
* Updates an existing notification.
*
* @since 2.11.4
*
* @param int $row_id
* @param array $data
* @param string $where
*
* @return bool
*/
public function update( $row_id, $data = array(), $where = '' ) {
return parent::update( $row_id, $this->maybeJsonEncode( $data ), $where );
}
/**
* Returns all notifications that have not been dismissed and should be
* displayed on this site.
*
* @since 2.11.4
*
* @param bool $conditionsOnly If set to true, then only the `conditions` column is retrieved
* for each notification.
*
* @return Notification[]
*/
public function getActiveNotifications( $conditionsOnly = false ) {
global $wpdb;
$environmentChecker = new EnvironmentChecker();
$notifications = $wpdb->get_results( $this->getActiveQuery( $conditionsOnly ) );
$models = array();
if ( is_array( $notifications ) ) {
foreach ( $notifications as $notification ) {
$model = new Notification( (array) $notification );
try {
// Only add to the array if all conditions are met or if the notification has no conditions.
if (
! $model->conditions ||
( is_array( $model->conditions ) && $environmentChecker->meetsConditions( $model->conditions ) )
) {
$models[] = $model;
}
} catch ( \Exception $e ) {
}
}
}
unset( $notifications );
return $models;
}
/**
* Builds the query for selecting or counting active notifications.
*
* @since 2.11.4
*
* @param bool $conditionsOnly
*
* @return string
*/
private function getActiveQuery( $conditionsOnly = false ) {
global $wpdb;
$select = $conditionsOnly ? 'conditions' : '*';
return $wpdb->prepare(
"SELECT {$select} FROM {$this->table_name}
WHERE dismissed = 0
AND (start <= %s OR start IS NULL)
AND (end >= %s OR end IS NULL)
ORDER BY start DESC, id DESC",
gmdate( 'Y-m-d H:i:s' ),
gmdate( 'Y-m-d H:i:s' )
);
}
/**
* Counts the number of active notifications.
* Note: We can't actually do a real `COUNT(*)` on the database, because we want
* to double-check the conditions are met before displaying. That's why we use
* `getActiveNotifications()` which runs the conditions through the EnvironmentChecker.
*
* @since 2.11.4
*
* @return int
*/
public function countActiveNotifications() {
$numberActive = wp_cache_get( 'edd_active_notification_count', 'edd_notifications' );
if ( false === $numberActive ) {
$numberActive = count( $this->getActiveNotifications( true ) );
wp_cache_set( 'edd_active_notification_count', $numberActive, 'edd_notifications' );
}
return $numberActive;
}
/**
* Creates the table.
*
* @since 2.11.4
*/
public function create_table() {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
global $wpdb;
dbDelta( "CREATE TABLE {$this->table_name} (
id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
remote_id bigint(20) UNSIGNED DEFAULT NULL,
title text NOT NULL,
content longtext NOT NULL,
buttons longtext DEFAULT NULL,
type varchar(64) NOT NULL,
conditions longtext DEFAULT NULL,
start datetime DEFAULT NULL,
end datetime DEFAULT NULL,
dismissed tinyint(1) UNSIGNED NOT NULL DEFAULT 0,
date_created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(),
date_updated datetime NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (id),
KEY dismissed_start_end (dismissed, start, end)
) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate};" );
update_option( $this->table_name . '_db_version', $this->version );
}
}

View File

@ -0,0 +1,384 @@
# Custom Tables #
### The schema for each custom table is described below
## The Adjustments Table:
This table stores things that can be used to adjust an order. This includes things like discount codes and tax rates. Note that these things do not represent an adjustment that was used for a specific order. To see a record of those, look at the order_adjustments table.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| parent | This column does not currently serve any purpose, but might be used in the future. |
| name | The name of the adjustment. For discount codes, this is the name of the discount. For tax rates, this is the name of the country for which the tax rate applies. All tax rates in a country share the same value in this column. For example, all tax rates in Canada will use "CA" here. |
| code | For discount codes, this is the value which users can enter upon checkout. For tax rates, this column is blank. |
| status | A string which indicates the status of the adjustment. For tax rates this will be "active" or "inactive". For discount codes, this will be "active" even if the discount has expired, and this is intentional. |
| type | The type of adjustment this is. For discounts this is "discount". For tax rates this is "tax_rate". |
| scope | A value which defines how the adjustment can be used. For discount codes the value is always "global". For tax rates, the values can be "country", or "region". |
| amount_type | The type of amount this is, either "percent" or "flat", with flat being a monetary value. |
| amount | The amount of the adjustment, stored as a decimal and representing either a percent or flat amount. |
| description | For tax rates, this is the "state" or "province". For example, for Ontario (the province in Canada), this value will be "ON". For discount codes this column is not currently used. |
| max_uses | An integer indicating the maximum number of times this adjustment can be used. |
| use_count | An integer indicating the number of times this adjustment has been used. |
| once_per_customer | A boolean value in the form of 1 (for true) and 0 (for false). If 1, this adjustment should only be used once per customer. If 0, there is no limit to the number of times it can be used. |
| min_charge_amount | For discount codes, this is the minimum amount required in the cart prior to this adjustment being applied. For tax rates this is typically not applicable. |
| start_date | For discount codes, this is the date when a discount code will begin to work. This is not applicable to tax rates. |
| end_date | For discount codes, this is the date when a discount code will cease to work. This is not applicable to tax rates. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Adjustment Meta Table:
This table stores various and custom/extra information about an adjustment.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_adjustment_id | The id of the adjustment to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Customer Addresses Table:
This table stores the addresses of customers.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| customer_id | The id of the customer to which this address belongs. This id corresponds to the id column in the Customers table. |
| name | The name of the person connected to this physical address. |
| type | The type of address this row represents. Typical values are "billing" and "shipping". |
| status | This currently does not serve any purpose, but might in the future. |
| address | The first line of a physical address. |
| address2 | The second line of a physical address. |
| city | The city of a physical address. |
| region | A 2 letter representation of the region/state/province. For example, in the US, this is the "State". In Canada, this is the "Province". |
| postal_code | The postal code for a physical address. It accepts any string. |
| country | The 2 letter representation of a country for a physical address. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Customer Email Addresses Table:
This table stores the email addresses of customers.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| customer_id | The id of the customer to which this email address belongs. This id corresponds to the id column in the Customers table. |
| type | A string representing the priority (or importance) of this email address. Typical values are "primary" and "secondary". |
| status | This does not serve any purpose at this time, but might in the future. |
| email | An email address, which is connected to a customer. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Customer Meta Table:
This table stores various and custom/extra information about a customer.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_customer_id | The id of the customer to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Customers Table:
This table stores customers. Customers are people who have made a purchase in your store.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. This is also the id of the customer. |
| user_id | The id of the WordPress user which is linked to this customer. The same real-world person owns both, the WP user, and the EDD customer. |
| email | The primary email address of this customer. This value will typically match whatever the "primary" email is in the customer emails table in the "type" column. |
| name | This is the customer's name, and includes their first and last name together in a single string. |
| status | Currently, this stores the word "active" for all customers, until such time as functionality for "inactive" customers gets added to EDD. |
| purchase_value | This is the total amount of money this customer has paid. |
| purchase_count | This is the total number of purchases this customer has initiated. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Log Meta Table:
This table stores various and custom/extra information about a log.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_log_id | The id of the log to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Logs Table:
This table stores general-purpose logs, which are typically records of events happening, like a payment being completed or refunded. Note that logs are intended to be "created by a machine" as opposed to "created by a human". If you are writing code that automatically logs something, make it a log in this table. If you are writing code that creates a UI which allows a human being to write a note, store it in the notes table.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| object_id | The id of the thing to which this log relates. For example, the id of the "order" or the "discount code". |
| object_type | This describes the type of thing this log is for. For example, "order" indicates this log is for an order. |
| user_id | This is the ID of the WordPress user who created this log. |
| type | This column indicates the type of log this is. For example, the word "refund" would indicate that this log is about a refund taking place. |
| title | This is the title of the log. Typically this is a short sentence describing what the log is about. |
| content | This is a longer description of the log. Typically this will be a sentence or paragraph describing the event which took place. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Logs API Requests Table:
Every time a request is made to the EDD REST API, that request is logged in this table.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| user_id | This stores the ID of the WordPress user who created this log. |
| api_key | This stores the api key used to make this API request. |
| token | This stores the token used to make this API request. |
| version | This stores the version of the API for which this call was made. |
| request | This stores what the URL variables were when the request was made. |
| error | Errors that took place during the call. Defaults to be empty. |
| ip | The IP address of the machine which made the request. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Log API Request Meta Table:
This table stores various and custom/extra information about an API Request Log.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_logs_api_request_id | The id of the api request log to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Logs File Downloads Table:
Every time a deliverable file is downloaded via EDD, it is logged in this table.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| product_id | The ID of the EDD product whose file was downloaded. |
| file_id | The id of the file being downloaded. This ID comes from the files attached to an EDD product. |
| order_id | The ID of the order which is enabling this download to take place. |
| price_id | The variable price ID which was purchased, and which enabled this download to take place. 0 if the product is not variably-priced. |
| customer_id | The ID of the customer who downloaded this file. |
| ip | The IP address of the machine which made the request to download the file. |
| user_agent | The name/user-agent of the browser which was used to download the file. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Log File Download Meta Table:
This table stores various and custom/extra information about a file download log.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_logs_file_download_id | The id of the file download log to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Note Meta Table:
This table stores various and custom/extra information about a note.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_note_id | The id of the note to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Notes Table:
This table is for storing notes created by human beings, as opposed to notes/logs/data created automatically by code or automatic code events happening. Note that logs are intended to be "created by a machine" as opposed to "created by a human". If you are writing code that automatically logs something, make it a log in the logs table. If you are writing code that creates a UI which allows a human being to write a note, store it in the notes table here.
This table's data is intended to be mutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| object_id | The id of the thing to which this note relates. For example, the id of the "order" for which this note was created. |
| object_type | This describes the type of thing this note is for. For example, "order" indicates this note is for/about an order. |
| user_id | This is the ID of the WordPress user who created this note. |
| content | This is the main/unique content of the note, the note itself. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Order Addresses Table:
When a user completes a purchase/order and enters their address on the checkout page, that address is stored in a new row here. This allows the address attached to the order to remain what it was at the time of purchase, regardless of whether the customer changes their address in the future. This is because the address attached to an order should remain unchanged forever. These addresses should be considered immutable. Even if a customer has 2 orders and uses the exact same address for each order, a new row will be created here, unique to that order, despite possibly being identical to a previous row.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| order_id | The id of the order to which this address is attached. |
| name | The name of the person attached to this physical address. |
| type | The type of address this row represents. Typical values are "billing" and "shipping". |
| address | The first line of a physical address. |
| address2 | The second line of a physical address. |
| city | The city of a physical address. |
| region | A 2 letter representation of the region/state/province. For example, in the US, this is the "State". In Canada, this is the "Province". |
| postal_code | The postal code for a physical address. It accepts any string. |
| country | The 2 letter representation of a country for a physical address. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Order Adjustment Meta Table:
This table stores various and custom/extra information about an order adjustment.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_order_adjustment_id | The id of the adjustment to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Order Adjustments Table:
This table stores things that adjusted the total amount of a specific order, or the amount of an item within an order. This includes things like discount codes and tax rates.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| parent | The ID of another order adjustment which is considered to be the parent of this adjustment. This is used for adjustments attached to refunds. The parent references the ID of the original order adjustment that was refunded. |
| object_id | The ID of the row that this row adjusted the amount/cost of. This is typically an order (in the orders table) or an order_item (in the order_items table). The type of object is indicated in the object_type column. |
| object_type | This typically indicates the EDD custom table that the object_id value can be found within, and to which row within that table this row relates. For example, the orders table (indicated by the word "order") or the order_items table (indicated by the word "order_item"). |
| type_id | This value indicates the row ID in the adjustments table from which this order adjustment originated. For example, if this value is "25", go to the adjustments table and look at the row with the ID "25" to see the corresponding adjustment. |
| type | A string which indicates the type of adjustment this is. Typically this is something like "fee", "tax_rate", or "discount". |
| type_key | The fees API allows for customizing the array key value for a given fee. This can be a string or numeric. This "fee ID" is stored as the type_key, as it represents the fee's key in the 2.x array. |
| description | A description of the order adjustment. |
| subtotal | If the amount type for this row is a percentage, the value in this column is intentionally unused. Otherwise, it stores the monetary amount of this adjustment before tax. For example, if you have a $10 shipping fee with a 10% tax rate, $10 is stored in this column. |
| tax | If the object_type for this row is a percentage, the value in this column is intentionally unused. Otherwise, it stores the monetary amount of the tax on this adjustment. For example, if you have a $10 shipping fee, the tax on the $10 is stored in this column. |
| total | Like the subtotal and tax columns, this column stores a monetary amount sometimes, and at others stores a percentage rate. To determine the type of amount being stored, percentage vs flat amount, trace the row back to the adjustments table using the type_id value from this table, and check the amount_type column's value from the adjustments table. For example, if you have a $10 shipping fee with a 10% tax rate, $11 is stored in this column. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Order Item Meta Table:
This table stores various and custom/extra information about an order item.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_order_item_id | The id of the order item to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Order Items Table:
This table stores items (or "products", also known as "downloads" in EDD) that were part of an order. It also stores various data about the items, like the tax that was on the item,.
One way to think about this is that a "for-sale thing" is called a "product" when in an un-purchased state, and called an "item" when in a purchased state.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| parent | The ID of another order item which is considered to be the parent of this item. This is used for order items attached to refunds. The parent references the ID of the original order item that was refunded. |
| order_id | The ID of the order to which this item belongs. |
| product_id | The ID of the product which was purchased. |
| product_name | This is what the name of the product was at the time of this purchase. |
| price_id | This is the ID of the variable price which was purchased. |
| price_name | This is what the name of the variable price was at the time of this purchase. |
| cart_index | This is the position at which this item was sitting in the cart when this order took place, starting at 0 for the first position. |
| type | This indicates the type of product that this item is. In its current form, all things sold in EDD have the type of "download", and thus does not currently have any functional relevance. This is here to enable possible future changes only. |
| status | This indicates the status of this item in regards to purchase completion. Typical values include (but are not limited to) "completed", and "refunded". When set to "inherit", it will inherit the status of the order to which it belongs. When set to anything other than "inherit" it will override the status of the order, but only for this item. |
| quantity | A single item in the cart can have a quantity. This indicates that quantity. Through this column's data, a single order_item can actually represent multiple items, and the values in the subtotal and total columns reflect that quantity. |
| amount | This is what the unadjusted price of this item was at the time of purchase. It does not include tax, discounts, fees, or any other price adjusters. |
| subtotal | This is the cost of the line item in the cart including quantity, but not including tax, discounts, fees, or any other price adjusters. |
| discount | This column stores the portion of the discount from the total that applied directly to this item. |
| tax | This column stores the portion of tax from the total that applied directly to this item. |
| total | This contains the total cost of this item, including quantity, taxes, item-specific discounts (but not cart-wide discounts). *Note that this amount does not include any fees in the cart that are specific to this item. For example, a shipping fee that exists because of this item is not included in the total found in this column. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Order Transactions Table:
Where a transaction represents an actual exchange of money, this table stores all of the transactions that were part of an order. Some orders will contain multiple transactions. For example, many payment gateways (for example: Stripe and PayPal) do not allow the purchasing of multiple recurring-enabled items in a single transaction. This is because 1 item could be monthly, and another could yearly. Each item will create a different transaction on the customer's credit card, and will show up separately on the customer's credit card statement. This table helps you to keep track of which transactions were part of which order.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. |
| object_id | The ID of the row to which this transaction belongs. Typically this will be the ID of an order in the orders table. |
| object_type | The table that the object_id value can be found within, and to which row within that table this row relates. For example, the orders table is indicated by the word "order", and is typically the value that will be found here. |
| transaction_id | The ID of the transaction, which originates from the payment gateway. |
| gateway | The name of the payment gateway where this transaction took place. |
| status | The status of this transaction. For example, if complete, the status will be set to "complete". |
| total | The total amount of this transaction. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |
## The Order Meta Table:
This table stores various and custom/extra information about an order.
This table's data is intended to be immutable.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| meta_id | The unique id of the row, which auto increments. |
| edd_order_id | The id of the order item to which this row relates. |
| meta_key | The reference key (like a variable name) of the data in question. |
| meta_value | The value. This can be anything needed as its purpose is for anything extra. |
## The Orders Table:
This table stores orders (called "payments" prior to EDD 3.0). It also stores various data about the order, like the customer ID, the email entered by the customer at checkout, the IP address of the machine where checkout was completed, and more. See table below for full breakdown of each column.
This table's data is intended to be immutable. However, some column data is also intended to be mutable. The user_id customer_id, and email column values will change if an order is re-assigned to a new customer.
| Table Column | Table Column's Description |
| ------------- | ------------- |
| id | The unique id of the row, which auto increments. This also serves as the id of the order itself. |
| parent | The ID of another order which is considered to be the parent of this order. This is used in scenarios like refund orders, which are automatically generated when a refund takes place. Refund orders use this column to refer to the original order where the item being refunded was originally purchased. Another scenario where this is used is for renewal payments done through the EDD Recurring Payments extension. Each renewal payment will use this column to indicate which order was the one where the customer originally initiated the subscription. |
| order_number | This column serves several different purposes: <br><br> 1. By default, it will be blank for every order (except "refund" orders). <br><br> 2. If the order in question is a "refund" order, this will contain a string in this format: "ORIGINAL_ORDER_NUMBER-R-THE_NUMBER_OF_REFUNDS_IN_THAT_ORDER". So if it is the 2nd refund from order #1, it will be "1-R-2". <br><br> 3. If you have "Sequential Order Numbers" enabled in your EDD settings, this column will be populated by the value determined by your settings for that.<br><br> 4. If the order in question is a refund for a "Sequentially Ordered" order, the format is the same as for "Non-Sequentially Ordered" orders, but it is important to note that the ORIGINAL_ORDER_NUMBER value will be the value from the "id" column of the original order, not the "order_number" column. <br><br> 5. Extensions may modify the way this column works. For example, the "Advanced Sequential Order Numbers" extension for EDD will put its own value in this column, overriding the values from EDD core. |
| status | This column has 2 purposes:<br><br> 1) It identifies the financial/accounting status of the order. <br> a) If the transaction(s) for the order have completed successfully, this value here will be "complete". <br> b) If the transaction(s) for the order have not yet completed successfully, this value here will be "pending". <br> c) If the transaction(s) for the order have not completed successfully and it has been 7 days, this value here will be "abandoned". <br> d) If the transaction(s) for the order failed at the payment gateway (for example, insufficient funds), this will be set to "failed". <br> e) If this order has been partially refunded, the status of the order currently remains set to "complete". <br> f) If all of the items in this order have been refunded, this value will be "refunded". <br><br>2) It identifies if the order is in the trash. If the order has been put in the trash, the financial status is no longer stored here, but gets moved to the order_meta table with the key "pre_trash_status". The value in this column will then be "trash". |
| type | The type of order this is. Typical values are "sale" or "refund". |
| user_id | The ID of the user currently attached to this order. Note that this column is mutable and will change if the user attached to the EDD customer changes, or if the customer attached to an order changes. |
| customer_id | The ID of the customer currently attached to this order. Note that this column is mutable and will change if the customer attached to the EDD order changes, or if the user attached to a customer changes. |
| email | The email address currently attached to this order. Note that this column is mutable and will change if the customer attached to the EDD order changes, or if the customer's email is updated. |
| ip | The IP address of the machine on which this order was completed. |
| gateway | A string representing the payment gateway which was used to complete the payments on this order. |
| mode | This stores whether the order was done in test mode or live mode. |
| currency | The 3 letter currency code which this order used/will-use. |
| payment_key | A unique key representing this payment. This key is generated by combining a few different values about this order, like the email address, the date, an optional auth key which can be defined as a constant, and a unique id generated by the uniqid function in PHP. See class-edd-payment.php for the full breakdown of how this is generated. |
| subtotal | This is the amount of the items in the cart added together. It does not include any taxes or discounts. Note: Fees are considered to be both line items and adjustments. In relation to the orders table, fees are treated as line items, and are thus included in the subtotal. But note that they are the only "adjustments" that are included in the subtotal, as other adjustments are not included in the subtotal. |
| discount | This is the total amount of discount(s) that were applied to the order. |
| tax | This is the total amount of the tax that was applied to the order. |
| total | This is the total amount of the order. |
| date_created | The date this row was created. |
| date_modified | The date this row was last modified. |
| uuid | A unique identifying string representing this row. |

View File

@ -0,0 +1,337 @@
<?php
/**
* Base Custom Database Class.
*
* @package Database
* @subpackage Base
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
namespace EDD\Database;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* The base class that all other database base classes extend.
*
* This class attempts to provide some universal immutability to all other
* classes that extend it, starting with a magic getter, but likely expanding
* into a magic call handler and others.
*
* @since 1.0.0
*/
class Base {
/**
* The name of the PHP global that contains the primary database interface.
*
* For example, WordPress traditionally uses 'wpdb', but other applications
* may use something else, or you may be doing something really cool that
* requires a custom interface.
*
* A future version of this utility may abstract this out entirely, so
* custom calls to the get_db() should be avoided if at all possible.
*
* @since 1.0.0
* @var string
*/
protected $db_global = 'wpdb';
/** Global Properties *****************************************************/
/**
* Global prefix used for tables/hooks/cache-groups/etc...
*
* @since 1.0.0
* @var string
*/
protected $prefix = 'edd';
/**
* The last database error, if any.
*
* @since 1.0.0
* @var mixed
*/
protected $last_error = false;
/** Public ****************************************************************/
/**
* Magic isset'ter for immutability.
*
* @since 1.0.0
*
* @param string $key
* @return mixed
*/
public function __isset( $key = '' ) {
// No more uppercase ID properties ever
if ( 'ID' === $key ) {
$key = 'id';
}
// Class method to try and call
$method = "get_{$key}";
// Return property if exists
if ( method_exists( $this, $method ) ) {
return true;
// Return get method results if exists
} elseif ( property_exists( $this, $key ) ) {
return true;
}
// Return false if not exists
return false;
}
/**
* Magic getter for immutability.
*
* @since 1.0.0
*
* @param string $key
* @return mixed
*/
public function __get( $key = '' ) {
// No more uppercase ID properties ever
if ( 'ID' === $key ) {
$key = 'id';
}
// Class method to try and call
$method = "get_{$key}";
// Return property if exists
if ( method_exists( $this, $method ) ) {
return call_user_func( array( $this, $method ) );
// Return get method results if exists
} elseif ( property_exists( $this, $key ) ) {
return $this->{$key};
}
// Return null if not exists
return null;
}
/**
* Converts the given object to an array.
*
* @since 1.0.0
*
* @return array Array version of the given object.
*/
public function to_array() {
return get_object_vars( $this );
}
/** Protected *************************************************************/
/**
* Maybe append the prefix to string.
*
* @since 1.0.0
*
* @param string $string
* @param string $sep
* @return string
*/
protected function apply_prefix( $string = '', $sep = '_' ) {
return ! empty( $this->prefix )
? "{$this->prefix}{$sep}{$string}"
: $string;
}
/**
* Return the first letters of a string of words with a separator.
*
* Used primarily to guess at table aliases when none is manually set.
*
* Applies the following formatting to a string:
* - Trim whitespace
* - No accents
* - No trailing underscores
*
* @since 1.0.0
*
* @param string $string
* @param string $sep
* @return string
*/
protected function first_letters( $string = '', $sep = '_' ) {
// Set empty default return value
$retval = '';
// Bail if empty or not a string
if ( empty( $string ) || ! is_string( $string ) ) {
return $retval;
}
// Trim spaces off the ends
$unspace = trim( $string );
$accents = remove_accents( $unspace );
$lower = strtolower( $accents );
$parts = explode( $sep, $lower );
// Loop through parts and concatenate the first letters together
foreach ( $parts as $part ) {
$retval .= substr( $part, 0, 1 );
}
// Return the result
return $retval;
}
/**
* Sanitize a table name string.
*
* Used to make sure that a table name value meets MySQL expectations.
*
* Applies the following formatting to a string:
* - Trim whitespace
* - No accents
* - No special characters
* - No hyphens
* - No double underscores
* - No trailing underscores
*
* @since 1.0.0
*
* @param string $name The name of the database table
*
* @return string Sanitized database table name
*/
protected function sanitize_table_name( $name = '' ) {
// Bail if empty or not a string
if ( empty( $name ) || ! is_string( $name ) ) {
return false;
}
// Trim spaces off the ends
$unspace = trim( $name );
// Only non-accented table names (avoid truncation)
$accents = remove_accents( $unspace );
// Only lowercase characters, hyphens, and dashes (avoid index corruption)
$lower = sanitize_key( $accents );
// Replace hyphens with single underscores
$under = str_replace( '-', '_', $lower );
// Single underscores only
$single = str_replace( '__', '_', $under );
// Remove trailing underscores
$clean = trim( $single, '_' );
// Bail if table name was garbaged
if ( empty( $clean ) ) {
return false;
}
// Return the cleaned table name
return $clean;
}
/**
* Set class variables from arguments.
*
* @since 1.0.0
* @param array $args
*/
protected function set_vars( $args = array() ) {
// Bail if empty or not an array
if ( empty( $args ) ) {
return;
}
// Cast to an array
if ( ! is_array( $args ) ) {
$args = (array) $args;
}
// Set all properties
foreach ( $args as $key => $value ) {
$this->{$key} = $value;
}
}
/**
* Return the global database interface.
*
* See: https://core.trac.wordpress.org/ticket/31556
*
* @since 1.0.0
*
* @return \wpdb Database interface, or False if not set
*/
protected function get_db() {
// Default database return value (might change)
$retval = false;
// Look for a commonly used global database interface
if ( isset( $GLOBALS[ $this->db_global ] ) ) {
$retval = $GLOBALS[ $this->db_global ];
}
/*
* Developer note:
*
* It should be impossible for a database table to be interacted with
* before the primary database interface it is setup.
*
* However, because applications are complicated, it is unsafe to assume
* anything, so this silently returns false instead of halting everything.
*
* If you are here because this method is returning false for you, that
* means the database table is being invoked too early in the lifecycle
* of the application.
*
* In WordPress, that means before the $wpdb global is created; in other
* environments, you will need to adjust accordingly.
*/
// Return the database interface
return $retval;
}
/**
* Check if an operation succeeded.
*
* @since 1.0.0
*
* @param mixed $result
* @return bool
*/
protected function is_success( $result = false ) {
// Bail if no row exists
if ( empty( $result ) ) {
$retval = false;
// Bail if an error occurred
} elseif ( is_wp_error( $result ) ) {
$this->last_error = $result;
$retval = false;
// No errors
} else {
$retval = true;
}
// Return the result
return (bool) $retval;
}
}

View File

@ -0,0 +1,965 @@
<?php
/**
* Base Custom Database Table Column Class.
*
* @package Database
* @subpackage Column
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
namespace EDD\Database;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Base class used for each column for a custom table.
*
* @since 1.0.0
*
* @see Column::__construct() for accepted arguments.
*/
class Column extends Base {
/** Table Attributes ******************************************************/
/**
* Name for the database column.
*
* Required. Must contain lowercase alphabetical characters only. Use of any
* other character (number, ascii, unicode, emoji, etc...) will result in
* fatal application errors.
*
* @since 1.0.0
* @var string
*/
public $name = '';
/**
* Type of database column.
*
* See: https://dev.mysql.com/doc/en/data-types.html
*
* @since 1.0.0
* @var string
*/
public $type = '';
/**
* Length of database column.
*
* See: https://dev.mysql.com/doc/en/storage-requirements.html
*
* @since 1.0.0
* @var string
*/
public $length = false;
/**
* Is integer unsigned?
*
* See: https://dev.mysql.com/doc/en/numeric-type-overview.html
*
* @since 1.0.0
* @var bool
*/
public $unsigned = true;
/**
* Is integer filled with zeroes?
*
* See: https://dev.mysql.com/doc/en/numeric-type-overview.html
*
* @since 1.0.0
* @var bool
*/
public $zerofill = false;
/**
* Is data in a binary format?
*
* See: https://dev.mysql.com/doc/en/binary-varbinary.html
*
* @since 1.0.0
* @var bool
*/
public $binary = false;
/**
* Is null an allowed value?
*
* See: https://dev.mysql.com/doc/en/data-type-defaults.html
*
* @since 1.0.0
* @var bool
*/
public $allow_null = false;
/**
* Typically empty/null, or date value.
*
* See: https://dev.mysql.com/doc/en/data-type-defaults.html
*
* @since 1.0.0
* @var string
*/
public $default = '';
/**
* auto_increment, etc...
*
* See: https://dev.mysql.com/doc/en/data-type-defaults.html
*
* @since 1.0.0
* @var string
*/
public $extra = '';
/**
* Typically inherited from the database interface (wpdb).
*
* By default, this will use the globally available database encoding. You
* most likely do not want to change this; if you do, you already know what
* to do.
*
* See: https://dev.mysql.com/doc/mysql/en/charset-column.html
*
* @since 1.0.0
* @var string
*/
public $encoding = '';
/**
* Typically inherited from the database interface (wpdb).
*
* By default, this will use the globally available database collation. You
* most likely do not want to change this; if you do, you already know what
* to do.
*
* See: https://dev.mysql.com/doc/mysql/en/charset-column.html
*
* @since 1.0.0
* @var string
*/
public $collation = '';
/**
* Typically empty; probably ignore.
*
* By default, columns do not have comments. This is unused by any other
* relative code, but you can include less than 1024 characters here.
*
* @since 1.0.0
* @var string
*/
public $comment = '';
/** Special Attributes ****************************************************/
/**
* Is this the primary column?
*
* By default, columns are not the primary column. This is used by the Query
* class for several critical functions, including (but not limited to) the
* cache key, meta-key relationships, auto-incrementing, etc...
*
* @since 1.0.0
* @var bool
*/
public $primary = false;
/**
* Is this the column used as a created date?
*
* By default, columns do not represent the date a value was first entered.
* This is used by the Query class to set its value automatically to the
* current datetime value immediately before insert.
*
* @since 1.0.0
* @var bool
*/
public $created = false;
/**
* Is this the column used as a modified date?
*
* By default, columns do not represent the date a value was last changed.
* This is used by the Query class to update its value automatically to the
* current datetime value immediately before insert|update.
*
* @since 1.0.0
* @var bool
*/
public $modified = false;
/**
* Is this the column used as a unique universal identifier?
*
* By default, columns are not UUIDs. This is used by the Query class to
* generate a unique string that can be used to identify a row in a database
* table, typically in such a way that is unrelated to the row data itself.
*
* @since 1.0.0
* @var bool
*/
public $uuid = false;
/** Query Attributes ******************************************************/
/**
* What is the string-replace pattern?
*
* By default, column patterns will be guessed based on their type. Set this
* manually to `%s|%d|%f` only if you are doing something weird, or are
* explicitly storing numeric values in text-based column types.
*
* @since 1.0.0
* @var string
*/
public $pattern = '';
/**
* Is this column searchable?
*
* By default, columns are not searchable. When `true`, the Query class will
* add this column to the results of search queries.
*
* Avoid setting to `true` on large blobs of text, unless you've optimized
* your database server to accommodate these kinds of queries.
*
* @since 1.0.0
* @var bool
*/
public $searchable = false;
/**
* Is this column a date?
*
* By default, columns do not support date queries. When `true`, the Query
* class will accept complex statements to help narrow results down to
* specific periods of time for values in this column.
*
* @since 1.0.0
* @var bool
*/
public $date_query = false;
/**
* Is this column used in orderby?
*
* By default, columns are not sortable. This ensures that the database
* table does not perform costly operations on unindexed columns or columns
* of an inefficient type.
*
* You can safely turn this on for most numeric columns, indexed columns,
* and text columns with intentionally limited lengths.
*
* @since 1.0.0
* @var bool
*/
public $sortable = false;
/**
* Is __in supported?
*
* By default, columns support being queried using an `IN` statement. This
* allows the Query class to retrieve rows that match your array of values.
*
* Consider setting this to `false` for longer text columns.
*
* @since 1.0.0
* @var bool
*/
public $in = true;
/**
* Is __not_in supported?
*
* By default, columns support being queried using a `NOT IN` statement.
* This allows the Query class to retrieve rows that do not match your array
* of values.
*
* Consider setting this to `false` for longer text columns.
*
* @since 1.0.0
* @var bool
*/
public $not_in = true;
/** Cache Attributes ******************************************************/
/**
* Does this column have its own cache key?
*
* By default, only primary columns are used as cache keys. If this column
* is unique, or is frequently used to get database results, you may want to
* consider setting this to true.
*
* Use in conjunction with a database index for speedy queries.
*
* @since 1.0.0
* @var string
*/
public $cache_key = false;
/** Action Attributes *****************************************************/
/**
* Does this column fire a transition action when it's value changes?
*
* By default, columns do not fire transition actions. In some cases, it may
* be desirable to know when a database value changes, and what the old and
* new values are when that happens.
*
* The Query class is responsible for triggering the event action.
*
* @since 1.0.0
* @var bool
*/
public $transition = false;
/** Callback Attributes ***************************************************/
/**
* Maybe validate this data before it is written to the database.
*
* By default, column data is validated based on the type of column that it
* is. You can set this to a callback function of your choice to override
* the default validation behavior.
*
* @since 1.0.0
* @var string
*/
public $validate = '';
/**
* Array of capabilities used to interface with this column.
*
* These are used by the Query class to allow and disallow CRUD access to
* column data, typically based on roles or capabilities.
*
* @since 1.0.0
* @var array
*/
public $caps = array();
/**
* Array of possible aliases this column can be referred to as.
*
* These are used by the Query class to allow for columns to be renamed
* without requiring complex architectural backwards compatibility support.
*
* @since 1.0.0
* @var array
*/
public $aliases = array();
/**
* Array of possible relationships this column has with columns in other
* database tables.
*
* These are typically unenforced foreign keys, and are used by the Query
* class to help prime related items.
*
* @since 1.0.0
* @var array
*/
public $relationships = array();
/** Methods ***************************************************************/
/**
* Sets up the order query, based on the query vars passed.
*
* @since 1.0.0
*
* @param string|array $args {
* Optional. Array or query string of order query parameters. Default empty.
*
* @type string $name Name of database column
* @type string $type Type of database column
* @type int $length Length of database column
* @type bool $unsigned Is integer unsigned?
* @type bool $zerofill Is integer filled with zeroes?
* @type bool $binary Is data in a binary format?
* @type bool $allow_null Is null an allowed value?
* @type mixed $default Typically empty/null, or date value
* @type string $extra auto_increment, etc...
* @type string $encoding Typically inherited from wpdb
* @type string $collation Typically inherited from wpdb
* @type string $comment Typically empty
* @type bool $pattern What is the string-replace pattern?
* @type bool $primary Is this the primary column?
* @type bool $created Is this the column used as a created date?
* @type bool $modified Is this the column used as a modified date?
* @type bool $uuid Is this the column used as a universally unique identifier?
* @type bool $searchable Is this column searchable?
* @type bool $sortable Is this column used in orderby?
* @type bool $date_query Is this column a datetime?
* @type bool $in Is __in supported?
* @type bool $not_in Is __not_in supported?
* @type bool $cache_key Is this column queried independently?
* @type bool $transition Does this column transition between changes?
* @type string $validate A callback function used to validate on save.
* @type array $caps Array of capabilities to check.
* @type array $aliases Array of possible column name aliases.
* @type array $relationships Array of columns in other tables this column relates to.
* }
*/
public function __construct( $args = array() ) {
// Parse arguments
$r = $this->parse_args( $args );
// Maybe set variables from arguments
if ( ! empty( $r ) ) {
$this->set_vars( $r );
}
}
/** Argument Handlers *****************************************************/
/**
* Parse column arguments
*
* @since 1.0.0
* @param array $args Default empty array.
* @return array
*/
private function parse_args( $args = array() ) {
// Parse arguments
$r = wp_parse_args( $args, array(
// Table
'name' => '',
'type' => '',
'length' => '',
'unsigned' => false,
'zerofill' => false,
'binary' => false,
'allow_null' => false,
'default' => '',
'extra' => '',
'encoding' => $this->get_db()->charset,
'collation' => $this->get_db()->collate,
'comment' => '',
// Query
'pattern' => false,
'searchable' => false,
'sortable' => false,
'date_query' => false,
'transition' => false,
'in' => true,
'not_in' => true,
// Special
'primary' => false,
'created' => false,
'modified' => false,
'uuid' => false,
// Cache
'cache_key' => false,
// Validation
'validate' => '',
// Capabilities
'caps' => array(),
// Backwards Compatibility
'aliases' => array(),
// Column Relationships
'relationships' => array()
) );
// Force some arguments for special column types
$r = $this->special_args( $r );
// Set the args before they are sanitized
$this->set_vars( $r );
// Return array
return $this->validate_args( $r );
}
/**
* Validate arguments after they are parsed.
*
* @since 1.0.0
* @param array $args Default empty array.
* @return array
*/
private function validate_args( $args = array() ) {
// Sanitization callbacks
$callbacks = array(
'name' => 'sanitize_key',
'type' => 'strtoupper',
'length' => 'intval',
'unsigned' => 'wp_validate_boolean',
'zerofill' => 'wp_validate_boolean',
'binary' => 'wp_validate_boolean',
'allow_null' => 'wp_validate_boolean',
'default' => array( $this, 'sanitize_default' ),
'extra' => 'wp_kses_data',
'encoding' => 'wp_kses_data',
'collation' => 'wp_kses_data',
'comment' => 'wp_kses_data',
'primary' => 'wp_validate_boolean',
'created' => 'wp_validate_boolean',
'modified' => 'wp_validate_boolean',
'uuid' => 'wp_validate_boolean',
'searchable' => 'wp_validate_boolean',
'sortable' => 'wp_validate_boolean',
'date_query' => 'wp_validate_boolean',
'transition' => 'wp_validate_boolean',
'in' => 'wp_validate_boolean',
'not_in' => 'wp_validate_boolean',
'cache_key' => 'wp_validate_boolean',
'pattern' => array( $this, 'sanitize_pattern' ),
'validate' => array( $this, 'sanitize_validation' ),
'caps' => array( $this, 'sanitize_capabilities' ),
'aliases' => array( $this, 'sanitize_aliases' ),
'relationships' => array( $this, 'sanitize_relationships' )
);
// Default args array
$r = array();
// Loop through and try to execute callbacks
foreach ( $args as $key => $value ) {
// Callback is callable
if ( isset( $callbacks[ $key ] ) && is_callable( $callbacks[ $key ] ) ) {
$r[ $key ] = call_user_func( $callbacks[ $key ], $value );
// Callback is malformed so just let it through to avoid breakage
} else {
$r[ $key ] = $value;
}
}
// Return sanitized arguments
return $r;
}
/**
* Force column arguments for special column types
*
* @since 1.0.0
* @param array $args Default empty array.
* @return array
*/
private function special_args( $args = array() ) {
// Primary key columns are always used as cache keys
if ( ! empty( $args['primary'] ) ) {
$args['cache_key'] = true;
// All UUID columns need to follow a very specific pattern
} elseif ( ! empty( $args['uuid'] ) ) {
$args['name'] = 'uuid';
$args['type'] = 'varchar';
$args['length'] = '100';
$args['in'] = false;
$args['not_in'] = false;
$args['searchable'] = false;
$args['sortable'] = false;
}
// Return args
return (array) $args;
}
/** Public Helpers ********************************************************/
/**
* Return if a column type is numeric or not.
*
* @since 1.0.0
* @return bool
*/
public function is_numeric() {
return $this->is_type( array(
'tinyint',
'int',
'mediumint',
'bigint'
) );
}
/** Private Helpers *******************************************************/
/**
* Return if this column is of a certain type.
*
* @since 1.0.0
* @param mixed $type Default empty string. The type to check. Also accepts an array.
* @return bool True if of type, False if not
*/
private function is_type( $type = '' ) {
// If string, cast to array
if ( is_string( $type ) ) {
$type = (array) $type;
}
// Make them lowercase
$types = array_map( 'strtolower', $type );
// Return if match or not
return (bool) in_array( strtolower( $this->type ), $types, true );
}
/** Private Sanitizers ****************************************************/
/**
* Sanitize capabilities array
*
* @since 1.0.0
* @param array $caps Default empty array.
* @return array
*/
private function sanitize_capabilities( $caps = array() ) {
return wp_parse_args( $caps, array(
'select' => 'exist',
'insert' => 'exist',
'update' => 'exist',
'delete' => 'exist'
) );
}
/**
* Sanitize aliases array using `sanitize_key()`
*
* @since 1.0.0
* @param array $aliases Default empty array.
* @return array
*/
private function sanitize_aliases( $aliases = array() ) {
return array_map( 'sanitize_key', $aliases );
}
/**
* Sanitize relationships array
*
* @todo
* @since 1.0.0
* @param array $relationships Default empty array.
* @return array
*/
private function sanitize_relationships( $relationships = array() ) {
return array_filter( $relationships );
}
/**
* Sanitize the default value
*
* @since 1.0.0
* @param string $default
* @return string|null
*/
private function sanitize_default( $default = '' ) {
// Null
if ( ( true === $this->allow_null ) && is_null( $default ) ) {
return null;
// String
} elseif ( is_string( $default ) ) {
return wp_kses_data( $default );
// Integer
} elseif ( $this->is_numeric( $default ) ) {
return (int) $default;
}
// @todo datetime, decimal, and other column types
// Unknown, so return the default's default
return '';
}
/**
* Sanitize the pattern
*
* @since 1.0.0
* @param mixed $pattern
* @return string
*/
private function sanitize_pattern( $pattern = false ) {
// Allowed patterns
$allowed_patterns = array( '%s', '%d', '%f' );
// Return pattern if allowed
if ( in_array( $pattern, $allowed_patterns, true ) ) {
return $pattern;
}
// Fallback to digit or string
return $this->is_numeric()
? '%d'
: '%s';
}
/**
* Sanitize the validation callback
*
* @since 1.0.0
* @param string $callback Default empty string. A callable PHP function name or method
* @return string The most appropriate callback function for the value
*/
private function sanitize_validation( $callback = '' ) {
// Return callback if it's callable
if ( is_callable( $callback ) ) {
return $callback;
}
// UUID special column
if ( true === $this->uuid ) {
$callback = array( $this, 'validate_uuid' );
// Datetime fallback
} elseif ( $this->is_type( 'datetime' ) ) {
$callback = array( $this, 'validate_datetime' );
// Decimal fallback
} elseif ( $this->is_type( 'decimal' ) ) {
$callback = array( $this, 'validate_decimal' );
// Intval fallback
} elseif ( $this->is_numeric() ) {
$callback = 'intval';
}
// Return the callback
return $callback;
}
/** Public Validators *****************************************************/
/**
* Fallback to validate a datetime value if no other is set.
*
* This assumes NO_ZERO_DATES is off or overridden.
*
* If MySQL drops support for zero dates, this method will need to be
* updated to support different default values based on the environment.
*
* @since 1.0.0
* @param string $value Default ''. A datetime value that needs validating
* @return string A valid datetime value
*/
public function validate_datetime( $value = '' ) {
// Handle "empty" values
if ( empty( $value ) || ( '0000-00-00 00:00:00' === $value ) ) {
$value = ! empty( $this->default )
? $this->default
: '';
// Convert to MySQL datetime format via date() && strtotime
} elseif ( function_exists( 'date' ) ) {
$value = date( 'Y-m-d H:i:s', strtotime( $value ) );
}
// Return the validated value
return $value;
}
/**
* Validate a decimal
*
* (Recommended decimal column length is '18,9'.)
*
* This is used to validate a mixed value before it is saved into a decimal
* column in a database table.
*
* Uses number_format() which does rounding to the last decimal if your
* value is longer than specified.
*
* @since 1.0.0
* @param mixed $value Default empty string. The decimal value to validate
* @param int $decimals Default 9. The number of decimal points to accept
* @return float
*/
public function validate_decimal( $value = 0, $decimals = 9 ) {
// Protect against non-numeric values
if ( ! is_numeric( $value ) ) {
$value = 0;
}
// Protect against non-numeric decimals
if ( ! is_numeric( $decimals ) ) {
$decimals = 9;
}
// Is the value negative?
$negative_exponent = ( $value < 0 )
? -1
: 1;
// Only numbers and period
$value = preg_replace( '/[^0-9\.]/', '', (string) $value );
// Format to number of decimals, and cast as float
$formatted = number_format( $value, $decimals, '.', '' );
// Adjust for negative values
$retval = $formatted * $negative_exponent;
// Return
return $retval;
}
/**
* Validate a UUID.
*
* This uses the v4 algorithm to generate a UUID that is used to uniquely
* and universally identify a given database row without any direct
* connection or correlation to the data in that row.
*
* From http://php.net/manual/en/function.uniqid.php#94959
*
* @since 1.0.0
* @param string $value The UUID value (empty on insert, string on update)
* @return string Generated UUID.
*/
public function validate_uuid( $value = '' ) {
// Default URN UUID prefix
$prefix = 'urn:uuid:';
// Bail if not empty and correctly prefixed
// (UUIDs should _never_ change once they are set)
if ( ! empty( $value ) && ( 0 === strpos( $value, $prefix ) ) ) {
return $value;
}
// Put the pieces together
$value = sprintf( "{$prefix}%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
// Return the new UUID
return $value;
}
/** Table Helpers *********************************************************/
/**
* Return a string representation of what this column's properties look like
* in a MySQL.
*
* @todo
* @since 1.0.0
* @return string
*/
public function get_create_string() {
// Default return val
$retval = '';
// Bail if no name
if ( ! empty( $this->name ) ) {
$retval .= $this->name;
}
// Type
if ( ! empty( $this->type ) ) {
$retval .= " {$this->type}";
}
// Length
if ( ! empty( $this->length ) ) {
$retval .= '(' . $this->length . ')';
}
// Unsigned
if ( ! empty( $this->unsigned ) ) {
$retval .= " unsigned";
}
// Zerofill
if ( ! empty( $this->zerofill ) ) {
// TBD
}
// Binary
if ( ! empty( $this->binary ) ) {
// TBD
}
// Allow null
if ( ! empty( $this->allow_null ) ) {
$retval .= " NOT NULL ";
}
// Default
if ( ! empty( $this->default ) ) {
$retval .= " default '{$this->default}'";
// A literal false means no default value
} elseif ( false !== $this->default ) {
// Numeric
if ( $this->is_numeric() ) {
$retval .= " default '0'";
} elseif ( $this->is_type( 'datetime' ) ) {
$retval .= " default '0000-00-00 00:00:00'";
} else {
$retval .= " default ''";
}
}
// Extra
if ( ! empty( $this->extra ) ) {
$retval .= " {$this->extra}";
}
// Encoding
if ( ! empty( $this->encoding ) ) {
} else {
}
// Collation
if ( ! empty( $this->collation ) ) {
} else {
}
// Return the create string
return $retval;
}
}

View File

@ -0,0 +1,157 @@
<?php
/**
* Base Custom Database Table Compare Query Class.
*
* @package Database
* @subpackage Compare
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
namespace EDD\Database\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Class used for generating SQL for compare clauses.
*
* This class is used to generate the SQL when a `compare` argument is passed to
* the `Base` query class. It extends `Meta` so the `compare` key accepts
* the same parameters as the ones passed to `Meta`.
*
* @since 1.0.0
*/
class Compare extends Meta {
/**
* Generate SQL WHERE clauses for a first-order query clause.
*
* "First-order" means that it's an array with a 'key' or 'value'.
*
* @since 1.0.0
*
* @param array $clause Query clause (passed by reference).
* @param array $parent_query Parent query array.
* @param string $clause_key Optional. The array key used to name the clause in the original `$meta_query`
* parameters. If not provided, a key will be generated automatically.
* @return array {
* Array containing WHERE SQL clauses to append to a first-order query.
*
* @type string $where SQL fragment to append to the main WHERE clause.
* }
*/
public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) {
global $wpdb;
$sql_chunks = array(
'where' => array(),
'join' => array(),
);
if ( isset( $clause['compare'] ) ) {
$clause['compare'] = strtoupper( $clause['compare'] );
} else {
$clause['compare'] = isset( $clause['value'] ) && is_array( $clause['value'] ) ? 'IN' : '=';
}
if ( ! in_array(
$clause['compare'], array(
'=',
'!=',
'>',
'>=',
'<',
'<=',
'LIKE',
'NOT LIKE',
'IN',
'NOT IN',
'BETWEEN',
'NOT BETWEEN',
'EXISTS',
'NOT EXISTS',
'REGEXP',
'NOT REGEXP',
'RLIKE',
), true
) ) {
$clause['compare'] = '=';
}
if ( isset( $clause['compare_key'] ) && 'LIKE' === strtoupper( $clause['compare_key'] ) ) {
$clause['compare_key'] = strtoupper( $clause['compare_key'] );
} else {
$clause['compare_key'] = '=';
}
$compare = $clause['compare'];
$compare_key = $clause['compare_key'];
// Build the WHERE clause.
// Column name and value.
if ( array_key_exists( 'key', $clause ) && array_key_exists( 'value', $clause ) ) {
$column = sanitize_key( $clause['key'] );
$value = $clause['value'];
if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ), true ) ) {
if ( ! is_array( $value ) ) {
$value = preg_split( '/[,\s]+/', $value );
}
} else {
$value = trim( $value );
}
switch ( $compare ) {
case 'IN':
case 'NOT IN':
$compare_string = '(' . substr( str_repeat( ',%s', count( $value ) ), 1 ) . ')';
$where = $wpdb->prepare( $compare_string, $value );
break;
case 'BETWEEN':
case 'NOT BETWEEN':
$value = array_slice( $value, 0, 2 );
$where = $wpdb->prepare( '%s AND %s', $value );
break;
case 'LIKE':
case 'NOT LIKE':
$value = '%' . $wpdb->esc_like( $value ) . '%';
$where = $wpdb->prepare( '%s', $value );
break;
// EXISTS with a value is interpreted as '='.
case 'EXISTS':
$compare = '=';
$where = $wpdb->prepare( '%s', $value );
break;
// 'value' is ignored for NOT EXISTS.
case 'NOT EXISTS':
$where = '';
break;
default:
$where = $wpdb->prepare( '%s', $value );
break;
}
if ( $where ) {
$sql_chunks['where'][] = "{$column} {$compare} {$where}";
}
}
/*
* Multiple WHERE clauses (for meta_key and meta_value) should
* be joined in parentheses.
*/
if ( 1 < count( $sql_chunks['where'] ) ) {
$sql_chunks['where'] = array( '( ' . implode( ' AND ', $sql_chunks['where'] ) . ' )' );
}
return $sql_chunks;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,29 @@
<?php
/**
* Base Custom Database Table Meta Query Class.
*
* @package Database
* @subpackage Meta
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.1.0
*/
namespace EDD\Database\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
// @todo Remove the need for this dependency
use \WP_Meta_Query;
/**
* Class for generating SQL clauses that filter a primary query according to meta.
*
* It currently extends the WP_Meta_Query class in WordPress, but in the future
* will be derived completely from other registered tables.
*
* @since 1.1.0
*/
class Meta extends WP_Meta_Query {
}

View File

@ -0,0 +1,65 @@
<?php
/**
* Base Custom Database Table Row Class.
*
* @package Database
* @subpackage Row
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
namespace EDD\Database;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Base database row class.
*
* This class exists solely for other classes to extend (and to encapsulate
* database schema changes for those objects) to help separate the needs of the
* application layer from the requirements of the database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 1.0.0
*/
class Row extends Base {
/**
* Construct a database object.
*
* @since 1.0.0
*
* @param mixed Null by default, Array/Object if not
*/
public function __construct( $item = null ) {
if ( ! empty( $item ) ) {
$this->init( $item );
}
}
/**
* Initialize class properties based on data array.
*
* @since 1.0.0
*
* @param array $data
*/
private function init( $data = array() ) {
$this->set_vars( $data );
}
/**
* Determines whether the current row exists.
*
* @since 1.0.0
*
* @return bool
*/
public function exists() {
return ! empty( $this->id );
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* Base Custom Database Table Schema Class.
*
* @package Database
* @subpackage Schema
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
namespace EDD\Database;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* A base database table schema class, which houses the collection of columns
* that a table is made out of.
*
* This class is intended to be extended for each unique database table,
* including global tables for multisite, and users tables.
*
* @since 1.0.0
*/
class Schema extends Base {
/**
* Array of database column objects to turn into Column.
*
* @since 1.0.0
* @var array
*/
protected $columns = array();
/**
* Invoke new column objects based on array of column data.
*
* @since 1.0.0
*/
public function __construct() {
// Bail if no columns
if ( empty( $this->columns ) || ! is_array( $this->columns ) ) {
return;
}
// Juggle original columns array
$columns = $this->columns;
$this->columns = array();
// Loop through columns and create objects from them
foreach ( $columns as $column ) {
if ( is_array( $column ) ) {
$this->columns[] = new Column( $column );
} elseif ( $column instanceof Column ) {
$this->columns[] = $column;
}
}
}
/**
* Return the schema in string form.
*
* @since 1.0.0
*
* @return string Calls get_create_string() on every column.
*/
protected function to_string() {
// Default return value
$retval = '';
// Bail if no columns to convert
if ( empty( $this->columns ) ) {
return $retval;
}
// Loop through columns...
foreach ( $this->columns as $column_info ) {
if ( method_exists( $column_info, 'get_create_string' ) ) {
$retval .= '\n' . $column_info->get_create_string() . ', ';
}
}
// Return the string
return $retval;
}
}

View File

@ -0,0 +1,963 @@
<?php
/**
* Base Custom Database Table Class.
*
* @package Database
* @subpackage Table
* @copyright Copyright (c) 2020
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
namespace EDD\Database;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* A base database table class, which facilitates the creation of (and schema
* changes to) individual database tables.
*
* This class is intended to be extended for each unique database table,
* including global tables for multisite, and users tables.
*
* It exists to make managing database tables as easy as possible.
*
* Extending this class comes with several automatic benefits:
* - Activation hook makes it great for plugins
* - Tables store their versions in the database independently
* - Tables upgrade via independent upgrade abstract methods
* - Multisite friendly - site tables switch on "switch_blog" action
*
* @since 1.0.0
*/
abstract class Table extends Base {
/**
* Table name, without the global table prefix.
*
* @since 1.0.0
* @var string
*/
protected $name = '';
/**
* Optional description.
*
* @since 1.0.0
* @var string
*/
protected $description = '';
/**
* Database version.
*
* @since 1.0.0
* @var mixed
*/
protected $version = '';
/**
* Is this table for a site, or global.
*
* @since 1.0.0
* @var bool
*/
protected $global = false;
/**
* Database version key (saved in _options or _sitemeta)
*
* @since 1.0.0
* @var string
*/
protected $db_version_key = '';
/**
* Current database version.
*
* @since 1.0.0
* @var mixed
*/
protected $db_version = 0;
/**
* Table prefix, including the site prefix.
*
* @since 1.0.0
* @var string
*/
protected $table_prefix = '';
/**
* Table name.
*
* @since 1.0.0
* @var string
*/
protected $table_name = '';
/**
* Table name, prefixed from the base.
*
* @since 1.0.0
* @var string
*/
protected $prefixed_name = '';
/**
* Table schema.
*
* @since 1.0.0
* @var string
*/
protected $schema = '';
/**
* Database character-set & collation for table.
*
* @since 1.0.0
* @var string
*/
protected $charset_collation = '';
/**
* Key => value array of versions => methods.
*
* @since 1.0.0
* @var array
*/
protected $upgrades = array();
/** Methods ***************************************************************/
/**
* Hook into queries, admin screens, and more!
*
* @since 1.0.0
*/
public function __construct() {
// Setup the database table
$this->setup();
// Bail if setup failed
if ( empty( $this->name ) || empty( $this->db_version_key ) ) {
return;
}
// Add the table to the database interface
$this->set_db_interface();
// Set the database schema
$this->set_schema();
// Add hooks
$this->add_hooks();
// Maybe force upgrade if testing
if ( $this->is_testing() ) {
$this->maybe_upgrade();
}
}
/** Abstract **************************************************************/
/**
* Setup this database table.
*
* @since 1.0.0
*/
protected abstract function set_schema();
/** Multisite *************************************************************/
/**
* Update table version & references.
*
* Hooked to the "switch_blog" action.
*
* @since 1.0.0
*
* @param int $site_id The site being switched to
*/
public function switch_blog( $site_id = 0 ) {
// Update DB version based on the current site
if ( ! $this->is_global() ) {
$this->db_version = get_blog_option( $site_id, $this->db_version_key, false );
}
// Update interface for switched site
$this->set_db_interface();
}
/** Public Helpers ********************************************************/
/**
* Maybe upgrade the database table. Handles creation & schema changes.
*
* Hooked to the `admin_init` action.
*
* @since 1.0.0
*/
public function maybe_upgrade() {
// Bail if not upgradeable
if ( ! $this->is_upgradeable() ) {
return;
}
// Bail if upgrade not needed
if ( ! $this->needs_upgrade() ) {
return;
}
// Upgrade
if ( $this->exists() ) {
$this->upgrade();
// Install
} else {
$this->install();
}
}
/**
* Return whether this table needs an upgrade.
*
* @since 1.0.0
*
* @param mixed $version Database version to check if upgrade is needed
*
* @return bool True if table needs upgrading. False if not.
*/
public function needs_upgrade( $version = false ) {
// Use the current table version if none was passed
if ( empty( $version ) ) {
$version = $this->version;
}
// Get the current database version
$this->get_db_version();
// Is the database table up to date?
$is_current = version_compare( $this->db_version, $version, '>=' );
// Return false if current, true if out of date
return ( true === $is_current )
? false
: true;
}
/**
* Return whether this table can be upgraded.
*
* @since 1.0.0
*
* @return bool True if table can be upgraded. False if not.
*/
public function is_upgradeable() {
// Bail if global and upgrading global tables is not allowed
if ( $this->is_global() && ! wp_should_upgrade_global_tables() ) {
return false;
}
// Kinda weird, but assume it is
return true;
}
/**
* Return the current table version from the database.
*
* This is public method for accessing a private variable so that it cannot
* be externally modified.
*
* @since 1.0.0
*
* @return string
*/
public function get_version() {
$this->get_db_version();
return $this->db_version;
}
/**
* Install a database table by creating the table and setting the version.
*
* @since 1.0.0
*/
public function install() {
$created = $this->create();
// Set the DB version if create was successful
if ( true === $created ) {
$this->set_db_version();
}
}
/**
* Destroy a database table by dropping the table and deleting the version.
*
* @since 1.0.0
*/
public function uninstall() {
$dropped = $this->drop();
// Delete the DB version if drop was successful
if ( true === $dropped ) {
$this->delete_db_version();
}
}
/** Public Management *****************************************************/
/**
* Check if table already exists.
*
* @since 1.0.0
*
* @return bool
*/
public function exists() {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Query statement
$query = "SHOW TABLES LIKE %s";
$like = $db->esc_like( $this->table_name );
$prepared = $db->prepare( $query, $like );
$result = $db->get_var( $prepared );
// Does the table exist?
return $this->is_success( $result );
}
/**
* Create the table.
*
* @since 1.0.0
*
* @return bool
*/
public function create() {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Query statement
$query = "CREATE TABLE {$this->table_name} ( {$this->schema} ) {$this->charset_collation}";
$result = $db->query( $query );
// Was the table created?
return $this->is_success( $result );
}
/**
* Drop the database table.
*
* @since 1.0.0
*
* @return bool
*/
public function drop() {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Query statement
$query = "DROP TABLE {$this->table_name}";
$result = $db->query( $query );
// Did the table get dropped?
return $this->is_success( $result );
}
/**
* Truncate the database table.
*
* @since 1.0.0
*
* @return bool
*/
public function truncate() {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Query statement
$query = "TRUNCATE TABLE {$this->table_name}";
$result = $db->query( $query );
// Did the table get truncated?
return $this->is_success( $result );
}
/**
* Delete all items from the database table.
*
* @since 1.0.0
*
* @return bool
*/
public function delete_all() {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Query statement
$query = "DELETE FROM {$this->table_name}";
$deleted = $db->query( $query );
// Did the table get emptied?
return $deleted;
}
/**
* Clone this database table.
*
* Pair with copy().
*
* @since 1.1.0
*
* @param string $new_table_name The name of the new table, without prefix
*
* @return bool
*/
public function _clone( $new_table_name = '' ) {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Sanitize the new table name
$table_name = $this->sanitize_table_name( $new_table_name );
// Bail if new table name is invalid
if ( empty( $table_name ) ) {
return false;
}
// Query statement
$table = $this->apply_prefix( $table_name );
$query = "CREATE TABLE {$table} LIKE {$this->table_name}";
$result = $db->query( $query );
// Did the table get cloned?
return $this->is_success( $result );
}
/**
* Copy the contents of this table to a new table.
*
* Pair with clone().
*
* @since 1.1.0
*
* @param string $new_table_name The name of the new table, without prefix
*
* @return bool
*/
public function copy( $new_table_name = '' ) {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Sanitize the new table name
$table_name = $this->sanitize_table_name( $new_table_name );
// Bail if new table name is invalid
if ( empty( $table_name ) ) {
return false;
}
// Query statement
$table = $this->apply_prefix( $table_name );
$query = "INSERT INTO {$table} SELECT * FROM {$this->table_name}";
$result = $db->query( $query );
// Did the table get copied?
return $this->is_success( $result );
}
/**
* Count the number of items in the database table.
*
* @since 1.0.0
*
* @return int
*/
public function count() {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return 0;
}
// Query statement
$query = "SELECT COUNT(*) FROM {$this->table_name}";
$count = $db->get_var( $query );
// Query success/fail
return intval( $count );
}
/**
* Check if column already exists.
*
* @since 1.0.0
*
* @param string $name Value
*
* @return bool
*/
public function column_exists( $name = '' ) {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
// Query statement
$query = "SHOW COLUMNS FROM {$this->table_name} LIKE %s";
$like = $db->esc_like( $name );
$prepared = $db->prepare( $query, $like );
$result = $db->query( $prepared );
// Does the column exist?
return $this->is_success( $result );
}
/**
* Check if index already exists.
*
* @since 1.0.0
*
* @param string $name Value
* @param string $column Column name
*
* @return bool
*/
public function index_exists( $name = '', $column = 'Key_name' ) {
// Get the database interface
$db = $this->get_db();
// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}
$column = esc_sql( $column );
// Query statement
$query = "SHOW INDEXES FROM {$this->table_name} WHERE {$column} LIKE %s";
$like = $db->esc_like( $name );
$prepared = $db->prepare( $query, $like );
$result = $db->query( $prepared );
// Does the index exist?
return $this->is_success( $result );
}
/** Upgrades **************************************************************/
/**
* Upgrade this database table.
*
* @since 1.0.0
*
* @return bool
*/
public function upgrade() {
// Get pending upgrades
$upgrades = $this->get_pending_upgrades();
// Bail if no upgrades
if ( empty( $upgrades ) ) {
$this->set_db_version();
// Return, without failure
return true;
}
// Default result
$result = false;
// Try to do the upgrades
foreach ( $upgrades as $version => $callback ) {
// Do the upgrade
$result = $this->upgrade_to( $version, $callback );
// Bail if an error occurs, to avoid skipping upgrades
if ( ! $this->is_success( $result ) ) {
return false;
}
}
// Success/fail
return $this->is_success( $result );
}
/**
* Return array of upgrades that still need to run.
*
* @since 1.1.0
*
* @return array Array of upgrade callbacks, keyed by their db version.
*/
public function get_pending_upgrades() {
// Default return value
$upgrades = array();
// Bail if no upgrades, or no database version to compare to
if ( empty( $this->upgrades ) || empty( $this->db_version ) ) {
return $upgrades;
}
// Loop through all upgrades, and pick out the ones that need doing
foreach ( $this->upgrades as $version => $callback ) {
if ( true === version_compare( $version, $this->db_version, '>' ) ) {
$upgrades[ $version ] = $callback;
}
}
// Return
return $upgrades;
}
/**
* Upgrade to a specific database version.
*
* @since 1.0.0
*
* @param mixed $version Database version to check if upgrade is needed
* @param string $callback Callback function or class method to call
*
* @return bool
*/
public function upgrade_to( $version = '', $callback = '' ) {
// Bail if no upgrade is needed
if ( ! $this->needs_upgrade( $version ) ) {
return false;
}
// Allow self-named upgrade callbacks
if ( empty( $callback ) ) {
$callback = $version;
}
// Is the callback... callable?
$callable = $this->get_callable( $callback );
// Bail if no callable upgrade was found
if ( empty( $callable ) ) {
return false;
}
// Do the upgrade
$result = call_user_func( $callable );
$success = $this->is_success( $result );
// Bail if upgrade failed
if ( true !== $success ) {
return false;
}
// Set the database version to this successful version
$this->set_db_version( $version );
// Return success
return true;
}
/** Private ***************************************************************/
/**
* Setup the necessary table variables.
*
* @since 1.0.0
*/
private function setup() {
// Bail if no database interface is available
if ( ! $this->get_db() ) {
return;
}
// Sanitize the database table name
$this->name = $this->sanitize_table_name( $this->name );
// Bail if database table name was garbage
if ( false === $this->name ) {
return;
}
// Separator
$glue = '_';
// Setup the prefixed name
$this->prefixed_name = $this->apply_prefix( $this->name, $glue );
// Maybe create database key
if ( empty( $this->db_version_key ) ) {
$this->db_version_key = implode(
$glue,
array(
sanitize_key( $this->db_global ),
$this->prefixed_name,
'version'
)
);
}
}
/**
* Set this table up in the database interface.
*
* This must be done directly because the database interface does not
* have a common mechanism for manipulating them safely.
*
* @since 1.0.0
*/
private function set_db_interface() {
// Get the database once, to avoid duplicate function calls
$db = $this->get_db();
// Bail if no database
if ( empty( $db ) ) {
return;
}
// Set variables for global tables
if ( $this->is_global() ) {
$site_id = 0;
$tables = 'ms_global_tables';
// Set variables for per-site tables
} else {
$site_id = null;
$tables = 'tables';
}
// Set the table prefix and prefix the table name
$this->table_prefix = $db->get_blog_prefix( $site_id );
// Get the prefixed table name
$prefixed_table_name = "{$this->table_prefix}{$this->prefixed_name}";
// Set the database interface
$db->{$this->prefixed_name} = $this->table_name = $prefixed_table_name;
// Create the array if it does not exist
if ( ! isset( $db->{$tables} ) ) {
$db->{$tables} = array();
}
// Add the table to the global table array
$db->{$tables}[] = $this->prefixed_name;
// Charset
if ( ! empty( $db->charset ) ) {
$this->charset_collation = "DEFAULT CHARACTER SET {$db->charset}";
}
// Collation
if ( ! empty( $db->collate ) ) {
$this->charset_collation .= " COLLATE {$db->collate}";
}
}
/**
* Set the database version for the table.
*
* @since 1.0.0
*
* @param mixed $version Database version to set when upgrading/creating
*/
private function set_db_version( $version = '' ) {
// If no version is passed during an upgrade, use the current version
if ( empty( $version ) ) {
$version = $this->version;
}
// Update the DB version
$this->is_global()
? update_network_option( get_main_network_id(), $this->db_version_key, $version )
: update_option( $this->db_version_key, $version );
// Set the DB version
$this->db_version = $version;
}
/**
* Get the table version from the database.
*
* @since 1.0.0
*/
private function get_db_version() {
$this->db_version = $this->is_global()
? get_network_option( get_main_network_id(), $this->db_version_key, false )
: get_option( $this->db_version_key, false );
/**
* If the DB version is higher than the stated version and is 12 digits
* long, we need to update it to our new, shorter format of 9 digits.
*
* This is only for 3.0 beta testers, and can be removed in 3.0.1 or above.
*
* @link https://github.com/easydigitaldownloads/easy-digital-downloads/issues/7579
*/
if ( version_compare( $this->db_version, $this->version, '<=' ) || ( 12 !== strlen( $this->db_version ) ) ) {
return;
}
// Parse the new version number from the existing. Converting from
// {YYYY}{mm}{dd}{xxxx} to {YYYY}{mm}{dd}{x}
$date = substr( $this->db_version, 0, 8 );
$increment = substr( $this->db_version, 8, 4 );
// Trims off the three prefixed zeros.
$this->db_version = intval( $date . intval( $increment ) );
$this->set_db_version( $this->db_version );
}
/**
* Delete the table version from the database.
*
* @since 1.0.0
*/
private function delete_db_version() {
$this->db_version = $this->is_global()
? delete_network_option( get_main_network_id(), $this->db_version_key )
: delete_option( $this->db_version_key );
}
/**
* Add class hooks to the parent application actions.
*
* @since 1.0.0
*/
private function add_hooks() {
// Add table to the global database object
add_action( 'switch_blog', array( $this, 'switch_blog' ) );
add_action( 'admin_init', array( $this, 'maybe_upgrade' ) );
}
/**
* Check if the current request is from some kind of test.
*
* This is primarily used to skip 'admin_init' and force-install tables.
*
* @since 1.0.0
*
* @return bool
*/
private function is_testing() {
return (bool)
// Tests constant is being used
( defined( 'WP_TESTS_DIR' ) && WP_TESTS_DIR )
||
// Scaffolded (https://make.wordpress.org/cli/handbook/plugin-unit-tests/)
function_exists( '_manually_load_plugin' );
}
/**
* Check if table is global.
*
* @since 1.0.0
*
* @return bool
*/
private function is_global() {
return ( true === $this->global );
}
/**
* Try to get a callable upgrade, with some magic to avoid needing to
* do this dance repeatedly inside subclasses.
*
* @since 1.0.0
*
* @param string $callback
*
* @return mixed Callable string, or false if not callable
*/
private function get_callable( $callback = '' ) {
// Default return value
$callable = $callback;
// Look for global function
if ( ! is_callable( $callable ) ) {
// Fallback to local class method
$callable = array( $this, $callback );
if ( ! is_callable( $callable ) ) {
// Fallback to class method prefixed with "__"
$callable = array( $this, "__{$callback}" );
if ( ! is_callable( $callable ) ) {
$callable = false;
}
}
}
// Return callable string, or false if not callable
return $callable;
}
}

View File

@ -0,0 +1,170 @@
<?php
/**
* Adjustment Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying adjustments.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Adjustment::__construct() for accepted arguments.
*/
class Adjustment extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access protected
* @var string
*/
protected $table_name = 'adjustments';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access protected
* @var string
*/
protected $table_alias = 'a';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access protected
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Adjustments';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access protected
* @var string
*/
protected $item_name = 'adjustment';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access protected
* @var string
*/
protected $item_name_plural = 'adjustments';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access protected
* @var mixed
*/
protected $item_shape = '\\EDD\\Database\\Rows\\Adjustment';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access protected
* @var string
*/
protected $cache_group = 'adjustments';
/** Methods ***************************************************************/
/**
* Sets up the adjustment query, based on the query vars passed.
*
* @since 3.0
* @access protected
*
* @param string|array $query {
* Optional. Array or query string of adjustment query parameters. Default empty.
*
* @type int $id A adjustment ID to only return that adjustment. Default empty.
* @type array $id__in Array of adjustment IDs to include. Default empty.
* @type array $id__not_in Array of adjustment IDs to exclude. Default empty.
* @type int $parent A parent adjustment ID to only return adjustments with
* that parent. Default empty.
* @type array $parent_id__in An array of parent IDs to include. Default empty.
* @type array $parent_id__not_in An array of parent IDs to exclude. Default empty.
* @type int $code A adjustment code to only return that adjustment. Default empty.
* @type array $code__in Array of adjustment codes to include. Default empty.
* @type array $code__not_in Array of adjustment codes to exclude. Default empty.
* @type int $status A adjustment status to only return that status. Default empty.
* @type array $status__in Array of adjustment statuses to include. Default empty.
* @type array $status__not_in Array of adjustment statuses to exclude. Default empty.
* @type int $type A adjustment type to only return that type. Default empty.
* @type array $type__in Array of adjustment types to include. Default empty.
* @type array $type__not_in Array of adjustment types to exclude. Default empty.
* @type int $scope A adjustment scope to only return that scope. Default empty.
* @type array $scope__in Array of adjustment scopes to include. Default empty.
* @type array $scope__not_in Array of adjustment scopes to exclude. Default empty.
* @type int $amount_type A adjustment amount type to only return that type. Default empty.
* @type array $amount_type__in Array of amount adjustment types to include. Default empty.
* @type array $amount_type__not_in Array of amount adjustment types to exclude. Default empty.
* @type int|float $amount A adjustment amount to only return that amount. Default empty.
* @type array $amount__in Array of adjustment amounts to include. Default empty.
* @type array $amount__not_in Array of adjustment amounts to exclude. Default empty.
* @type int $max_uses A adjustment max_uses to only return that amount. Default empty.
* @type array $max_uses__in Array of adjustment max_uses to include. Default empty.
* @type array $max_uses__not_in Array of adjustment max_uses to exclude. Default empty.
* @type int $use_count A adjustment use_count to only return that count. Default empty.
* @type array $use_count__in Array of adjustment use_counts to include. Default empty.
* @type array $use_count__not_in Array of adjustment use_counts to exclude. Default empty.
* @type int $once_per_customer '1' for true, '0' for false. Default empty.
* @type int|float $min_charge_amount Minimum charge amount. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit adjustments by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $start_date_query Date query clauses to limit adjustments by. See WP_Date_Query.
* Default null.
* @type array $end_date_query Date query clauses to limit adjustments by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a adjustment count (true) or array of adjustment objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete adjustment objects). Default empty.
* @type int $number Limit number of adjustments to retrieve. Default 100.
* @type int $offset Number of adjustments to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'parent', 'name', 'code', 'status', 'type',
* 'scope', 'amount_type', 'amount', 'start_date', 'end_date',
* 'date_created', and 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching adjustments for. Default empty.
* @type bool $update_cache Whether to prime the cache for found adjustments. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,169 @@
<?php
/**
* Customer Address Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying customer addresses.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Customer_Address::__construct() for accepted arguments.
*/
class Customer_Address extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'customer_addresses';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'ca';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Customer_Addresses';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'customer_address';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'customer_addresses';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Customers\\Customer_Address';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'customer_addresses';
/** Methods ***************************************************************/
/**
* Sets up the customer query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of customer query parameters. Default empty.
*
* @type int $id An address ID to only return that address. Default empty.
* @type array $id__in Array of address IDs to include. Default empty.
* @type array $id__not_in Array of address IDs to exclude. Default empty.
* @type int $customer_id A customer ID to only return that object. Default empty.
* @type array $customer_id__in Array of customer IDs to include. Default empty.
* @type array $customer_id__not_in Array of customer IDs to exclude. Default empty.
* @type int $is_primary Search for primary or non-primary addresses
* @type array $is_primary__in Array of 0 and/or 1 to get primary and/or non-primary.
* @type array $is_primary__not_in Array of 0 and/or 1 to avoid getting addresses of primary designation.
* @type string $type Limit results to those affiliated with a given type. Default empty.
* @type array $type__in Array of types to include affiliated addresses for. Default empty.
* @type array $type__not_in Array of types to exclude affiliated addresses for. Default empty.
* @type string $status An address statuses to only return that address. Default empty.
* @type array $status__in Array of address statuses to include. Default empty.
* @type array $status__not_in Array of address statuses to exclude. Default empty.
* @type string $name A name to only return addresses with that name. Default empty.
* @type array $name__in An array of names to include. Default empty.
* @type array $name__not_in An array of names to exclude. Default empty.
* @type string $address An address line 1 to only return that address. Default empty.
* @type array $address__in Array of addresses to include. Default empty.
* @type array $address__not_in Array of addresses to exclude. Default empty.
* @type string $address2 An address line 2 to only return that address. Default empty.
* @type array $address2__in Array of addresses to include. Default empty.
* @type array $address2__not_in Array of addresses to exclude. Default empty.
* @type string $city A city to only return that address. Default empty.
* @type array $city__in Array of cities to include. Default empty.
* @type array $city__not_in Array of cities to exclude. Default empty.
* @type string $region A region to only return that region. Default empty.
* @type array $region__in Array of regions to include. Default empty.
* @type array $region__not_in Array of regions to exclude. Default empty.
* @type string $postal_code A postal code to only return that post code. Default empty.
* @type array $postal_code__in Array of postal codes to include. Default empty.
* @type array $postal_code__not_in Array of postal codes to exclude. Default empty.
* @type string $country A country to only return that country. Default empty.
* @type array $country__in Array of countries to include. Default empty.
* @type array $country__not_in Array of countries to exclude. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit customers by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a customer count (true) or array of customer objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete customer objects). Default empty.
* @type int $number Limit number of customers to retrieve. Default 100.
* @type int $offset Number of customers to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'is_primary', 'type', 'status', 'name',
* 'address', 'address2', 'city', 'region', 'postal_code',
* 'country', 'date_created', 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching customers for. Default empty.
* @type bool $update_cache Whether to prime the cache for found customers. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,146 @@
<?php
/**
* Customer Email Address Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying customer email addresses.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Customer_Email_Address::__construct() for accepted arguments.
*/
class Customer_Email_Address extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'customer_email_addresses';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'cea';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Customer_Email_Addresses';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'customer_email_address';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'customer_email_addresses';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Customers\\Email_Address';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'customer_email_addresses';
/** Methods ***************************************************************/
/**
* Sets up the customer query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of customer query parameters. Default empty.
*
* @type int $id An email address ID to only return that email address. Default empty.
* @type array $id__in Array of email IDs to include. Default empty.
* @type array $id__not_in Array of email IDs to exclude. Default empty.
* @type int $customer_id A customer ID to only return that customer. Default empty.
* @type array $customer_id__in Array of customer IDs to include. Default empty.
* @type array $customer_id__not_in Array of customer IDs to exclude. Default empty.
* @type string $type Limit results to those affiliated with a given type. Default empty.
* @type array $type__in Array of types to include. Default empty.
* @type array $type__not_in Array of types to exclude. Default empty.
* @type string $status An address statuses to only return that status. Default empty.
* @type array $status__in Array of address statuses to include. Default empty.
* @type array $status__not_in Array of address statuses to exclude. Default empty.
* @type string $email An email address to only return that email address. Default empty.
* @type array $email__in Array of email addresses to include. Default empty.
* @type array $email__not_in Array of email addresses to exclude. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit results by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return an item count (true) or array of item objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete customer objects). Default empty.
* @type int $number Limit number of results to retrieve. Default 100.
* @type int $offset Number of items to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'type', 'email', 'date_created', 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching emails for. Default empty.
* @type bool $update_cache Whether to prime the cache for found emails. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,146 @@
<?php
/**
* Customer Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying customers.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Customer::__construct() for accepted arguments.
*/
class Customer extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'customers';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'c';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Customers';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'customer';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'customers';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD_Customer';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'customers';
/** Methods ***************************************************************/
/**
* Sets up the customer query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of customer query parameters. Default empty.
*
* @type int $id An customer ID to only return that customer. Default empty.
* @type array $id__in Array of customer IDs to include. Default empty.
* @type array $id__not_in Array of customer IDs to exclude. Default empty.
* @type int $user_id A user ID to only return that user. Default empty.
* @type array $user_id__in Array of user IDs to include. Default empty.
* @type array $user_id__not_in Array of user IDs to exclude. Default empty.
* @type string $email Limit results to those affiliated with a given email. Default empty.
* @type array $email__in Array of email to include affiliated orders for. Default empty.
* @type array $email__not_in Array of email to exclude affiliated orders for. Default empty.
* @type string $status A status to only return that status. Default empty.
* @type array $status__in Array of order statuses to include. Default empty.
* @type array $status__not_in Array of order statuses to exclude. Default empty.
* @type float $purchase_value A purchase value. Default empty.
* @type int $purchase_count A numeric value. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit customers by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a customer count (true) or array of customer objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete customer objects). Default empty.
* @type int $number Limit number of customers to retrieve. Default 100.
* @type int $offset Number of customers to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'email', 'name', 'status', 'purchase_value',
* 'purchase_count', 'date_created', 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching customers for. Default empty.
* @type bool $update_cache Whether to prime the cache for found customers. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* API Request Log Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying items.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Log_Api_Request::__construct() for accepted arguments.
*/
class Log_Api_Request extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'logs_api_requests';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'la';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Logs_Api_Requests';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'logs_api_request';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'logs_api_requests';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = 'EDD\\Logs\\Api_Request_Log';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'logs_api_requests';
/** Methods ***************************************************************/
/**
* Sets up the query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An log ID to only return that log. Default empty.
* @type array $id__in Array of log IDs to include. Default empty.
* @type array $id__not_in Array of log IDs to exclude. Default empty.
* @type string $user_id A user ID to only return those users. Default empty.
* @type array $user_id__in Array of user IDs to include. Default empty.
* @type array $user_id__not_in Array of user IDs to exclude. Default empty.
* @type string $api_key An API key to only return that key. Default empty.
* @type array $api_key__in Array of API keys to include. Default empty.
* @type array $api_key__not_in Array of API keys to exclude. Default empty.
* @type string $token A token to only return that token. Default empty.
* @type array $token__in Array of tokens to include. Default empty.
* @type array $token__not_in Array of tokens to exclude. Default empty.
* @type string $version A version to only return that version. Default empty.
* @type array $version__in Array of versions to include. Default empty.
* @type array $version__not_in Array of versions to exclude. Default empty.
* @type string $request Request to search by. Default empty.
* @type string $error Error to search by. Default empty.
* @type string $ip An IP to only return that IP address. Default empty.
* @type array $ip__in Array of IPs to include. Default empty.
* @type array $ip__not_in Array of IPs to exclude. Default empty.
* @type string $time A time to only return that time. Default empty.
* @type array $time__in Array of times to include. Default empty.
* @type array $time__not_in Array of times to exclude. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a count (true) or array of objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete objects). Default empty.
* @type int $number Limit number of logs to retrieve. Default 100.
* @type int $offset Number of logs to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'user_id', 'api_key', 'token', 'version', 'ip',
* 'time', 'date_created', and 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching logs for. Default empty.
* @type bool $update_cache Whether to prime the cache for found logs. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* File Download Log Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying items.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Log_File_Download::__construct() for accepted arguments.
*/
class Log_File_Download extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'logs_file_downloads';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'lf';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Logs_File_Downloads';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'logs_file_download';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'logs_file_downloads';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = 'EDD\\Logs\\File_Download_Log';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'logs_file_downloads';
/** Methods ***************************************************************/
/**
* Sets up the query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An log ID to only return that log. Default empty.
* @type array $id__in Array of log IDs to include. Default empty.
* @type array $id__not_in Array of log IDs to exclude. Default empty.
* @type string $product_id A product ID to only return those products. Default empty.
* @type array $product_id__in Array of product IDs to include. Default empty.
* @type array $product_id__not_in Array of product IDs to exclude. Default empty.
* @type string $file_id A file ID to only return those files. Default empty.
* @type array $file_id__in Array of file IDs to include. Default empty.
* @type array $file_id__not_in Array of file IDs to exclude. Default empty.
* @type string $order_id An order ID to only return those orders. Default empty.
* @type array $order_id__in Array of order IDs to include. Default empty.
* @type array $order_id__not_in Array of order IDs to exclude. Default empty.
* @type string $price_id A price ID to only return those prices. Default empty.
* @type array $price_id__in Array of price IDs to include. Default empty.
* @type array $price_id__not_in Array of price IDs to exclude. Default empty.
* @type string $customer_id A customer ID to only return those customers. Default empty.
* @type array $customer_id__in Array of customer IDs to include. Default empty.
* @type array $customer_id__not_in Array of customer IDs to exclude. Default empty.
* @type string $ip An IP to only return that IP address. Default empty.
* @type array $ip__in Array of IPs to include. Default empty.
* @type array $ip__not_in Array of IPs to exclude. Default empty.
* @type string $user_agent A user agent to only return that agent. Default empty.
* @type array $user_agent__in Array of user agents to include. Default empty.
* @type array $user_agent__not_in Array of user agents to exclude. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a count (true) or array of objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete objects). Default empty.
* @type int $number Limit number of logs to retrieve. Default 100.
* @type int $offset Number of logs to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'product_id', 'file_id', 'order_id', 'customer_id',
* 'ip', 'date_created', and 'date_modified'. Also accepts false,
* an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching logs for. Default empty.
* @type bool $update_cache Whether to prime the cache for found logs. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
* Log Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying items.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Log::__construct() for accepted arguments.
*/
class Log extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'logs';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'l';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Logs';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'log';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'logs';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = 'EDD\\Logs\\Log';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'logs';
/** Methods ***************************************************************/
/**
* Sets up the query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An log ID to only return that log. Default empty.
* @type array $id__in Array of log IDs to include. Default empty.
* @type array $id__not_in Array of log IDs to exclude. Default empty.
* @type string $object_id An object ID to only return those objects. Default empty.
* @type array $object_id__in Array of object IDs to include. Default empty.
* @type array $object_id__not_in Array of IDs object to exclude. Default empty.
* @type string $object_type An object types to only return that type. Default empty.
* @type array $object_type__in Array of object types to include. Default empty.
* @type array $object_type__not_in Array of object types to exclude. Default empty.
* @type string $user_id A user ID to only return those users. Default empty.
* @type array $user_id__in Array of user IDs to include. Default empty.
* @type array $user_id__not_in Array of user IDs to exclude. Default empty.
* @type string $type A type to only return those types. Default empty.
* @type array $type__in Array of types to include. Default empty.
* @type array $type__not_in Array of types to exclude. Default empty.
* @type string $title Title to search by. Default empty.
* @type string $content Content to search by. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a count (true) or array of objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete objects). Default empty.
* @type int $number Limit number of logs to retrieve. Default 100.
* @type int $offset Number of logs to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'object_id', 'object_type', 'user_id', 'type',
* 'title', 'date_created', and 'date_modified'. Also accepts false,
* an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order rsults. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching logs for. Default empty.
* @type bool $update_cache Whether to prime the cache for found logs. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,145 @@
<?php
/**
* Note Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying items.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Note::__construct() for accepted arguments.
*/
class Note extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'notes';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'n';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Notes';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'note';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'notes';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Notes\\Note';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'notes';
/** Methods ***************************************************************/
/**
* Sets up the query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An note ID to only return that note. Default empty.
* @type array $id__in Array of note IDs to include. Default empty.
* @type array $id__not_in Array of note IDs to exclude. Default empty.
* @type string $object_id An object ID to only return those objects. Default empty.
* @type array $object_id__in Array of object IDs to include. Default empty.
* @type array $object_id__not_in Array of IDs object to exclude. Default empty.
* @type string $object_type An object types to only return that type. Default empty.
* @type array $object_type__in Array of object types to include. Default empty.
* @type array $object_type__not_in Array of object types to exclude. Default empty.
* @type string $user_id A user ID to only return those users. Default empty.
* @type array $user_id__in Array of user IDs to include. Default empty.
* @type array $user_id__not_in Array of user IDs to exclude. Default empty.
* @type array $content Content to query by. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a count (true) or array of objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete objects). Default empty.
* @type int $number Limit number of notes to retrieve. Default 100.
* @type int $offset Number of notes to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'object_id', 'object_type', 'user_id', 'date_created',
* 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching notes for. Default empty.
* @type bool $update_cache Whether to prime the cache for found notes. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,162 @@
<?php
/**
* Order Address Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying customer addresses.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Order_Address::__construct() for accepted arguments.
*/
class Order_Address extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'order_addresses';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'oa';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Order_Addresses';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'order_address';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'order_addresses';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Orders\\Order_Address';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'order_addresses';
/** Methods ***************************************************************/
/**
* Sets up the customer query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An address ID to only return that order address. Default empty.
* @type array $id__in Array of order address IDs to include. Default empty.
* @type array $id__not_in Array of order address IDs to exclude. Default empty.
* @type int $order_id A order ID to only return that order. Default empty.
* @type array $order_id__in Array of order IDs to include. Default empty.
* @type array $order_id__not_in Array of order IDs to exclude. Default empty.
* @type string $type An order address type. Default empty.
* @type array $type__in An array of types to include. Default empty.
* @type array $type__not_in An array of types to exclude. Default empty.
* @type string $name A name to only return that address.
* @type array $name__in Array of names to include. Default empty.
* @type array $name__not_in Array of names to exclude. Default empty.
* @type string $address An address line 1 to only return that address. Default empty.
* @type array $address__in Array of addresses to include. Default empty.
* @type array $address__not_in Array of addresses to exclude. Default empty.
* @type string $address2 An address line 2 to only return that address. Default empty.
* @type array $address2__in Array of addresses to include. Default empty.
* @type array $address2__not_in Array of addresses to exclude. Default empty.
* @type string $city A city to only return that address. Default empty.
* @type array $city__in Array of cities to include. Default empty.
* @type array $city__not_in Array of cities to exclude. Default empty.
* @type string $region A region to only return that address. Default empty.
* @type array $region__in Array of regions to include. Default empty.
* @type array $region__not_in Array of regions to exclude. Default empty.
* @type string $postal_code A postal code to only return that address. Default empty.
* @type array $postal_code__in Array of postal codes to include. Default empty.
* @type array $postal_code__not_in Array of postal codes to exclude. Default empty.
* @type string $country A country to only return that address. Default empty.
* @type array $country__in Array of countries to include. Default empty.
* @type array $country__not_in Array of countries to exclude. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit results by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return an item count (true) or array of item objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete item objects). Default empty.
* @type int $number Limit number of results to retrieve. Default 100.
* @type int $offset Number of items to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'type', 'name', 'address', 'address2', 'city',
* 'region', 'postal_code', 'country', 'date_created', 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching results for. Default empty.
* @type bool $update_cache Whether to prime the cache for found items. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,162 @@
<?php
/**
* Order Adjustment Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying order order adjustments.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Order_Adjustment::__construct() for accepted arguments.
*/
class Order_Adjustment extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'order_adjustments';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'oa';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Order_Adjustments';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'order_adjustment';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'order_adjustments';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Orders\\Order_Adjustment';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'order_adjustments';
/** Methods ***************************************************************/
/**
* Sets up the order query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An order adjustment ID to only return that item. Default empty.
* @type array $id__in Array of order adjustment IDs to include. Default empty.
* @type array $id__not_in Array of order adjustment IDs to exclude. Default empty.
* @type int $parent A parent ID to only return items with that parent. Default empty.
* @type array $parent__in An array of parent IDs to include. Default empty.
* @type array $parent__not_in An array of parent IDs to exclude. Default empty.
* @type string $object_id An object ID to only return those objects. Default empty.
* @type array $object_id__in Array of object IDs to include. Default empty.
* @type array $object_id__not_in Array of IDs object to exclude. Default empty.
* @type string $object_type An object types to only return that type. Default empty.
* @type array $object_type__in Array of object types to include. Default empty.
* @type array $object_type__not_in Array of object types to exclude. Default empty.
* @type string $type_id A type ID to only return that type. Default empty.
* @type array $type_id__in Array of types IDs to include. Default empty.
* @type array $type_id__not_in Array of types IDS to exclude. Default empty.
* @type string $type A type to only return that type. Default empty.
* @type array $type__in Array of types to include. Default empty.
* @type array $type__not_in Array of types to exclude. Default empty.
* @type string $type_key Filter by type key. Default empty.
* @type array $type_key__in An array of type keys to include. Default empty.
* @type array $type_key__not_in An array of type keys to exclude. Default empty.
* @type float $tax Limit results to those with a specific tax amount. Default empty.
* @type array $tax__in Array of tax amounts to include. Default empty.
* @type array $tax__not_in Array of tax amounts to exclude. Default empty.
* @type float $subtotal Limit results to those affiliated with a given subtotal. Default empty.
* @type array $subtotal__in Array of subtotal amounts to include. Default empty.
* @type array $subtotal__not_in Array of subtotal amounts to exclude. Default empty.
* @type float $total Limit results to those affiliated with a given total. Default empty.
* @type array $total__in Array of totals to include. Default empty.
* @type array $total__not_in Array of totals to exclude. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return an item count (true) or array of item objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete item objects). Default empty.
* @type int $number Limit number of order adjustments to retrieve. Default 100.
* @type int $offset Number of order adjustments to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'object_id', 'object_type', 'type_id', 'type',
* 'type_key', 'subtotal', 'tax', 'total', 'date_created', 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching order adjustments for. Default empty.
* @type bool $update_cache Whether to prime the cache for found order adjustments. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* Order Item Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying order items.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Order_Item::__construct() for accepted arguments.
*/
class Order_Item extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'order_items';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'oi';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Order_Items';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'order_item';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'order_items';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Orders\\Order_Item';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'order_items';
/** Methods ***************************************************************/
/**
* Sets up the order query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An order item ID to only return that item. Default empty.
* @type array $id__in Array of order item IDs to include. Default empty.
* @type array $id__not_in Array of order item IDs to exclude. Default empty.
* @type int $parent A parent ID to only return items with that parent. Default empty.
* @type array $parent__in An array of parent IDs to include. Default empty.
* @type array $parent__not_in An array of parent IDs to exclude. Default empty.
* @type int $order_id An order ID to only return those order items. Default empty.
* @type array $order_id__in Array of order IDs to include. Default empty.
* @type array $order_id__not_in Array of order IDs to exclude. Default empty.
* @type int $product_id A product ID to only return those products. Default empty.
* @type array $product_id__in Array of product IDs to include. Default empty.
* @type array $product_id__not_in Array of product IDs to exclude. Default empty.
* @type string $product_name A product name to filter by. Default empty.
* @type array $product_name__in An array of product names to include. Default empty.
* @type array $product_name__not_in An array of product names to exclude. Default empty.
* @type int $price_id A price ID to only return that price. Default empty.
* @type array $price_id__in Array of price IDs to include. Default empty.
* @type array $price_id__not_in Array of price IDs to exclude. Default empty.
* @type int $cart_index A cart index to only return that index. Default empty.
* @type array $cart_index__in Array of cart index to include. Default empty.
* @type array $cart_index__not_in Array of cart index to exclude. Default empty.
* @type string $type A product type to only return that type. Default empty.
* @type array $type__in Array of product types to include. Default empty.
* @type array $type__not_in Array of product types to exclude. Default empty.
* @type string $status An order statuses to only return that status. Default empty.
* @type array $status__in Array of order statuses to include. Default empty.
* @type array $status__not_in Array of order statuses to exclude. Default empty.
* @type int $quantity A quantity to only return those quantities. Default empty.
* @type array $quantity__in Array of quantities to include. Default empty.
* @type array $quantity__not_in Array of quantities to exclude. Default empty.
* @type float $amount Limit results to those affiliated with a given amount. Default empty.
* @type array $amount__in Array of amounts to include affiliated order items for. Default empty.
* @type array $amount__not_in Array of amounts to exclude affiliated order items for. Default empty.
* @type float $subtotal Limit results to those affiliated with a given subtotal. Default empty.
* @type array $subtotal__in Array of subtotals to include affiliated order items for. Default empty.
* @type array $subtotal__not_in Array of subtotals to exclude affiliated order items for. Default empty.
* @type float $discount Limit results to those affiliated with a given discount. Default empty.
* @type array $discount__in Array of discounts to include affiliated order items for. Default empty.
* @type array $discount__not_in Array of discounts to exclude affiliated order items for. Default empty.
* @type float $tax Limit results to those affiliated with a given tax. Default empty.
* @type array $tax__in Array of taxes to include affiliated order items for. Default empty.
* @type array $tax__not_in Array of taxes to exclude affiliated order items for. Default empty.
* @type float $total Limit results to those affiliated with a given total. Default empty.
* @type array $total__in Array of totals to include affiliated order items for. Default empty.
* @type array $total__not_in Array of totals to exclude affiliated order items for. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a order count (true) or array of order objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete order objects). Default empty.
* @type int $number Limit number of order items to retrieve. Default 100.
* @type int $offset Number of order items to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'order_id', 'product_id', 'price_id', 'cart_index', 'type'
* 'status', 'quantity', 'amount', 'subtotal', 'discount', 'tax',
* 'total', 'date_created', 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching order items for. Default empty.
* @type bool $update_cache Whether to prime the cache for found order items. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,154 @@
<?php
/**
* Order Transaction Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying order transactions.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Order_Transaction::__construct() for accepted arguments.
*/
class Order_Transaction extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'order_transactions';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'ot';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Order_Transactions';
/** Item ******************************************************************/
/**
* Name for a single item.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'order_transaction';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'order_transactions';
/**
* Callback function for turning IDs into objects.
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Orders\\Order_Transaction';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'order_transactions';
/** Methods ***************************************************************/
/**
* Sets up the order query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of query parameters. Default empty.
*
* @type int $id An ID to only return that order transaction. Default empty.
* @type array $id__in Array of order transaction IDs to include. Default empty.
* @type array $id__not_in Array of order transaction IDs to exclude. Default empty.
* @type string $object_id An object ID to only return those objects. Default empty.
* @type array $object_id__in Array of object IDs to include. Default empty.
* @type array $object_id__not_in Array of IDs object to exclude. Default empty.
* @type string $object_type An object type to only return that type. Default empty.
* @type array $object_type__in Array of object types to include. Default empty.
* @type array $object_type__not_in Array of object types to exclude. Default empty.
* @type string $transaction_id A transaction ID to only return that transaction. Default empty.
* @type array $transaction_id__in Array of transaction IDs to include. Default empty.
* @type array $transaction_id__not_in Array of transaction IDs to exclude. Default empty.
* @type string $gateway A gateway to filter by. Default empty.
* @type array $gateway__in Array of gateways to include. Default empty.
* @type array $gateway__not_in Array of gateways to exclude. Default empty.
* @type string $status A status to only return that status. Default empty.
* @type array $status__in Array of statuses to include. Default empty.
* @type array $status__not_in Array of statuses to exclude. Default empty.
* @type float $total Limit results to those affiliated with a given total. Default empty.
* @type array $total__in Array of totals to include affiliated order items for. Default empty.
* @type array $total__not_in Array of totals to exclude affiliated order items for. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type array $date_modified_query Date query clauses to limit by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return an item count (true) or array of item objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete order transactions objects).
* Default empty.
* @type int $number Limit number of order transactions to retrieve. Default 100.
* @type int $offset Number of items to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'object_id', 'object_type', 'transaction_id', 'gateway',
* 'status', 'total', 'date_created', 'date_modified'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order results. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching order transactions for. Default empty.
* @type bool $update_cache Whether to prime the cache for found order transactions. Default false.
* }
*/
public function __construct( $query = array() ) {
parent::__construct( $query );
}
}

View File

@ -0,0 +1,446 @@
<?php
/**
* Order Query Class.
*
* @package EDD
* @subpackage Database\Queries
* @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\Queries;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Query;
/**
* Class used for querying orders.
*
* @since 3.0
*
* @see \EDD\Database\Queries\Order::__construct() for accepted arguments.
*/
class Order extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_name = 'orders';
/**
* String used to alias the database table in MySQL statement.
*
* @since 3.0
* @access public
* @var string
*/
protected $table_alias = 'o';
/**
* Name of class used to setup the database schema
*
* @since 3.0
* @access public
* @var string
*/
protected $table_schema = '\\EDD\\Database\\Schemas\\Orders';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name = 'order';
/**
* Plural version for a group of items.
*
* @since 3.0
* @access public
* @var string
*/
protected $item_name_plural = 'orders';
/**
* Callback function for turning IDs into objects
*
* @since 3.0
* @access public
* @var mixed
*/
protected $item_shape = '\\EDD\\Orders\\Order';
/** Cache *****************************************************************/
/**
* Group to cache queries and queried items in.
*
* @since 3.0
* @access public
* @var string
*/
protected $cache_group = 'orders';
/** Methods ***************************************************************/
/**
* Sets up the order query, based on the query vars passed.
*
* @since 3.0
* @access public
*
* @param string|array $query {
* Optional. Array or query string of order query parameters. Default empty.
*
* @type int $id An order ID to only return that order. Default empty.
* @type array $id__in Array of order IDs to include. Default empty.
* @type array $id__not_in Array of order IDs to exclude. Default empty.
* @type int $parent A parent ID to only return orders with that parent. Default empty.
* @type array $parent__in An array of parent IDs to include. Default empty.
* @type array $parent__not_in An array of parent IDs to exclude. Default empty.
* @type string $order_number An order number to only return that number. Default empty.
* @type array $order_number__in Array of order numbers to include. Default empty.
* @type array $order_number__not_in Array of order numbers to exclude. Default empty.
* @type string $status An order status to only return that status. Default empty.
* @type array $status__in Array of order statuses to include. Default empty.
* @type array $status__not_in Array of order statuses to exclude. Default empty.
* @type string $type An order type to only return that type. Default empty.
* @type array $type__in Array of order types to include. Default empty.
* @type array $type__not_in Array of order types to exclude. Default empty.
* @type int $user_id A user ID to only return that user. Default empty.
* @type array $user_id__in Array of user IDs to include. Default empty.
* @type array $user_id__not_in Array of user IDs to exclude. Default empty.
* @type int $customer_id A customer ID to only return that customer. Default empty.
* @type array $customer_id__in Array of customer IDs to include. Default empty.
* @type array $customer_id__not_in Array of customer IDs to exclude. Default empty.
* @type string $email Limit results to those affiliated with a given email. Default empty.
* @type array $email__in Array of email to include affiliated orders for. Default empty.
* @type array $email__not_in Array of email to exclude affiliated orders for. Default empty.
* @type string $ip A filter IP address to only include orders with that IP. Default empty.
* @type array $ip__in An array of IPs to include. Default empty.
* @type array $ip__not_in An array of IPs to exclude. Default empty.
* @type string $gateway Limit results to those affiliated with a given gateway. Default empty.
* @type array $gateway__in Array of gateways to include affiliated orders for. Default empty.
* @type array $gateway__not_in Array of gateways to exclude affiliated orders for. Default empty.
* @type string $mode Limit results to those affiliated with a given mode. Default empty.
* @type array $mode__in Array of modes to include affiliated orders for. Default empty.
* @type array $mode__not_in Array of modes to exclude affiliated orders for. Default empty.
* @type string $currency Limit results to those affiliated with a given currency. Default empty.
* @type array $currency__in Array of currencies to include affiliated orders for. Default empty.
* @type array $currency__not_in Array of currencies to exclude affiliated orders for. Default empty.
* @type string $payment_key Limit results to those affiliated with a given payment key. Default empty.
* @type array $payment_key__in Array of payment keys to include affiliated orders for. Default empty.
* @type array $payment_key__not_in Array of payment keys to exclude affiliated orders for. Default empty.
* @type int $tax_rate_id A tax rate ID to filter by. Default empty.
* @type array $tax_rate_id__in Array of tax rate IDs to filter by. Default empty.
* @type array $tax_rate_id__not_in Array of tax rate IDs to exclude orders for. Default empty.
* @type array $date_query Query all datetime columns together. See WP_Date_Query.
* @type array $date_created_query Date query clauses to limit orders by. See WP_Date_Query.
* Default null.
* @type array $date_completed_query Date query clauses to limit orders by. See WP_Date_Query.
* Default null.
* @type array $date_refundable_query Date query clauses to limit orders by. See WP_Date_Query.
* Default null.
* @type bool $count Whether to return a order count (true) or array of order objects.
* Default false.
* @type string $fields Item fields to return. Accepts any column known names
* or empty (returns an array of complete order objects). Default empty.
* @type int $number Limit number of orders to retrieve. Default 100.
* @type int $offset Number of orders to offset the query. Used to build LIMIT clause.
* Default 0.
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
* @type string|array $orderby Accepts 'id', 'parent', 'order_number', 'status', 'type',
* 'user_id', 'customer_id', 'email', 'ip', 'gateway',
* 'tax_rate_id', 'subtotal', 'discount', 'tax', 'total',
* 'date_created', 'date_modified', 'date_completed', 'date_refundable'.
* Also accepts false, an empty array, or 'none' to disable `ORDER BY` clause.
* Default 'id'.
* @type string $order How to order retrieved orders. Accepts 'ASC', 'DESC'. Default 'DESC'.
* @type string $search Search term(s) to retrieve matching orders for. Default empty.
* @type bool $update_cache Whether to prime the cache for found orders. Default false.
* @type string $country Limit results to those affiliated with a given country. Default empty.
* @type string $region Limit results to those affiliated with a given region. Default empty.
* @type int $product_id Filter by product ID. Default empty.
* @type int $product_price_id Filter by product price ID. Default empty.
* @type string $txn Filter by transaction ID.
* @type int $discount_id Filter by discount code.
* }
*/
public function __construct( $query = array() ) {
// In EDD 3.0 we converted our use of the status 'publish' to 'complete', this accounts for queries using publish.
if ( isset( $query['status'] ) ) {
if ( is_array( $query['status'] ) && in_array( 'publish', $query['status'], true ) ) {
foreach ( $query['status'] as $key => $status ) {
if ( 'publish' === $status ) {
unset( $query['status'][ $key ] );
}
}
$query['status'][] = 'complete';
} elseif ( 'publish' === $query['status'] ) {
$query['status'] = 'complete';
}
}
parent::__construct( $query );
}
/**
* Set up the filter callback to add the country and region from the order addresses table.
*
* @since 3.0
* @access public
*
* @param string|array $query See Order::__construct() for accepted arguments.
*
* @see Order::__construct()
*/
public function query( $query = array() ) {
$query_clauses_filters = $this->get_query_clauses_filters( $query );
foreach ( $query_clauses_filters as $filter ) {
if ( $filter['condition'] ) {
add_filter( 'edd_orders_query_clauses', array( $this, $filter['callback'] ) );
}
}
$result = parent::query( $query );
foreach ( $query_clauses_filters as $filter ) {
if ( $filter['condition'] ) {
remove_filter( 'edd_orders_query_clauses', array( $this, $filter['callback'] ) );
}
}
return $result;
}
/**
* Filter the query clause to add the country and region from the order addresses table.
*
* @since 3.0
* @access public
*
* @param string|array $clauses The clauses which will generate the final SQL query.
*/
public function query_by_country( $clauses ) {
if ( empty( $this->query_vars['country'] ) || 'all' === $this->query_vars['country'] ) {
return $clauses;
}
global $wpdb;
$primary_alias = $this->table_alias;
$primary_column = parent::get_primary_column_name();
$order_addresses_query = new \EDD\Database\Queries\Order_Address();
$join_alias = $order_addresses_query->table_alias;
// Filter by the order address's region (state/province/etc)..
if ( ! empty( $this->query_vars['region'] ) && 'all' !== $this->query_vars['region'] ) {
$location_join = $wpdb->prepare(
" INNER JOIN {$order_addresses_query->table_name} {$join_alias} ON ({$primary_alias}.{$primary_column} = {$join_alias}.order_id AND {$join_alias}.country = %s AND {$join_alias}.region = %s)",
$this->query_vars['country'],
$this->query_vars['region']
);
// Add the region to the query var defaults.
$this->query_var_defaults['region'] = $this->query_vars['region'];
// Filter only by the country, not by region.
} else {
$location_join = $wpdb->prepare(
" INNER JOIN {$order_addresses_query->table_name} {$join_alias} ON ({$primary_alias}.{$primary_column} = {$join_alias}.order_id AND {$join_alias}.country = %s)",
$this->query_vars['country']
);
// Add the country to the query var defaults.
$this->query_var_defaults['country'] = $this->query_vars['country'];
}
// Add the customized join to the query.
$clauses['join'] .= ' ' . $location_join;
return $clauses;
}
/**
* Filter the query clause to filter by product ID.
*
* @since 3.0
* @access public
*
* @param string|array $clauses The clauses which will generate the final SQL query.
*/
public function query_by_product( $clauses ) {
if (
empty( $this->query_vars['product_id'] ) &&
( ! isset( $this->query_vars['product_price_id'] ) || ! is_numeric( $this->query_vars['product_price_id'] ) )
) {
return $clauses;
}
global $wpdb;
$primary_column = parent::get_primary_column_name();
$order_items_query = new Order_Item();
// Build up our conditions.
$conditions = array();
foreach ( array( 'product_id' => 'product_id', 'product_price_id' => 'price_id' ) as $query_var => $db_col ) {
if ( isset( $this->query_vars[ $query_var ] ) && is_numeric( $this->query_vars[ $query_var ] ) ) {
$conditions[] = $wpdb->prepare(
"AND {$order_items_query->table_alias}.{$db_col} = %d",
absint( $this->query_vars[ $query_var ] )
);
}
}
$conditions = implode( ' ', $conditions );
$clauses['join'] .= " INNER JOIN {$order_items_query->table_name} {$order_items_query->table_alias} ON(
{$this->table_alias}.{$primary_column} = {$order_items_query->table_alias}.order_id
{$conditions}
)";
return $clauses;
}
/**
* Filter the query clause to filter by transaction ID.
*
* @since 3.0.2
* @param string $clauses
* @return string
*/
public function query_by_txn( $clauses ) {
if ( empty( $this->query_vars['txn'] ) ) {
return $clauses;
}
global $wpdb;
$primary_column = parent::get_primary_column_name();
$order_transaction_query = new Order_Transaction();
$clauses['join'] .= $wpdb->prepare(
" INNER JOIN {$order_transaction_query->table_name} {$order_transaction_query->table_alias}
ON( {$this->table_alias}.{$primary_column} = {$order_transaction_query->table_alias}.object_id
AND {$order_transaction_query->table_alias}.transaction_id = %s )",
sanitize_text_field( $this->query_vars['txn'] )
);
return $clauses;
}
/**
* Filter the query clause to filter by discount ID.
*
* @since 3.0.2
* @param string $clauses
* @return string
*/
public function query_by_discount_id( $clauses ) {
if ( empty( $this->query_vars['discount_id'] ) ) {
return $clauses;
}
global $wpdb;
$primary_column = parent::get_primary_column_name();
$order_adjustment_query = new Order_Adjustment();
$clauses['join'] .= $wpdb->prepare(
" INNER JOIN {$order_adjustment_query->table_name} {$order_adjustment_query->table_alias}
ON( {$this->table_alias}.{$primary_column} = {$order_adjustment_query->table_alias}.object_id
AND {$order_adjustment_query->table_alias}.type_id = %d )",
absint( $this->query_vars['discount_id'] )
);
return $clauses;
}
/**
* Set the query var defaults for country and region.
*
* @since 3.0
* @access public
*/
protected function set_query_var_defaults() {
parent::set_query_var_defaults();
$this->query_var_defaults['country'] = false;
$this->query_var_defaults['region'] = false;
$this->query_var_defaults['product_id'] = false;
$this->query_var_defaults['product_product_id'] = false;
}
/**
* Adds an item to the database
*
* @since 3.0
*
* @param array $data
* @return false|int Returns the item ID on success; false on failure.
*/
public function add_item( $data = array() ) {
// Every order should have a currency assigned.
if ( empty( $data['currency'] ) ) {
$data['currency'] = edd_get_currency();
}
// If the payment key isn't already created, generate it.
if ( empty( $data['payment_key'] ) ) {
$email = ! empty( $data['email'] ) ? $data['email'] : '';
$data['payment_key'] = edd_generate_order_payment_key( $email );
}
// Add the IP address if it hasn't been already.
if ( empty( $data['ip'] ) ) {
$data['ip'] = edd_get_ip();
}
return parent::add_item( $data );
}
/**
* Get the array of possible query clause filters.
*
* @since 3.0.2
* @param array $query
* @return array
*/
private function get_query_clauses_filters( $query ) {
return array(
array(
'condition' => ! empty( $query['country'] ),
'callback' => 'query_by_country',
),
array(
'condition' => ! empty( $query['product_id'] ) || ( isset( $query['product_price_id'] ) && is_numeric( $query['product_price_id'] ) ),
'callback' => 'query_by_product',
),
array(
'condition' => ! empty( $query['txn'] ),
'callback' => 'query_by_txn',
),
array(
'condition' => ! empty( $query['discount_id'] ),
'callback' => 'query_by_discount_id',
),
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Adjustment Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Adjustment database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Adjustment extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Customer Address Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Customer address database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Customer_Address extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Customer Email Address Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Customer email address database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Customer_Email_Address extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Customer Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Customer database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Customer extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* API Request Log Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* API Request Log database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Log_Api_Request extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* File Download Log Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* File Download Log database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Log_File_Download extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Log Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Log database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Log extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Note Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Note database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Note extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Order Address Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Order address database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Order_Address extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Order Adjustment Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Order adjustment database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Order_Adjustment extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Order Item Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Order item database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Order_Item extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Order Transaction Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Order transaction database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Order_Transaction extends Row {
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Order Database Object Class.
*
* @package EDD
* @subpackage Database\Rows
* @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\Rows;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Row;
/**
* Order database row class.
*
* This class exists solely to encapsulate database schema changes, to help
* separate the needs of the application layer from the requirements of the
* database layer.
*
* For example, if a database column is renamed or a return value needs to be
* formatted differently, this class will make sure old values are still
* supported and new values do not conflict.
*
* @since 3.0
*/
class Order extends Row {
}

View File

@ -0,0 +1,210 @@
<?php
/**
* Adjustments Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Adjustments Schema Class.
*
* @since 3.0
*/
final class Adjustments extends Schema {
/**
* Array of database column objects.
*
* @since 3.0
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// parent
array(
'name' => 'parent',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true,
'transition' => true
),
// name
array(
'name' => 'name',
'type' => 'varchar',
'length' => '200',
'searchable' => true,
'sortable' => true
),
// code
array(
'name' => 'code',
'type' => 'varchar',
'length' => '50',
'searchable' => true,
'sortable' => true
),
// status
array(
'name' => 'status',
'type' => 'varchar',
'length' => '20',
'default' => 'draft',
'sortable' => true,
'transition' => true
),
// type
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true,
'transition' => true
),
// scope
array(
'name' => 'scope',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true,
'transition' => true
),
// amount_type
array(
'name' => 'amount_type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true,
'transition' => true
),
// amount
array(
'name' => 'amount',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true
),
// description
array(
'name' => 'description',
'type' => 'longtext',
'default' => '',
'searchable' => true
),
// max_uses
array(
'name' => 'max_uses',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0'
),
// use_count
array(
'name' => 'use_count',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true,
),
// once_per_customer
array(
'name' => 'once_per_customer',
'type' => 'int',
'length' => '1',
'default' => '0'
),
// min_charge_amount
array(
'name' => 'min_charge_amount',
'type' => 'decimal',
'length' => '18,9',
'default' => '0'
),
// start_date
array(
'name' => 'start_date',
'type' => 'datetime',
'default' => null,
'allow_null' => true,
'date_query' => true,
'sortable' => true
),
// end_date
array(
'name' => 'end_date',
'type' => 'datetime',
'default' => null,
'allow_null' => true,
'date_query' => true,
'sortable' => true
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,169 @@
<?php
/**
* Customer Addresses Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Customer Addresses Schema Class.
*
* @since 3.0
*/
class Customer_Addresses extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// customer_id
array(
'name' => 'customer_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0'
),
// is_primary
array(
'name' => 'is_primary',
'type' => 'tinyint',
'length' => '1',
'unsigned' => false,
'default' => '0',
'sortable' => true,
'transition' => true,
),
// type
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => 'billing',
'sortable' => true,
'transition' => true
),
// status
array(
'name' => 'status',
'type' => 'varchar',
'length' => '20',
'default' => 'active',
'sortable' => true,
'transition' => true
),
// name
array(
'name' => 'name',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// address
array(
'name' => 'address',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// address2
array(
'name' => 'address2',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// city
array(
'name' => 'city',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// region
array(
'name' => 'region',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// postal_code
array(
'name' => 'postal_code',
'type' => 'varchar',
'length' => '32',
'default' => '',
'searchable' => true,
'sortable' => true
),
// country
array(
'name' => 'country',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,112 @@
<?php
/**
* Customer Email Addresses Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Customer Email Addresses Schema Class.
*
* @since 3.0
*/
class Customer_Email_Addresses extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// customer_id
array(
'name' => 'customer_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'cache_key' => true
),
// type
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => 'secondary',
'sortable' => true,
'transition' => true
),
// status
array(
'name' => 'status',
'type' => 'varchar',
'length' => '20',
'default' => 'active',
'sortable' => true,
'transition' => true
),
// email
array(
'name' => 'email',
'type' => 'varchar',
'length' => '100',
'default' => '',
'cache_key' => true,
'searchable' => true,
'sortable' => true
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,128 @@
<?php
/**
* Customer Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Discounts Schema Class.
*
* @since 3.0
*/
class Customers extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// user_id
array(
'name' => 'user_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'cache_key' => true
),
// email
array(
'name' => 'email',
'type' => 'varchar',
'length' => '100',
'cache_key' => true,
'searchable' => true,
'sortable' => true
),
// name
array(
'name' => 'name',
'type' => 'varchar',
'length' => '255',
'searchable' => true,
'sortable' => true
),
// status
array(
'name' => 'status',
'type' => 'varchar',
'length' => '20',
'default' => 'active',
'sortable' => true,
'transition' => true
),
// purchase_value
array(
'name' => 'purchase_value',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true
),
// purchase_count
array(
'name' => 'purchase_count',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,148 @@
<?php
/**
* API Request Logs Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* API Request Logs Schema Class.
*
* @since 3.0
*/
class Logs_Api_Requests extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// user_id
array(
'name' => 'user_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// api_key
array(
'name' => 'api_key',
'type' => 'varchar',
'length' => '32',
'default' => 'public',
'searchable' => true,
'sortable' => true
),
// token
array(
'name' => 'token',
'type' => 'varchar',
'length' => '32',
'default' => '',
'searchable' => true,
'sortable' => true
),
// version
array(
'name' => 'version',
'type' => 'varchar',
'length' => '32',
'default' => '',
'sortable' => true
),
// request
array(
'name' => 'request',
'type' => 'longtext',
'default' => '',
'searchable' => true,
'in' => false,
'not_in' => false
),
// error
array(
'name' => 'error',
'type' => 'longtext',
'default' => '',
'searchable' => true,
'in' => false,
'not_in' => false
),
// ip
array(
'name' => 'ip',
'type' => 'varchar',
'length' => '60',
'default' => '',
'searchable' => true,
'sortable' => true
),
// time
array(
'name' => 'time',
'type' => 'varchar',
'length' => '60',
'default' => '',
'sortable' => true
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,139 @@
<?php
/**
* File Download Logs Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* File Download Logs Schema Class.
*
* @since 3.0
*/
class Logs_File_Downloads extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// product_id
array(
'name' => 'product_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// file_id
array(
'name' => 'file_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// order_id
array(
'name' => 'order_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// price_id
array(
'name' => 'price_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0'
),
// customer_id
array(
'name' => 'customer_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// ip
array(
'name' => 'ip',
'type' => 'varchar',
'length' => '60',
'default' => '',
'sortable' => true,
'searchable' => true
),
// user_agent
array(
'name' => 'user_agent',
'type' => 'varchar',
'length' => '200',
'default' => '',
'sortable' => true,
'searchable' => true,
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,134 @@
<?php
/**
* Logs Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Logs Schema Class.
*
* @since 3.0
*/
class Logs extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// object_id
array(
'name' => 'object_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true,
'cache_key' => true,
),
// object_type
array(
'name' => 'object_type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true,
'cache_key' => true,
'allow_null' => true
),
// user_id
array(
'name' => 'user_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true,
'cache_key' => true,
),
// type
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true
),
// title
array(
'name' => 'title',
'type' => 'varchar',
'length' => '200',
'default' => '',
'searchable' => true,
'sortable' => true,
'in' => false,
'not_in' => false
),
// content
array(
'name' => 'content',
'type' => 'longtext',
'default' => '',
'searchable' => true,
'in' => false,
'not_in' => false
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,109 @@
<?php
/**
* Notes Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Notes Schema Class.
*
* @since 3.0
*/
class Notes extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// object_id
array(
'name' => 'object_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// object_type
array(
'name' => 'object_type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true
),
// user_id
array(
'name' => 'user_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// content
array(
'name' => 'content',
'type' => 'longtext',
'default' => '',
'searchable' => true,
'in' => false,
'not_in' => false
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,148 @@
<?php
/**
* Order Addresses Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Order Addresses Schema Class.
*
* @since 3.0
*/
class Order_Addresses extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// order_id
array(
'name' => 'order_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0'
),
// type.
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => 'billing',
'sortable' => true,
'transition' => true,
),
// name
array(
'name' => 'name',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// address
array(
'name' => 'address',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// address2
array(
'name' => 'address2',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// city
array(
'name' => 'city',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// region
array(
'name' => 'region',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// postal_code
array(
'name' => 'postal_code',
'type' => 'varchar',
'length' => '32',
'default' => '',
'searchable' => true,
'sortable' => true
),
// country
array(
'name' => 'country',
'type' => 'mediumtext',
'searchable' => true,
'sortable' => true
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,178 @@
<?php
/**
* Order Adjustments Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Order Adjustments Schema Class.
*
* @since 3.0
*/
class Order_Adjustments extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// parent
array(
'name' => 'parent',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// object_id
array(
'name' => 'object_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// object_type
array(
'name' => 'object_type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true
),
// type_id
array(
'name' => 'type_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => null,
'sortable' => true,
'allow_null' => true,
),
// type
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true,
'transition' => true
),
// type key
array(
'name' => 'type_key',
'type' => 'varchar',
'length' => '255',
'default' => null,
'allow_null' => true,
'sortable' => true,
),
// description
array(
'name' => 'description',
'type' => 'varchar',
'length' => '100',
'default' => '',
'searchable' => true,
'sortable' => true
),
// subtotal
array(
'name' => 'subtotal',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// tax
array(
'name' => 'tax',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// total
array(
'name' => 'total',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// rate
array(
'name' => 'rate',
'type' => 'decimal',
'length' => '10,5',
'default' => '1.00000',
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,219 @@
<?php
/**
* Order Items Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Order Items Schema Class.
*
* @since 3.0
*/
class Order_Items extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// parent
array(
'name' => 'parent',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// order_id
array(
'name' => 'order_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// product_id
array(
'name' => 'product_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// product_name
array(
'name' => 'product_name',
'type' => 'text',
'default' => '',
'searchable' => true,
'in' => false,
'not_in' => false
),
// price_id
array(
'name' => 'price_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => null,
'sortable' => true,
'allow_null' => true,
),
// cart_index
array(
'name' => 'cart_index',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// type
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => 'download',
'sortable' => true,
'transition' => true
),
// status
array(
'name' => 'status',
'type' => 'varchar',
'length' => '20',
'default' => 'pending',
'sortable' => true,
'transition' => true
),
// quantity
array(
'name' => 'quantity',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// amount
array(
'name' => 'amount',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// subtotal
array(
'name' => 'subtotal',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// discount
array(
'name' => 'discount',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// tax
array(
'name' => 'tax',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// total
array(
'name' => 'total',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// rate
array(
'name' => 'rate',
'type' => 'decimal',
'length' => '10,5',
'default' => '1.00000',
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,134 @@
<?php
/**
* Order Transactions Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Order Transactions Schema Class.
*
* @since 3.0
*/
class Order_Transactions extends Schema {
/**
* Array of database column objects
*
* @since 3.0
* @access public
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// object_id
array(
'name' => 'object_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// object_type
array(
'name' => 'object_type',
'type' => 'varchar',
'length' => '20',
'default' => '',
'sortable' => true
),
// transaction_id
array(
'name' => 'transaction_id',
'type' => 'varchar',
'length' => '256',
'cache_key' => true,
'searchable' => true,
'sortable' => true
),
// gateway
array(
'name' => 'gateway',
'type' => 'varchar',
'length' => '20',
'sortable' => true,
),
// status
array(
'name' => 'status',
'type' => 'varchar',
'length' => '20',
'default' => 'pending',
'sortable' => true,
'transition' => true
),
// total
array(
'name' => 'total',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true
),
// rate
array(
'name' => 'rate',
'type' => 'decimal',
'length' => '10,5',
'default' => '1.00000',
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

View File

@ -0,0 +1,255 @@
<?php
/**
* Orders Schema Class.
*
* @package EDD
* @subpackage Database\Schemas
* @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\Schemas;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Schema;
/**
* Orders Schema Class.
*
* @since 3.0
*/
class Orders extends Schema {
/**
* Array of database column objects.
*
* @since 3.0
* @var array
*/
public $columns = array(
// id
array(
'name' => 'id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'extra' => 'auto_increment',
'primary' => true,
'sortable' => true
),
// parent
array(
'name' => 'parent',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// order_number
array(
'name' => 'order_number',
'type' => 'varchar',
'length' => '255',
'searchable' => true,
'sortable' => true
),
// status
array(
'name' => 'status',
'type' => 'varchar',
'length' => '20',
'default' => 'pending',
'sortable' => true,
'transition' => true
),
// type
array(
'name' => 'type',
'type' => 'varchar',
'length' => '20',
'default' => 'sale',
'sortable' => true
),
// user_id
array(
'name' => 'user_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// customer_id
array(
'name' => 'customer_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => '0',
'sortable' => true
),
// email
array(
'name' => 'email',
'type' => 'varchar',
'length' => '100',
'searchable' => true,
'sortable' => true
),
// ip
array(
'name' => 'ip',
'type' => 'varchar',
'length' => '60',
'sortable' => true
),
// gateway
array(
'name' => 'gateway',
'type' => 'varchar',
'length' => '100',
'sortable' => true,
'default' => 'manual',
),
// mode
array(
'name' => 'mode',
'type' => 'varchar',
'length' => '20'
),
// currency
array(
'name' => 'currency',
'type' => 'varchar',
'length' => '20',
'validate' => 'strtoupper',
),
// payment_key
array(
'name' => 'payment_key',
'type' => 'varchar',
'length' => '64',
'searchable' => true,
),
// tax_rate_id
array(
'name' => 'tax_rate_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'default' => null,
'allow_null' => true,
'sortable' => true
),
// subtotal
array(
'name' => 'subtotal',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// discount
array(
'name' => 'discount',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// tax
array(
'name' => 'tax',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// total
array(
'name' => 'total',
'type' => 'decimal',
'length' => '18,9',
'default' => '0',
'sortable' => true,
'validate' => 'edd_sanitize_amount'
),
// rate
array(
'name' => 'rate',
'type' => 'decimal',
'length' => '10,5',
'default' => '1.00000',
),
// date_created
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'created' => true,
'date_query' => true,
'sortable' => true
),
// date_modified
array(
'name' => 'date_modified',
'type' => 'datetime',
'default' => '', // Defaults to current time in query class
'modified' => true,
'date_query' => true,
'sortable' => true
),
// date_completed
array(
'name' => 'date_completed',
'type' => 'datetime',
'default' => null,
'allow_null' => true,
'date_query' => true,
'sortable' => true
),
// date_refundable
array(
'name' => 'date_refundable',
'type' => 'datetime',
'default' => null,
'allow_null' => true,
'date_query' => true,
'sortable' => true
),
// uuid
array(
'uuid' => true,
)
);
}

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;
}
}