Post by Reptile » Sat May 06, 2023 2:19 pm

I just finished my first event driven extension and was wondering how I can update this if I release a new version?

Normally with VQMod clients would simply overwrite the files and stored data wouldn’t be affected.
But now the extension is installed through the extension installer and the only way to install the same extension again is to remove it first which will remove all data/settings from the database.

How can clients update an extension which is installed through the extension installer without losing data?
Last edited by Reptile on Thu May 11, 2023 6:02 am, edited 1 time in total.

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by straightlight » Sat May 06, 2023 9:25 pm

Reptile wrote:
Sat May 06, 2023 2:19 pm
I just finished my first event driven extension and was wondering how I can update this if I release a new version?

Normally with VQMod clients would simply overwrite the files and stored data wouldn’t be affected.
But now the extension is installed through the extension installer and the only way to install the same extension again is to remove it first which will remove all data/settings from the database.

How can clients update an extension which is installed through the extension installer without losing data?
OC version. As for updating extensions without loosing data, there are no guarantee from any extension distributions that may present to the buyers.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by halfhope » Sat May 06, 2023 11:24 pm

Hi!

I'm adding an update to the index function, in the admin. If the add-on is old for some reason, then I start the automatic update and display a message about the successful update, if it's new, then I skip the step.

My FREE extensions in marketplace. [ security | flexibility | speedup ]


User avatar
Active Member

Posts

Joined
Tue Dec 10, 2013 9:44 pm
Location - San Diego

Post by Reptile » Sun May 07, 2023 5:21 pm

I don't think you guys understand my question.

As from now my extension is installed through the extension installer and show there with a version number let's say version 1.0.
Now if I update my extension and make a version 1.1 you can't install this through the extension installer as you get a error "Extension already installed"
So if I want to install the new version I need to uninstall the module first and then remove the extension in the extension installer.
By doing so all saved settings will be removed from the database.

Now that I am writing this message I got an idea.

I could build in an export/import settings button so users can export their settings before uninstalling the module.
And import them again after installing the new version.
But this is extra work for the client which I preferably don't want.

How do you guys do this in your extensions?

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by straightlight » Sun May 07, 2023 9:03 pm

Reptile wrote:
Sun May 07, 2023 5:21 pm
I don't think you guys understand my question.

As from now my extension is installed through the extension installer and show there with a version number let's say version 1.0.
Now if I update my extension and make a version 1.1 you can't install this through the extension installer as you get a error "Extension already installed"
So if I want to install the new version I need to uninstall the module first and then remove the extension in the extension installer.
By doing so all saved settings will be removed from the database.

Now that I am writing this message I got an idea.

I could build in an export/import settings button so users can export their settings before uninstalling the module.
And import them again after installing the new version.
But this is extra work for the client which I preferably don't want.

How do you guys do this in your extensions?
The OC version still hasn't been posted. By building an API, this can be accomplished. There are lots of extensions on the Marketplace that can accomplish update automations already. I would suggest to take a look.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Reptile » Sun May 07, 2023 10:54 pm

straightlight wrote:
Sun May 07, 2023 9:03 pm
Reptile wrote:
Sun May 07, 2023 5:21 pm
I don't think you guys understand my question.

As from now my extension is installed through the extension installer and show there with a version number let's say version 1.0.
Now if I update my extension and make a version 1.1 you can't install this through the extension installer as you get a error "Extension already installed"
So if I want to install the new version I need to uninstall the module first and then remove the extension in the extension installer.
By doing so all saved settings will be removed from the database.

Now that I am writing this message I got an idea.

I could build in an export/import settings button so users can export their settings before uninstalling the module.
And import them again after installing the new version.
But this is extra work for the client which I preferably don't want.

How do you guys do this in your extensions?
The OC version still hasn't been posted. By building an API, this can be accomplished. There are lots of extensions on the Marketplace that can accomplish update automations already. I would suggest to take a look.

What do you mean by the oc version hasn’t been posted?
I’m posting in the Opencart 4 forum so I am talking about 4.x

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by straightlight » Sun May 07, 2023 11:35 pm

Reptile wrote:
Sun May 07, 2023 10:54 pm
straightlight wrote:
Sun May 07, 2023 9:03 pm
Reptile wrote:
Sun May 07, 2023 5:21 pm
I don't think you guys understand my question.

As from now my extension is installed through the extension installer and show there with a version number let's say version 1.0.
Now if I update my extension and make a version 1.1 you can't install this through the extension installer as you get a error "Extension already installed"
So if I want to install the new version I need to uninstall the module first and then remove the extension in the extension installer.
By doing so all saved settings will be removed from the database.

Now that I am writing this message I got an idea.

I could build in an export/import settings button so users can export their settings before uninstalling the module.
And import them again after installing the new version.
But this is extra work for the client which I preferably don't want.

How do you guys do this in your extensions?
The OC version still hasn't been posted. By building an API, this can be accomplished. There are lots of extensions on the Marketplace that can accomplish update automations already. I would suggest to take a look.

What do you mean by the oc version hasn’t been posted?
I’m posting in the Opencart 4 forum so I am talking about 4.x
Each versions are different, even by features. Forum rules.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Reptile » Mon May 08, 2023 12:04 am

straightlight wrote:
Sun May 07, 2023 11:35 pm
Reptile wrote:
Sun May 07, 2023 10:54 pm
straightlight wrote:
Sun May 07, 2023 9:03 pm


The OC version still hasn't been posted. By building an API, this can be accomplished. There are lots of extensions on the Marketplace that can accomplish update automations already. I would suggest to take a look.

What do you mean by the oc version hasn’t been posted?
I’m posting in the Opencart 4 forum so I am talking about 4.x
Each versions are different, even by features. Forum rules.
Ok 4.0.2.1 then :P

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by straightlight » Mon May 08, 2023 12:10 am

Reptile wrote:
Mon May 08, 2023 12:04 am
straightlight wrote:
Sun May 07, 2023 11:35 pm
Reptile wrote:
Sun May 07, 2023 10:54 pm



What do you mean by the oc version hasn’t been posted?
I’m posting in the Opencart 4 forum so I am talking about 4.x
Each versions are different, even by features. Forum rules.
Ok 4.0.2.1 then :P
Still, at this time, it has been suggested many times by forum supporters that OC v4.x releases not to use it until a stable version gets released.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Reptile » Mon May 08, 2023 12:26 am

straightlight wrote:
Mon May 08, 2023 12:10 am
Reptile wrote:
Mon May 08, 2023 12:04 am
straightlight wrote:
Sun May 07, 2023 11:35 pm


Each versions are different, even by features. Forum rules.
Ok 4.0.2.1 then :P
Still, at this time, it has been suggested many times by forum supporters that OC v4.x releases not to use it until a stable version gets released.
I understand that.
But it is good to convert atleast one extension just to see how much work it is and what issues you might experience.

And this is the only question I still have after converting my extension.
How should a client install a new version of my extension without losing all previous set settings in the extension?

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by JNeuhoff » Mon May 08, 2023 5:46 pm

Unfortunately there is no built-in way in OpenCart 4 (that I know of) to upgrade an existing extension without loosing all its data.

IMHO the current way OpenCart 4 implements the installation of extensions is poorly implemented. This is just one of many issues which need to be addressed.

In general the extensions feature should at least address below issues:
  • Have the extension name in the install.json, so developer can use any filename for his extension
  • Use proper namespaces for extensions, reflecting the underlying folder structure
  • Simplify the uninstall, it should remove all of its files from its extension folder
  • Upgrade functionality from older to newer extension version without loosing existing data
  • Better ways to override or modify core functions beyond event handlers, especially for library files
There might be other issues, too. Please share them with us here on this forum.

I am thinking about writing up a plugin manager for OpenCart 4, have already addressed the namespace issue.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Reptile » Tue May 09, 2023 5:07 am

JNeuhoff wrote:
Mon May 08, 2023 5:46 pm
Unfortunately there is no built-in way in OpenCart 4 (that I know of) to upgrade an existing extension without loosing all its data.

IMHO the current way OpenCart 4 implements the installation of extensions is poorly implemented. This is just one of many issues which need to be addressed.

In general the extensions feature should at least address below issues:
  • Have the extension name in the install.json, so developer can use any filename for his extension
  • Use proper namespaces for extensions, reflecting the underlying folder structure
  • Simplify the uninstall, it should remove all of its files from its extension folder
  • Upgrade functionality from older to newer extension version without loosing existing data
  • Better ways to override or modify core functions beyond event handlers, especially for library files
There might be other issues, too. Please share them with us here on this forum.

I am thinking about writing up a plugin manager for OpenCart 4, have already addressed the namespace issue.
This answer was very helpful.
I couldn’t agree more.
So I was right about no possibility to upgrade your extension without losing data.
You have some good points.
I hope they will fix some of these issues in the following releases.

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by Johnathan » Tue May 09, 2023 5:39 am

Yes, I agree with all of JNeuhoff's proposed improvements. Hopefully one of these days Daniel will listen to you and try to implement them!

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by frank79 » Tue May 09, 2023 5:06 pm

Hi Reptile, in your case the easiest way would be to write a couple of small functions in your plugin(s), called install() and uninstall(), they must be placed in the (admin) controller of your extension. Opencart calls them automatically when you install/uninstall your extension, you don't have to add any feature like buttons or anything like that to manually export the settings.
Look at the file admin/controller/extension/module.php (Opencart 4.0.0.0) :

function install() , Line ~ 126:

Code: Select all

// Call install method if it exists
$this->load->controller('extension/' . $extension . '/module/' . $code . '|install');
function uninstall(), Line ~ 180:

Code: Select all

// Call uninstall method if it exists
$this->load->controller('extension/' . $this->request->get['extension'] . '/module/' . $this->request->get['code'] . '|uninstall');
The function uninstall() on your plugin saves settings in a sql file and store it somewhere on the server (system/storage/blabla for example, if you have many plugins create a nice folder structure where you can organize saved data). The function install() will check if there is any sql backup, if yes, restores it.

Our new Opencart Extension:
AI Assistant - automatic product and category text generator


User avatar
New member

Posts

Joined
Thu Apr 26, 2012 12:01 am

Post by Reptile » Wed May 10, 2023 12:45 am

frank79 wrote:
Tue May 09, 2023 5:06 pm
Hi Reptile, in your case the easiest way would be to write a couple of small functions in your plugin(s), called install() and uninstall(), they must be placed in the (admin) controller of your extension. Opencart calls them automatically when you install/uninstall your extension, you don't have to add any feature like buttons or anything like that to manually export the settings.
Look at the file admin/controller/extension/module.php (Opencart 4.0.0.0) :

function install() , Line ~ 126:

Code: Select all

// Call install method if it exists
$this->load->controller('extension/' . $extension . '/module/' . $code . '|install');
function uninstall(), Line ~ 180:

Code: Select all

// Call uninstall method if it exists
$this->load->controller('extension/' . $this->request->get['extension'] . '/module/' . $this->request->get['code'] . '|uninstall');
The function uninstall() on your plugin saves settings in a sql file and store it somewhere on the server (system/storage/blabla for example, if you have many plugins create a nice folder structure where you can organize saved data). The function install() will check if there is any sql backup, if yes, restores it.
Thanks for the tip!
The install and uninstall functions are already used to register and remove the events.
I just finished playing around with the import/ export buttons and this works.
But your idea is better.
I will remove these buttons and save the settings file on the server.
Then when installing check if there is a file present and restore this.

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by Reptile » Thu May 11, 2023 2:53 am

I tried using the uninstall method but this won’t work.
Even if I try to get all settings in the first line of the method I get an empty array.
So the module settings are cleared before I can get them.
So I added the logic of saving the settings in the Save method instead.
And this works fine.
Each time you save the settings they are also written to a file in the storage folder.
And if you install a new version of the extension I check for this file in the Install method and restore the settings.

All my extensions: Click here or Click here


User avatar
Active Member

Posts

Joined
Mon Jan 30, 2012 7:23 pm
Location - The Netherlands

Post by by mona » Thu May 11, 2023 3:16 am

Thankyou for coming back with your solution.
If you could edit the title to include [SOLVED] that would be great.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by asif » Tue Oct 03, 2023 4:16 pm

I am quite late on this. The easiest way to do this without code change is to delete the modification from the modification menu. Once its deleted, modification record will be removed from the DB but the extension remains at the place and its settings are not removed from the DB. Now, go to the extension installer and install the extension again. This time there will be no error and the new PHP files will also be replaced along with the new modification file. That's the best workaround, i have found.

New member

Posts

Joined
Wed Jan 16, 2008 10:35 pm
Who is online

Users browsing this forum: No registered users and 1 guest