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

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

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

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