Initial Commit
This commit is contained in:
113
inc/database/webhooks/class-webhook-query.php
Normal file
113
inc/database/webhooks/class-webhook-query.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying webhooks.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Webhooks
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Webhooks;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Query;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Class used for querying webhooks.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Webhook_Query extends Query {
|
||||
|
||||
/** Table Properties ******************************************************/
|
||||
|
||||
/**
|
||||
* Name of the database table to query.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_name = 'webhooks';
|
||||
|
||||
/**
|
||||
* String used to alias the database table in MySQL statement.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_alias = 'w';
|
||||
|
||||
/**
|
||||
* Name of class used to setup the database schema
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $table_schema = '\\WP_Ultimo\\Database\\Webhooks\\Webhooks_Schema';
|
||||
|
||||
/** Item ******************************************************************/
|
||||
|
||||
/**
|
||||
* Name for a single item
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name = 'webhook';
|
||||
|
||||
/**
|
||||
* Plural version for a group of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $item_name_plural = 'webhooks';
|
||||
|
||||
/**
|
||||
* Callback function for turning IDs into objects
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var mixed
|
||||
*/
|
||||
protected $item_shape = '\\WP_Ultimo\\Models\\Webhook';
|
||||
|
||||
/**
|
||||
* Group to cache queries and queried items in.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_group = 'webhooks';
|
||||
|
||||
/**
|
||||
* 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 Webhook_Query;
|
136
inc/database/webhooks/class-webhooks-schema.php
Normal file
136
inc/database/webhooks/class-webhooks-schema.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* Webhook schema class
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Webhooks
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Webhooks;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Schema;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Webhooks Schema Class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Webhooks_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' => 'migrated_from_id',
|
||||
'type' => 'bigint',
|
||||
'length' => '20',
|
||||
'unsigned' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'name',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'webhook_url',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'event',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'event_count',
|
||||
'type' => 'int',
|
||||
'length' => '10',
|
||||
'default' => 0,
|
||||
'sortable' => true,
|
||||
'aliases' => array('sent_events_count'),
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'active',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 1,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'hidden',
|
||||
'type' => 'tinyint',
|
||||
'length' => '4',
|
||||
'unsigned' => true,
|
||||
'default' => 0,
|
||||
'transition' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'integration',
|
||||
'type' => 'varchar',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_last_failed',
|
||||
'type' => 'datetime',
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_created',
|
||||
'type' => 'datetime',
|
||||
'created' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
),
|
||||
|
||||
array(
|
||||
'name' => 'date_modified',
|
||||
'type' => 'datetime',
|
||||
'default' => null,
|
||||
'modified' => true,
|
||||
'date_query' => true,
|
||||
'sortable' => true,
|
||||
'allow_null' => true,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
} // end class Webhooks_Schema;
|
129
inc/database/webhooks/class-webhooks-table.php
Normal file
129
inc/database/webhooks/class-webhooks-table.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used for querying domain mappings.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Database\Webhook
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Database\Webhooks;
|
||||
|
||||
use WP_Ultimo\Database\Engine\Table;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Setup the "wu_webhooks" database table
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class Webhooks_Table extends Table {
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'webhooks';
|
||||
|
||||
/**
|
||||
* 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,
|
||||
);
|
||||
|
||||
/**
|
||||
* Webhook 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() {
|
||||
|
||||
// phpcs:disable
|
||||
|
||||
$this->schema = "id bigint(20) NOT NULL auto_increment,
|
||||
migrated_from_id bigint(20) DEFAULT NULL,
|
||||
name varchar(191) NOT NULL,
|
||||
webhook_url varchar(191) NOT NULL,
|
||||
event varchar(40) NOT NULL,
|
||||
event_count int(10) default 0,
|
||||
active tinyint(4) default 1,
|
||||
hidden tinyint(4) default 0,
|
||||
integration varchar(191) NOT NULL,
|
||||
date_last_failed datetime NOT NULL,
|
||||
date_created datetime NULL,
|
||||
date_modified datetime NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY event (event)";
|
||||
|
||||
// phpcs:enable
|
||||
|
||||
} // 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 Webhooks_Table;
|
Reference in New Issue
Block a user