From: Chuck Scott Date: Tue, 15 Dec 2015 15:45:53 +0000 (-0500) Subject: Cleanup to smooth database updates and diagnostics. X-Git-Tag: v1.0.49^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=2a02694568ec4c37195ed4d0f7481a8731330018;p=WP-Plugins%2Fglm-member-db.git Cleanup to smooth database updates and diagnostics. --- diff --git a/activate.php b/activate.php index f976d0d6..db36506b 100644 --- a/activate.php +++ b/activate.php @@ -67,8 +67,7 @@ class glmMembersPluginActivate extends glmPluginSupport // Make sure the current user has this capability if (! current_user_can('activate_plugins')) { - $this->addNotice("Interesting, you don't have permission to activate plugins."); - die(); + die("Interesting, you don't have permission to activate plugins."); } // Save WordPress Database object @@ -79,9 +78,8 @@ class glmMembersPluginActivate extends glmPluginSupport if (!$noDatabaseCheck) { - // Check the database and permit installation of a new database tables if they doesn't exist and any updates + // Check the database - allow installation of tables for a new add-on if (!$this->checkDatabase('install')) { - // There was some kind of database failure, this is fatal so die die('Database check failure'); } diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 008ed9c6..0fcb27d8 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -186,9 +186,8 @@ class GlmPluginSupport // Do a quick check for there being a database version but not all the required tables for that version if ($dbVersion) { - // Check if the database version set for this plug-in is invalid. + // 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."); @@ -198,10 +197,10 @@ class GlmPluginSupport // Get the number of tables for this plugin database version that should exist. $tables = $a['database']['dbVersions'][$dbVersion]['tables']; - // Since MYSQL considers an "_" to be a single character wild-card, we need to escape them. + // 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 do currently exist. + // Get the number of tables for this plugin that match the $existingTables = $this->wpdb->get_var(" SELECT COUNT(*) FROM information_schema.tables diff --git a/controllers/admin.php b/controllers/admin.php index f9d6b332..e9091401 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -109,12 +109,12 @@ class glmMembersAdmin extends GlmPluginSupport /** * Admin Controller Constructor * - * This contructor is executed by the main plugin index file when the site + * This constructor is executed by the main plugin index file when the site * Dashboard is displayed. It's responsible for setting up any needed hooks * into WordPress and setting up any support classes required to do admin * work. * - * (no prameters) + * (no parameter) * * @return void * @access public @@ -128,12 +128,9 @@ class glmMembersAdmin extends GlmPluginSupport // Save plugin configuration object $this->config = $config; - // Check the database + // Check the database - allow installation of tables for a new add-on if (!$this->checkDatabase('install')) { - - // There was some kind of dataase failure, so die to prevent WordPress from marking plugin as activated. - die(); - + die('Database check failure'); } /* diff --git a/controllers/front.php b/controllers/front.php index b7abbfc8..a863b577 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -52,9 +52,8 @@ class glmMembersFront extends GlmPluginSupport // Save plugin configuration object $this->config = $config; - // Check the database and permit installation of a new database tables if they doesn't exist and any updates + // Check the database - allow installation of tables for a new add-on if (!$this->checkDatabase('install')) { - // There was some kind of database failure, this is fatal so die die('Database check failure'); } diff --git a/glm-member-db.php b/glm-member-db.php index 92fcf550..93615297 100644 --- a/glm-member-db.php +++ b/glm-member-db.php @@ -28,10 +28,12 @@ * Note that the database version matches the version of the last * plugin version where there was a change in the database. * - * Updates to checkDatabase() in glmPluginSupport.php must be - * made together with the DB_VERSION below. ONLY bump the DB - * version when there's a change in the database!! Use the - * version number of that release for the DB version. + * Database updates for the main plugin and add-ons must also be + * listed in the /setup/databaseScripts/dbVersions.php file of + * the corresponding plugin/add-on. The table in that file + * determines which version is installed for a new activation + * and which update scrips are run to bring the database up to + * the current version. */ define('GLM_MEMBERS_PLUGIN_VERSION', '1.0.48'); diff --git a/models/admin/management/addons.php b/models/admin/management/addons.php index 0ec82ddf..31f74469 100644 --- a/models/admin/management/addons.php +++ b/models/admin/management/addons.php @@ -94,6 +94,7 @@ class GlmMembersAdmin_management_addons $addOns = array(); foreach ($this->config['addOns'] as $a) { + $a['shortcodesDescription'] = '(not shown here - see "Shortcodes" menu)
'; $addOns[$a['slug']] = $a; $d = print_r($a,1); $dTrimmed = substr($d, 8, strlen($d)-11); diff --git a/models/admin/management/development.php b/models/admin/management/development.php index 6fdb845e..23a2a76f 100644 --- a/models/admin/management/development.php +++ b/models/admin/management/development.php @@ -175,7 +175,7 @@ class GlmMembersAdmin_management_development } break; - +/* case 'drop': case 'reset': @@ -207,9 +207,40 @@ class GlmMembersAdmin_management_development } break; - +*/ case 'list': + // 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'].'
'; + + if ($a['database'] ) { + + // 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 do currently exist. + $existingTables = $this->wpdb->get_results(" + SELECT table_name + FROM information_schema.tables + WHERE table_name like '".$prefixEscaped."%'; + ", ARRAY_A); + + if (is_array($existingTables)) { + foreach($existingTables as $t){ + $templateData['resultMessage'] .= $t['table_name'].'
'; + } + } else { + $templateData['resultMessage'] .= 'No tables currently exist
'; + } + } 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. if (!isset($activate->dbVersions[$dbVersion])) { $templateData['resultMessage'] .= "The last database version set for the ".GLM_MEMBERS_PLUGIN_NAME." (V$dbVersion) isn't valid.
"; @@ -218,27 +249,7 @@ class GlmMembersAdmin_management_development // Get the number of tables for this plugin database version that should exist. $tables = $activate->dbVersions[$dbVersion]['tables']; - - // Get the number of tables for this plugin that do currently exist. - $existingTables = $this->wpdb->get_results(" - SELECT table_name - FROM information_schema.tables - WHERE table_name like '".GLM_MEMBERS_PLUGIN_DB_PREFIX."%'; - ", ARRAY_A); - - if (is_array($existingTables)) { - - - - - $templateData['resultMessage'] .= 'Current database tables
'; - } else { - $templateData['resultMessage'] .= 'No tables currently exist
'; - } +*/ break; diff --git a/views/admin/management/development.html b/views/admin/management/development.html index 4ce4fe2b..7d2ad628 100644 --- a/views/admin/management/development.html +++ b/views/admin/management/development.html @@ -90,9 +90,11 @@

Database