Jump to content

[solved] Module Code: Shop in Demo Mode : Disallow Uninstall


El Patron

Recommended Posts

I can not for the life of me understand how, when I put a shop in demo mode (1.6.0.6) in this example, that the 'uninstall' function is still executed. 

 

could someone review this and let me know what I am doing wrong, thanks in advance.

    public function uninstall()
	{
		if (!parent::uninstall() || _PS_MODE_DEMO_ )
			return false;
		$this->_do_uninstall_stuff();
		return true;
	}
Link to comment
Share on other sites

Since you are using || if the parent::uninstall fails (returns false), then demo mode is never evaluated.  If you want both statements to be evaluated, then you need to use a single |

if (!parent::uninstall() | _PS_MODE_DEMO_ )

If you are trying to avoid uninstalling the module while in demo mode, then you should reverse your statement so that demo mode is checked first, and if it is true then parent::uninstall will never trigger.  Here you will use ||

if ( _PS_MODE_DEMO_ || !parent::uninstall() )

And sometimes it is better to just do this

public function uninstall()
{
    if (_PS_MODE_DEMO_)
        return false;

    if (!parent::uninstall())
        return false;

    $this->_do_uninstall_stuff();
    return true;
}


 

  • Like 1
Link to comment
Share on other sites

Hi El Patrón, for testing:

public function uninstall()
    {
        if (_PS_MODE_DEMO_ == true OR parent::uninstall() == false)
            return false;
		return true;
    }

Regards

 

This did it, I also tested bellini's solution, both worked great.

 

Thanks for helping, my brain got very tired and needed a little help from the community to put me back on track.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...