MyBB Community Forums

Full Version: MyBB Plugin cannot be installed - can only be uninstalled
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I am making a post requirement referral payout plugin for NewPoints. The plugin is almost complete but there is one problem. The user who was referred to join the forums might be able to delete his or her post and make another new post. And hence the user who who is the referrer might earn the referral payout two times.

I came up with a way to fix this. That is, create a column (newpoints_refpayout_paid) in TABLE_PREFIXusers. Once the referred made the required post number and the referrer was paid, the column will be changed from 0 Boolean to 1 Boolean. And if the Boolean is zero, the referral payout plugin will be ignored. So I try using the code below.


function newpoints_refpayout_install()
{
    global $db, $mybb;
    // insert newpoints_refpayout_paid row into the user database
    $db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD `newpoints_refpayout_paid` BOOLEAN NOT NULL DEFAULT FALSE");
}

function newpoints_refpayout_uninstall()
{
    global $db, $mybb;
    // delete newpoints_refpayout_paid row into the user database
    $db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP `newpoints_refpayout_paid`");
}


The problem here is that when I  go to http://yoursite.org/MyBB/Admin/index.php...ts-plugins, there is only two links - Active and Uninstall. I try clicking on the Uninstall link and it prompt me an error[url=http://localhost/MyBB/Admin/index.php?module=newpoints-plugins&action=activate&plugin=newpoints_refpayout&my_post_key=36dfaa6ecfd96847ea6aa880574895ba][/url] saying that the table I was trying to delete do not exist - because I did not create it.

So I head over to PHPMyAdmin and add the column manually. I clicked on Uninstall link again, they deleted the column perfectly. However, I am still left with two links - Active and Uninstall. It seem that there is no way to install a plugin.

When I was trying to install NewPoints 2.0 plugin (downloaded from MyBB.com) on my new 1806 MyBB copy I get the same error - only Uninstall link, no install link. I switched over to MyBB 1800 and the problem is somewhat "fixed" - I can install NewPoints and activate it. Hence, I believe that this is a error in the MyBB script.

Edit: I can PM the 6KB PHP Script to those who would like to test in on their own server and help me fix the bug.
Where is your is_installed() method? These two methods just tell the script what to do when you click the install and uninstall button, they don't update the buttons on the plugin page.
Oh. I thought is_installed() is optional. I will be adding it to my script and test it out.

Edit: It fixed the problem. I used the code.

function newpoints_refpayout_install()
{
	global $db;
	// insert newpoints_refpayout_paid row into the user database
	$db->write_query("ALTER TABLE ".TABLE_PREFIX."users ADD `newpoints_refpayout_paid` BOOLEAN NOT NULL DEFAULT FALSE");
}

function newpoints_refpayout_is_installed()
{
	global $db;
	if($db->field_exists("newpoints_refpayout_paid", "users")){
        return true;
    } 
}

function newpoints_refpayout_uninstall()
{
	global $db;
	// delete newpoints_refpayout_paid row into the user database
	$db->write_query("ALTER TABLE ".TABLE_PREFIX."users DROP `newpoints_refpayout_paid`");
}