From f737a7370b10dbbf094961bc8750095f39c1681e Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 17 Oct 2019 16:40:03 -0400 Subject: [PATCH] Update tables Worked on the tables for each section. Adding functionality to the plugin detail page. Plugin detail page can now edit the prod_version and dev_version columns. They'll update the actual database record. --- models/admin/ajax/pluginListSites.php | 6 +- models/admin/ajax/sitePluginUpdate.php | 125 +++++++++++++++++++++++++ models/admin/plugins/plugins.php | 2 +- setup/validActions.php | 5 +- views/admin/plugins/index.html | 21 +++++ views/admin/plugins/plugin-detail.html | 31 ++++-- views/admin/plugins/plugins.html | 21 +++++ views/admin/plugins/sites.html | 28 +++++- 8 files changed, 224 insertions(+), 15 deletions(-) create mode 100644 models/admin/ajax/sitePluginUpdate.php diff --git a/models/admin/ajax/pluginListSites.php b/models/admin/ajax/pluginListSites.php index 23b6a45..d5c7235 100644 --- a/models/admin/ajax/pluginListSites.php +++ b/models/admin/ajax/pluginListSites.php @@ -73,12 +73,12 @@ class GlmMembersAdmin_ajax_pluginListSites extends GlmDataSites public function modelAction( $actionData = false ) { - // $where = "T.prod_server = 2"; // norax - $where = "T.prod_server = 1"; // eleusis + $where = "T.prod_server = 2"; // norax + // $where = "T.prod_server = 1"; // eleusis $where .= " AND T.id IN (SELECT site FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "site_plugins - WHERE plugin = 7) + WHERE plugin = 15) "; $config = array( diff --git a/models/admin/ajax/sitePluginUpdate.php b/models/admin/ajax/sitePluginUpdate.php new file mode 100644 index 0000000..7aeb654 --- /dev/null +++ b/models/admin/ajax/sitePluginUpdate.php @@ -0,0 +1,125 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +require_once GLM_MEMBERS_PLUGINS_PLUGIN_CLASS_PATH.'/data/dataSitePlugins.php'; +/** + * Steve Note + * + * You can get to this using the following URL. + * + * + {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runQueue + * + * You should be able to do this as POST or GET and should be able to add and read additional parameters. + * I added a "mystuff" parameter to the URL above and it does output from the code in the + * modelAction() function below. + * + * To add another model under models/admin/ajax all you need to do is create it and add it to the + * setup/validActions.php file. + * + */ + +// Load Members data abstract +// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php'; + +/** + * This class performs the work of handling images passed to it via + * an AJAX call that goes through the WorPress AJAX Handler. + * + */ +class GlmMembersAdmin_ajax_sitePluginUpdate extends GlmDataSitePlugin +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + 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 ); + + } + + public function modelAction( $actionData = false ) { + if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) { + + $return = array( + 'prodStatus' => false, + 'devStatus' => false, + 'id' => $id, + ); + + $this->wpdb->update( + $this->table, + array( + 'prod_version' => $_REQUEST['prodVersion'], + 'dev_version' => $_REQUEST['devVersion'] + ), + array( 'id' => $id ), + array( '%s', '%s' ), + array( '%d' ) + ); + // Get entry. + $sitePlugin = $this->getEntry( $id ); + if ( $sitePlugin ) { + + // Now check to see prod and dev version status are ok or not and return. + $latestVersion = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT latest_version + FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "plugins + WHERE id = %d", + $sitePlugin['plugin']['value'] + ) + ); + if ( $latestVersion ) { + if ( $sitePlugin['prod_version'] && version_compare( $latestVersion, $sitePlugin['prod_version'], '>' ) ) { + $return['prodStatus'] = false; + } elseif ( $sitePlugin['prod_version'] ) { + $return['prodStatus'] = true; + } + if ( $sitePlugin['dev_version'] && version_compare( $latestVersion, $sitePlugin['dev_version'], '>' ) ) { + $return['devStatus'] = false; + } elseif ( $sitePlugin['dev_version'] ) { + $return['devStatus'] = true; + } + } + } + } + + echo json_encode( $return ); + + exit; + } +} diff --git a/models/admin/plugins/plugins.php b/models/admin/plugins/plugins.php index 74166f3..9040b68 100644 --- a/models/admin/plugins/plugins.php +++ b/models/admin/plugins/plugins.php @@ -215,7 +215,7 @@ class GlmMembersAdmin_plugins_plugins extends GlmDataPlugins // Find all sites for this plugin. $tData['sites'] = $this->wpdb->get_results( $this->wpdb->prepare( - "SELECT S.name as site_name,S.id,SP.prod_version,SP.dev_version,PS.name as prod_server,DS.name as dev_server + "SELECT S.name as site_name,S.id,SP.id as site_plugin_id,SP.prod_version,SP.dev_version,PS.name as prod_server,DS.name as dev_server FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "site_plugins SP LEFT OUTER JOIN " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "sites S ON (S.id = SP.site) LEFT OUTER JOIN " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "servers PS ON (PS.id = S.prod_server) diff --git a/setup/validActions.php b/setup/validActions.php index 7798060..fd1f4e7 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -60,10 +60,11 @@ $glmMemberPluginsAddOnValidActions = array( 'adminActions' => array( 'ajax' => array( - 'pluginListSites' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, + 'pluginListSites' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, + 'sitePluginUpdate' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, ), 'plugins' => array( - 'index' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, + 'index' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, 'plugins' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, 'sites' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, 'servers' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG, diff --git a/views/admin/plugins/index.html b/views/admin/plugins/index.html index f996296..7b348df 100644 --- a/views/admin/plugins/index.html +++ b/views/admin/plugins/index.html @@ -14,6 +14,14 @@ +
+
+ +
+
+ +
+