From 64d27b7b7ff21479b26f404bad5fbcbe86c333f3 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 18 Feb 2016 13:23:56 -0500 Subject: [PATCH] Cleaned up some documentation, example database setup, and fixed a few bugs. --- index.php | 25 +++++++--------- setup/adminMenus.php | 2 +- .../SAMPLE.update_database_V0.0.2.sql | 30 ------------------- .../create_database_V0.0.1.sql} | 12 ++++---- .../dbVersions.php} | 4 +-- setup/databaseScripts/examples/readme.txt | 21 +++++++++++++ .../update_database_V0.0.2.php} | 20 ++++++------- .../examples/update_database_V0.0.2.sql | 21 +++++++++++++ setup/databaseScripts/readme.txt | 10 +++++-- 9 files changed, 80 insertions(+), 65 deletions(-) delete mode 100644 setup/databaseScripts/SAMPLE.update_database_V0.0.2.sql rename setup/databaseScripts/{SAMPLE.create_database_V0.0.1.sql => examples/create_database_V0.0.1.sql} (79%) rename setup/databaseScripts/{SAMPLE.dbVersions.php => examples/dbVersions.php} (90%) create mode 100644 setup/databaseScripts/examples/readme.txt rename setup/databaseScripts/{SAMPLE.update_database_V0.0.2.php => examples/update_database_V0.0.2.php} (67%) create mode 100644 setup/databaseScripts/examples/update_database_V0.0.2.sql diff --git a/index.php b/index.php index fa60ac7..5f6e10d 100644 --- a/index.php +++ b/index.php @@ -99,11 +99,19 @@ require_once('defines.php'); // Required to be able to get user capabilities when being called as a filter from the main plugin require_once(ABSPATH . 'wp-includes/pluggable.php'); +// Include defines to tell if a plugin is active +include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + /* - * Do some checks to make sure the main GLM Member DB is active and of a recceint enough version + * Do some preliminary sanity checks */ -// Function to generate message regarding main GLM Member DB plugin not installed and active +// Check if database version should be defined and it isn't - This would be a plugin/add-on setup issue +if (is_file(GLM_MEMBERS_SAMPLE_PLUGIN_PATH.'/setup/databaseScripts/dbVersions.php') && !defined('GLM_MEMBERS_SAMPLE_PLUGIN_DB_VERSION')) { + die('You have database scripts but have not defined a current database version at the top of index.php for this plugin/add-on!'); +} + +// Check for main plugin and that it's active function glmMembersSamplePluginRequired() { echo '
@@ -112,21 +120,14 @@ function glmMembersSamplePluginRequired() {
'; } - -/* - * Check installation, activation, and version of main Member DB plugin - */ -include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $plugin_name = 'glm-member-db/glm-member-db.php'; $is_active = is_plugin_active($plugin_name); - -// If it's not active, then warn user and deactivate this add-on plugin if ($is_active != '1') { add_action( 'admin_notices', 'glmMembersSamplePluginRequired' ); deactivate_plugins('/'.GLM_MEMBERS_SAMPLE_PLUGIN_SLUG.'/'.GLM_MEMBERS_SAMPLE_PLUGIN_SLUG.'.php'); } -// Function to generate message regarding main GLM Member DB plugin version is not receint enought to run this add-on +// Check for Minimum DB version for main Member DB function glmMembersPluginSampleMinVerRequired() { echo '
@@ -137,10 +138,6 @@ function glmMembersPluginSampleMinVerRequired() {
'; } - -/* - * Check for Minimum DB version for main Member DB - */ $glmMembersDatabasePluginVersion = get_option('glmMembersDatabasePluginVersion'); if (version_compare($glmMembersDatabasePluginVersion, GLM_MEMBERS_SAMPLE_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION) < 0) { define('GLM_MEMBERS_SAMPLE_MIN_VERSION_NOTE', "Members DB: $glmMembersDatabasePluginVersion, Sample Requires: ".GLM_MEMBERS_SAMPLE_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION); diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 6a1932a..fd9e3be 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -42,7 +42,7 @@ * 'GLM Sample', // Menu Title * 'glm-members-members', // Capability * 'glm-members-admin-menu-glm-sample', // Menu Slug - * function() {$this->controller('sample');}, // Called function + * function() {$this->controller('sample');}, // Called function - typically controller() with the menu name * false, // Icon URL * '92' // Menu Position * ); diff --git a/setup/databaseScripts/SAMPLE.update_database_V0.0.2.sql b/setup/databaseScripts/SAMPLE.update_database_V0.0.2.sql deleted file mode 100644 index 286cb84..0000000 --- a/setup/databaseScripts/SAMPLE.update_database_V0.0.2.sql +++ /dev/null @@ -1,30 +0,0 @@ --- Gaslight Media Members Database --- File Created: 12/09/14 15:27:15 --- Database Version: 0.0.2 --- Database Update From Previous Version Script --- --- To permit each query below to be executed separately, --- all queries must be separated by a line with four dashses - --- Package Management Settings -CREATE TABLE {prefix}management ( - id INT NOT NULL AUTO_INCREMENT, - canonical_package_page TINYTEXT NULL, -- Canonical page slug for package detail - PRIMARY KEY (id) -); - ----- - --- Set default package management entry -INSERT INTO {prefix}management - ( id, canonical_package_page ) - VALUES - ( 1, 'package-detail' ) -; - ----- - -ALTER TABLE {prefix}packages ADD COLUMN package_slug TINYTEXT; - - - diff --git a/setup/databaseScripts/SAMPLE.create_database_V0.0.1.sql b/setup/databaseScripts/examples/create_database_V0.0.1.sql similarity index 79% rename from setup/databaseScripts/SAMPLE.create_database_V0.0.1.sql rename to setup/databaseScripts/examples/create_database_V0.0.1.sql index ae98344..d4598c9 100644 --- a/setup/databaseScripts/SAMPLE.create_database_V0.0.1.sql +++ b/setup/databaseScripts/examples/create_database_V0.0.1.sql @@ -24,18 +24,18 @@ -- **********************************************************************/ --- Sample Management Settings -CREATE TABLE {prefix}management ( +-- Sample Table +CREATE TABLE {prefix}sometablename ( id INT NOT NULL AUTO_INCREMENT, - canonical_sample_page TINYTEXT NULL, -- Canonical page slug for detail + somefield TINYTEXT NULL, PRIMARY KEY (id) ); ---- --- Set default sample management entry -INSERT INTO {prefix}management - ( id, canonical_sample_page ) +-- Sample default entry in table +INSERT INTO {prefix}sometablename + ( id, somefield ) VALUES ( 1, 'sample data' ) ; diff --git a/setup/databaseScripts/SAMPLE.dbVersions.php b/setup/databaseScripts/examples/dbVersions.php similarity index 90% rename from setup/databaseScripts/SAMPLE.dbVersions.php rename to setup/databaseScripts/examples/dbVersions.php index c2b6a9f..1b9b48b 100644 --- a/setup/databaseScripts/SAMPLE.dbVersions.php +++ b/setup/databaseScripts/examples/dbVersions.php @@ -34,7 +34,7 @@ $glmMembersSampleDbVersions = array( - '0.0.1' => array('version' => '0.0.1', 'tables' => 2), - '0.0.2' => array('version' => '0.0.2', 'tables' => 3) + '0.0.1' => array('version' => '0.0.1', 'tables' => 1), + '0.0.2' => array('version' => '0.0.2', 'tables' => 2) ); diff --git a/setup/databaseScripts/examples/readme.txt b/setup/databaseScripts/examples/readme.txt new file mode 100644 index 0000000..f4f3b48 --- /dev/null +++ b/setup/databaseScripts/examples/readme.txt @@ -0,0 +1,21 @@ +DATABASE EXAMPLE FILES +---------------------- + +*** THESE ARE EXAMPLES ONLY *** + +The files in this directory are examples only. Do not use any of these as they are! + +The example here is of a set of one table for the add-on that is initially created +by the create_database_V0.0.1.sql script. That file creates one table and inserts +one entry into that table. + +In this example, the database is later updated by two files. Either of these may +be included separately if only a PHP file is needed to update the database, or +just an SQL script. Sometimes both are needed. + +There is also an entry in the dbVersions.php file that describes the update. + +Note that the number of tables needs to be set to the updated number for each update. + +Also note taht the SQL update scripts are run before the PHP update scripts. + diff --git a/setup/databaseScripts/SAMPLE.update_database_V0.0.2.php b/setup/databaseScripts/examples/update_database_V0.0.2.php similarity index 67% rename from setup/databaseScripts/SAMPLE.update_database_V0.0.2.php rename to setup/databaseScripts/examples/update_database_V0.0.2.php index c4ac161..5b47ba2 100644 --- a/setup/databaseScripts/SAMPLE.update_database_V0.0.2.php +++ b/setup/databaseScripts/examples/update_database_V0.0.2.php @@ -24,26 +24,26 @@ **********************************************************************/ /* - * Update sample records to build sample_slug field data from title + * Update sample records to take data from one field, change it, then store it in the new field */ -// Get all sample records -$sampleRecords = $this->wpdb->get_results('SELECT id, title FROM '.GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'samples;', ARRAY_A); +// Get all records from the sometablename table. +$sampleRecords = $this->wpdb->get_results('SELECT id, title FROM '.GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'sometablename;', ARRAY_A); -// If there's any sample records +// If there's any records if ($sampleRecords && count($sampleRecords) > 0) { - // For each sample record + // For each record foreach ($sampleRecords as $p) { - // Create a slug from the title - $slug = sanitize_title($p['title']).'-'.$p['id']; + // Create a slug from the somefield field + $newData = sanitize_title($p['somefield']).'-'.$p['id']; - // Store this value back into the record + // Store this value back into the record in the new yetanotherfield field $this->wpdb->update( - GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'samples', + GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'sometablename', array( - 'sample_slug' => $slug + 'yetanotherfield' => $slug ), array( 'id' => $p['id'] ), array( '%s' ), diff --git a/setup/databaseScripts/examples/update_database_V0.0.2.sql b/setup/databaseScripts/examples/update_database_V0.0.2.sql new file mode 100644 index 0000000..c8f89af --- /dev/null +++ b/setup/databaseScripts/examples/update_database_V0.0.2.sql @@ -0,0 +1,21 @@ +-- Gaslight Media Members Database +-- File Created: 12/09/14 15:27:15 +-- Database Version: 0.0.2 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + +-- A sample database update script +CREATE TABLE {prefix}anothertablename ( + id INT NOT NULL AUTO_INCREMENT, + anotherfield TINYTEXT NULL, + PRIMARY KEY (id) +); + +---- + +ALTER TABLE {prefix}sometablename ADD COLUMN yetanotherfield TINYTEXT; + + + diff --git a/setup/databaseScripts/readme.txt b/setup/databaseScripts/readme.txt index ff3b4e7..8d2866e 100644 --- a/setup/databaseScripts/readme.txt +++ b/setup/databaseScripts/readme.txt @@ -1,4 +1,10 @@ This directory contains database creation and update scripts for this add-on. -This directly is optional. If there are no data tables added by this add-on, -this directory should be omitted. +The files in this directory are checked by the checkDatabase() function in the +main plugin classes/glmPluginSupport.php file. + +This directory is optional. If there are no data tables that need to be created +for this add-on, there should be no files in this directory. The directory may +also be deleted. + +See the "examples" directory for a sample of what can go in this directory. -- 2.17.1