From c95d5e50b7e9afb7691f8b20685463ab332bc788 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 13 Jun 2019 16:37:37 -0400 Subject: [PATCH] Adding database files. Creating data classes and database sql files. --- classes/data/dataPlugins.php | 169 +++++++++++++ classes/data/dataServers.php | 169 +++++++++++++ classes/data/dataSites.php | 224 ++++++++++++++++++ models/admin/plugins/index.php | 141 +++++++++++ setup/adminMenus.php | 11 +- .../create_database_V0.0.1.sql | 53 +++++ setup/databaseScripts/dbVersions.php | 19 ++ setup/validActions.php | 5 +- views/admin/footer.html | 12 + views/admin/header.html | 8 + views/admin/plugins/index.html | 21 ++ 11 files changed, 830 insertions(+), 2 deletions(-) create mode 100644 classes/data/dataPlugins.php create mode 100644 classes/data/dataServers.php create mode 100644 classes/data/dataSites.php create mode 100644 models/admin/plugins/index.php create mode 100644 setup/databaseScripts/create_database_V0.0.1.sql create mode 100644 setup/databaseScripts/dbVersions.php create mode 100644 views/admin/footer.html create mode 100644 views/admin/header.html create mode 100644 views/admin/plugins/index.html diff --git a/classes/data/dataPlugins.php b/classes/data/dataPlugins.php new file mode 100644 index 0000000..df4ef24 --- /dev/null +++ b/classes/data/dataPlugins.php @@ -0,0 +1,169 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataEmailMessages class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataPlugins extends GlmDataAbstract +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Data Table Name + * + * @var $table + * @access public + */ + public $table; + /** + * Field definitions + * + * 'type' is type of field as defined by the application + * text Regular text field + * pointer Pointer to an entry in another table + * 'filters' is the filter name for a particular filter ID in PHP filter + * functions + * See PHP filter_id() + * + * 'use' is when to use the field + * l = List + * g = Get + * n = New + * i = Insert + * e = Edit + * u = Update + * d = Delete + * a = All + * + * @var $ini + * @access public + */ + public $fields = false; + + public $postStats = false; + public $postSent = false; + + /** + * Constructor + * + * @param object $d database connection + * @param array $config Configuration array + * @param bool $limitedEdit Flag to say indicate limited edit requested + * + * @return void + * @access public + */ + public function __construct($wpdb, $config, $limitedEdit = false) + { + + // If this class is not being extended along with existing $wpdb and $config + if (!$this->wpdb) { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + /* + * Table Name + */ + $this->table = GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . 'plugins'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Name + 'name' => array ( + 'field' => 'name', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Latest Version + 'latest_version' => array ( + 'field' => 'latest_version', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Name + 'notes' => array ( + 'field' => 'notes', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + ); + + } + + /** + * Entry Post Processing Call-Back Method + * + * Perform post-processing for all result entries. + * + * In this case we're using it to append an array of category + * data to each member result and also sort by member name. + * + * @param array $r Array of field result data for a single entry + * @param string $a Action being performed (l, i, g, ...) + * + * @return object Class object + * + */ + public function entryPostProcessing($r, $a) + { + return $r; + } + + +} diff --git a/classes/data/dataServers.php b/classes/data/dataServers.php new file mode 100644 index 0000000..7199327 --- /dev/null +++ b/classes/data/dataServers.php @@ -0,0 +1,169 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataEmailMessages class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataServers extends GlmDataAbstract +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Data Table Name + * + * @var $table + * @access public + */ + public $table; + /** + * Field definitions + * + * 'type' is type of field as defined by the application + * text Regular text field + * pointer Pointer to an entry in another table + * 'filters' is the filter name for a particular filter ID in PHP filter + * functions + * See PHP filter_id() + * + * 'use' is when to use the field + * l = List + * g = Get + * n = New + * i = Insert + * e = Edit + * u = Update + * d = Delete + * a = All + * + * @var $ini + * @access public + */ + public $fields = false; + + public $postStats = false; + public $postSent = false; + + /** + * Constructor + * + * @param object $d database connection + * @param array $config Configuration array + * @param bool $limitedEdit Flag to say indicate limited edit requested + * + * @return void + * @access public + */ + public function __construct($wpdb, $config, $limitedEdit = false) + { + + // If this class is not being extended along with existing $wpdb and $config + if (!$this->wpdb) { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + /* + * Table Name + */ + $this->table = GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . 'servers'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Location + 'location' => array ( + 'field' => 'location', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // PHP Version + 'php_version' => array ( + 'field' => 'php_version', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Mysql Version + 'mysql_version' => array ( + 'field' => 'mysql_version', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + ); + + } + + /** + * Entry Post Processing Call-Back Method + * + * Perform post-processing for all result entries. + * + * In this case we're using it to append an array of category + * data to each member result and also sort by member name. + * + * @param array $r Array of field result data for a single entry + * @param string $a Action being performed (l, i, g, ...) + * + * @return object Class object + * + */ + public function entryPostProcessing($r, $a) + { + return $r; + } + + +} diff --git a/classes/data/dataSites.php b/classes/data/dataSites.php new file mode 100644 index 0000000..feb08de --- /dev/null +++ b/classes/data/dataSites.php @@ -0,0 +1,224 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataEmailMessages class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataSites extends GlmDataAbstract +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Data Table Name + * + * @var $table + * @access public + */ + public $table; + /** + * Field definitions + * + * 'type' is type of field as defined by the application + * text Regular text field + * pointer Pointer to an entry in another table + * 'filters' is the filter name for a particular filter ID in PHP filter + * functions + * See PHP filter_id() + * + * 'use' is when to use the field + * l = List + * g = Get + * n = New + * i = Insert + * e = Edit + * u = Update + * d = Delete + * a = All + * + * @var $ini + * @access public + */ + public $fields = false; + + public $postStats = false; + public $postSent = false; + + /** + * Constructor + * + * @param object $d database connection + * @param array $config Configuration array + * @param bool $limitedEdit Flag to say indicate limited edit requested + * + * @return void + * @access public + */ + public function __construct($wpdb, $config, $limitedEdit = false) + { + + // If this class is not being extended along with existing $wpdb and $config + if (!$this->wpdb) { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + /* + * Table Name + */ + $this->table = GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . 'sites'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Production Server + 'prod_server' => array ( + 'field' => 'prod_server', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . 'servers', + 'p_field' => 'name', + 'p_orderby' => 'name', + 'required' => true, + 'force_list' => true, + 'use' => 'a' + ), + + // Develepment Server + 'dev_server' => array ( + 'field' => 'dev_server', + 'type' => 'pointer', + 'p_table' => GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . 'servers', + 'p_field' => 'name', + 'p_orderby' => 'name', + 'required' => true, + 'force_list' => true, + 'use' => 'a' + ), + // Name + 'name' => array ( + 'field' => 'name', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Production URL + 'prod_url' => array ( + 'field' => 'prod_url', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Development URL + 'dev_url' => array ( + 'field' => 'dev_url', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + // Map Key + 'map_key' => array ( + 'field' => 'map_key', + 'type' => 'text', + 'required' => true, + 'use' => 'a' + ), + + ); + + } + + /** + * Entry Post Processing Call-Back Method + * + * Perform post-processing for all result entries. + * + * In this case we're using it to append an array of category + * data to each member result and also sort by member name. + * + * @param array $r Array of field result data for a single entry + * @param string $a Action being performed (l, i, g, ...) + * + * @return object Class object + * + */ + public function entryPostProcessing($r, $a) + { + if ( $this->postStats ) { + // get number of queued emails for this message. + $queued = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT max( queue_date ) + FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "email_queue + WHERE message_id = %d", + $r['id'] + ) + ); + $r['stats'] = ( $queued ) ? strtotime( $queued ) : ''; + } + if ( $this->postSent ) { + // get number of queued emails for this message. + $queued = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT max( send_date ) + FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "email_logs + WHERE message_id = %d", + $r['id'] + ) + ); + $r['sent'] = ( $queued ) ? strtotime( $queued ) : ''; + } + return $r; + } + + +} diff --git a/models/admin/plugins/index.php b/models/admin/plugins/index.php new file mode 100644 index 0000000..c8ca597 --- /dev/null +++ b/models/admin/plugins/index.php @@ -0,0 +1,141 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Members data abstract +// require_once GLM_MEMBERS_PLUGINS_PLUGIN_CLASS_PATH.'/data/dataEmailMessages.php'; +// require_once GLM_MEMBERS_PLUGINS_PLUGIN_CLASS_PATH.'/data/dataEmailTemplates.php'; + +/* + * This class performs the work for the default action of the "Members" menu + * option, which is to display the members dashboard. + * + */ +class GlmMembersAdmin_plugins_index // extends GlmDataEmailMessages +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ( $wpdb, $config ) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + // parent::__construct( false, false ); + + } + + /* + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction ( $actionData = false ) + { + $view = 'index'; + $success = true; + $option = ''; + $option2 = false; + $viewPath = 'admin/plugins/'; + + if ( isset( $_REQUEST['option'] ) ) { + $option = $_REQUEST['option']; + } + + if ( isset( $_REQUEST['option2'] ) ) { + $option2 = $_REQUEST['option2']; + } + + $tData = array(); + $templateData = array( + 'newEntry' => false, + 'thisOption' => $option, + ); + + switch ( $option ) { + + default: + break; + } + + $templateData = array_merge( $templateData, $tData ); + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => $viewPath . $view . '.html', + 'data' => $templateData + ); + + } + +} diff --git a/setup/adminMenus.php b/setup/adminMenus.php index d9a8315..0aa7571 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -49,4 +49,13 @@ * is named the same as the "glm_action" parameter. * */ - +add_submenu_page( + 'glm-members-admin-menu-members', + 'Plugin Manager', + 'Plugin Manager', + 'glm_members_members', + 'glm-members-admin-menu-plugins', + function() { + $this->controller( 'plugins' ); + } +); diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql new file mode 100644 index 0000000..565c1c7 --- /dev/null +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -0,0 +1,53 @@ +-- Gaslight Media Plugins Database +-- File Created: 6/13/19 +-- Database Version: 0.0.1 +-- Database Creation Script - Messages Add-On +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Servers +CREATE TABLE {prefix}servers ( + id INT NOT NULL AUTO_INCREMENT, + name TINYTEXT NOT NULL, + location TINYTEXT NULL, + php_version TINYTEXT NULL, + mysql_version TINYTEXT NULL, + PRIMARY KEY (id) +); + +---- + +-- Plugins +CREATE TABLE {prefix}plugins ( + id INT NOT NULL AUTO_INCREMENT, + name TINYTEXT NOT NULL, + latest_version TINYTEXT NOT NULL, + notes TEXT NULL, + PRIMARY KEY (id) +); + +---- + +-- Sites +CREATE TABLE {prefix}server ( + id INT NOT NULL AUTO_INCREMENT, + name TINYTEXT NOT NULL, + prod_url TINYTEXT NULL, + dev_url TINYTEXT NULL, + prod_server INT NULL, + dev_server INT NULL, + PRIMARY KEY (id) +); + +---- + +-- Site Plugins +CREATE TABLE {prefix}site_plugins ( + id INT NOT NULL AUTO_INCREMENT, + site INT NOT NULL, + plugin INT NOT NULL, + prod_version TINYTEXT NULL, + dev_version TINYTEXT NULL, + PRIMARY KEY (id) +); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php new file mode 100644 index 0000000..dbbe817 --- /dev/null +++ b/setup/databaseScripts/dbVersions.php @@ -0,0 +1,19 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release dbVersions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +$glmMemberPluginsDbVersions = array( + '0.0.1' => array('version' => '0.0.1', 'tables' => 4, 'date' => '06/13/2019'), +); + diff --git a/setup/validActions.php b/setup/validActions.php index e00521e..30cc68b 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -59,9 +59,12 @@ $glmMemberPluginsAddOnValidActions = array( 'adminActions' => array( + 'plugins' => array( + 'index' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, + ), ), 'frontActions' => array( ) ); -?> \ No newline at end of file +?> diff --git a/views/admin/footer.html b/views/admin/footer.html new file mode 100644 index 0000000..7221530 --- /dev/null +++ b/views/admin/footer.html @@ -0,0 +1,12 @@ + + + + + + + diff --git a/views/admin/header.html b/views/admin/header.html new file mode 100644 index 0000000..dd460b4 --- /dev/null +++ b/views/admin/header.html @@ -0,0 +1,8 @@ +
+

Plugin Manager

+ +
diff --git a/views/admin/plugins/index.html b/views/admin/plugins/index.html new file mode 100644 index 0000000..9e75412 --- /dev/null +++ b/views/admin/plugins/index.html @@ -0,0 +1,21 @@ +{include file='admin/header.html'} + +

Plugins Dashboard

+ +
+
+
+ +
+ Add Site +
+ +
+
+
+ +{include file='admin/footer.html'} -- 2.17.1