opencart / opencart

A free shopping cart system. OpenCart is an open source PHP-based online e-commerce solution.

Home Page:https://www.opencart.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[OC 4.x] Events when uninstalliing (deleting) an extension are not deleted (also)

osworx opened this issue · comments

This issue is also valid for the 3.x branches!

When uninstalling an extension (added before through the marketplace / installer) all files are removed - well done.
But, when events are used (and therefore stored in the database), they should be also deleted then.

So the entries still exist and are called (while the endpoints are now deleted).
When many are pointing to non living / existing functions, overall it could also take down (a lilltle bit) the performance.
Beside - entries in the event list may confuse someone .. especially when a developer want to check if something is going wrong!

There was a similar issue with access and modify permissions, which has been resolved in the upcoming OC 3.0.4.0.

I thought about doing something similar for events introduced by the extension which is now to be uninstalled. In general, a 3rd party extension can introduce all sorts of new resources, including event handlers, and it should really be the responsibility of the extension's uninstall function to remove the now obsolete event handlers.

been reported multiple times and has open issues

its also down to the extension creator to add the uninstall coode

been reported multiple times and has open issues

its also down to the extension creator to add the uninstall coode

Sorry Daniel, but I have tried it now (Sunday here and that's why the asnwer is late) several times.
And the events are still existing after uninstalling the extension - while I have a uninstall(..) function inside all of my extensions (since many years)

Problem is, the function uninstall(..) inside the extension is never called!
Only when the extension is disabled (therefore uninstalled) via the list at the extensions > the admin/controller/extension/module.php calls the uninstaller of the extension itself (if exist):

$this->load->controller('extension/' . $this->request->get['extension'] . '/module/' . $this->request->get['code'] . '.uninstall');

But not called when uninstalling (removing) from the marketplace/installer uninstall!

There was a similar issue with access and modify permissions, which has been resolved in the upcoming OC 3.0.4.0.

I thought about doing something similar for events introduced by the extension which is now to be uninstalled. In general, a 3rd party extension can introduce all sorts of new resources, including event handlers, and it should really be the responsibility of the extension's uninstall function to remove the now obsolete event handlers.

See my previuos comment - it's very easy to try by yourself ...
Then you will see that the uninstall function inside your extension is not called when deleting (removing) the extension from the Extension > Installer page!

Deleting (removing) the extension from the Extension > Installer shouldn't even be possible unless the uninstall has been called via e.g. Extensions > Extensions > Modules > uninstall button

And the problem goes further.

When someone uninstall an extension from the Extension > Installer page, a call of the uninstall(..) function of the extension is at the moment impossible.
Why?
Because the extension is in several tables:

  1. extension
  2. extension_install
  3. extension_path

Currently the uninstaller (from Extension > Installer is trying to get the extension_id:

if (isset($this->request->get['extension_install_id'])) {

But with only this id, the function can never call the extension uninstaller itself.
Because there is stored only:

  1. extension_install_id
  2. extesnion_download_id
  3. filename
  4. date_added

I would say, adding a new fields to the table extension_install (maybe called extension_name), pulling that name is then easy to call before removing the files in admin/controller/marketplace/installer.php

same as it is in admin/controller/extension/extension/module:

// Call uninstall method if it exsits $this->load->controller('extension/module/' . $this->request->get['extension'] . '/uninstall');

p.s.: forgot to mention, IF the extension has own database tables, these stay also intact (and are then orphans 'till the system dies' ... ) ..

Deleting (removing) the extension from the Extension > Installer shouldn't even be possible unless the uninstall has been called via e.g. Extensions > Extensions > Modules > uninstall button

And currently IT IS possible!
So adding such as I proposed above would solve all ..
Or the uninstall function from Extension > Installer must call before the Extension list and simulate a click on the uninstall button (which is not a really applicable way in doing ..).

Just tested the uninstall sequence for my 'Export/Import tool' extension on an OpenCart 4.0.2.3 system, as follows:

  1. Extensions > Extensions > Other > Export/Import Tool > uninstall
  2. Extensions > Installer > Export/Import Tool > uninstall
  3. Extensions > Installer > Export/Import Tool > delete

and it all works fine. The events were all removed in the first step. The code for this was in my

extension/export_import/admin/controller/other/export_import.php:

	public function uninstall(): void {
		// remove events
		$this->load->model('setting/event');
		$this->model_setting_event->deleteEventByCode('other_export_import');

		// remove access rights
		$this->removeAccessRights();
	}

The bottom line is, your extension's uninstall function should be responsible for removing all of the extension-specific resources such as extra DB tables, events, access rights, etc.

@mhcwebdesign Sure - but that works only (!!) - and as detailed explained above - when the etxneion is UNinstalled via Extensions > Module (or Payment/Shipping/etc.).

So we all know that works - how would you think I create my own extensions ?

But (and now we are at the fact): UNinstalling an extension completely from the Extension > Installer IS NOT POSSIBLE!
Because the uninstall function inside our extensions is NEVER called!

And how often do you think will customers go this way - easy uninstall an extension from the Installer page and not from the Extension page!
So what do you write as step 1 will not always be done - because the customers will see that tiny shining red button at the Extension > Installer page and hit that WITHOUT deleting the extension as you describe.

@osworx : I am all in for a more user-friendly interface, and in that sense your right.

Perhaps the Uninstall button from Extensions > Installer should be renamed, to something like Deactivate ?

I am all in for a more user-friendly interface, and in that sense your right.

Perhaps the Uninstall button from Extensions > Installer should be renamed, to something like Deactivate ?

Deactivate sound not bad .. but (yeah I know, always a but): that function at Extensions > Installer removes also all files, so it's more than a deactivation ..

I think, the whole logic UNinstalling at 2 places should be discussed.

At the Extensions > Extensions (Module, etc.) level we have such that:
grafik

which means:
grafik > Install
grafik > Add New
grafik > Uninstall
grafik > Delete
grafik > Edit (when enabled)

And at the Extensions > Installer we have:
grafik

all Uninstall

But the Uninstall at Extensions > Extensions and Extensions > Installer is not the same.
And that's confusing.

The Uninstall at Extensions > Extensions > ... is calling the function uninstall(..) (if exists), BUT do not remove anything from the system.
The Uninstall at the Extensions > Installer is NOT calling the function uninstall(..) of the extension, BUT REMOVE ALL FILES from the system (which good, but has disadvantages currently in leaving back many orphans).

From my point of view the only correct way to solve that issue would be:

A. Extensions > Extensions > (Module, Payment, etc.): leave the buttons, titles and functions as they are currently
B. Extensons > Installer: change the title (and adopt the functions behind) to really REMOVE (everything) from that extension additionally with some text above the list (to explain what's going on here) - like I have it since OC 3.0 in the German translation:
grafik