Jump to content
thirty bees forum

Impossible to save modification in product


Pilou

Recommended Posts

 

4 hours ago, Pilou said:

Hey Petr,

Thank you for your answer.

Here is the paygreen Module

This module contains a bug. With every request, file /var/paygreen/autoload.cache.php is over-written with list (subset) of module classes used by current thread. This file is also used by autoloader to load classes.

This can (and does) lead to race condition -- one thread can write new content to this file, while other thread is reading it. 

Note that this is bug in the module, not in the thirtybees. You are experiencing it in back office, because thirtybees trigger multiple ajax requests at the same time, creating ideal conditions for this race condition to happen. But it's more than likely the same problem occurs on your frontend as well, if there is enough visitors so multiple request arrives at the same time (or close enough)

You need to fix the module, or ask its developer to do that. 

 

  • Like 1
Link to comment
Share on other sites

13 minutes ago, Pilou said:

Hi Petr,

Thank you very much for your professional opinion.
Not being able to solve this bug alone, I will wait patiently for the reaction of Paygreen.

Meanwhile, this is what you can do:

edit file /modules/paygreen/bundles/PGFramework/Services/Autoloader.php

and delete content of function extendCache. -- find this code 

    protected function extendCache($className, $src)
    {
        $this->classNames[$className] = $src;

        $cache = '<?php return ' . var_export($this->classNames, true) . ';' . PHP_EOL;

        @file_put_contents($this->getCacheFilename(), $cache, LOCK_EX);
    }

and replace it with

    protected function extendCache($className, $src)
    {
    }

And it should work. 

  • Like 2
Link to comment
Share on other sites

It's possible the connection type or speed or perhaps IP address might have something to do with this @datakick when I was on "true wifFi", an actual wiFi connection today it worked fine, with the Save function fine, this evening I'm on "Wifi" but its actually a WifI connection to a phone thats running cell data... and the Save in products does not work again, everything else is the same... apart from the connection.

It doesnt work regardless of device/ browser

 

 

Edited by Mark
Link to comment
Share on other sites

24 minutes ago, Mark said:

It's possible the connection type or speed or perhaps IP address might have something to do with this @datakick when I was on "true wifFi", an actual wiFi connection today it worked fine, with the Save function fine, this evening I'm on "Wifi" but its actually a WifI connection to a phone thats running cell data... and the Save in products does not work again, everything else is the same... apart from the connection.

It doesnt work regardless of device/ browser

@Mark it is really hard to tell what's wrong without any technical information. Does the system show popup window with any error? Is there any javascript error in browser's console? Is there any failed (404/502/527/...) http request to the server displayed in Network tab in browser's console? If so, what is the returned content of this failed request? (look into preview subtab)

Link to comment
Share on other sites

CONSOLE:

 

Loading failed for the <script> with source “blob:https://product.solutions.org.nz/4d36e740-8dfb-4afe-a1f7-1ba2157fd731”. index.php:1:1
The character encoding of a framed document was not declared. The document may appear different if viewed without the document framing it. enquire.min.js
The character encoding of a framed document was not declared. The document may appear different if viewed without the document framing it. admin-theme.js

 

Network attached as HAR @datakick

Edited by datakick: removed HAR file, as it contains sensitive information

 

Link to comment
Share on other sites

@Mark you are not on the latest bleeding edge, or you didn't clear your browser/server/cloudflare cache.

File js/admin/products.js does not contain the fix. Line 213 contains 

if (typeof this.current_request !== 'undefined' && typeof this.current_request === "function") {

instead of the correct one

if (typeof this.current_request !== 'undefined' && typeof this.current_request.complete === "function") {

You need to upgrade to latest version, and clear *all* caches. Don't forget the cloudflare one.

Link to comment
Share on other sites

  • 2 weeks later...

Hey @datakick

Paygreen updated their module to v2.6.3 and the same problem came back... (can't save product modification).

I modified the file /modules/paygreen/bundles/PGFramework/Services/Autoloader.php as you mentionned before and it works.

But I hope I do not make mistakes, so I attached the module to this post.
If you have time to take a look at it 😉

Kind regards

v2.6.3-paygreen.zip

Link to comment
Share on other sites

Yeah, you are right. It still doesn't work.

They use flock to lock the file, but it's not enough. Probably one of these kicked in (from php documentation):

Quote

Because flock() requires a file pointer, you may have to use a special lock file to protect access to a file that you intend to truncate by opening it in write mode (with a "w" or "w+" argument to fopen()).

Quote

On some operating systems flock() is implemented at the process level. When using a multithreaded server API like ISAPI you may not be able to rely on flock() to protect files against other PHP scripts running in parallel threads of the same server instance!

 

You should report this bug once again. And while you are at it, tell them to remove this 'cache' functionality completely. The extendCache method tries very hard to create var/paygreen/autoload.cache.php cache file. But they don't actually use this file at all - the module reads it in constructor into property $classNames, but this variable is never used for anything.

This means that if we modify the file and delete:

  • property $classNames
  • constructor
  • extendCache method
  • and the call $this->extendCache

we will end up with much smaller, faster code doing exactly the same. But without this race-condition bug.

I'm attaching modified file, please pass it to the dev of the module when you report this issue. 

Autoloader.php

 
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi all,

I received a mail from Paygreen which tell me to upgrade the module to last version (v2.7.1)

In BO, all seems ok, I can save product modification.

But in front, when I click 'next' after choosing the delivery option, I have this error message:

Argument 1 passed to PGDomainServicesManagersProductManager::isEligibleProduct() must be an instance of PGDomainInterfacesEntitiesProductInterface, null given, called in /home/mandcdhp/public_html/gigapc/modules/paygreen/bundles/PGDomain/Services/Managers/ButtonManager.php on line 128
in file modules/paygreen/bundles/PGDomain/Services/Managers/ProductManager.php at line 43
Source file: modules/paygreen/bundles/PGDomain/Services/Managers/ProductManager.php

24: * @package PGDomain\Services\Managers
25: * @method PGDomainInterfacesRepositoriesProductRepositoryInterface getRepository()
26: */
27:class PGDomainServicesManagersProductManager extends PGFrameworkFoundationsAbstractManager
28:{
29:    /**
30:     * @param int $id
31:     * @return PGDomainInterfacesEntitiesProductInterface|null
32:     */
33:    public function getByPrimary($id)
34:    {
35:        return $this->getRepository()->findByPrimary($id);
36:    }
37:
38:    /**
39:     * @param PGDomainInterfacesEntitiesProductInterface $product
40:     * @package string $type
41:     * @return bool
42:     */
43:    public function isEligibleProduct(PGDomainInterfacesEntitiesProductInterface $product, $type)
44:    {
45:        /** @var PGDomainServicesManagersCategoryHasPaymentTypeManager $categoryPaymentManager */
46:        $categoryPaymentManager = $this->getService('manager.category_has_payment_type');
47:
48:        /** @var PGDomainInterfacesEntitiesCategoryInterface[] $categories */
49:        $categories = $product->getCategories();
50:
51:        $is_eligible = false;
52:
53:        /** @var PGDomainInterfacesEntitiesCategoryInterface $category */

Of course, if I uninstall the Paygreen module, I can go next to payment option.

 

What can I do please ?

 

Kind regards,
Pilou

 

v2.7.1-paygreen.zip

Link to comment
Share on other sites

1 hour ago, Pilou said:

What can I do please ?

Report the issue to the developer and wait for a fixed version.

Meanwhile, you can edit file 

/paygreen/bundles/PGDomain/Services/Managers/ButtonManager.php on line 128

And add null check. But be aware that, most likely, this will only hide some larger underlying problem.

 

Link to comment
Share on other sites

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