89 lines
2.8 KiB
PHP
89 lines
2.8 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) exit;
|
|
|
|
class WMW_Activator {
|
|
|
|
public static function activate() {
|
|
global $wpdb;
|
|
|
|
$charset = $wpdb->get_charset_collate();
|
|
|
|
// Views table (track article views)
|
|
$views_table = $wpdb->prefix . 'wmw_views';
|
|
$sql_views = "CREATE TABLE IF NOT EXISTS $views_table (
|
|
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
article_id BIGINT(20) UNSIGNED NOT NULL,
|
|
view_count BIGINT(20) UNSIGNED NOT NULL DEFAULT 1,
|
|
PRIMARY KEY (id),
|
|
UNIQUE KEY article_id (article_id)
|
|
) $charset;";
|
|
|
|
// Search index table
|
|
$search_table = $wpdb->prefix . 'wmw_search_index';
|
|
$sql_search = "CREATE TABLE IF NOT EXISTS $search_table (
|
|
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
article_id BIGINT(20) UNSIGNED NOT NULL,
|
|
wiki_id BIGINT(20) UNSIGNED NOT NULL,
|
|
keywords LONGTEXT NOT NULL,
|
|
PRIMARY KEY (id),
|
|
UNIQUE KEY article_id (article_id),
|
|
KEY wiki_id (wiki_id)
|
|
) $charset;";
|
|
|
|
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
|
dbDelta( $sql_views );
|
|
dbDelta( $sql_search );
|
|
|
|
// Store DB version
|
|
update_option( 'wmw_db_version', '1.0.0' );
|
|
|
|
// Default settings
|
|
if ( ! get_option( 'wmw_settings' ) ) {
|
|
update_option( 'wmw_settings', array(
|
|
'show_toc' => 1,
|
|
'show_breadcrumbs' => 1,
|
|
'show_related' => 1,
|
|
'show_search' => 1,
|
|
'articles_per_page' => 20,
|
|
'sidebar_position' => 'left',
|
|
'color_scheme' => 'auto',
|
|
) );
|
|
}
|
|
|
|
// Flag to flush rewrite rules
|
|
update_option( 'wmw_flush_rewrite', 1 );
|
|
|
|
// Register post types early so permalinks work
|
|
$pt = new WMW_Post_Types();
|
|
$pt->register();
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
public static function deactivate() {
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
public static function uninstall() {
|
|
global $wpdb;
|
|
|
|
// Remove custom tables
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wmw_views" );
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wmw_search_index" );
|
|
|
|
// Remove options
|
|
delete_option( 'wmw_settings' );
|
|
delete_option( 'wmw_db_version' );
|
|
|
|
// Remove all wiki and article posts
|
|
$posts = get_posts( array(
|
|
'post_type' => array( 'wmw_wiki', 'wmw_article' ),
|
|
'post_status' => 'any',
|
|
'posts_per_page' => -1,
|
|
'fields' => 'ids',
|
|
) );
|
|
foreach ( $posts as $post_id ) {
|
|
wp_delete_post( $post_id, true );
|
|
}
|
|
}
|
|
}
|