Cleanup to smooth database updates and diagnostics.
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 15 Dec 2015 15:45:53 +0000 (10:45 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 15 Dec 2015 15:45:53 +0000 (10:45 -0500)
activate.php
classes/glmPluginSupport.php
controllers/admin.php
controllers/front.php
glm-member-db.php
models/admin/management/addons.php
models/admin/management/development.php
views/admin/management/development.html

index f976d0d..db36506 100644 (file)
@@ -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');
             }
 
index 008ed9c..0fcb27d 100644 (file)
@@ -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
index f9d6b33..e909140 100644 (file)
@@ -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');
         }
 
         /*
index b7abbfc..a863b57 100644 (file)
@@ -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');
         }
 
index 92fcf55..9361529 100644 (file)
  *  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');
index 0ec82dd..31f7446 100644 (file)
@@ -94,6 +94,7 @@ class GlmMembersAdmin_management_addons
         $addOns = array();
 
         foreach ($this->config['addOns'] as $a) {
+            $a['shortcodesDescription'] = '<span class="glm-notice">(not shown here - see "Shortcodes" menu)</span><br />';
             $addOns[$a['slug']] = $a;
             $d = print_r($a,1);
             $dTrimmed = substr($d, 8, strlen($d)-11);
index 6fdb845..23a2a76 100644 (file)
@@ -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'] .= '<b>Current database tables for: '.$a['name'].'</b><br><div style="margin-left: 2em; margin-bottom: 2em;">';
+
+                    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'].'<br>';
+                            }
+                        } else {
+                            $templateData['resultMessage'] .= '<b>No tables currently exist</b><br>';
+                        }
+                    } else {
+                        $templateData['resultMessage'] .= '(This plugin/add-on does not have database tables.)<br>';
+                    }
+
+                     $templateData['resultMessage'] .= '</div>';
+                }
+/*
                 // 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.<br>";
@@ -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'] .= '<b>Current database tables</b><br><ul>';
-                    foreach($existingTables as $t){
-                        $templateData['resultMessage'] .= "<li>".$t['table_name'].'</li><br>';
-                    }
-                    $templateData['resultMessage'] .= '</ul>';
-                } else {
-                    $templateData['resultMessage'] .= '<b>No tables currently exist</b><br>';
-                }
+*/
 
                 break;
 
index 4ce4fe2..7d2ad62 100644 (file)
             </ul>
             <H3>Database</H3>
             <ul>
+<!-- These need to be converted to using the dbVersions tables for all plugins             
                 <li><a href="{$thisURL}?page={$thisPage}&glm_action=development&option=drop">Drop database tables</a> (WARNING: Destroys all current data)</li>
                 <li><a href="{$thisURL}?page={$thisPage}&glm_action=development&option=create">Create database tables</a></li>
                 <li><a href="{$thisURL}?page={$thisPage}&glm_action=development&option=reset">Fully Reset Database (drop/create)</a> (WARNING: Destroys all current data)</li>
+-->                
                 <li><a href="{$thisURL}?page={$thisPage}&glm_action=development&option=list">List database tables</a></li>
             </ul>
         </li>