WordPress.org

Ready to get started?Download WordPress

Forums

Proper Network Activation
Cannot create tables on net activate even with proper network activate installed (3 posts)

  1. Tomas
    Member
    Posted 1 year ago #

    Hi, I'm unable to get the tables from my plugin created at network activate.
    I can see the progress bar counting up for all blogs but no tables are created. Is there something wrong with my plugin?

    function _assert_db_structure() {
    			global $wpdb;
    
    			$wpdb->query("CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."blogstats ( <code>stat_post_id</code> int NOT NULL default '0', <code>stat_date</code> datetime NOT NULL default '0000-00-00 00:00:00' , <code>stat_visitor_id</code> VARCHAR( 32 ) NULL , INDEX ".$wpdb->prefix."blogstats_post_ids (stat_post_id,stat_date)) ENGINE = MYISAM");
    
    			 $wpdb->query("CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."blogstats_daily (<code>stat_post_id</code> INT NOT NULL DEFAULT '0', <code>day</code> DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', <code>unique_visits</code> INT NOT NULL DEFAULT '0', <code>total_visits</code> INT NOT NULL DEFAULT '0', INDEX ".$wpdb->prefix."blogstats_daily_post_ids (stat_post_id,day) ) ENGINE = MYISAM");
    
    			$wpdb->query("CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."blogstats_total (<code>stat_post_id</code> INT NOT NULL DEFAULT '0', <code>until_day</code> DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', <code>unique_visits</code> INT NOT NULL DEFAULT '0', <code>total_visits</code> INT NOT NULL DEFAULT '0') ENGINE = MYISAM");
    
    			// If indexes dont exist after update
    			$result = $wpdb->get_results("show index from ".$wpdb->prefix."blogstats where key_name='".$wpdb->prefix."blogstats_post_ids'", ARRAY_N);
    			if (count($result) == 0) {
    				$wpdb->query("CREATE INDEX ".$wpdb->prefix."blogstats_post_ids on ".$wpdb->prefix."blogstats (stat_post_id,stat_date);");
    			}
    
    			$result = $wpdb->get_results("show index from ".$wpdb->prefix."blogstats_daily where key_name='".$wpdb->prefix."blogstats_daily_post_ids'", ARRAY_N);
    			if (count($result) == 0) {
    				$wpdb->query("CREATE INDEX ".$wpdb->prefix."blogstats_daily_post_ids on ".$wpdb->prefix."blogstats_daily (stat_post_id,day);");
    			}
    
    		}

    Many thanks
    Tomas

    http://wordpress.org/extend/plugins/proper-network-activation/

  2. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    You pasted the code for the _assert_db_structure() function, but where are you hooking it?

  3. Tomas
    Member
    Posted 1 year ago #

    Thanks for your prompt reply.
    hmm I'm no good with plugins so I'm not sure what you mean. Can I post the complete plugin so you can have a look?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic