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

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

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

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