* @return boolean False if some failure
* @access private
*/
- public function checkDatabase ($option = false)
+ public function checkDatabase ()
{
+ global $startupNotices;
$all_db_setup_status = true;
foreach ($this->config['addOns'] as $a) {
$db_setup_status = false;
+ $db_error = false;
// Has this plug-in registered any database versions
if ($a['database']) {
// 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 .= "<p>The last database version set for the ".$a['name']." (V$dbVersion) isn't valid.<p>";
+ $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 .= '<p>We do not have the correct number of tables for the currently set database version (V'.$dbVersion.') for '.$a['name'].'.'
+ ."<br>There should be $tables but there are currently $existingTables. Please call for support.</p>";
+ $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'].'.'
- ."<br>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'];
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 .= '<P>New database tables installed for the '.$a['name'].' plugin.</P>';
// Save the version of the installed database
update_option($a['database']['dbActiveVersionOption'], $dbVersion);
$db_setup_status = true;
} else {
- update_option('glmMembersInstallErrors', 'Failure installing database tables for the '.$a['name']
+ $startupNotices .= '<P>Failure installing database tables for the '.$a['name']
.'<br><b>Database Installation Error:</b> '.print_r($queryError,1)
- .'<br><pre>'.$q.'</pre>'
- );
+ .'<br><pre>'.$q.'</pre></P>';
}
// Otherwise, check if we need to update the database
}
} 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;
}
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 .= '<p>Plugin '.$a['name'].' Deactivated.<p>';
+
+ }
} // For each plugin
return $all_db_setup_status;
}
+/**
+ * Display Git Branch as an admin warning
+ *
+ * @return void
+ * @access public
+ */
+function glmMembersInstallErrorsNotice() {
+ $installErrors = get_option('glmMembersInstallErrors');
+ echo '<div class="error"><h3 class="glm-error">Plugin Git Branch Warning:</h3><br>'.$installErrors.'</div>';
+ delete_option('glmMembersInstallErrors');
+}