From f42f087c206c90ad371ee95d5007918b77bf40ae Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 29 Oct 2019 14:49:54 -0400 Subject: [PATCH] Updating get plugin site list adding request vars for server and plugin names. --- models/admin/ajax/pluginListSites.php | 63 +++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/models/admin/ajax/pluginListSites.php b/models/admin/ajax/pluginListSites.php index d5c7235..3654386 100644 --- a/models/admin/ajax/pluginListSites.php +++ b/models/admin/ajax/pluginListSites.php @@ -73,13 +73,56 @@ class GlmMembersAdmin_ajax_pluginListSites extends GlmDataSites public function modelAction( $actionData = false ) { - $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 = 15) - "; + $where = ''; + $server = false; + $plugin = false; + $whereParts = array(); + + if ( isset( $_REQUEST['server'] ) && $serverName = filter_var( $_REQUEST['server'] ) ) { + $server = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "servers + WHERE name = %s", + $serverName + ), + ARRAY_A + ); + if ( $server ) { + if ( $server['production'] ) { + $whereParts[] = "T.prod_server = " . $server['id']; + $whereParts[] = "T.active"; + } else { + $whereParts[] = "T.dev_server = " . $server['id']; + } + } else { + die( 'no server given' ); + } + } else { + die( 'no server given' ); + } + + if ( isset( $_REQUEST['plugin'] ) && $pluginName = filter_var( $_REQUEST['plugin'] ) ) { + $plugin = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "plugins + WHERE name = %s", + $pluginName + ), + ARRAY_A + ); + if ( $plugin ) { + $whereParts[] = "T.id IN ( + SELECT site + FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "site_plugins + WHERE plugin = " . $plugin['id'] . ")"; + } + } + + if ( !empty( $whereParts ) ) { + $where = implode( ' AND ', $whereParts ); + } $config = array( 'order' => 'name', @@ -90,7 +133,11 @@ class GlmMembersAdmin_ajax_pluginListSites extends GlmDataSites $siteOut = array(); foreach ( $sites as $site ) { - $siteOut[] = $site['prod_url']; + if ( $server['production'] ) { + $siteOut[] = $site['prod_url']; + } else { + $siteOut[] = $site['dev_url']; + } } echo implode( "\n", $siteOut ); -- 2.17.1