From 212d233eff20d9bc5906a1f6dbb2059e4cb62710 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 26 Nov 2014 11:00:49 -0500 Subject: [PATCH] Starting with setting up database tables setup hooks for activation db updates and uninstall --- controllers/admin.php | 38 +++++++++++++++++ glm-members.php | 14 ++++++- models/database.php | 98 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 controllers/admin.php create mode 100644 models/database.php diff --git a/controllers/admin.php b/controllers/admin.php new file mode 100644 index 0000000..321fe8a --- /dev/null +++ b/controllers/admin.php @@ -0,0 +1,38 @@ + + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @version SVN: (0.1) + * @link <> + */ + +/** + * Gaslight Members Admin Controller + * + * Controller for all admin + * + * @category Toolkit + * @package Package + * @author Steve Sutton + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @release Release: (0.1) + * @link <> + */ +class admin +{ + public $wpdb; + + public function __construct($wpdb) + { + $this->wpdb = $wpdb; + } +} diff --git a/glm-members.php b/glm-members.php index a33e6e6..f2023b1 100644 --- a/glm-members.php +++ b/glm-members.php @@ -1,6 +1,6 @@ + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @version SVN: (0.1) + * @link <> + */ + +/** + * Toolkit_Package_database + * + * Description of database + * + * @category Toolkit + * @package Package + * @author Steve Sutton + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @release Release: (0.1) + * @link <> + */ +class glm_members_models_database +{ + public $wpdb; + public $membersTable; + public $locationTable; + public $contactTable; + public $regionTable; + public $countyTable; + public $cityTable; + + public function __construct($wpdb) + { + $this->wpdb = $wpdb; + register_activation_hook( + GLM_MEMBERS_PLUGIN_FILE_PATH, + array($this, 'install') + ); + register_uninstall_hook( + GLM_MEMBERS_PLUGIN_FILE_PATH, + array($this, 'delete') + ); + add_action('plugins_loaded', array($this, 'glm_members_update_db_check')); + + $this->membersTable = $this->wpdb->prefix . GLM_MEMBERS_MEMBER_TABLE; + $this->locationTable = $this->wpdb->prefix . GLM_MEMBERS_LOCATION_TABLE; + $this->contactTable = $this->wpdb->prefix . GLM_MEMBERS_CONTACT_TABLE; + $this->regionTable = $this->wpdb->prefix . GLM_MEMBERS_REGION_TABLE; + $this->countyTable = $this->wpdb->prefix . GLM_MEMBERS_COUNTY_TABLE; + $this->cityTable = $this->wpdb->prefix . GLM_MEMBERS_CITY_TABLE; + } + + public function install() + { + + + $charset_collate = $this->wpdb->get_charset_collate(); + + $sql = "CREATE TABLE {$this->membersTable} ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + create_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, + name text NOT NULL, + url text DEFAULT '' NOT NULL, + join_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, + phone text DEFAULT '' NOT NULL, + logo text DEFAULT '' NOT NULL, + UNIQUE KEY id (id) + ) {$charset_collate}"; + include ABSPATH . 'wp-admin/includes/upgrade.php'; + dbDelta($sql); + + update_option(GLM_MEMBERS_VRS_OPTION_NAME, GLM_MEMBERS_VERSION); + } + + public function glm_members_update_db_check() + { + if (GLM_MEMBERS_VERSION != get_option(GLM_MEMBERS_VRS_OPTION_NAME)) { + $this->install(); + } + } + + public function delete() + { + $sql = " + DROP TABLE IF EXISTS {$this->membersTable} "; + $this->wpdb->query($sql); + delete_option(GLM_MEMBERS_VRS_OPTION_NAME); + } + +} -- 2.17.1