Post by MaxD » Thu Jul 06, 2023 7:19 am

Hi ppl!

As you know, Opencart 4 has a built-in upgrade function. But the fact is - it is not working at all.
Oh, if that person that wrote that code (whomever it is) had tested it a single time - but he didn't.
I can't imagine how this can happen at all!

Anyway, here is the fix from me. Actually, it took 12 fixes that any normal programmer will not be able to carry just to upgrade the single store.
But the fact is with this fix the Opencart 4 upgrade should execute ok just by a few clicks in admin.

Please give me feedback, especially if it doesn't work for you.

Link to the fix - https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=45216

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm


Post by straightlight » Thu Jul 06, 2023 7:26 am

Code: Select all

// Rise files per batch limit
                    $php = str_replace("\$limit = 200;",
                    "\$limit = 1000;", $php);
                    

Code: Select all

// Fix file copy error display
                    $php = str_replace("\$this->language->get('error_copy')",
                        "'Failed to copy file %s to %s'", $php);
                        

Code: Select all

$json['text'] = 'Upgrading DB, this may take some time...';
TWIG files are hardcoded text from:

Code: Select all

$('#status').html(
Any reasons for those codes to be added?

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 MaxD » Thu Jul 06, 2023 8:09 am

straightlight wrote:
Thu Jul 06, 2023 7:26 am
Any reasons for those codes to be added?
Sure, each code is added for a reason )

Code: Select all

// Rise files per batch limit
                    $php = str_replace("\$limit = 200;",
                    "\$limit = 1000;", $php);
Current update implementation has super-slow zip extraction way - it actually opens zip for each file, extracts single file, and closes it. Fixing this increased unzip speed 10x at least. After that the limit to extract 200 files per request is very low, so it is raised. Even with limit 1000 single request takes like 2 seconds.

Code: Select all

// Fix file copy error display
                    $php = str_replace("\$this->language->get('error_copy')",
                        "'Failed to copy file %s to %s'", $php);
The "error_copy" string is simply missing in install/language/en-gb/upgrade/upgrade.php, and guess what? If upgrade step 2 (most files extraction) fails to write some file - it just says error_copy instead of any details )))

Code: Select all

$json['text'] = 'Upgrading DB, this may take some time...';
Upgrading DB takes most time in upgrade process now, and it is not indicated in any special way. People can think that the process got hung, so I added additional indication what's going on and that this will take some time.

Code: Select all

$('#status').html(
If some error happen (that gives error output instead of pretty JSON), the upgrade tool makes the worst thing it could do - nothing! Literally nothing, it keeps showing current step text (like 'Extracting files ...') forever. Poor user will wait some 10 minutes thinking the process is going - but it was finished with error long ago ))

This is the fix for that, if any sort of error happens - it will be displayed as big red text.

If you are wondering why there are 2 hardcoded text strings - I'm pretty sure that nobody will do translations specially for my fix.

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm


Post by straightlight » Thu Jul 06, 2023 8:35 am

MaxD wrote:
Thu Jul 06, 2023 8:09 am
straightlight wrote:
Thu Jul 06, 2023 7:26 am
Any reasons for those codes to be added?
Sure, each code is added for a reason )

Code: Select all

// Rise files per batch limit
                    $php = str_replace("\$limit = 200;",
                    "\$limit = 1000;", $php);
Current update implementation has super-slow zip extraction way - it actually opens zip for each file, extracts single file, and closes it. Fixing this increased unzip speed 10x at least. After that the limit to extract 200 files per request is very low, so it is raised. Even with limit 1000 single request takes like 2 seconds.

Code: Select all

// Fix file copy error display
                    $php = str_replace("\$this->language->get('error_copy')",
                        "'Failed to copy file %s to %s'", $php);
The "error_copy" string is simply missing in install/language/en-gb/upgrade/upgrade.php, and guess what? If upgrade step 2 (most files extraction) fails to write some file - it just says error_copy instead of any details )))

Code: Select all

$json['text'] = 'Upgrading DB, this may take some time...';
Upgrading DB takes most time in upgrade process now, and it is not indicated in any special way. People can think that the process got hung, so I added additional indication what's going on and that this will take some time.

Code: Select all

$('#status').html(
If some error happen (that gives error output instead of pretty JSON), the upgrade tool makes the worst thing it could do - nothing! Literally nothing, it keeps showing current step text (like 'Extracting files ...') forever. Poor user will wait some 10 minutes thinking the process is going - but it was finished with error long ago ))

This is the fix for that, if any sort of error happens - it will be displayed as big red text.

If you are wondering why there are 2 hardcoded text strings - I'm pretty sure that nobody will do translations specially for my fix.
I am not wondering. It rather remains to be seen if it is meant to be fixed.

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 straightlight » Thu Jul 06, 2023 9:39 pm


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 MaxD » Fri Jul 07, 2023 1:54 am

straightlight wrote:
Thu Jul 06, 2023 9:39 pm
Here's the answer: https://github.com/opencart/opencart/is ... 1623693891 .
Thank you, answered Daniel there.

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm


Post by MaxD » Fri Jul 07, 2023 2:06 pm

Classical Daniel. Still no chances it will be nominally working in next release )

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm


Post by MaxD » Thu Jul 13, 2023 8:54 am

Version 1.01: Now it skips all unnecessary DB operations on tables that has not changed.

Default install upgrades itself from 4.0.2.1 to 4.0.2.2 in 40 seconds )

User avatar
Active Member

Posts

Joined
Fri Jul 06, 2012 6:37 pm

Who is online

Users browsing this forum: No registered users and 2 guests