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 events.
*
* @package WP_Ultimo
* @subpackage Database\Events
* @since 2.0.0
*/
namespace WP_Ultimo\Database\Events;
use WP_Ultimo\Database\Engine\Query;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* Class used for querying events.
*
* @since 2.0.0
*/
class Event_Query extends Query {
/** Table Properties ******************************************************/
/**
* Name of the database table to query.
*
* @since 2.0.0
* @access public
* @var string
*/
protected $table_name = 'events';
/**
* String used to alias the database table in MySQL statement.
*
* @since 2.0.0
* @access public
* @var string
*/
protected $table_alias = 'e';
/**
* Name of class used to setup the database schema
*
* @since 2.0.0
* @access public
* @var string
*/
protected $table_schema = '\\WP_Ultimo\\Database\\Events\\Events_Schema';
/** Item ******************************************************************/
/**
* Name for a single item
*
* @since 2.0.0
* @access public
* @var string
*/
protected $item_name = 'event';
/**
* Plural version for a group of items.
*
* @since 2.0.0
* @access public
* @var string
*/
protected $item_name_plural = 'events';
/**
* Callback function for turning IDs into objects
*
* @since 2.0.0
* @access public
* @var mixed
*/
protected $item_shape = '\\WP_Ultimo\\Models\\Event';
/**
* Group to cache queries and queried items in.
*
* @since 2.0.0
* @access public
* @var string
*/
protected $cache_group = 'events';
/**
* 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 Event_Query;

View File

@ -0,0 +1,108 @@
<?php
/**
* Event schema class
*
* @package WP_Ultimo
* @subpackage Database\Events
* @since 2.0.0
*/
namespace WP_Ultimo\Database\Events;
use WP_Ultimo\Database\Engine\Schema;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* Events Schema Class.
*
* @since 2.0.0
*/
class Events_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' => 'severity',
'type' => 'tinyint',
'length' => '1',
'unsigned' => true,
'sortable' => true,
),
array(
'name' => 'initiator',
'type' => 'enum(\'system\', \'manual\')',
'default' => 'none',
),
array(
'name' => 'author_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'sortable' => true,
'transition' => true,
),
array(
'name' => 'object_type',
'type' => 'varchar',
'length' => 20,
'default' => 'network',
'sortable' => true,
'searchable' => true,
),
array(
'name' => 'object_id',
'type' => 'bigint',
'length' => '20',
'unsigned' => true,
'sortable' => true,
'transition' => true,
),
array(
'name' => 'slug',
'type' => 'longtext',
'default' => '',
),
array(
'name' => 'payload',
'type' => 'longtext',
'default' => '',
),
array(
'name' => 'date_created',
'type' => 'datetime',
'default' => null,
'created' => true,
'date_query' => true,
'sortable' => true,
'allow_null' => true,
),
);
} // end class Events_Schema;

View File

@ -0,0 +1,123 @@
<?php
/**
* Class used for querying events.
*
* @package WP_Ultimo
* @subpackage Database\Event
* @since 2.0.0
*/
namespace WP_Ultimo\Database\Events;
use WP_Ultimo\Database\Engine\Table;
// Exit if accessed directly
defined('ABSPATH') || exit;
/**
* Setup the "wu_events" database table
*
* @since 2.0.0
*/
final class Events_Table extends Table {
/**
* Table name
*
* @since 2.0.0
* @var string
*/
protected $name = 'events';
/**
* 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,
);
/**
* Event 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,
severity tinyint(4),
initiator enum('system', 'manual'),
author_id bigint(20) NOT NULL default '0',
object_id bigint(20) NOT NULL default '0',
object_type varchar(20) DEFAULT 'network',
slug varchar(255),
payload longtext,
date_created datetime NULL,
PRIMARY KEY (id),
KEY severity (severity),
KEY author_id (author_id),
KEY initiator (initiator)";
} // end set_schema;
/**
* Fixes the datetime columns to accept null.
*
* @since 2.1.2
*/
protected function __20230601(): bool {
$null_columns = array(
'date_created',
);
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 Events_Table;