From: Chuck Scott Date: Thu, 18 Feb 2016 18:23:56 +0000 (-0500) Subject: Cleaned up some documentation, example database setup, and fixed a few bugs. X-Git-Tag: v0.0.7^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=64d27b7b7ff21479b26f404bad5fbcbe86c333f3;p=WP-Plugins%2Fglm-member-db-sample.git Cleaned up some documentation, example database setup, and fixed a few bugs. --- 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.create_database_V0.0.1.sql b/setup/databaseScripts/SAMPLE.create_database_V0.0.1.sql deleted file mode 100644 index ae98344..0000000 --- a/setup/databaseScripts/SAMPLE.create_database_V0.0.1.sql +++ /dev/null @@ -1,42 +0,0 @@ --- Gaslight Media Members Database - Sample --- File Created: 12/02/15 15:27:15 --- Database Version: 0.0.1 --- Database Creation Script --- --- This file is called to create a new set of tables for this --- add-on for the most receint database version for this add-on. --- --- There should only be one such file in this directory --- --- To permit each query below to be executed separately, --- all queries must be separated by a line with four dashes - - --- ********************************************************************** --- NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED --- --- Please change all references to sample, Sample, or SAMPLE to a name --- appropriate for your new Add-On. --- --- Tables and queries in this file are sample only. --- --- Remove this message before using this file in production! --- **********************************************************************/ - - --- Sample Management Settings -CREATE TABLE {prefix}management ( - id INT NOT NULL AUTO_INCREMENT, - canonical_sample_page TINYTEXT NULL, -- Canonical page slug for detail - PRIMARY KEY (id) -); - ----- - --- Set default sample management entry -INSERT INTO {prefix}management - ( id, canonical_sample_page ) - VALUES - ( 1, 'sample data' ) -; - diff --git a/setup/databaseScripts/SAMPLE.dbVersions.php b/setup/databaseScripts/SAMPLE.dbVersions.php deleted file mode 100644 index c2b6a9f..0000000 --- a/setup/databaseScripts/SAMPLE.dbVersions.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @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/ - */ - - -/********************************************************************** - * NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED - * - * Please change all references to sample, Sample, or SAMPLE to a name - * appropriate for your new Add-On. - * - * This file lists all versions of the database tables for this add-on. - * The last entry in the array below should be for the most recent - * version and should match the "create_database_V..." file in this - * directory. - * - * NOTE: When first creating a new add-on with database tables, there - * should only be one line in the array below and there should be no - * "update_database..." files in this directory. - * - * Remove this message before using this file in production! - **********************************************************************/ - - -$glmMembersSampleDbVersions = array( - '0.0.1' => array('version' => '0.0.1', 'tables' => 2), - '0.0.2' => array('version' => '0.0.2', 'tables' => 3) -); - diff --git a/setup/databaseScripts/SAMPLE.update_database_V0.0.2.php b/setup/databaseScripts/SAMPLE.update_database_V0.0.2.php deleted file mode 100644 index c4ac161..0000000 --- a/setup/databaseScripts/SAMPLE.update_database_V0.0.2.php +++ /dev/null @@ -1,54 +0,0 @@ -wpdb->get_results('SELECT id, title FROM '.GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'samples;', ARRAY_A); - -// If there's any sample records -if ($sampleRecords && count($sampleRecords) > 0) { - - // For each sample record - foreach ($sampleRecords as $p) { - - // Create a slug from the title - $slug = sanitize_title($p['title']).'-'.$p['id']; - - // Store this value back into the record - $this->wpdb->update( - GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'samples', - array( - 'sample_slug' => $slug - ), - array( 'id' => $p['id'] ), - array( '%s' ), - array( '%d') - ); - } - -} 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/examples/create_database_V0.0.1.sql b/setup/databaseScripts/examples/create_database_V0.0.1.sql new file mode 100644 index 0000000..d4598c9 --- /dev/null +++ b/setup/databaseScripts/examples/create_database_V0.0.1.sql @@ -0,0 +1,42 @@ +-- Gaslight Media Members Database - Sample +-- File Created: 12/02/15 15:27:15 +-- Database Version: 0.0.1 +-- Database Creation Script +-- +-- This file is called to create a new set of tables for this +-- add-on for the most receint database version for this add-on. +-- +-- There should only be one such file in this directory +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + + +-- ********************************************************************** +-- NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED +-- +-- Please change all references to sample, Sample, or SAMPLE to a name +-- appropriate for your new Add-On. +-- +-- Tables and queries in this file are sample only. +-- +-- Remove this message before using this file in production! +-- **********************************************************************/ + + +-- Sample Table +CREATE TABLE {prefix}sometablename ( + id INT NOT NULL AUTO_INCREMENT, + somefield TINYTEXT NULL, + PRIMARY KEY (id) +); + +---- + +-- Sample default entry in table +INSERT INTO {prefix}sometablename + ( id, somefield ) + VALUES + ( 1, 'sample data' ) +; + diff --git a/setup/databaseScripts/examples/dbVersions.php b/setup/databaseScripts/examples/dbVersions.php new file mode 100644 index 0000000..1b9b48b --- /dev/null +++ b/setup/databaseScripts/examples/dbVersions.php @@ -0,0 +1,40 @@ + + * @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/ + */ + + +/********************************************************************** + * NOTE: THIS IS A SAMPLE FILE - DO NOT USE UNMODIFIED + * + * Please change all references to sample, Sample, or SAMPLE to a name + * appropriate for your new Add-On. + * + * This file lists all versions of the database tables for this add-on. + * The last entry in the array below should be for the most recent + * version and should match the "create_database_V..." file in this + * directory. + * + * NOTE: When first creating a new add-on with database tables, there + * should only be one line in the array below and there should be no + * "update_database..." files in this directory. + * + * Remove this message before using this file in production! + **********************************************************************/ + + +$glmMembersSampleDbVersions = array( + '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/examples/update_database_V0.0.2.php b/setup/databaseScripts/examples/update_database_V0.0.2.php new file mode 100644 index 0000000..5b47ba2 --- /dev/null +++ b/setup/databaseScripts/examples/update_database_V0.0.2.php @@ -0,0 +1,54 @@ +wpdb->get_results('SELECT id, title FROM '.GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'sometablename;', ARRAY_A); + +// If there's any records +if ($sampleRecords && count($sampleRecords) > 0) { + + // For each record + foreach ($sampleRecords as $p) { + + // Create a slug from the somefield field + $newData = sanitize_title($p['somefield']).'-'.$p['id']; + + // Store this value back into the record in the new yetanotherfield field + $this->wpdb->update( + GLM_MEMBERS_SAMPLE_PLUGIN_DB_PREFIX.'sometablename', + array( + 'yetanotherfield' => $slug + ), + array( 'id' => $p['id'] ), + array( '%s' ), + array( '%d') + ); + } + +} 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.