From b872be55225d8e8cf5f14c81532eddcc5c049ecd Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 14 Jan 2016 14:48:17 -0500 Subject: [PATCH] Database list enhancement in Management sub-menu --- activate.php | 4 -- classes/glmPluginSupport.php | 8 +-- config.php | 2 - controllers/admin.php | 4 +- controllers/front.php | 3 +- deactivate.php | 2 - defines.php | 1 - glm-member-db.php | 39 ++++++++------ models/admin/management/development.php | 70 +++++++++++++++++-------- uninstall.php | 2 - views/admin/management/development.html | 53 +++++++++++++++++++ 11 files changed, 129 insertions(+), 59 deletions(-) diff --git a/activate.php b/activate.php index db36506b..d02f2f0e 100644 --- a/activate.php +++ b/activate.php @@ -276,8 +276,4 @@ class glmMembersPluginActivate extends glmPluginSupport } - - } - -?> diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index b8039ae3..9bf0d45d 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -204,7 +204,7 @@ class GlmPluginSupport $existingTables = $this->wpdb->get_var(" SELECT COUNT(*) FROM information_schema.tables - WHERE table_schema = '".DB_NAME."' + WHERE table_schema = '".DB_NAME."' AND table_name like '$prefixEscaped%'; "); @@ -359,7 +359,9 @@ class GlmPluginSupport } } else { - $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' has been reactivated using the existing database tables.'); + if ($option == 'install') { + $this->addNotice('The '.$a['name'].' plugin/add-on has been reactivated using the existing database tables.'); + } $db_setup_status = true; } @@ -378,5 +380,3 @@ class GlmPluginSupport } } - -?> \ No newline at end of file diff --git a/config.php b/config.php index 7284d12f..f10cd48e 100644 --- a/config.php +++ b/config.php @@ -44,5 +44,3 @@ if (file_exists($currentThemeDirectory.'/glm-member-db/plugin.ini')) { $config = array_replace($config, $themeIni); } - -?> diff --git a/controllers/admin.php b/controllers/admin.php index 905423af..7c1f0103 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -129,7 +129,7 @@ class glmMembersAdmin extends GlmPluginSupport $this->config = $config; // Check the database - allow installation of tables for a new add-on - if (!$this->checkDatabase('install')) { + if (!$this->checkDatabase()) { die('Database check failure'); } @@ -857,5 +857,3 @@ class glmMembersAdmin extends GlmPluginSupport } } - - diff --git a/controllers/front.php b/controllers/front.php index 0f6daed4..b1239470 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -53,7 +53,7 @@ class glmMembersFront extends GlmPluginSupport $this->config = $config; // Check the database - allow installation of tables for a new add-on - if (!$this->checkDatabase('install')) { + if (!$this->checkDatabase()) { die('Database check failure'); } @@ -488,4 +488,3 @@ class glmMembersFront extends GlmPluginSupport } } -?> \ No newline at end of file diff --git a/deactivate.php b/deactivate.php index 6d62b89b..dd5e3ecb 100644 --- a/deactivate.php +++ b/deactivate.php @@ -103,5 +103,3 @@ class glmMembersPluginDeactivate extends glmPluginSupport } } } - -?> \ No newline at end of file diff --git a/defines.php b/defines.php index de451292..17fce4cd 100644 --- a/defines.php +++ b/defines.php @@ -61,4 +61,3 @@ global $wpdb; define('GLM_MEMBERS_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_members_'); define('GLM_MEMBERS_PLUGIN_ACTIVE_DB_OPTION', 'glmMembersDatabaseDbVersion'); -?> diff --git a/glm-member-db.php b/glm-member-db.php index 3cdce837..77a5b0d1 100644 --- a/glm-member-db.php +++ b/glm-member-db.php @@ -200,6 +200,11 @@ $startupNotices = ''; // Get standard defined parameters require_once('defines.php'); +// Check if plugin version is not current in WordPress option and if needed updated it +if (GLM_MEMBERS_PLUGIN_VERSION != get_option('glmMembersDatabasePluginVersion')) { + update_option('glmMembersDatabasePluginVersion', GLM_MEMBERS_PLUGIN_VERSION); +} + // Get configuration require_once('config.php'); @@ -389,12 +394,14 @@ if (function_exists('is_user_logged_in')) { * * Determine which controller to load * - * The first is for displaying notices in another window, possibly for debug output. - * */ + +// If the call to this code is to display a separate debug window if (isset($_REQUEST['glmDebugWindow']) && $_REQUEST['glmDebugWindow'] == true) { glmMembersAdminNotices(true); exit; + +// Otherwise select appropriate controller } elseif (is_admin()) { require_once (GLM_MEMBERS_PLUGIN_PATH . '/controllers/admin.php'); new glmMembersAdmin($wpdb, $config); @@ -519,16 +526,6 @@ function glmMembersAdminNotices($windowed = true) } -/* - * If not doing debug, then just keep all of the debug messages cleared - */ -if (!GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - delete_option('glmMembersAdminNoticeAlerts'); - delete_option('glmMembersAdminNotices'); - delete_option('glmMembersAdminNoticeProcess'); - delete_option('glmMembersAdminNoticeDataBlocks'); -} - /* * Check if there's any startup notices in this file. (stuff that happens before we get all setup) * @@ -539,7 +536,7 @@ function glmMembersStartupNotices() { echo '

'.GLM_MEMBERS_PLUGIN_NAME.' Plugin Warning

'.$startupNotices.'

'; } if ($startupNotices != '') { - add_action('admin_notices','glmMembersStartupNotices'); + //add_action('admin_notices','glmMembersStartupNotices'); } /* @@ -552,12 +549,20 @@ if ($startupNotices != '') { * addNotice() function in the classes/glmPluginSupport.php file. Should have addNotice() * function be able to add to another option specifically for doing this. */ -$notices = get_option('glmMembersAdminNotices'); -if (is_admin() && $notices && !GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - // Add action to output the notices +// Check for any notices that need to display at the top of an admin screen +$notices = get_option('glmMembersAdminNotices'); +if (is_admin() && $notices) { add_action('admin_notices','glmMembersAdminNotices'); +} +/* + * If not doing debug, then just keep all of the debug messages cleared + */ +if (!GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + delete_option('glmMembersAdminNoticeAlerts'); +// delete_option('glmMembersAdminNotices'); + delete_option('glmMembersAdminNoticeProcess'); + delete_option('glmMembersAdminNoticeDataBlocks'); } -?> diff --git a/models/admin/management/development.php b/models/admin/management/development.php index 23a2a76f..c0f7b157 100644 --- a/models/admin/management/development.php +++ b/models/admin/management/development.php @@ -93,19 +93,18 @@ class GlmMembersAdmin_management_development public function modelAction ($actionData = false) { + $resultMessage = ''; + $success = false; + $haveMembers = false; + $import = false; + $importNotice = ''; + $haveDatabaseTableList = false; + $databaseList = false; + // Get current database version $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION; settype($dbVersion, 'string'); - $templateData['resultMessage'] = ''; - $templateData['success'] = false; - $templateData['haveNotices'] = false; - $notices = array(); - $templateData['haveMembers'] = false; - $templateData['import'] = false; - $templateData['importNotice'] = false; - $templateData['haveDatabaseTableList'] = false; - // Load database activation class to get access to database version information require_once (GLM_MEMBERS_PLUGIN_PATH . '/activate.php'); $activate = new glmMembersPluginActivate($this->wpdb, $this->config, true); @@ -145,7 +144,7 @@ class GlmMembersAdmin_management_development } } - $templateData['import'] = true; + $import = true; $templateData['membersImported'] = $Connections->doImport(); } else { @@ -157,12 +156,12 @@ class GlmMembersAdmin_management_development break; } $templateData['numbEntries'] = $c; - $importNotice = 'Connections Business Directory plugin is active.
Number of businesses listed: '.$c.'
'; + $importNotice .= 'Connections Business Directory plugin is active.
Number of businesses listed: '.$c.'
'; // Get the basic business data for review. $templateData['members'] = $Connections->getList(); if ($templateData['members'] === false) { - $importNotice = 'No businesses were retieved.'; + $importNotice .= 'No businesses were retieved.
'; break; } @@ -210,13 +209,22 @@ class GlmMembersAdmin_management_development */ case 'list': + $databaseList = array(); + // For each plug-in in the registered add-on array (includes the main plugin) - Updated for plug-able database tables foreach ($this->config['addOns'] as $a) { - $templateData['resultMessage'] .= 'Current database tables for: '.$a['name'].'
'; + $databaseList[$a['name']] = array( + 'addonName' => $a['name'], + 'haveDatabase' => false + ); if ($a['database'] ) { + // Add add-on database info to list + $databaseList[$a['name']] = array_merge_recursive($databaseList[$a['name']], $a['database']); + $databaseList[$a['name']]['haveDatabase'] = true; + // Since MYSQL considers an underscore (_) to be a single character wild-card, we need to escape them. $prefixEscaped = str_replace('_', '\_', $a['database']['dbPrefix']); @@ -224,21 +232,33 @@ class GlmMembersAdmin_management_development $existingTables = $this->wpdb->get_results(" SELECT table_name FROM information_schema.tables - WHERE table_name like '".$prefixEscaped."%'; + WHERE table_schema = '".DB_NAME."' + AND table_name like '".$prefixEscaped."%'; ", ARRAY_A); + // If we have a good list of tables if (is_array($existingTables)) { - foreach($existingTables as $t){ - $templateData['resultMessage'] .= $t['table_name'].'
'; + + // Check for request to list a table's fields + if (isset($_REQUEST['descTable'])) { + while (list ($k, $v) = each ($existingTables)) { + if ($_REQUEST['descTable'] == $v['table_name']) { + $existingTables[$k]['desctable'] = true; + $fields = $this->wpdb->get_results(" + DESCRIBE ".$v['table_name']." + ", ARRAY_A); + $existingTables[$k]['tablefields'] = $fields; + } + } } + + $databaseList[$a['name']]['tables'] = $existingTables; + } else { - $templateData['resultMessage'] .= 'No tables currently exist
'; + $databaseList[$a['name']]['tables'] = false; } - } else { - $templateData['resultMessage'] .= '(This plugin/add-on does not have database tables.)
'; } - $templateData['resultMessage'] .= '
'; } /* // Check if the database version set for this plugin is invalid. @@ -259,6 +279,14 @@ class GlmMembersAdmin_management_development } + $templateData['resultMessage'] = $resultMessage; + $templateData['success'] = $success; + $templateData['haveMembers'] = $haveMembers; + $templateData['importNotice'] = $importNotice; + $templateData['haveDatabaseTableList'] = $haveDatabaseTableList; + $templateData['databaseList'] = $databaseList; + + // Return status, suggested view, and data to controller return array( 'status' => true, @@ -363,5 +391,3 @@ class GlmMembersAdmin_management_development } } - -?> \ No newline at end of file diff --git a/uninstall.php b/uninstall.php index 49ffa279..273e3782 100644 --- a/uninstall.php +++ b/uninstall.php @@ -53,5 +53,3 @@ $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql); // Removing the tables using the script global $wpdb; $wpdb->query($sql); - -?> diff --git a/views/admin/management/development.html b/views/admin/management/development.html index b69636be..9687cbb1 100644 --- a/views/admin/management/development.html +++ b/views/admin/management/development.html @@ -110,6 +110,59 @@ {$resultMessage} {/if} + +{if $databaseList} +
+
+

List of Database Tables

+ {foreach $databaseList as $d} +
+

{$d.addonName}

+
+ {if $d.haveDatabase} + + + + + + + + + + + +
Prefix: {$d.dbPrefix}
Current Version: {$d.dbCurrentVersion}
Versions: + + {foreach $d.dbVersions as $v} + + {/foreach} +
{$v.version}Number of tables: {$v.tables}
+
Tables: + + {foreach $d.tables as $t} + + + + {if isset($t.desctable)} + + {/if} + {/foreach} +
{$t.table_name}
+ + {foreach $t.tablefields as $f} + + {/foreach} +
{$f.Field}{$f.Type}
+
+
+ {else} + (No database tables) + {/if} +
+
+ {/foreach} +
+{/if} {if $haveMembers}