Initial Commit

This commit is contained in:
David Stone
2024-11-30 18:24:12 -07:00
commit e8f7955c1c
5432 changed files with 1397750 additions and 0 deletions

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

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

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

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