Jump to content

Doesn't execute script during upgrade custom module


Recommended Posts

Hi, I'm working on a custom module on PrestaShop. My goal is to update the module in order to set the permissions for a web service created during installation.

I succeeded in my purpose this way:

 public function install()
    {

        $keyId = $this->getKeyId();
        $wsKey = new WebserviceKey($keyId ? $keyId : null);
        $wsKey->active = true;
        $wsKey->description = self::KEY_DESCRIPTION_MARKER;

        do {
            $wsKey->key = $this->generateKey(self::KEY_LENGTH);
        } while (WebserviceKey::keyExists($wsKey->key));

        $wsKey->add();

        $permissions_file = "../modules/".$this->name."/data/permissions.json";
        $jsonPermissions = file_get_contents($permissions_file); //TODO controlli sul file
        $permissions_to_set = json_decode($jsonPermissions,true);
        $wsKey->setPermissionForAccount($wsKey->id,$permissions_to_set);

        $configuration = new stdClass();
        $configuration->soap_key = $wsKey->key;

        return parent::install() &&
            $this->registerHook('actionAdminControllerSetMedia') &&
            $this->registerHook('displayBackOfficeHeader');
    }

in this way during the installation of the module, I set the permissions in the correct way, taking them from the JSON file present in data/permissions.json

this is ok for the new installations, but if I have to update an already installed module, how can I do? I tried this way:

function upgrade_module_2_1_4($module, $install = true)
{

    return true;
}

thinking that by passing install = true the module would re-run the install function,

but PrestaShop seems to update the module, but does not update the permissions as indicated in the function to update

Share this post


Link to post
Share on other sites
  • 1 year later...

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More