From: Chuck Scott Menu: $menuItem, Action = $action *** Failed checking for valid menu selection *** *** Failed checking for valid menu action *** Loop: $loopCheck *** Failed checking model file *** *** Failed checking model class name *** *** Failed checking for valid view file *** Dear User:
+ Pardon our mess, but something really went wrong with our innards here. Because of
+ that, we\'re dumping some information that hopefully will be useful to our programmers.
+ Please give us a little time to get our innards sorted out.
+ Thanks, The Management
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) {
+ $all_db_setup_status = true;
- // If $option is not 'install', then don't do it;
- if ($option != 'install') {
- return false;
- }
-
- // Get current database version
- $dbVersion = GLM_MEMBERS_PLUGIN_DB_VERSION;
+ // For each plug-in in the registered add-on array (includes the main plugin)
+ foreach ($this->config['addOns'] as $a) {
- // Read in Database creation script
- $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/create_database_V'.$dbVersion.'.sql';
- $sql = file_get_contents($sqlFile);
+ $db_setup_status = false;
- // Replace {prefix} with table name prefix
- $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+ // Has this plug-in registered any database versions
+ if ($a['database']) {
- // Split script into separate queries by looking for lines with only "---"
- $queries = preg_split('/^----$/m', $sql);
+ $dbVersion = get_option($a['database']['dbActiveVersionOption']);
- // Try executing all queries to build database
- do {
- $q = current($queries);
- $this->wpdb->query($q);
- $queryError = $this->wpdb->last_error;
- } while ($queryError == '' && next($queries));
+ // Do a quick check for there being a database version but not all the required tables for that version
+ if ($dbVersion) {
- // If there were no errors
- if (trim($queryError) == '') {
+ // Check if the database version set for this plug-in is invalid.
+ if (!isset($a['database']['dbVersions'][$dbVersion])) {
- // Notify the user that the database has been installed
- update_option('glmMembersInstallErrors', 'New database tables installed for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin.');
+ update_option(
+ 'glmMembersInstallErrors',
+ "The last database version set for the ".$a['name']." (V$dbVersion) isn't valid.");
+ return false;
+ }
- // Save the version of the installed database
- update_option('glmMembersDatabaseDbVersion', $ver);
+ // Get the number of tables for this plugin database version that should exist.
+ $tables = $a['database']['dbVersions'][$dbVersion]['tables'];
- // Indicate that we were successfull
- $db_setup_status = true;
+ // Since MYSQL considers an "_" to be a single character wild-card, we need to escape them.
+ $prefixEscaped = str_replace('_', '\_', $a['database']['dbPrefix']);
- } else {
- update_option('glmMembersInstallErrors', 'Failure installing database tables for the '.GLM_MEMBERS_PLUGIN_NAME
- .'
Database Installation Error: '.print_r($queryError,1)
- .''.$q.'
'
- );
- }
+ // Get the number of tables for this plugin that do currently exist.
+ $existingTables = $this->wpdb->get_var("
+ SELECT COUNT(*)
+ FROM information_schema.tables
+ WHERE table_schema = '".DB_NAME."'
+ AND table_name like '$prefixEscaped%';
+ ");
- // Otherwise, check if we need to update the database
- } elseif ($dbVersion != GLM_MEMBERS_PLUGIN_DB_VERSION) {
+ // If there's no tables, just assume we need to install all new ones.
+ if ($existingTables == 0) {
- // Include an admin message that we're updating the database
- $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' database tables require updating...');
+ $dbVersion = false;
- // Check if current glmMembersDatabaseDbVersion is invalid
- if (!in_array(GLM_MEMBERS_PLUGIN_DB_VERSION, $this->dbVersions)) {
- $this->addNotice('The database version currently installed for this plugin is unknown. '
- .'Unable to install/update the '.GLM_MEMBERS_PLUGIN_NAME.' plugin.
');
- }
+ // 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;
+ }
- // Traverse version list to find any required updates
- $curVerFound = false;
- $db_setup_status = true;
- foreach($this->dbVersions as $version) {
+ }
- $ver = $version['version'];
+ // If glmMembersDatabaseDbVersion is not set, install current version
+ if (!$dbVersion) {
- // Find the current version of the database
- if ($ver == $dbVersion) {
-// $this->addNotice('The database version installed for the '.GLM_MEMBERS_PLUGIN_NAME
-// .' plugin is current and does not require updating.');
- $db_setup_status = true;
- $curVerFound = true;
+ // If $option is not 'install', then don't do it;
+ if ($option != 'install') {
+ return false;
+ }
- // Otherwise if it's already been found and $ver is not the new target version
- } elseif ($curVerFound && $dbVersion != GLM_MEMBERS_PLUGIN_DB_VERSION) {
+ // Get current database version
+ $dbVersion = $a['database']['dbCurrentVersion'];
// Read in Database creation script
- $sqlFile = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/update_database_V'.$ver.'.sql';
+ $sqlFile = $a['database']['dbScriptPath'].'/create_database_V'.$dbVersion.'.sql';
$sql = file_get_contents($sqlFile);
// Replace {prefix} with table name prefix
- $sql = str_replace('{prefix}', GLM_MEMBERS_PLUGIN_DB_PREFIX, $sql);
+ $sql = str_replace('{prefix}', $a['database']['dbPrefix'], $sql);
// Split script into separate queries by looking for lines with only "---"
$queries = preg_split('/^----$/m', $sql);
- // Try executing all queries to update database
+ // Try executing all queries to build database
do {
$q = current($queries);
$this->wpdb->query($q);
$queryError = $this->wpdb->last_error;
} while ($queryError == '' && next($queries));
- // Check for PHP script to update database
- $phpScript = GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/update_database_V'.$ver.'.php';
+ // If there were no errors
+ if (trim($queryError) == '') {
- if (is_file($phpScript)) {
- include ($phpScript);
- }
+ // Notify the user that the database has been installed
+ update_option('glmMembersInstallErrors', 'New database tables installed for the '.$a['name'].' plugin.');
+
+ // Save the version of the installed database
+ update_option($a['database']['dbActiveVersionOption'], $dbVersion);
+
+ // Indicate that we were successfull
+ $db_setup_status = true;
- // If there were no errors
- if ($queryError == '') {
- $this->addNotice('The database for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin has been updated '
- .'from V'.$dbVersion.'_V'.$ver.'.');
} else {
- $this->addNotice('Failure updating the database tables for the '.GLM_MEMBERS_PLUGIN_NAME.' plugin '
- .'from V'.$dbVersion.'_V'.$ver.'.');
- $db_setup_status = false;
- $this->addNotice('Database Update Error: '.$queryError, 'Alert');
+ update_option('glmMembersInstallErrors', 'Failure installing database tables for the '.$a['name']
+ .'
Database Installation Error: '.print_r($queryError,1)
+ .''.$q.'
'
+ );
+ }
+
+ // Otherwise, check if we need to update the database
+ } elseif ($dbVersion != $a['database']['dbCurrentVersion']) {
+
+ // Include an admin message that we're updating the database
+ $this->addNotice('The '.$a['name'].' database tables require updating...');
+
+ // Check if current glmMembersDatabaseDbVersion is invalid
+ if (!in_array($a['database']['dbCurrentVersion'], $a['database']['dbVersions'])) {
+ $this->addNotice('The database version currently installed for this plugin is unknown. '
+ .'Unable to install/update the '.$a['name'].' plugin.
');
}
- $dbVersion = $ver;
+ // Traverse version list to find any required updates
+ $curVerFound = false;
$db_setup_status = true;
+ foreach($a['database']['dbVersions'] as $version) {
- }
+ $ver = $version['version'];
+
+ // Find the current version of the database
+ if ($ver == $dbVersion) {
+ // $this->addNotice('The database version installed for the '.GLM_MEMBERS_PLUGIN_NAME
+ // .' plugin is current and does not require updating.');
+ $db_setup_status = true;
+ $curVerFound = true;
+
+ // Otherwise if it's already been found and $ver is not the new target version
+ } elseif ($curVerFound && $dbVersion != $a['database']['dbCurrentVersion']) {
+
+ // Read in Database creation script
+ $sqlFile = $a['database']['dbScriptPath'].'/update_database_V'.$ver.'.sql';
+ $sql = file_get_contents($sqlFile);
+
+ // Replace {prefix} with table name prefix
+ $sql = str_replace('{prefix}', $a['database']['dbPrefix'], $sql);
+
+ // Split script into separate queries by looking for lines with only "---"
+ $queries = preg_split('/^----$/m', $sql);
+
+ // Try executing all queries to update database
+ do {
+ $q = current($queries);
+ $this->wpdb->query($q);
+ $queryError = $this->wpdb->last_error;
+ } while ($queryError == '' && next($queries));
+
+ // Check for PHP script to update database
+ $phpScript = $a['database']['dbScriptPath'].'/update_database_V'.$ver.'.php';
+
+ if (is_file($phpScript)) {
+ include ($phpScript);
+ }
+
+ // If there were no errors
+ if ($queryError == '') {
+ $this->addNotice('The database for the '.$a['name'].' plugin has been updated '
+ .'from V'.$dbVersion.'_V'.$ver.'.');
+ } else {
+ $this->addNotice('Failure updating the database tables for the '.$a['name'].' plugin '
+ .'from V'.$dbVersion.'_V'.$ver.'.');
+ $db_setup_status = false;
+ $this->addNotice('Database Update Error: '.$queryError, 'Alert');
+ }
- // Save the new version. If we've had a problem updating the database, then stop here.
- if ($db_setup_status) {
+ $dbVersion = $ver;
+ $db_setup_status = true;
- // Save the version of the installed database
- update_option('glmMembersDatabaseDbVersion', $dbVersion);
+ }
+
+ // Save the new version. If we've had a problem updating the database, then stop here.
+ if ($db_setup_status) {
+
+ // Save the version of the installed database
+ update_option($a['database']['dbActiveVersionOption'], $dbVersion);
+
+ } else {
+ break;
+ }
+
+ }
+
+ if ($db_setup_status) {
+
+ // Save the updated version of the installed database
+ // update_option('glmMembersDatabaseDbVersion', $dbVersion);
+
+ $this->addNotice('Database tables updated.');
+ }
} else {
- break;
+ $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' has been reactivated using the existing database tables.');
+ $db_setup_status = true;
}
- }
+ } else { // Plugin doesn't have registered database versions
- if ($db_setup_status) {
+ $db_setup_status = true;
- // Save the updated version of the installed database
- // update_option('glmMembersDatabaseDbVersion', $dbVersion);
+ } // Plugin has registered database versions
- $this->addNotice('Database tables updated.');
+ if (!$db_setup_status) {
+ $all_db_setup_status = false;
}
+ } // For each plugin
- } else {
- $this->addNotice('The '.GLM_MEMBERS_PLUGIN_NAME.' has been reactivated using the existing database tables.');
- $db_setup_status = true;
- }
-
- return $db_setup_status;
+ return $all_db_setup_status;
}
}
diff --git a/controllers/admin.php b/controllers/admin.php
index 09c6c277..f1872837 100644
--- a/controllers/admin.php
+++ b/controllers/admin.php
@@ -129,7 +129,12 @@ class glmMembersAdmin extends GlmPluginSupport
$this->config = $config;
// Check the database
- $this->checkDatabase();
+ if (!$this->checkDatabase('install')) {
+
+ // There was some kind of dataase failure, so die to prevent WordPress from marking plugin as activated.
+ die();
+
+ }
/*
* Check if there's a request to bypass the WordPress Dashboard and
@@ -216,8 +221,8 @@ class glmMembersAdmin extends GlmPluginSupport
trigger_error ( 'ERROR: No "glm_action" itme in POST array.', E_USER_ERROR);
}
- // Check for a valid action
- if (!isset($GLOBALS['glmMembersValidActions']['adminActions']['ajax'][$glmAction])) {
+ // Check for a valid action. This only looks in the main plugin. Might have to change this later.
+ if (!$this->config['addOns'][GLM_MEMBERS_PLUGIN_SLUG]['adminActions']['ajax'][$glmAction]) {
// Menu item/Action not in valid actions array
trigger_error ( 'ERROR: The specified action is not valid - '.$glmAction, E_USER_ERROR);
@@ -402,10 +407,14 @@ class glmMembersAdmin extends GlmPluginSupport
);
}
- // For each add-on, read in their menu additions
+ // For each add-on, read in their menu additions - These are optional files
foreach ($this->config['addOns'] as $a) {
- require_once(GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/adminMenus.php');
- require_once(GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/adminTabs.php');
+ if (is_file(GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/adminMenus.php')) {
+ require_once(GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/adminMenus.php');
+ }
+ if (is_file(GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/adminTabs.php')) {
+ require_once(GLM_MEMBERS_WORDPRESS_PLUGIN_PATH.$a['slug'].'/setup/adminTabs.php');
+ }
}
}
@@ -554,6 +563,7 @@ class glmMembersAdmin extends GlmPluginSupport
// Loop till we have a final action
$loopCheck = 0;
+ $loopTracking = "
Model: $modelName
Class: $classNameSerious failure looping on model load in "controllers/admin.php".
');
+ die('
+ Serious failure looping on model load in "controllers/admin.php".
+
{$a.print_r}+ {$a.name}
{$a.print_r}