From: Chuck Scott Date: Wed, 24 Feb 2016 19:30:25 +0000 (-0500) Subject: Better handling of database table issues X-Git-Tag: v2.0.0^2~72 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=4b140ba78e375b61c2e9f22b957fd0e07a5e8722;p=WP-Plugins%2Fglm-member-db.git Better handling of database table issues --- diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 545d8f67..b138c205 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -169,8 +169,9 @@ class GlmPluginSupport * @return boolean False if some failure * @access private */ - public function checkDatabase ($option = false) + public function checkDatabase () { + global $startupNotices; $all_db_setup_status = true; @@ -178,6 +179,7 @@ class GlmPluginSupport foreach ($this->config['addOns'] as $a) { $db_setup_status = false; + $db_error = false; // Has this plug-in registered any database versions if ($a['database']) { @@ -206,48 +208,42 @@ class GlmPluginSupport // Check if the database version set for this plug-in is invalid - not in the dbVersions array if (!isset($a['database']['dbVersions'][$dbVersion])) { - update_option( - 'glmMembersInstallErrors', - "The last database version set for the ".$a['name']." (V$dbVersion) isn't valid."); - return false; - } + $startupNotices .= "

The last database version set for the ".$a['name']." (V$dbVersion) isn't valid.

"; + $db_error = true; + } else { - // Get the number of tables for this plugin database version that should exist. - $tables = $a['database']['dbVersions'][$dbVersion]['tables']; + // Get the number of tables for this plugin database version that should exist. + $tables = $a['database']['dbVersions'][$dbVersion]['tables']; - // Since MYSQL considers an underscore (_) to be a single character wild-card, we need to escape them. - $prefixEscaped = str_replace('_', '\_', $a['database']['dbPrefix']); + // Since MYSQL considers an underscore (_) to be a single character wild-card, we need to escape them. + $prefixEscaped = str_replace('_', '\_', $a['database']['dbPrefix']); - // Get the number of tables for this plugin that match the - $existingTables = $this->wpdb->get_var(" - SELECT COUNT(*) - FROM information_schema.tables - WHERE table_schema = '".DB_NAME."' - AND table_name like '$prefixEscaped%'; - "); + // Get the number of tables for this plugin that match the + $existingTables = $this->wpdb->get_var(" + SELECT COUNT(*) + FROM information_schema.tables + WHERE table_schema = '".DB_NAME."' + AND table_name like '$prefixEscaped%'; + "); - // If there's no tables, just assume we need to install all new ones. - if ($existingTables == 0) { + // If there's no tables, just assume we need to install all new ones. + if ($existingTables == 0) { - $dbVersion = false; + $dbVersion = false; + + // Otherwise check if the number of tables is correct + } elseif ($tables != $existingTables) { + $startupNotices .= '

We do not have the correct number of tables for the currently set database version (V'.$dbVersion.') for '.$a['name'].'.' + ."
There should be $tables but there are currently $existingTables. Please call for support.

"; + $db_error = true; + } - // Otherwise check if the number of tables is correct - } elseif ($tables != $existingTables) { - update_option('glmMembersInstallErrors', 'We do not have the correct number of tables for the currently set database version (V'.$dbVersion.') for '.$a['name'].'.' - ."
There should be $tables but there are currently $existingTables. Please call for support." - ); - return false; } } // If glmMembersDatabaseDbVersion is not set, install current version - if (!$dbVersion) { - - // If $option is not 'install', then don't do it; - if ($option != 'install') { - return false; - } + if (!$dbVersion && !$db_error) { // Get current database version $dbVersion = $a['database']['dbCurrentVersion']; @@ -273,7 +269,7 @@ class GlmPluginSupport if (trim($queryError) == '') { // Notify the user that the database has been installed - update_option('glmMembersInstallErrors', 'New database tables installed for the '.$a['name'].' plugin.'); + $startupNotices .= '

New database tables installed for the '.$a['name'].' plugin.

'; // Save the version of the installed database update_option($a['database']['dbActiveVersionOption'], $dbVersion); @@ -282,10 +278,9 @@ class GlmPluginSupport $db_setup_status = true; } else { - update_option('glmMembersInstallErrors', 'Failure installing database tables for the '.$a['name'] + $startupNotices .= '

Failure installing database tables for the '.$a['name'] .'
Database Installation Error: '.print_r($queryError,1) - .'

'.$q.'
' - ); + .'
'.$q.'

'; } // Otherwise, check if we need to update the database @@ -377,9 +372,6 @@ class GlmPluginSupport } } else { - if ($option == 'install') { -// was always displaying since adding 'install' to the controllers call $this->addNotice('The '.$a['name'].' plugin/add-on has been reactivated using the existing database tables.'); - } $db_setup_status = true; } @@ -392,6 +384,15 @@ class GlmPluginSupport if (!$db_setup_status) { $all_db_setup_status = false; } + + // If there was any serious error with the database for this add-on + if ($db_error) { + // Deactivate this add-on + deactivate_plugins($a['slug'].'/index.php'); + global $startupNotices; + $startupNotices .= '

Plugin '.$a['name'].' Deactivated.

'; + + } } // For each plugin return $all_db_setup_status; @@ -519,3 +520,14 @@ function glmMembersAdminNotices($windowed = true) } +/** + * Display Git Branch as an admin warning + * + * @return void + * @access public + */ +function glmMembersInstallErrorsNotice() { + $installErrors = get_option('glmMembersInstallErrors'); + echo '

Plugin Git Branch Warning:


'.$installErrors.'
'; + delete_option('glmMembersInstallErrors'); +} diff --git a/glm-member-db.php b/glm-member-db.php index 3f000200..bf208495 100644 --- a/glm-member-db.php +++ b/glm-member-db.php @@ -425,7 +425,7 @@ if (isset($_REQUEST['glmDebugWindow']) && $_REQUEST['glmDebugWindow'] == true) { // Display any notices that need to be displayed at the top of the admin content area function glmMembersWordpressAdminNotices() { global $startupNotices; - echo '

'.GLM_MEMBERS_PLUGIN_NAME.' Plugin Warning

'.$startupNotices.'

'; + echo '
'.GLM_MEMBERS_PLUGIN_NAME.' Plugin Notice
'.$startupNotices.'
'; } if ($startupNotices != '') { add_action('admin_notices','glmMembersWordpressAdminNotices'); diff --git a/views/admin/management/addons.html b/views/admin/management/addons.html index 0154d614..69da0745 100644 --- a/views/admin/management/addons.html +++ b/views/admin/management/addons.html @@ -1,17 +1,39 @@ {include file='admin/management/header.html'}

Currently Installed and Active GLM Members DB Plugins

- + + {if $addOns} - - + +
+ {foreach $addOns as $a} + {$a.name}
+ {/foreach} +
+
+ +
{/if} {include file='admin/footer.html'}