From: Chuck Scott Date: Thu, 3 Dec 2015 18:48:51 +0000 (-0500) Subject: Completed reword for Plugable DB capabilities for add-ons. X-Git-Tag: v1.0.45^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=7528decbd26a226d1c2965566df3bfd4e86c302b;p=WP-Plugins%2Fglm-member-db.git Completed reword for Plugable DB capabilities for add-ons. --- diff --git a/activate.php b/activate.php index 25f3e828..f976d0d6 100644 --- a/activate.php +++ b/activate.php @@ -79,12 +79,10 @@ class glmMembersPluginActivate extends glmPluginSupport if (!$noDatabaseCheck) { - // Check the database and permit installation of a new database if it doesn't exist; + // Check the database and permit installation of a new database tables if they doesn't exist and any updates if (!$this->checkDatabase('install')) { - - // There was some kind of dataase failure, so die to prevent WordPress from marking plugin as activated. - die(); - + // There was some kind of database failure, this is fatal so die + die('Database check failure'); } // Check for plugin uploads directory diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index f1efbfd7..008ed9c6 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -20,27 +20,6 @@ class GlmPluginSupport { - /** - * Plugin Versions - * - * An array of past and current Member Database versions. - * Note that Database Versions match plugin versions. - * - * Each entry below uses a key so code can find data on - * a specific version and in the values are the version - * again and the proper number of tables that should - * exist with that version. - * - * @var $Versions - * @access private - */ - public $dbVersions = array( - '0.1' => array('version' => '0.1', 'tables' => 26), - '1.0.28' => array('version' => '1.0.28', 'tables' => 26), - '1.0.30' => array('version' => '1.0.30', 'tables' => 26), - '1.0.43' => array('version' => '1.0.43', 'tables' => 26) - ); - /* * Add a message to the 'glmMembersAdminNotices' option for output later. * @@ -186,191 +165,218 @@ class GlmPluginSupport * @param string $option Set to 'install' to permit installation of the database. * @param string $default Whether capability should be on by default * - * @return void + * @return boolean False if some failure * @access private */ public function checkDatabase ($option = false) { - $dbVersion = get_option('glmMembersDatabaseDbVersion'); - $db_setup_status = false; - - // 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 plugin is invalid. - if (!isset($this->dbVersions[$dbVersion])) { - update_option('glmMembersInstallErrors', "The last database version set for the ".GLM_MEMBERS_PLUGIN_NAME." (V$dbVersion) isn't valid."); - return false; - } - - // Get the number of tables for this plugin database version that should exist. - $tables = $this->dbVersions[$dbVersion]['tables']; - - // 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 '".GLM_MEMBERS_PLUGIN_DB_PREFIX."%'; - "); - - // If there's no tables, just assume we need to install all new ones. - if ($existingTables == 0) { - $dbVersion = false; - - // 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 '.GLM_MEMBERS_PLUGIN_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) { + $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 = "

Menu: $menuItem, Action = $action

"; $actionData = false; do { @@ -564,7 +574,7 @@ class glmMembersAdmin extends GlmPluginSupport $modelRedirect = false; // Verify that we have the requested menu item in the valid actions - if (!isset($GLOBALS['glmMembersValidActions']['adminActions'][$menuItem])) { + if (!isset($this->config['validActions']['adminActions'][$menuItem])) { if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { $this->addNotice('Error in Admin Controller: Menu Item not specified!', 'Alert'); @@ -575,11 +585,12 @@ class glmMembersAdmin extends GlmPluginSupport $action = 'index'; $errorMsg .= "Menu not in valid list: ".$menuItem; + $loopTracking .= "

*** Failed checking for valid menu selection ***

"; } // Verify Menu item and action using array at top of this file - if (! isset($GLOBALS['glmMembersValidActions']['adminActions'][$menuItem]) || - ! isset($GLOBALS['glmMembersValidActions']['adminActions'][$menuItem][$action])) { + if (! isset($this->config['validActions']['adminActions'][$menuItem]) || + ! isset($this->config['validActions']['adminActions'][$menuItem][$action])) { if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { $this->addNotice('Error in Admin Controller: Requested Menu Item is invalid! - '.$menuItem, 'Alert'); @@ -587,6 +598,9 @@ class glmMembersAdmin extends GlmPluginSupport $menuItem = 'error'; $action = 'badAction'; + + $loopTracking .= "

*** Failed checking for valid menu action ***

"; + } /* @@ -594,11 +608,12 @@ class glmMembersAdmin extends GlmPluginSupport */ // Get name of plugin where model and view are located - $plugIn = $GLOBALS['glmMembersValidActions']['adminActions'][$menuItem][$action]; + $plugIn = $this->config['validActions']['adminActions'][$menuItem][$action]; // Build model and path and class names $modelName = GLM_MEMBERS_WORDPRESS_PLUGIN_PATH . "$plugIn/models/admin/$menuItem/$action.php"; $className = 'GlmMembersAdmin_' . $menuItem . '_' . $action; + $loopTracking .= "

Loop: $loopCheck
Model: $modelName
Class: $className

"; // Create hook to add page tabs by add-on plugins $addOnTabs = array(); @@ -620,6 +635,8 @@ class glmMembersAdmin extends GlmPluginSupport $action = 'index'; $errorMsg .= "Model doesn't exist: ".$modelName; + $loopTracking .= "

*** Failed checking model file ***

"; + // Otherwise, load and run the model } else { @@ -638,6 +655,8 @@ class glmMembersAdmin extends GlmPluginSupport $action = 'index'; $errorMsg .= "Model class doesn't exist: ".$className; + $loopTracking .= "

*** Failed checking model class name ***

"; + } else { // Check if this is a re-direct with parameters @@ -687,6 +706,8 @@ class glmMembersAdmin extends GlmPluginSupport $menuItem = 'error'; $action = 'index'; $errorMsg .= "Bad or missing view file: ".$view; + + $loopTracking .= "

*** Failed checking for valid view file ***

"; } } // model class exists @@ -694,7 +715,21 @@ class glmMembersAdmin extends GlmPluginSupport // This is just a sanity check on this loop to keep it from getting out of control if (++$loopCheck > 10) { - die('

Serious failure looping on model load in "controllers/admin.php".

'); + die(' +

Serious failure looping on model load in "controllers/admin.php".

+
+

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

+
+

+ '.$loopTracking + ); } if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG && $modelRedirect) { diff --git a/controllers/front.php b/controllers/front.php index c8319169..30a95264 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -52,8 +52,11 @@ class glmMembersFront extends GlmPluginSupport // Save plugin configuration object $this->config = $config; - // Check if database needs to be setup or updated - $this->checkDatabase(); + // Check the database and permit installation of a new database tables if they doesn't exist and any updates + if (!$this->checkDatabase('install')) { + // There was some kind of database failure, this is fatal so die + die('Database check failure'); + } // Setup rewrite for member detail pages add_filter( 'rewrite_rules_array', @@ -312,7 +315,7 @@ class glmMembersFront extends GlmPluginSupport // Verify that we have the requested menu item in the valid actions - if (! isset($GLOBALS['glmMembersValidActions']['frontActions'][$menuItem])) { + if (! isset($this->config['validActions']['frontActions'][$menuItem])) { $modelRedirect = true; $menuItem = 'error'; $action = 'index'; @@ -320,9 +323,9 @@ class glmMembersFront extends GlmPluginSupport } // Verify Menu item and action using array at top of this file - if (! isset($GLOBALS['glmMembersValidActions']['frontActions']) || + if (! isset($this->config['validActions']['frontActions']) || ! isset($action, - $GLOBALS['glmMembersValidActions']['frontActions'][$menuItem])) { + $this->config['validActions']['frontActions'][$menuItem])) { $menuItem = 'error'; $action = 'badAction'; } diff --git a/defines.php b/defines.php index 01e8d32c..9186de5f 100644 --- a/defines.php +++ b/defines.php @@ -41,7 +41,8 @@ define('GLM_MEMBERS_PLUGIN_MEDIA_URL', $WPUploadDir['baseurl'].'/'.GLM_MEMBERS_P // Directories define('GLM_MEMBERS_PLUGIN_PATH', dirname(__FILE__)); -define('GLM_MEMBERS_PLUGIN_DB_SCRIPTS', dirname(__FILE__).'/misc/databaseScripts'); +define('GLM_MEMBERS_PLUGIN_SETUP_PATH', GLM_MEMBERS_PLUGIN_PATH.'/setup'); +define('GLM_MEMBERS_PLUGIN_DB_SCRIPTS', GLM_MEMBERS_PLUGIN_SETUP_PATH.'/databaseScripts'); define('GLM_MEMBERS_PLUGIN_CLASS_PATH', GLM_MEMBERS_PLUGIN_PATH.'/classes'); define('GLM_MEMBERS_PLUGIN_LIB_PATH', GLM_MEMBERS_PLUGIN_PATH.'/lib'); define('GLM_MEMBERS_PLUGIN_MEDIA_PATH', $WPUploadDir['basedir'].'/'.GLM_MEMBERS_PLUGIN_SLUG); @@ -51,8 +52,9 @@ define('GLM_MEMBERS_PLUGIN_CONFIG_PATH', GLM_MEMBERS_PLUGIN_PATH.'/config'); $pluginsPath = str_replace(GLM_MEMBERS_PLUGIN_SLUG, '', GLM_MEMBERS_PLUGIN_PATH); define('GLM_MEMBERS_WORDPRESS_PLUGIN_PATH', $pluginsPath); -// Database table prefixes +// Database defines 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 eace6ca5..ead4b9c6 100644 --- a/glm-member-db.php +++ b/glm-member-db.php @@ -37,81 +37,6 @@ define('GLM_MEMBERS_PLUGIN_VERSION', '1.0.44'); define('GLM_MEMBERS_PLUGIN_DB_VERSION', '1.0.43'); -/** - * Array of valid menu items and actions. - * - * The higher level elements are valid menu items. These correlate to - * actual menu or sub menu items that are hooks back to this controller - * class. - * - * The lower level items below each menu item are actions that may be specified - * by a "glmMembersAction" form field. - * - * The string after the action is the slug of the plugin where the model/view - * is to perform that action. - * - * This array is extended to include valid menus and actions from any add-on - * plugins. - */ -$GLOBALS['glmMembersValidActions'] = array( - 'adminActions' => array( - 'ajax' => array( - 'imageUpload' => 'glm-member-db' - ), - 'dashboardWidget' => array( - 'index' => 'glm-member-db' - ), - 'members' => array( - 'index' => 'glm-member-db', // member list - 'list' => 'glm-member-db', - 'reports' => 'glm-member-db', - 'other' => 'glm-member-db' - ), - 'member' => array( - 'index' => 'glm-member-db', // Member Dashboard - 'memberInfo' => 'glm-member-db', - 'locations' => 'glm-member-db', - 'facilities' => 'glm-member-db', - 'activities' => 'glm-member-db', - 'accommodations' => 'glm-member-db' - ) - , - 'configure' => array( - 'index' => 'glm-member-db', // Member Types - 'categories' => 'glm-member-db', - 'cities' => 'glm-member-db', - 'regions' => 'glm-member-db', - 'accommodationTypes' => 'glm-member-db', - 'amenities' => 'glm-member-db' - ), - 'management' => array( - 'index' => 'glm-member-db', // General Options - 'terms' => 'glm-member-db', - 'development' => 'glm-member-db', - 'import' => 'glm-member-db', - 'addons' => 'glm-member-db', - 'hooks' => 'glm-member-db' - ), - 'shortcodes' => array( - 'index' => 'glm-member-db' - ), - 'error' => array( - 'index' => 'glm-member-db', - 'badAction' => 'glm-member-db' - ) - ), - 'frontActions' => array( - 'members' => array( - 'list' => 'glm-member-db', - 'detail' => 'glm-member-db' - ), - 'error' => array( - 'index' => 'glm-member-db', - 'badAction' => 'glm-member-db' - ) - ) -); - /* * Copyright 2014 Charles Scott (email : cscott@gaslightmedia.com) * @@ -283,19 +208,78 @@ add_option('glmMembersDatabaseDbVersion', false); * * Hook in add-ons and integrate their actions * + * Each add-on should add an array element to the supplied array using the following structure. + * + * $addOns[{slug for add-on}] = array( + * 'dir' => {path to add-on directory}, + * 'name' => {text name for add-on}, + * 'short_name' => {an abreviated name for the add-on}, + * 'slug' => {slug for add-on}, + * 'actions' => array( + * 'adminActions => array( + * '{menu name}' => array( + * '{action}' => '{add-on slug}', + * ... additional actions ... + * ), + * ... additional menu names ... + * 'frontActions' => array( + * '{page}' => array( + * '{action name}' => '{add-on slug}', + * ... addional actions --- + * ), + * ... additional pages ... + * ) + * ), + * // if the add-on is adding database tables use this, otherwise FALSE + * 'database' => array( + * 'dbPrefix' => '{database prefix to use}', + * 'dbCurrentVersion' => '{current add-on database version number}', + * 'dbActiveVersionOption' => '{option name used to get current active database version}', + * 'dbScriptPath' => '{full path to add-on database scripts directory}', + * 'dbVersions' => array( + * '{version#}' => array('version' => '{version#}', 'tables' => {# of tables}, + * ... additional versions in order of version number - highest is last --- + * ) + * + * ) + * + * Note that the database prefix must not start with 'glm_members_'. It can however be something + * like 'glm_membersPackaging_', otherwise the tables will be counted along with those of the main + * plugin and database checks will fail. + * + * Also note that the default array includes information on the main member db plugin. This is + * done for consistency, particularly for database maintenance */ +require_once(GLM_MEMBERS_PLUGIN_SETUP_PATH.'/validActions.php'); +require_once(GLM_MEMBERS_PLUGIN_DB_SCRIPTS.'/dbVersions.php'); +$config['addOns'] = array( + GLM_MEMBERS_PLUGIN_SLUG => array( + 'dir' => GLM_MEMBERS_PLUGIN_PATH, + 'name' => GLM_MEMBERS_PLUGIN_NAME, + 'short_name' => GLM_MEMBERS_PLUGIN_SHORT_NAME, + 'slug' => GLM_MEMBERS_PLUGIN_SLUG, + 'actions' => $glmMembersValidActions, + 'database' => array( + 'dbPrefix' => GLM_MEMBERS_PLUGIN_DB_PREFIX, + 'dbCurrentVersion' => GLM_MEMBERS_PLUGIN_DB_VERSION, + 'dbActiveVersionOption' => GLM_MEMBERS_PLUGIN_ACTIVE_DB_OPTION, + 'dbScriptPath' => GLM_MEMBERS_PLUGIN_DB_SCRIPTS, + 'dbVersions' => $glmMembersDbVersions + ) + ) +); // Create hook for registering add-on plugins and their features -$config['addOns'] = array(); $config['addOns'] = apply_filters('glm-member-db-register-addon', $config['addOns']); // If any add-ons have registered, integrate their actions and drop the actions array from the $config object as they're not needed there +$config['validActions'] = array(); if (count($config['addOns']) > 0) { foreach ($config['addOns'] as $a) { - // Add valid actions from add-on + // Add valid actions if (isset($a['actions'])) { - $GLOBALS['glmMembersValidActions'] = array_merge_recursive($GLOBALS['glmMembersValidActions'], $a['actions']); + $config['validActions'] = array_merge_recursive($config['validActions'], $a['actions']); } // Check for add-on config file diff --git a/models/admin/ajax/imageUpload.php b/models/admin/ajax/imageUpload.php index b6d1a21d..f5978478 100644 --- a/models/admin/ajax/imageUpload.php +++ b/models/admin/ajax/imageUpload.php @@ -83,7 +83,7 @@ class GlmMembersAdmin_ajax_imageUpload extends GlmDataImages 'message' => '' ); - // Check for valid refType - See glmMembersAdminValidActions in Admin Controller + // Check for valid refType - See validActions in Admin Controller if (!isset($_REQUEST['glm_refType']) || !isset($this->config['ref_type_table'][$_REQUEST['glm_refType']])) { $return['message'] = 'Invalid target table does not exists!'; echo json_encode($return); diff --git a/models/admin/management/addons.php b/models/admin/management/addons.php index 27ee536b..0ec82ddf 100644 --- a/models/admin/management/addons.php +++ b/models/admin/management/addons.php @@ -95,7 +95,9 @@ class GlmMembersAdmin_management_addons foreach ($this->config['addOns'] as $a) { $addOns[$a['slug']] = $a; - $addOns[$a['slug']]['print_r'] = print_r($a,1); + $d = print_r($a,1); + $dTrimmed = substr($d, 8, strlen($d)-11); + $addOns[$a['slug']]['print_r'] = print_r($dTrimmed, 1); } // Return status, suggested view, and data to controller diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php new file mode 100644 index 00000000..2819fd88 --- /dev/null +++ b/setup/databaseScripts/dbVersions.php @@ -0,0 +1,33 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release dbVersions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/** + * Database Versions + * + * An array of past and current Member Database versions. + * + * Each entry below uses a key so code can find data on + * a specific version and in the values are the version + * again and the proper number of tables that should + * exist with that version. + */ +$glmMembersDbVersions = array( + '0.1' => array('version' => '0.1', 'tables' => 26), + '1.0.28' => array('version' => '1.0.28', 'tables' => 26), + '1.0.30' => array('version' => '1.0.30', 'tables' => 26), + '1.0.43' => array('version' => '1.0.43', 'tables' => 26) +); + + diff --git a/setup/validActions.php b/setup/validActions.php new file mode 100644 index 00000000..e4f28f3f --- /dev/null +++ b/setup/validActions.php @@ -0,0 +1,109 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release admin.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * Array of valid menu items and actions. + * + * The higher level elements are valid menu items. These correlate to + * actual menu or sub menu items that are hooks back to this controller + * class. + * + * The lower level items below each menu item are actions that may be specified + * by a "glmMembersAction" form field. + * + * The string after the action is the slug of the plugin where the model/view + * is to perform that action. + * + * This array is integrated into the valid actions array in the main GLM Member + * DB plugin when this plugin registers itself. + */ + +/** + * Array of valid menu items and actions. + * + * The higher level elements are valid menu items. These correlate to + * actual menu or sub menu items that are hooks back to this controller + * class. + * + * The lower level items below each menu item are actions that may be specified + * by a "glmMembersAction" form field. + * + * The string after the action is the slug of the plugin where the model/view + * is to perform that action. + * + * This array is extended to include valid menus and actions from any add-on + * plugins. + */ + +$glmMembersValidActions = array( + 'adminActions' => array( + 'ajax' => array( + 'imageUpload' => 'glm-member-db' + ), + 'dashboardWidget' => array( + 'index' => 'glm-member-db' + ), + 'members' => array( + 'index' => 'glm-member-db', // member list + 'list' => 'glm-member-db', + 'reports' => 'glm-member-db', + 'other' => 'glm-member-db' + ), + 'member' => array( + 'index' => 'glm-member-db', // Member Dashboard + 'memberInfo' => 'glm-member-db', + 'locations' => 'glm-member-db', + 'facilities' => 'glm-member-db', + 'activities' => 'glm-member-db', + 'accommodations' => 'glm-member-db' + ) + , + 'configure' => array( + 'index' => 'glm-member-db', // Member Types + 'categories' => 'glm-member-db', + 'cities' => 'glm-member-db', + 'regions' => 'glm-member-db', + 'accommodationTypes' => 'glm-member-db', + 'amenities' => 'glm-member-db' + ), + 'management' => array( + 'index' => 'glm-member-db', // General Options + 'terms' => 'glm-member-db', + 'development' => 'glm-member-db', + 'import' => 'glm-member-db', + 'addons' => 'glm-member-db', + 'hooks' => 'glm-member-db' + ), + 'shortcodes' => array( + 'index' => 'glm-member-db' + ), + 'error' => array( + 'index' => 'glm-member-db', + 'badAction' => 'glm-member-db' + ) + ), + 'frontActions' => array( + 'members' => array( + 'list' => 'glm-member-db', + 'detail' => 'glm-member-db' + ), + 'error' => array( + 'index' => 'glm-member-db', + 'badAction' => 'glm-member-db' + ) + ) +); + +?> \ No newline at end of file diff --git a/views/admin/management/addons.html b/views/admin/management/addons.html index 76dcda74..0154d614 100644 --- a/views/admin/management/addons.html +++ b/views/admin/management/addons.html @@ -1,14 +1,14 @@ {include file='admin/management/header.html'} -

Currently Installed and Active GLM Members DB Add-Ons

+

Currently Installed and Active GLM Members DB Plugins

{if $addOns}