Skip to content

Instantly share code, notes, and snippets.

@netsensei
Created July 6, 2013 15:23
Show Gist options
  • Save netsensei/5940215 to your computer and use it in GitHub Desktop.
Save netsensei/5940215 to your computer and use it in GitHub Desktop.
Uninstalls wp_mollom and upgrades the schema definition.
From 707f11370d155a20d83ce90dd89568b1b2e195b1 Mon Sep 17 00:00:00 2001
From: Matthias Vandermaesen <matthias@colada.be>
Date: Sat, 6 Jul 2013 16:47:14 +0200
Subject: [PATCH] Added: uninstall tables defined in MollomSchema::getSchema()
---
includes/Schema.php | 25 ++++++++++++++++++++++---
uninstall.php | 4 +++-
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/includes/Schema.php b/includes/Schema.php
index 29214ac..55a9491 100644
--- a/includes/Schema.php
+++ b/includes/Schema.php
@@ -30,11 +30,13 @@ class MollomSchema {
*/
public static function getSchema() {
global $wpdb;
+
$table = $wpdb->prefix . 'mollom';
// Note: dbDelta() requires no spaces between column names in the primary
// key definition.
- return "CREATE TABLE $table (
+ $schema = array(
+ $table => "CREATE TABLE $table (
entity_type VARCHAR(32) DEFAULT '' NOT NULL,
entity_id BIGINT DEFAULT 0 NOT NULL,
content_id VARCHAR(32),
@@ -42,7 +44,10 @@ class MollomSchema {
PRIMARY KEY (entity_type,entity_id),
KEY content_id (content_id),
KEY created (created)
-)";
+)"
+ );
+
+ return $schema;
}
/**
@@ -50,12 +55,26 @@ class MollomSchema {
*/
public static function install() {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
- dbDelta(self::getSchema());
+ $schema = self::getSchema();
+ foreach ($schema as $table => $create_query) {
+ dbDelta($create_query);
+ }
update_option('mollom_schema_version', self::getVersion());
}
/**
+ * Uninstalls the plugin database schema.
+ */
+ public static function uninstall() {
+ global $wpdb;
+ $schema = self::getSchema();
+ foreach (array_keys($schema) as $table) {
+ $wpdb->query("DROP TABLE IF EXISTS $table");
+ }
+ }
+
+ /**
* Updates the plugin database schema, if outdated.
*/
public static function update() {
diff --git a/uninstall.php b/uninstall.php
index c99095c..1ab709e 100644
--- a/uninstall.php
+++ b/uninstall.php
@@ -10,7 +10,9 @@ if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
-// @todo Delete mollom table.
+require_once dirname(__FILE__) . '/includes/Schema.php';
+MollomSchema::uninstall();
+
// @todo Delete meta data.
delete_option('mollom_public_key');
--
1.7.11.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment