Hello there, this is my first time reporting an issue so I apologize in advance if I have done something wrong in my reporting of these errors. Anyway here are the links to the specific lines in class.plugin.php that are not working or able to be executed from within a plugin:

The pre_uninstall and uninstall function are not working when trying to be executed from my plugin's class, for reference this how I call upon the function in my plugin:

function pre_uninstall(&$errors) {
        \\ A statement that is executed.
        return parent::pre_uninstall($errors);
    }

And for uninstall I would just put uninstall in place of pre_uninstall. If I have trying to use the function in a wrong way please provide me the correct use for this function. I would like to bring to attention how the function is only being executed when a plugin is installed but not when a plugin is disabled and re-enabled. Also global $ost is returning null when trying to be accessed by a plugin function, but when accessed in the enable function it works fine, so I have to create my own instance of ost in my plugin to be able to use it for logging errors in the ost system log. I would also like to note that some core plugins are using these functions too, but I am not sure if the functions work in them or not as I have not tested those core plugins. I would also like to note that I have opened an issue regarding this on GitHub which you can find here https://github.com/osTicket/osTicket/issues/6594

Not to bother anyone, just wanted to see if someone from the community or the team knew how I could achieve this? Basically add statement to execute during the uninstall process of a plugin?

omaramir

If you look at any of the official plugins we do not call pre_uninstall anywhere. With that being said from looking at the code it seems to be possible (although when we call uninstall $this might be simple Plugin object instead of the actual plugin object which would not call pre_uninstall at the actual plugin level; only the Plugin class level). I would have to test this which I do not have time for at the moment.

Cheers.

    KevinTheJedi
    After a bit of testing I found that the pre_uninstall function is not called in your plugin and only the pre_uninstall function in the class.plugin.php is called. I don't know why or how osTicket is handling the calling of the function but yeah that's where I am at right now.

      omaramir

      Then I think my comment above is what's happening:

      ... although when we call uninstall $this might be simple Plugin object instead of the actual plugin object which would not call pre_uninstall at the actual plugin level; only the Plugin class level ...

      Cheers.

        omaramir

        Then that suggests it should work. Again, I would have to test this which I do not have the time to do at the moment.

        Cheers.

          KevinTheJedi
          That's the thing I have tested it and can confirm that function is not working, so someone at your team has messed up or the code has not been updated to take account for 1.18.x as disable is not a function in the plugin class in 1.18.x.

          For now here is my current workaround, I am just using the isActive function for now which I know is not the best solution because when the plugin is uninstalled it would not run my method that I have in isActive but when the plugin is installed again it would be in it disabled state by default so I should be able to just run my methods then giving the new install a clean and fresh slate to work with. So this is how I call it in my plugin's class:

          function isActive() {
              if (!parent::isActive()) {
                  \\ Run a method or function when the plugin is not active.
              } else {
                  \\ Run a method or function when the plugin is active.
              }
              return parent::isActive();
          }

          This is also better than running a method or function when a plugin is enabled as that only happens when a plugin is installed not when a plugin is enabled or disabled as the name would indicate. But here is that function for anyone referring this in the future:

          function enable() {
              \\ Run a method or function when plugin is installed.
              return parent::enable();
          }

          I hope whenever the team has time in the future to fix this issue they do so as it would help in the future. Also please remove the mention of uninstall from your own auth-2fa core plugin as it is very confusing for someone referring to it when developing a plugin for 1.17.x+ as disable was only a function of osTicket in 1.16.x and before.

          a year later

          I run into the same issue.
          I have created a pull request to solve this behavior.
          It will caused by handling plugin actions, that only calls the core plugin class and not the plugin class, which extends the core class.
          To solve this behavior, we only need to call the impementation of selected plugin(s).

          Here the link to the pull request: https://github.com/osTicket/osTicket/pull/6793

          Write a Reply...