Initial Commit
This commit is contained in:
84
inc/database/broadcasts/class-broadcast-query.php
Normal file
84
inc/database/broadcasts/class-broadcast-query.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying broadcasts.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Posts
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Broadcasts;
|
||||
|
||||
use WP_Ultimo\Database\Posts\Post_Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying broadcasts.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Broadcast_Query extends Post_Query {
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'post';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'posts';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Broadcast';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'broadcasts';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Modifies the query call to add our types.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $query Query parameters being passed.
|
||||
* @return array
|
||||
*/
|
||||
public function query($query = array()) {
|
||||
|
||||
$query['type__in'] = array('broadcast_email', 'broadcast_notice');
|
||||
|
||||
return parent::query($query);
|
||||
|
||||
} // end query;
|
||||
|
||||
} // end class Broadcast_Query;
|
113
inc/database/checkout-forms/class-checkout-form-query.php
Normal file
113
inc/database/checkout-forms/class-checkout-form-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying forms.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Checkout_Forms
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Checkout_Forms;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying forms.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Checkout_Form_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'forms';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'f';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Checkout_Forms\\Checkout_Forms_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'form';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'forms';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Checkout_Form';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'forms';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Checkout_Form_Query;
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying forms' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Checkout_Forms
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Checkout_Forms;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_formmeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Checkout_Forms_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'formmeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Posts constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_form_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) DEFAULT NULL,
|
||||
meta_value longtext DEFAULT NULL,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY wu_form_id (wu_form_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Checkout_Forms_Meta_Table;
|
114
inc/database/checkout-forms/class-checkout-forms-schema.php
Normal file
114
inc/database/checkout-forms/class-checkout-forms-schema.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Checkout_Form schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Checkout_Forms
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Checkout_Forms;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Checkout_Forms Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Checkout_Forms_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'name',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'slug',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'active',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'settings',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
'transition' => true,
|
||||
'allow_null' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'custom_css',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'allowed_countries',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Checkout_Forms_Schema;
|
121
inc/database/checkout-forms/class-checkout-forms-table.php
Normal file
121
inc/database/checkout-forms/class-checkout-forms-table.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying events.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Event
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Checkout_Forms;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_events" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Checkout_Forms_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'forms';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Event constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL auto_increment,
|
||||
name tinytext NOT NULL DEFAULT '',
|
||||
slug varchar(255),
|
||||
active tinyint(4) default 1,
|
||||
settings longtext DEFAULT NULL,
|
||||
custom_css longtext DEFAULT NULL,
|
||||
allowed_countries text DEFAULT NULL,
|
||||
date_created datetime DEFAULT NULL,
|
||||
date_modified datetime DEFAULT NULL,
|
||||
PRIMARY KEY (id)";
|
||||
|
||||
} // end set_schema;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Checkout_Forms_Table;
|
115
inc/database/customers/class-customer-query.php
Normal file
115
inc/database/customers/class-customer-query.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying customers.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Customers
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Customers;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying webhooks.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Customer_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'customers';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'c';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Customers\\Customers_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'customer';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'customers';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Customer';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'customers';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
// $query['type'] = 'customer';
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Customer_Query;
|
82
inc/database/customers/class-customers-meta-table.php
Normal file
82
inc/database/customers/class-customers-meta-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying customers' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Customers
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Customers;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_customermeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Customers_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'customermeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Customers constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_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 wu_customer_id (wu_customer_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Customers_Meta_Table;
|
133
inc/database/customers/class-customers-schema.php
Normal file
133
inc/database/customers/class-customers-schema.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Customer schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Customers
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Customers;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Customers Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Customers_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.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,
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
// user_id
|
||||
array(
|
||||
'name' => 'user_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'type',
|
||||
'type' => 'varchar',
|
||||
'default' => 'customer',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
// date_registered
|
||||
array(
|
||||
'name' => 'date_registered',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// email_verification
|
||||
array(
|
||||
'name' => 'email_verification',
|
||||
'type' => 'enum(\'verified\', \'pending\', \'none\')',
|
||||
'default' => 'none',
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
// last_login
|
||||
array(
|
||||
'name' => 'last_login',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// has_trialed
|
||||
array(
|
||||
'name' => 'has_trialed',
|
||||
'type' => 'smallint',
|
||||
'length' => '',
|
||||
'unsigned' => true,
|
||||
'default' => null,
|
||||
'transition' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// vip
|
||||
array(
|
||||
'name' => 'vip',
|
||||
'type' => 'smallint',
|
||||
'length' => '',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
// ips
|
||||
array(
|
||||
'name' => 'ips',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// Added on 2.0 beta 7
|
||||
array(
|
||||
'name' => 'signup_form',
|
||||
'type' => 'varchar',
|
||||
'default' => 'by-admin',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Customers_Schema;
|
189
inc/database/customers/class-customers-table.php
Normal file
189
inc/database/customers/class-customers-table.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying domain mappings.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Customer
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Customers;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_customers" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Customers_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'customers';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20210508' => 20_210_508,
|
||||
'2.0.1-revision.20210607' => 20_210_607,
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Customer constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.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',
|
||||
type varchar(20) NOT NULL DEFAULT 'customer',
|
||||
email_verification enum('verified', 'pending', 'none') DEFAULT 'none',
|
||||
date_modified datetime NULL,
|
||||
date_registered datetime NULL,
|
||||
last_login datetime NULL,
|
||||
has_trialed smallint unsigned DEFAULT NULL,
|
||||
vip smallint unsigned DEFAULT '0',
|
||||
ips longtext,
|
||||
signup_form varchar(40) DEFAULT 'by-admin',
|
||||
PRIMARY KEY (id),
|
||||
KEY user_id (user_id)";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
/**
|
||||
* Adds the signup_form column.
|
||||
*
|
||||
* This does not work on older versions of MySQl, so we needed
|
||||
* the other migration below.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210508() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('signup_form');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `signup_form` varchar(40) default 'by-admin' AFTER `ips`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210508;
|
||||
|
||||
/**
|
||||
* Adds the signup_form column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210607() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('signup_form');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query_set = "SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';";
|
||||
|
||||
$result_set = $this->get_db()->query($query_set);
|
||||
|
||||
if ($this->is_success($result_set) === false) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `signup_form` varchar(40) default 'by-admin' AFTER `ips`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210607;
|
||||
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_modified',
|
||||
'date_registered',
|
||||
'last_login',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Customers_Table;
|
113
inc/database/discount-codes/class-discount-code-query.php
Normal file
113
inc/database/discount-codes/class-discount-code-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying discount codes.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Discount_Codes
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Discount_Codes;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying discount codes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Discount_Code_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'discount_codes';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'dc';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Discount_Codes\\Discount_Codes_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'discount_code';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'discount_codes';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Discount_Code';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'discount_codes';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Discount_Code_Query;
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying discount codes' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Discount_Code
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Discount_Codes;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_discount_codemeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Discount_Codes_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'discount_codemeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Products constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_discount_code_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) DEFAULT NULL,
|
||||
meta_value longtext DEFAULT NULL,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY wu_discount_code_id (wu_discount_code_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Discount_Codes_Meta_Table;
|
176
inc/database/discount-codes/class-discount-codes-schema.php
Normal file
176
inc/database/discount-codes/class-discount-codes-schema.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* Discount Code schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Discount_Codes
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Discount_Codes;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Discount Codes Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Discount_Codes_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'name',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'code',
|
||||
'type' => 'varchar',
|
||||
'length' => '20',
|
||||
'sortable' => true,
|
||||
'searchable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'description',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'uses',
|
||||
'type' => 'int',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'max_uses',
|
||||
'type' => 'int',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
'allow_null' => true,
|
||||
'default' => 0,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'apply_to_renewals',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'type',
|
||||
'type' => 'enum(\'percentage\', \'absolute\')',
|
||||
'default' => 'percentage',
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'value',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'setup_fee_type',
|
||||
'type' => 'enum(\'percentage\', \'absolute\')',
|
||||
'default' => 'percentage',
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'setup_fee_value',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'active',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_start',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_expiration',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Discount_Codes_Schema;
|
128
inc/database/discount-codes/class-discount-codes-table.php
Normal file
128
inc/database/discount-codes/class-discount-codes-table.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying discount_codes.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Discount_Code
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Discount_Codes;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_discount_codes" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Discount_Codes_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'discount_codes';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Discount_Code constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL auto_increment,
|
||||
name tinytext NOT NULL DEFAULT '',
|
||||
code varchar(20) NOT NULL default '',
|
||||
description longtext NULL default '',
|
||||
uses int default '0',
|
||||
max_uses int,
|
||||
apply_to_renewals tinyint(4) default 0,
|
||||
type enum('percentage', 'absolute') NOT NULL default 'percentage',
|
||||
value decimal(13,4) default 0,
|
||||
setup_fee_type enum('percentage', 'absolute') NOT NULL default 'percentage',
|
||||
setup_fee_value decimal(13,4) default 0,
|
||||
active tinyint(4) default 1,
|
||||
date_start datetime NULL,
|
||||
date_expiration datetime NULL,
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
PRIMARY KEY (id)";
|
||||
|
||||
} // end set_schema;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Discount_Codes_Table;
|
113
inc/database/domains/class-domain-query.php
Normal file
113
inc/database/domains/class-domain-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying domain mappings.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Domains
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Domains;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying domain mappings.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Domain_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'domain_mappings';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'd';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Domains\\Domains_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'domain';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'domains';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Domain';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'domains';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Domain_Query;
|
71
inc/database/domains/class-domain-stage.php
Normal file
71
inc/database/domains/class-domain-stage.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Domain Types enum.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage WP_Ultimo\Database\Domains
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Domains;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Database\Engine\Enum;
|
||||
|
||||
/**
|
||||
* Domain Stage.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Domain_Stage extends Enum {
|
||||
|
||||
/**
|
||||
* Default product type.
|
||||
*/
|
||||
const __default = 'checking-dns'; // phpcs:ignore
|
||||
|
||||
const FAILED = 'failed';
|
||||
const CHECKING_DNS = 'checking-dns';
|
||||
const CHECKING_SSL = 'checking-ssl-cert';
|
||||
const DONE_WITHOUT_SSL = 'done-without-ssl';
|
||||
const DONE = 'done';
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function classes() {
|
||||
|
||||
return array(
|
||||
static::FAILED => 'wu-bg-red-200 wu-text-red-700',
|
||||
static::CHECKING_DNS => 'wu-bg-blue-200 wu-text-blue-700',
|
||||
static::CHECKING_SSL => 'wu-bg-yellow-200 wu-text-yellow-700',
|
||||
static::DONE => 'wu-bg-green-200 wu-text-green-700',
|
||||
static::DONE_WITHOUT_SSL => 'wu-bg-gray-800 wu-text-white',
|
||||
);
|
||||
|
||||
} // end classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function labels() {
|
||||
|
||||
return array(
|
||||
static::FAILED => __('DNS Failed', 'wp-ultimo'),
|
||||
static::CHECKING_DNS => __('Checking DNS', 'wp-ultimo'),
|
||||
static::CHECKING_SSL => __('Checking SSL', 'wp-ultimo'),
|
||||
static::DONE => __('Ready', 'wp-ultimo'),
|
||||
static::DONE_WITHOUT_SSL => __('Ready (without SSL)', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
} // end labels;
|
||||
|
||||
} // end class Domain_Stage;
|
121
inc/database/domains/class-domains-schema.php
Normal file
121
inc/database/domains/class-domains-schema.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Domain schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Domains
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Domains;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Domains Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Domains_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'blog_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'aliases' => array('site_id', 'site'),
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'domain',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'active',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'primary_domain',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'secure',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'stage',
|
||||
'type' => 'enum(\'checking-dns\', \'checking-ssl-cert\', \'done-without-ssl\', \'done\', \'failed\')',
|
||||
'default' => 'checking-dns',
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Domains_Schema;
|
123
inc/database/domains/class-domains-table.php
Normal file
123
inc/database/domains/class-domains-table.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying domain mappings.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Domains
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Domains;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_domain_mapping" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Domains_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'domain_mappings';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Domains constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL auto_increment,
|
||||
blog_id bigint(20) NOT NULL,
|
||||
domain varchar(191) NOT NULL,
|
||||
active tinyint(4) default 1,
|
||||
primary_domain tinyint(4) default 0,
|
||||
secure tinyint(4) default 0,
|
||||
stage enum('checking-dns', 'checking-ssl-cert', 'done', 'failed', 'done-without-ssl') DEFAULT 'checking-dns',
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY blog_id (blog_id,domain,active),
|
||||
KEY domain (domain)";
|
||||
|
||||
} // end set_schema;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Domains_Table;
|
84
inc/database/emails/class-email-query.php
Normal file
84
inc/database/emails/class-email-query.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying emails.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Posts
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Emails;
|
||||
|
||||
use WP_Ultimo\Database\Posts\Post_Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying emails.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Email_Query extends Post_Query {
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'post';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'posts';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Email';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'emails';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Modifies the query call to add our types.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $query Query parameters being passed.
|
||||
* @return array
|
||||
*/
|
||||
public function query($query = array()) {
|
||||
|
||||
$query['type__in'] = array('system_email');
|
||||
|
||||
return parent::query($query);
|
||||
|
||||
} // end query;
|
||||
|
||||
} // end class Email_Query;
|
24
inc/database/engine/class-base.php
Normal file
24
inc/database/engine/class-base.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* BerlinDB Base Class Wrapper
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 extends \WP_Ultimo\Dependencies\BerlinDB\Database\Base {
|
||||
|
||||
protected $prefix = 'wu';
|
||||
|
||||
} // end class Base;
|
24
inc/database/engine/class-column.php
Normal file
24
inc/database/engine/class-column.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Column Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 Column extends \WP_Ultimo\Dependencies\BerlinDB\Database\Column {
|
||||
|
||||
protected $prefix = 'wu';
|
||||
|
||||
} // end class Column;
|
20
inc/database/engine/class-compare.php
Normal file
20
inc/database/engine/class-compare.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Compare Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 Compare extends \WP_Ultimo\Dependencies\BerlinDB\Database\Compare {} // end class Compare;
|
20
inc/database/engine/class-date.php
Normal file
20
inc/database/engine/class-date.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Date Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 Date extends \WP_Ultimo\Dependencies\BerlinDB\Database\Date {} // end class Date;
|
281
inc/database/engine/class-enum.php
Normal file
281
inc/database/engine/class-enum.php
Normal file
@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Ultimo ENUM base class.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage WP_Ultimo\Database\Engine
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* WP Ultimo ENUM base class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
abstract class Enum
|
||||
{
|
||||
/**
|
||||
* The default value.
|
||||
*/
|
||||
const __default = false;
|
||||
// phpcs:ignore
|
||||
/**
|
||||
* The options available.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
static $options = array();
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $value = '';
|
||||
/**
|
||||
* Constructor method. Takes the value you want to set.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $value The value to be set.
|
||||
*/
|
||||
public function __construct($value = '')
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
// end __construct;
|
||||
// Needs to be Implemented
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function classes();
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function labels();
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function icon_classes() {
|
||||
|
||||
return array();
|
||||
|
||||
}
|
||||
// end icon_classes;
|
||||
/**
|
||||
* Returns the options available as constants.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public static function get_options() {
|
||||
|
||||
$hook = static::get_hook_name();
|
||||
|
||||
if (!isset(static::$options[$hook])) {
|
||||
|
||||
$reflector = new \ReflectionClass(static::class);
|
||||
|
||||
static::$options[$hook] = apply_filters("wu_available_{$hook}_options", $reflector->getConstants());
|
||||
|
||||
} // end if;
|
||||
|
||||
return static::$options[$hook];
|
||||
|
||||
}
|
||||
// end get_options;
|
||||
public static function get_allowed_list($string = false) {
|
||||
|
||||
$options = array_unique(self::get_options());
|
||||
|
||||
return $string ? implode(',', $options) : $options;
|
||||
|
||||
}
|
||||
// end get_allowed_list;
|
||||
/**
|
||||
* Returns the value loaded here.
|
||||
*
|
||||
* This runs through is_valid and returns the
|
||||
* default value if a invalid value is passed on.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_value() {
|
||||
|
||||
if ($this->is_valid($this->value)) {
|
||||
|
||||
return $this->value;
|
||||
|
||||
} // end if;
|
||||
|
||||
return static::__default;
|
||||
|
||||
}
|
||||
// end get_value;
|
||||
/**
|
||||
* Check for the the validity of the value passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $value The string.
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_valid($value) {
|
||||
|
||||
$options = static::get_options();
|
||||
|
||||
return in_array($value, $options, true);
|
||||
|
||||
}
|
||||
// end is_valid;
|
||||
/**
|
||||
* Returns the label of a given value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_label() {
|
||||
|
||||
$hook = static::get_hook_name();
|
||||
|
||||
$labels = apply_filters("wu_available_{$hook}_labels", $this->labels());
|
||||
|
||||
return $this->exists_or_default($labels, $this->get_value());
|
||||
|
||||
}
|
||||
// end get_label;
|
||||
/**
|
||||
* Returns the classes of a given value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_classes() {
|
||||
|
||||
$hook = static::get_hook_name();
|
||||
|
||||
$classes = apply_filters("wu_available_{$hook}_classes", $this->classes());
|
||||
|
||||
return $this->exists_or_default($classes, $this->get_value());
|
||||
|
||||
}
|
||||
// end get_classes;
|
||||
/**
|
||||
* Returns the classes of a given value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_icon_classes() {
|
||||
|
||||
$hook = static::get_hook_name();
|
||||
|
||||
$classes = apply_filters("wu_available_{$hook}_icon_classes", $this->icon_classes());
|
||||
|
||||
return $this->exists_or_default($classes, $this->get_value());
|
||||
|
||||
}
|
||||
// end get_icon_classes;
|
||||
/**
|
||||
* Returns an array of options.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public static function to_array() {
|
||||
|
||||
static $instance;
|
||||
|
||||
if ($instance === null) {
|
||||
|
||||
$instance = new static;
|
||||
|
||||
} // end if;
|
||||
|
||||
$hook = $instance::get_hook_name();
|
||||
|
||||
$labels = apply_filters("wu_{$hook}_to_array", $instance->labels());
|
||||
|
||||
return $labels;
|
||||
|
||||
}
|
||||
// end to_array;
|
||||
/**
|
||||
* Get the hook name for this class, so we can add filters.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public static function get_hook_name() {
|
||||
|
||||
$class_name = (new \ReflectionClass(static::class))->getShortName();
|
||||
|
||||
return strtolower($class_name);
|
||||
|
||||
}
|
||||
// end get_hook_name;
|
||||
/**
|
||||
* Checks if a key exists on an array, otherwise returns a default value.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $array The array to check.
|
||||
* @param string $key The key to check.
|
||||
* @param string $default The default value.
|
||||
* @return string
|
||||
*/
|
||||
public function exists_or_default($array, $key, $default = '') {
|
||||
|
||||
if (empty($default)) {
|
||||
|
||||
$default = isset($array[static::__default]) ? $array[static::__default] : '';
|
||||
|
||||
} // end if;
|
||||
|
||||
return isset($array[$key]) ? $array[$key] : $default;
|
||||
|
||||
}
|
||||
// end exists_or_default;
|
||||
/**
|
||||
* Converts this to string.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string {
|
||||
|
||||
return $this->get_value();
|
||||
|
||||
}
|
||||
// end __toString;
|
||||
/**
|
||||
* Magic method to allow for constants to be called.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $name The name of the constants.
|
||||
* @param array $arguments The list of arguments. Not really needed here.
|
||||
* @return string
|
||||
*/
|
||||
public static function __callStatic($name, $arguments) {
|
||||
|
||||
$class_name = static::class;
|
||||
|
||||
return constant("$class_name::$name");
|
||||
|
||||
}
|
||||
// end __callStatic;
|
||||
} // end class Enum;
|
20
inc/database/engine/class-meta.php
Normal file
20
inc/database/engine/class-meta.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Meta Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 Meta extends \WP_Ultimo\Dependencies\BerlinDB\Database\Meta {} // end class Meta;
|
100
inc/database/engine/class-query.php
Normal file
100
inc/database/engine/class-query.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Table Query Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 Query extends \WP_Ultimo\Dependencies\BerlinDB\Database\Query {
|
||||
|
||||
/**
|
||||
* The prefix for the custom table.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = 'wu';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = false;
|
||||
|
||||
/**
|
||||
* Keep track of the global cache groups we've added.
|
||||
* This is to prevent adding the same group multiple times.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var array
|
||||
*/
|
||||
protected static $added_globals = array();
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural;
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'sites';
|
||||
|
||||
/**
|
||||
* The class constructor
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @param string|array $query Optional. An array or string of Query parameters.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
$cache_group = $this->apply_prefix($this->cache_group, '-');
|
||||
|
||||
if ($this->global_cache && !in_array($cache_group, self::$added_globals, true)) {
|
||||
|
||||
wp_cache_add_global_groups(array($cache_group));
|
||||
|
||||
self::$added_globals[] = $cache_group;
|
||||
|
||||
} // end if;
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Get the plural name.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_plural_name() {
|
||||
|
||||
return $this->item_name_plural;
|
||||
|
||||
} // end get_plural_name;
|
||||
|
||||
} // end class Query;
|
24
inc/database/engine/class-row.php
Normal file
24
inc/database/engine/class-row.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Row Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 Row extends \WP_Ultimo\Dependencies\BerlinDB\Database\Row {
|
||||
|
||||
protected $prefix = 'wu';
|
||||
|
||||
} // end class Row;
|
24
inc/database/engine/class-schema.php
Normal file
24
inc/database/engine/class-schema.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Table Schema Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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 Schema extends \WP_Ultimo\Dependencies\BerlinDB\Database\Schema {
|
||||
|
||||
protected $prefix = 'wu';
|
||||
|
||||
} // end class Schema;
|
84
inc/database/engine/class-table.php
Normal file
84
inc/database/engine/class-table.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Base Custom Database Table Class.
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Engine;
|
||||
|
||||
// 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
|
||||
*/
|
||||
abstract class Table extends \WP_Ultimo\Dependencies\BerlinDB\Database\Table {
|
||||
|
||||
/**
|
||||
* Table prefix.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = 'wu';
|
||||
|
||||
/**
|
||||
* Caches the SHOW TABLES result.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var bool
|
||||
*/
|
||||
protected $_exists;
|
||||
|
||||
/**
|
||||
* Overrides the is_upgradeable method.
|
||||
*
|
||||
* We need to do this because we are using the table object
|
||||
* early in the lifecycle, which means that upgrade.php is not
|
||||
* available.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_upgradeable() {
|
||||
|
||||
if (!is_main_network()) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!is_main_site()) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
return true;
|
||||
|
||||
} // end is_upgradeable;
|
||||
|
||||
/**
|
||||
* Adds a caching layer to the parent exists method.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function exists() {
|
||||
|
||||
if ($this->_exists === null) {
|
||||
|
||||
$this->_exists = parent::exists();
|
||||
|
||||
} // end if;
|
||||
|
||||
return $this->_exists;
|
||||
|
||||
} // end exists;
|
||||
|
||||
} // end class Table;
|
113
inc/database/events/class-event-query.php
Normal file
113
inc/database/events/class-event-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying events.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Events
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Events;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying events.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Event_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'events';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'e';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Events\\Events_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'event';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'events';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Event';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'events';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Event_Query;
|
108
inc/database/events/class-events-schema.php
Normal file
108
inc/database/events/class-events-schema.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Event schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Events
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Events;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Events Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Events_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'severity',
|
||||
'type' => 'tinyint',
|
||||
'length' => '1',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'initiator',
|
||||
'type' => 'enum(\'system\', \'manual\')',
|
||||
'default' => 'none',
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'author_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'object_type',
|
||||
'type' => 'varchar',
|
||||
'length' => 20,
|
||||
'default' => 'network',
|
||||
'sortable' => true,
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'object_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'slug',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'payload',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Events_Schema;
|
123
inc/database/events/class-events-table.php
Normal file
123
inc/database/events/class-events-table.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying events.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Event
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Events;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_events" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Events_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'events';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Event constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL auto_increment,
|
||||
severity tinyint(4),
|
||||
initiator enum('system', 'manual'),
|
||||
author_id bigint(20) NOT NULL default '0',
|
||||
object_id bigint(20) NOT NULL default '0',
|
||||
object_type varchar(20) DEFAULT 'network',
|
||||
slug varchar(255),
|
||||
payload longtext,
|
||||
date_created datetime NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY severity (severity),
|
||||
KEY author_id (author_id),
|
||||
KEY initiator (initiator)";
|
||||
|
||||
} // end set_schema;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Events_Table;
|
113
inc/database/memberships/class-membership-query.php
Normal file
113
inc/database/memberships/class-membership-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying memberships.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Memberships
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Memberships;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying memberships.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Membership_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'memberships';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'm';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Memberships\\Memberships_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'membership';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'memberships';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Membership';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'memberships';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Membership_Query;
|
74
inc/database/memberships/class-membership-status.php
Normal file
74
inc/database/memberships/class-membership-status.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Membership Status enum.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage WP_Ultimo\Database\Memberships
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Memberships;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Database\Engine\Enum;
|
||||
|
||||
/**
|
||||
* Membership Status.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Membership_Status extends Enum {
|
||||
|
||||
/**
|
||||
* Default product type.
|
||||
*/
|
||||
const __default = 'pending'; // phpcs:ignore
|
||||
|
||||
const PENDING = 'pending';
|
||||
const ACTIVE = 'active';
|
||||
const TRIALING = 'trialing';
|
||||
const EXPIRED = 'expired';
|
||||
const ON_HOLD = 'on-hold';
|
||||
const CANCELLED = 'cancelled';
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function classes() {
|
||||
|
||||
return array(
|
||||
static::PENDING => 'wu-bg-gray-200 wu-text-gray-700',
|
||||
static::ACTIVE => 'wu-bg-green-200 wu-text-green-700',
|
||||
static::TRIALING => 'wu-bg-orange-200 wu-text-orange-700',
|
||||
static::ON_HOLD => 'wu-bg-blue-200 wu-text-blue-700',
|
||||
static::EXPIRED => 'wu-bg-yellow-200 wu-text-yellow-700',
|
||||
static::CANCELLED => 'wu-bg-red-200 wu-text-red-700',
|
||||
);
|
||||
|
||||
} // end classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function labels() {
|
||||
|
||||
return array(
|
||||
static::PENDING => __('Pending', 'wp-ultimo'),
|
||||
static::ACTIVE => __('Active', 'wp-ultimo'),
|
||||
static::TRIALING => __('Trialing', 'wp-ultimo'),
|
||||
static::ON_HOLD => __('On Hold', 'wp-ultimo'),
|
||||
static::EXPIRED => __('Expired', 'wp-ultimo'),
|
||||
static::CANCELLED => __('Cancelled', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
} // end labels;
|
||||
|
||||
} // end class Membership_Status;
|
82
inc/database/memberships/class-memberships-meta-table.php
Normal file
82
inc/database/memberships/class-memberships-meta-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying memberships' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Memberships
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Memberships;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_membershipmeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Memberships_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'membershipmeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Memberships constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_membership_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) DEFAULT NULL,
|
||||
meta_value longtext DEFAULT NULL,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY wu_membership_id (wu_membership_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Memberships_Meta_Table;
|
334
inc/database/memberships/class-memberships-schema.php
Normal file
334
inc/database/memberships/class-memberships-schema.php
Normal file
@ -0,0 +1,334 @@
|
||||
<?php
|
||||
/**
|
||||
* Membership schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Memberships
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Memberships;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Memberships Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Memberships_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.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,
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
// customer_id
|
||||
array(
|
||||
'name' => 'customer_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
),
|
||||
|
||||
// user_id
|
||||
array(
|
||||
'name' => 'user_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'default' => null,
|
||||
'allow_null' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'migrated_from_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// object_id
|
||||
array(
|
||||
'name' => 'plan_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
// addons
|
||||
array(
|
||||
'name' => 'addon_products',
|
||||
'type' => 'longtext',
|
||||
),
|
||||
|
||||
// currency
|
||||
array(
|
||||
'name' => 'currency',
|
||||
'type' => 'varchar',
|
||||
'length' => '20',
|
||||
'default' => 'USD',
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'initial_amount',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'recurring',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'auto_renew',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'duration',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '0',
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'duration_unit',
|
||||
'type' => 'enum(\'day\', \'month\', \'week\', \'year\')',
|
||||
'default' => 'none',
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'amount',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
// date_created
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_activated
|
||||
array(
|
||||
'name' => 'date_activated',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_trial_end
|
||||
array(
|
||||
'name' => 'date_trial_end',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_renewed
|
||||
array(
|
||||
'name' => 'date_renewed',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_cancellation
|
||||
array(
|
||||
'name' => 'date_cancellation',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_expiration
|
||||
array(
|
||||
'name' => 'date_expiration',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_payment_plan_completed
|
||||
array(
|
||||
'name' => 'date_payment_plan_completed',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// auto_renew
|
||||
array(
|
||||
'name' => 'auto_renew',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '0',
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
// times_billed
|
||||
array(
|
||||
'name' => 'times_billed',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '0',
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
// billing_cycles
|
||||
array(
|
||||
'name' => 'billing_cycles',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '0',
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
// status
|
||||
array(
|
||||
'name' => 'status',
|
||||
'type' => 'varchar',
|
||||
'length' => '12',
|
||||
'default' => 'pending',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
// gateway_customer_id
|
||||
array(
|
||||
'name' => 'gateway_customer_id',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
// gateway_subscription_id
|
||||
array(
|
||||
'name' => 'gateway_subscription_id',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
// gateway
|
||||
array(
|
||||
'name' => 'gateway',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
// signup_method
|
||||
array(
|
||||
'name' => 'signup_method',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
),
|
||||
|
||||
// subscription_key
|
||||
array(
|
||||
'name' => 'subscription_key',
|
||||
'type' => 'varchar',
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
// upgraded_from
|
||||
array(
|
||||
'name' => 'upgraded_from',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'default' => ''
|
||||
),
|
||||
|
||||
// date_modified
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
// disabled
|
||||
array(
|
||||
'name' => 'disabled',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '',
|
||||
'pattern' => '%d'
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Memberships_Schema;
|
153
inc/database/memberships/class-memberships-table.php
Normal file
153
inc/database/memberships/class-memberships-table.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying memberships.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Memberships
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Memberships;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_membership" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Memberships_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'memberships';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Memberships constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema.
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.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',
|
||||
user_id bigint(20) unsigned DEFAULT NULL,
|
||||
migrated_from_id bigint(20) DEFAULT NULL,
|
||||
plan_id bigint(20) NOT NULL default '0',
|
||||
addon_products longtext,
|
||||
currency varchar(10) NOT NULL DEFAULT 'USD',
|
||||
initial_amount decimal(13,4) default 0,
|
||||
recurring smallint unsigned NOT NULL DEFAULT '0',
|
||||
auto_renew smallint unsigned NOT NULL DEFAULT '0',
|
||||
duration smallint default 0,
|
||||
duration_unit enum('day', 'week', 'month', 'year'),
|
||||
amount decimal(13,4) default 0,
|
||||
date_created datetime NULL,
|
||||
date_activated datetime NULL,
|
||||
date_trial_end datetime NULL,
|
||||
date_renewed datetime NULL,
|
||||
date_cancellation datetime NULL,
|
||||
date_expiration datetime NULL,
|
||||
date_payment_plan_completed datetime NULL,
|
||||
times_billed smallint unsigned NOT NULL DEFAULT '0',
|
||||
billing_cycles smallint unsigned NOT NULL DEFAULT '0',
|
||||
status varchar(12) NOT NULL DEFAULT 'pending',
|
||||
gateway_customer_id tinytext DEFAULT NULL,
|
||||
gateway_subscription_id tinytext DEFAULT NULL,
|
||||
gateway tinytext default '',
|
||||
signup_method tinytext default '',
|
||||
subscription_key varchar(32) default '',
|
||||
upgraded_from bigint(20) unsigned DEFAULT NULL,
|
||||
date_modified datetime NULL,
|
||||
disabled smallint unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY customer_id (customer_id),
|
||||
KEY plan_id (plan_id),
|
||||
KEY status (status),
|
||||
KEY disabled (disabled)";
|
||||
|
||||
} // end set_schema;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_activated',
|
||||
'date_trial_end',
|
||||
'date_renewed',
|
||||
'date_cancellation',
|
||||
'date_expiration',
|
||||
'date_payment_plan_completed',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Memberships_Table;
|
113
inc/database/payments/class-payment-query.php
Normal file
113
inc/database/payments/class-payment-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying payments.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying payments.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payment_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'payments';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'pay';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Payments\\Payments_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'payment';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'payments';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Payment';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'payments';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Payment_Query;
|
97
inc/database/payments/class-payment-status.php
Normal file
97
inc/database/payments/class-payment-status.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment Status enum.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage WP_Ultimo\Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Database\Engine\Enum;
|
||||
|
||||
/**
|
||||
* Payment Status.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payment_Status extends Enum {
|
||||
|
||||
/**
|
||||
* Default product type.
|
||||
*/
|
||||
const __default = 'pending'; // phpcs:ignore
|
||||
|
||||
const PENDING = 'pending';
|
||||
const COMPLETED = 'completed';
|
||||
const REFUND = 'refunded';
|
||||
const PARTIAL_REFUND = 'partially-refunded';
|
||||
const PARTIAL = 'partially-paid';
|
||||
const FAILED = 'failed';
|
||||
const CANCELLED = 'cancelled';
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function classes() {
|
||||
|
||||
return array(
|
||||
static::PENDING => 'wu-bg-gray-200 wu-text-gray-700',
|
||||
static::COMPLETED => 'wu-bg-green-200 wu-text-green-700',
|
||||
static::REFUND => 'wu-bg-blue-200 wu-text-gray-700',
|
||||
static::PARTIAL_REFUND => 'wu-bg-blue-200 wu-text-gray-700',
|
||||
static::PARTIAL => 'wu-bg-yellow-200 wu-text-yellow-700',
|
||||
static::FAILED => 'wu-bg-red-200 wu-text-red-700',
|
||||
static::CANCELLED => 'wu-bg-orange-200 wu-text-orange-700',
|
||||
);
|
||||
|
||||
} // end classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function icon_classes() {
|
||||
|
||||
return array(
|
||||
static::PENDING => 'wu-align-middle dashicons-wu-clock wu-text-gray-700',
|
||||
static::COMPLETED => 'wu-align-middle dashicons-wu-check wu-text-green-700',
|
||||
static::REFUND => 'wu-align-middle dashicons-wu-cw wu-text-gray-700',
|
||||
static::PARTIAL_REFUND => 'wu-align-middle dashicons-wu-cw wu-text-gray-700',
|
||||
static::PARTIAL => 'wu-align-middle dashicons-wu-cw wu-text-yellow-700',
|
||||
static::FAILED => 'wu-align-middle dashicons-wu-circle-with-cross wu-text-red-700',
|
||||
static::CANCELLED => 'wu-align-middle dashicons-wu-circle-with-cross wu-text-orange-700',
|
||||
);
|
||||
|
||||
} // end icon_classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function labels() {
|
||||
|
||||
return array(
|
||||
static::PENDING => __('Pending', 'wp-ultimo'),
|
||||
static::COMPLETED => __('Completed', 'wp-ultimo'),
|
||||
static::REFUND => __('Refunded', 'wp-ultimo'),
|
||||
static::PARTIAL_REFUND => __('Partially Refunded', 'wp-ultimo'),
|
||||
static::PARTIAL => __('Partially Paid', 'wp-ultimo'),
|
||||
static::FAILED => __('Failed', 'wp-ultimo'),
|
||||
static::CANCELLED => __('Cancelled', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
} // end labels;
|
||||
|
||||
} // end class Payment_Status;
|
82
inc/database/payments/class-payments-meta-table.php
Normal file
82
inc/database/payments/class-payments-meta-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying payments' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_paymentmeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Payments_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'paymentmeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Payments constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_payment_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) DEFAULT NULL,
|
||||
meta_value longtext DEFAULT NULL,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY wu_payment_id (wu_payment_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Payments_Meta_Table;
|
192
inc/database/payments/class-payments-schema.php
Normal file
192
inc/database/payments/class-payments-schema.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* Payment schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Payments Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Payments_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.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,
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'status',
|
||||
'type' => 'varchar',
|
||||
'length' => '12',
|
||||
'default' => 'pending',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
// customer_id
|
||||
array(
|
||||
'name' => 'customer_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'membership_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'parent_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'product_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'migrated_from_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// currency
|
||||
array(
|
||||
'name' => 'currency',
|
||||
'type' => 'varchar',
|
||||
'length' => '20',
|
||||
'default' => 'USD',
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'discount_code',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'discount_total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'subtotal',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'refund_total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'tax_total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'total',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
// gateway
|
||||
array(
|
||||
'name' => 'gateway',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
// gateway
|
||||
array(
|
||||
'name' => 'gateway_payment_id',
|
||||
'type' => 'tinytext',
|
||||
'default' => '',
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
// date_created
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
// date_modified
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Payments_Schema;
|
198
inc/database/payments/class-payments-table.php
Normal file
198
inc/database/payments/class-payments-table.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying payment.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Payments
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Payments;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_payments" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Payments_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'payments';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20210417' => 20_210_417,
|
||||
'2.0.1-revision.20210607' => 20_210_607,
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Payments constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema.
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
status varchar(20) NOT NULL DEFAULT 'pending',
|
||||
customer_id bigint(20) unsigned NOT NULL default '0',
|
||||
membership_id bigint(20) unsigned NOT NULL default '0',
|
||||
parent_id bigint(20) unsigned NOT NULL default '0',
|
||||
product_id bigint(9) NOT NULL default '0',
|
||||
migrated_from_id bigint(20) DEFAULT NULL,
|
||||
discount_code tinytext NOT NULL default '',
|
||||
currency varchar(10) NOT NULL DEFAULT 'USD',
|
||||
subtotal decimal(13,4) default 0,
|
||||
refund_total decimal(13,4) default 0,
|
||||
tax_total decimal(13,4) default 0,
|
||||
discount_total decimal(13,4) default 0,
|
||||
total decimal(13,4) default 0,
|
||||
gateway tinytext NOT NULL default '',
|
||||
gateway_payment_id tinytext DEFAULT NULL,
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY customer_id (customer_id),
|
||||
KEY membership_id (membership_id),
|
||||
KEY parent_id (parent_id),
|
||||
KEY product_id (product_id),
|
||||
KEY status (status)";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
/**
|
||||
* Adds the refund_total column.
|
||||
*
|
||||
* This does not work on older versions of MySQL, so we needed
|
||||
* the other migration below.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210417() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('refund_total');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `refund_total` decimal(13,4) default 0 AFTER `subtotal`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210417;
|
||||
|
||||
/**
|
||||
* Adds the refund_total column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210607() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('refund_total');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query_set = "SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';";
|
||||
|
||||
$result_set = $this->get_db()->query($query_set);
|
||||
|
||||
if ($this->is_success($result_set) === false) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `refund_total` decimal(13,4) default 0 AFTER `subtotal`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210607;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Payments_Table;
|
111
inc/database/posts/class-post-query.php
Normal file
111
inc/database/posts/class-post-query.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying posts.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Posts
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Posts;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying posts.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Post_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'posts';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'po';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Posts\\Posts_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'post';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'posts';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Post_Base_Model';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'posts';
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function query($query = array()) {
|
||||
|
||||
if (!isset($query['type__in'])) {
|
||||
|
||||
$query['type'] = $this->item_name;
|
||||
|
||||
} // end if;
|
||||
|
||||
return parent::query($query);
|
||||
|
||||
} // end query;
|
||||
|
||||
} // end class Post_Query;
|
82
inc/database/posts/class-posts-meta-table.php
Normal file
82
inc/database/posts/class-posts-meta-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying posts' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Posts
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Posts;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_postmeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Posts_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'postmeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Posts constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_post_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) DEFAULT NULL,
|
||||
meta_value longtext DEFAULT NULL,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY wu_post_id (wu_post_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Posts_Meta_Table;
|
125
inc/database/posts/class-posts-schema.php
Normal file
125
inc/database/posts/class-posts-schema.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Post schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Posts
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Posts;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Posts Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Posts_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'author_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'type',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'slug',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'title',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'content',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
'searchable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'excerpt',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
'searchable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'list_order',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 10,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'status',
|
||||
'type' => 'varchar', // An "enum" here would possibly limit custom post status.
|
||||
'default' => 'draft',
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Posts_Schema;
|
123
inc/database/posts/class-posts-table.php
Normal file
123
inc/database/posts/class-posts-table.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying posts.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Posts
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Posts;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_post" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Posts_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'posts';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Posts constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
author_id bigint(20) NOT NULL,
|
||||
type tinytext NOT NULL DEFAULT '',
|
||||
slug tinytext NOT NULL DEFAULT '',
|
||||
title tinytext NOT NULL DEFAULT '',
|
||||
content longtext NOT NULL default '',
|
||||
excerpt longtext NOT NULL default '',
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
list_order tinyint default 10,
|
||||
status varchar(100) NOT NULL default 'draft',
|
||||
PRIMARY KEY (id)";
|
||||
|
||||
} // end set_schema;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Posts_Table;
|
113
inc/database/products/class-product-query.php
Normal file
113
inc/database/products/class-product-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying products.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Products
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Products;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying products.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Product_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'products';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'p';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Products\\Products_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'product';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'products';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Product';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'products';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Product_Query;
|
65
inc/database/products/class-product-type.php
Normal file
65
inc/database/products/class-product-type.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Product Types enum.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage WP_Ultimo\Database\Products
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Products;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Database\Engine\Enum;
|
||||
|
||||
/**
|
||||
* Product Types.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Product_Type extends Enum {
|
||||
|
||||
/**
|
||||
* Default product type.
|
||||
*/
|
||||
const __default = 'plan'; // phpcs:ignore
|
||||
|
||||
const PLAN = 'plan';
|
||||
const PACKAGE = 'package';
|
||||
const SERVICE = 'service';
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function classes() {
|
||||
|
||||
return array(
|
||||
static::PLAN => 'wu-bg-green-200 wu-text-green-700',
|
||||
static::PACKAGE => 'wu-bg-gray-200 wu-text-blue-700',
|
||||
static::SERVICE => 'wu-bg-yellow-200 wu-text-yellow-700',
|
||||
);
|
||||
|
||||
} // end classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function labels() {
|
||||
|
||||
return array(
|
||||
static::PLAN => __('Plan', 'wp-ultimo'),
|
||||
static::PACKAGE => __('Package', 'wp-ultimo'),
|
||||
static::SERVICE => __('Service', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
} // end labels;
|
||||
|
||||
} // end class Product_Type;
|
82
inc/database/products/class-products-meta-table.php
Normal file
82
inc/database/products/class-products-meta-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying products' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Products
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Products;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_productmeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Products_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'productmeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Products constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$max_index_length = 191;
|
||||
|
||||
$this->schema = "meta_id bigint(20) unsigned NOT NULL auto_increment,
|
||||
wu_product_id bigint(20) unsigned NOT NULL default '0',
|
||||
meta_key varchar(255) DEFAULT NULL,
|
||||
meta_value longtext DEFAULT NULL,
|
||||
PRIMARY KEY (meta_id),
|
||||
KEY wu_product_id (wu_product_id),
|
||||
KEY meta_key (meta_key({$max_index_length}))";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Products_Meta_Table;
|
221
inc/database/products/class-products-schema.php
Normal file
221
inc/database/products/class-products-schema.php
Normal file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* Product schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Products
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Products;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Products Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Products_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'slug',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'parent_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'migrated_from_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'name',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'description',
|
||||
'type' => 'longtext',
|
||||
'default' => '',
|
||||
'searchable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'product_group',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'currency',
|
||||
'type' => 'varchar',
|
||||
'length' => '10',
|
||||
'default' => 'USD',
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'pricing_type',
|
||||
'type' => 'varchar',
|
||||
'length' => '10',
|
||||
'default' => 'paid',
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'amount',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'setup_fee',
|
||||
'type' => 'decimal(13,4)',
|
||||
'default' => '',
|
||||
'sortable' => true,
|
||||
'transition' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'recurring',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'trial_duration',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '0',
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'trial_duration_unit',
|
||||
'type' => 'enum(\'day\', \'month\', \'week\', \'year\')',
|
||||
'default' => 'none',
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'duration',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '0',
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'duration_unit',
|
||||
'type' => 'enum(\'day\', \'month\', \'week\', \'year\')',
|
||||
'default' => 'none',
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'billing_cycles',
|
||||
'type' => 'smallint',
|
||||
'unsigned' => true,
|
||||
'default' => '0',
|
||||
'sortable' => true,
|
||||
'transition' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'list_order',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 10,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'active',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'type',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Products_Schema;
|
197
inc/database/products/class-products-table.php
Normal file
197
inc/database/products/class-products-table.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying products.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Products
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Products;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_product" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Products_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'products';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20210419' => 20_210_419,
|
||||
'2.0.1-revision.20210607' => 20_210_607,
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Products constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
name tinytext NOT NULL DEFAULT '',
|
||||
slug tinytext NOT NULL DEFAULT '',
|
||||
parent_id bigint(20),
|
||||
migrated_from_id bigint(20) DEFAULT NULL,
|
||||
description longtext NOT NULL default '',
|
||||
product_group varchar(20) DEFAULT '',
|
||||
currency varchar(10) NOT NULL DEFAULT 'USD',
|
||||
pricing_type varchar(10) NOT NULL DEFAULT 'paid',
|
||||
amount decimal(13,4) default 0,
|
||||
setup_fee decimal(13,4) default 0,
|
||||
recurring tinyint(4) default 1,
|
||||
trial_duration smallint default 0,
|
||||
trial_duration_unit enum('day', 'week', 'month', 'year'),
|
||||
duration smallint default 0,
|
||||
duration_unit enum('day', 'week', 'month', 'year'),
|
||||
billing_cycles smallint default 0,
|
||||
list_order tinyint default 10,
|
||||
active tinyint(4) default 1,
|
||||
type tinytext NOT NULL DEFAULT '',
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
PRIMARY KEY (id)";
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
/**
|
||||
* Adds the product_group column.
|
||||
*
|
||||
* This does not work on older versions of MySQL, so we needed
|
||||
* the other migration below.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210419() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('product_group');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `product_group` varchar(20) default '' AFTER `description`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210419;
|
||||
|
||||
/**
|
||||
* Adds the product_group column.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return bool
|
||||
*/
|
||||
protected function __20210607() { // phpcs:ignore
|
||||
|
||||
$result = $this->column_exists('product_group');
|
||||
|
||||
// Maybe add column
|
||||
if (empty($result)) {
|
||||
|
||||
$query_set = "SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';";
|
||||
|
||||
$result_set = $this->get_db()->query($query_set);
|
||||
|
||||
if ($this->is_success($result_set) === false) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} ADD COLUMN `product_group` varchar(20) default '' AFTER `description`;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
} // end if;
|
||||
|
||||
// Return success/fail
|
||||
return $this->is_success($result);
|
||||
|
||||
} // end __20210607;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Products_Table;
|
121
inc/database/sites/class-site-query.php
Normal file
121
inc/database/sites/class-site-query.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying products.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Sites
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Sites;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying products.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Site_Query extends Query {
|
||||
|
||||
/**
|
||||
* Table prefix, including the site prefix.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'blogs';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 's';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Sites\\Sites_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'blog';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'blogs';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Site';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'sites';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Site_Query;
|
73
inc/database/sites/class-site-type.php
Normal file
73
inc/database/sites/class-site-type.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Site Types enum.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage WP_Ultimo\Database\Sites
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Sites;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Database\Engine\Enum;
|
||||
|
||||
/**
|
||||
* Site Types.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Site_Type extends Enum {
|
||||
|
||||
/**
|
||||
* Default type.
|
||||
*/
|
||||
const __default = 'default'; // phpcs:ignore
|
||||
|
||||
const REGULAR = 'default';
|
||||
const SITE_TEMPLATE = 'site_template';
|
||||
const CUSTOMER_OWNED = 'customer_owned';
|
||||
const PENDING = 'pending';
|
||||
const EXTERNAL = 'external';
|
||||
const MAIN = 'main';
|
||||
|
||||
/**
|
||||
* Returns an array with values => CSS Classes.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function classes() {
|
||||
|
||||
return array(
|
||||
static::REGULAR => 'wu-bg-gray-700 wu-text-gray-200',
|
||||
static::SITE_TEMPLATE => 'wu-bg-yellow-200 wu-text-yellow-700',
|
||||
static::CUSTOMER_OWNED => 'wu-bg-green-200 wu-text-green-700',
|
||||
static::PENDING => 'wu-bg-purple-200 wu-text-purple-700',
|
||||
static::EXTERNAL => 'wu-bg-blue-200 wu-text-blue-700',
|
||||
static::MAIN => 'wu-bg-pink-200 wu-text-pink-700',
|
||||
);
|
||||
|
||||
} // end classes;
|
||||
|
||||
/**
|
||||
* Returns an array with values => labels.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
protected function labels() {
|
||||
|
||||
return array(
|
||||
static::REGULAR => __('Regular Site', 'wp-ultimo'),
|
||||
static::SITE_TEMPLATE => __('Site Template', 'wp-ultimo'),
|
||||
static::CUSTOMER_OWNED => __('Customer-Owned', 'wp-ultimo'),
|
||||
static::PENDING => __('Pending', 'wp-ultimo'),
|
||||
static::MAIN => __('Main Site', 'wp-ultimo'),
|
||||
);
|
||||
|
||||
} // end labels;
|
||||
|
||||
} // end class Site_Type;
|
82
inc/database/sites/class-sites-meta-table.php
Normal file
82
inc/database/sites/class-sites-meta-table.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying products' meta data.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Sites
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Sites;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_productmeta" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Sites_Meta_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table prefix, including the site prefix.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'blogmeta';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Sites constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = false;
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
} // end class Sites_Meta_Table;
|
151
inc/database/sites/class-sites-schema.php
Normal file
151
inc/database/sites/class-sites-schema.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Site schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Sites
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Sites;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Sites Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Sites_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Table prefix, including the site prefix.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'blog_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true,
|
||||
'aliases' => array('id', 'ID'),
|
||||
'searchable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'site_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'domain',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'path',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'registered',
|
||||
'type' => 'datetime',
|
||||
'default' => '0000-00-00 00:00:00',
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'last_updated',
|
||||
'type' => 'datetime',
|
||||
'default' => '0000-00-00 00:00:00',
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'public',
|
||||
'type' => 'tinyint',
|
||||
'length' => '2',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'archived',
|
||||
'type' => 'tinyint',
|
||||
'length' => '2',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'mature',
|
||||
'type' => 'tinyint',
|
||||
'length' => '2',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'spam',
|
||||
'type' => 'tinyint',
|
||||
'length' => '2',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'deleted',
|
||||
'type' => 'tinyint',
|
||||
'length' => '2',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'lang_id',
|
||||
'type' => 'int',
|
||||
'length' => '11',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Sites_Schema;
|
89
inc/database/sites/class-sites-table.php
Normal file
89
inc/database/sites/class-sites-table.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying blogs.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Sites
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Sites;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wp_blog" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Sites_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table prefix, including the site prefix.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'blogs';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.0';
|
||||
|
||||
/**
|
||||
* Sites constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
$this->schema = false;
|
||||
|
||||
} // end set_schema;
|
||||
|
||||
/**
|
||||
* Do nothing as this table already exists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function install() {} // end install;
|
||||
|
||||
} // end class Sites_Table;
|
113
inc/database/webhooks/class-webhook-query.php
Normal file
113
inc/database/webhooks/class-webhook-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying webhooks.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Webhooks
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Webhooks;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying webhooks.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Webhook_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'webhooks';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'w';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Webhooks\\Webhooks_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'webhook';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'webhooks';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Webhook';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'webhooks';
|
||||
|
||||
/**
|
||||
* If we should use a global cache group.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @var bool
|
||||
*/
|
||||
protected $global_cache = true;
|
||||
|
||||
/**
|
||||
* Sets up the customer query, based on the query vars passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
*
|
||||
* @param string|array $query Array of query arguments.
|
||||
*/
|
||||
public function __construct($query = array()) {
|
||||
|
||||
parent::__construct($query);
|
||||
|
||||
} // end __construct;
|
||||
|
||||
} // end class Webhook_Query;
|
136
inc/database/webhooks/class-webhooks-schema.php
Normal file
136
inc/database/webhooks/class-webhooks-schema.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Webhook schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Webhooks
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Webhooks;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Webhooks Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Webhooks_Schema extends Schema {
|
||||
|
||||
/**
|
||||
* Array of database column objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
public $columns = array(
|
||||
|
||||
array(
|
||||
'name' => 'id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'extra' => 'auto_increment',
|
||||
'primary' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'migrated_from_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'name',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'webhook_url',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'event',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'event_count',
|
||||
'type' => 'int',
|
||||
'length' => '10',
|
||||
'default' => 0,
|
||||
'sortable' => true,
|
||||
'aliases' => array('sent_events_count'),
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'active',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'hidden',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'integration',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_last_failed',
|
||||
'type' => 'datetime',
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Webhooks_Schema;
|
129
inc/database/webhooks/class-webhooks-table.php
Normal file
129
inc/database/webhooks/class-webhooks-table.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying domain mappings.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Webhook
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Webhooks;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_webhooks" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Webhooks_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'webhooks';
|
||||
|
||||
/**
|
||||
* Is this table global?
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var boolean
|
||||
*/
|
||||
protected $global = true;
|
||||
|
||||
/**
|
||||
* Table current version
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $version = '2.0.1-revision.20230601';
|
||||
|
||||
/**
|
||||
* List of table upgrades.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $upgrades = array(
|
||||
'2.0.1-revision.20230601' => 20_230_601,
|
||||
);
|
||||
|
||||
/**
|
||||
* Webhook constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
} // end __construct;
|
||||
|
||||
/**
|
||||
* Setup the database schema
|
||||
*
|
||||
* @access protected
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
protected function set_schema() {
|
||||
|
||||
// phpcs:disable
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL auto_increment,
|
||||
migrated_from_id bigint(20) DEFAULT NULL,
|
||||
name varchar(191) NOT NULL,
|
||||
webhook_url varchar(191) NOT NULL,
|
||||
event varchar(40) NOT NULL,
|
||||
event_count int(10) default 0,
|
||||
active tinyint(4) default 1,
|
||||
hidden tinyint(4) default 0,
|
||||
integration varchar(191) NOT NULL,
|
||||
date_last_failed datetime NOT NULL,
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY event (event)";
|
||||
|
||||
// phpcs:enable
|
||||
|
||||
} // end set_schema;
|
||||
/**
|
||||
* Fixes the datetime columns to accept null.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*/
|
||||
protected function __20230601(): bool {
|
||||
|
||||
$null_columns = array(
|
||||
'date_created',
|
||||
'date_modified',
|
||||
);
|
||||
|
||||
foreach ($null_columns as $column) {
|
||||
|
||||
$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `{$column}` datetime DEFAULT NULL;";
|
||||
|
||||
$result = $this->get_db()->query($query);
|
||||
|
||||
if (!$this->is_success($result)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
return true;
|
||||
|
||||
} // end __20230601;
|
||||
|
||||
} // end class Webhooks_Table;
|
Reference in New Issue
Block a user