Initial Commit
This commit is contained in:
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;
|
Reference in New Issue
Block a user