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

View File

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

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

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