Affiliate Plugin giving database errors

Hi all,

While it does not seem to break anything visibly, I have been getting lots of database errors in my error logs, like the following:

[28-Mar-2011 05:36:39] WordPress database error Table 'pbs_wrdpr.wp_358_affiliatereferrers' doesn't exist for query SELECT * FROM wp_358_affiliatereferrers WHERE user_id = 13 AND period = '201103' ORDER BY referred DESC LIMIT 0, 15 made by wp_dashboard, do_meta_boxes, call_user_func, affiliatedashboard->dashboard_aff_report

[28-Mar-2011 05:36:40] WordPress database error Table 'pbs_wrdpr.wp_358_affiliatedata' doesn't exist for query SELECT * FROM wp_358_affiliatedata WHERE user_id = 13 ORDER BY period DESC LIMIT 0, 18 made by do_action, call_user_func_array, affiliatedashboard->ajax__aff_getdashstats

Any idea what is going on there?

  • Marty Thornley
    • Site Builder, Child of Zeus

    Hi Phil,
    Yep, still have 358. The error was coming as we were editing it.

    I seem to see this error when a super admin is visiting a site they are not actively added to as a user.

    I get the error other times too, but that is a definite case.

    btw - using wp 3.0.5, affiliate latest version.

  • Aaron
    • CTO

    You haven't confirmed that the tables actually exist. Can you do that please?

    If they don't exist for many blogs my guess is it's an artifact of a plugin like new blog templates not being configured correctly for it.

    And if they do exist (which I doubt), try running the query on them in phpmyadmin
    SELECT * FROM wp_358_affiliatereferrers WHERE user_id = 13 AND period = '201103' ORDER BY referred DESC LIMIT 0, 15

  • Marty Thornley
    • Site Builder, Child of Zeus

    Ahhh. Now you are hitting on something. I do use newblogtemplates. Is there a work around or maybe I need the latest version if I don't already have it?

    I can check to confirm but it seems the error is telling us they don't exist.

    And yeah, it seems to be for many (if not all) blogs. But wouldn't network activate create the table for all the blogs?

  • Aaron
    • CTO

    The way most multisite plugins that need per blog tables work is they set a blog option, like "xxx_installed" that gets checked, and if not set the db tables are installed. The problem is that network activate doesn't fire the activation hook so this is necessary.

    New blog templates copies over all blog options, so if you copy over the installed one the db script doesn't get executed.

    So you either need to copy the tables in addition, add a special filter to skip that blog option, or make sure the template blog doesn't have that plugin ever installed.

    To fix your existing problem, you either need to delete that option from all blogs, or manually install the tables via the sql script.

  • Marty Thornley
    • Site Builder, Child of Zeus

    Okay. Sounds like I can figure something out here. I already had added some options to the blog templates plugin that i didn't want touched so that should be easy enough.

    I was about to suggest a filter to let us tie in options we want to exclude but I see that latest version has that. Maybe Affiliate needs a quick addition to tell blog templates not to copy that setting? Or could it add a check to see if the table is there and if not, run the activation function.

    Seems like the plugin should be able to figure this out by itself somehow and not require these workarounds. But I definitely appreciate the specifics of how to fix it.

    Also... Am I missing something. I have been looking through Affiliates and do not see any xxx_installed option or any check for it. There is only the install function that is fired by

    register_activation_hook(__FILE__, array(&$this, 'install'));

    Or am I not seeing something?

    From what I can tell, all that install() function does is look for the tables,

    if($this->db->get_var( "SHOW TABLES LIKE '" . $this->affiliatedata . "' ") != $this->affiliatedata) {

    And if they are not there, adds them. Couldn't you do this somewhere else too as a double check? Maybe have it fire at register_activation_hook and do:

    add_action ('init',array(&$this, 'install'));

  • Marty Thornley
    • Site Builder, Child of Zeus

    Ahh... nevermind, found it in the admin class... It used a capital 'I' and tricked my bulk text search :slight_smile:

    Okay, another easier idea than all that above... It checks the build number. Couldn't I just change the build number from 3 to something else so it doesn't line up with the saved option, so installs again?

  • Marty Thornley
    • Site Builder, Child of Zeus

    Update to last idea... I added the 'Aff_Installed' option to be ignored by blog templates, then changed line 6 of affiliateadmin.php from:

    var $build = 3;

    to

    var $build = 3.1;

    No more errors!

    Thank you so much for pointing me in the right spot. Never would have thought this was a blog templates thing.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.