Commit b3947d6a authored by Thomas's avatar Thomas
Browse files

Prepares db changes

parent 6bf9c7d3
......@@ -22,7 +22,7 @@
*/
class Mastodon_comments_Activator {
private static $_db_version = '1.0.0';
private static $_db_version = '1.0.4';
/**
* Short Description. (use period)
*
......@@ -33,6 +33,9 @@ class Mastodon_comments_Activator {
public static function activate() {
Mastodon_comments_Activator::create_users();
//Create cache since version 1.0.4
//Remove an unused field in table
Mastodon_comments_Activator::create_cache();
}
......@@ -50,7 +53,6 @@ class Mastodon_comments_Activator {
user_id VARCHAR(255),
threshold INTEGER DEFAULT -1,
token VARCHAR(255),
targeted_element VARCHAR(255),
date datetime DEFAULT '0000-00-00 00:00:00',
UNIQUE KEY id (id)
) $charset_collate;";
......@@ -60,4 +62,42 @@ class Mastodon_comments_Activator {
add_option( 'tom79_mastodon_comment_db_version', $tom79_mastodon_comment_db_version );
}
/**
* Cache results
*
* Calls to instances will be saved in the db
* An old field is removed for the table 'mastodon_comment_users'
*
* @since 1.0.4
*/
private static function create_cache()
{
global $wpdb;
global $tom79_mastodon_comment_db_version;
$tom79_mastodon_comment_db_version = Mastodon_comments_Activator::$_db_version;
$installed_ver = get_option( "tom79_mastodon_comment_db_version" );
if ( $installed_ver <= $tom79_mastodon_comment_db_version ) {
$table_name = $wpdb->prefix . 'mastodon_comment_cache';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
URL VARCHAR(255) NOT NULL ,
cache TEXT NOT NULL,
date datetime DEFAULT '0000-00-00 00:00:00',
UNIQUE KEY id (id)
) $charset_collate;";
$table_name = $wpdb->prefix . 'mastodon_comment_users';
$sqlRemove = "ALTER TABLE " . $table_name . " DROP COLUMN targeted_element;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
dbDelta( $sqlRemove );
update_option( "tom79_mastodon_comment_db_version", $tom79_mastodon_comment_db_version );
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment