getgrav / grav-plugin-license-manager

License Manager Plugin for Grav Premium
https://getgrav.org/premium
MIT License
0 stars 1 forks source link

error when trying to access License Manager : Method name must be a string #6

Open MattAppleton opened 3 years ago

MattAppleton commented 3 years ago

I have a problem where license manager crashes with this error after installing it whenever I click on the plugin in the admin interface...

Error
Method name must be a string

highlighting this line below $ret = $object->$method();

/srv/users/chrisbrooks/apps/chrisbrooks/public/vendor/twig/twig/src/Template.php
            if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
                return;
            }

            throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext());
        }

        if ($isDefinedTest) {
            return true;
        }

        if ($this->env->hasExtension('\Twig\Extension\SandboxExtension')) {
            $this->env->getExtension('\Twig\Extension\SandboxExtension')->checkMethodAllowed($object, $method);
        }

        // Some objects throw exceptions when they have __call, and the method we try
        // to call is not supported. If ignoreStrictCheck is true, we should return null.
        try {
            if (!$arguments) {
                $ret = $object->$method();
            } else {
                $ret = \call_user_func_array([$object, $method], $arguments);
            }
        } catch (\BadMethodCallException $e) {
            if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
                return;
            }
            throw $e;
        }

        // @deprecated in 1.28
        if ($object instanceof \Twig_TemplateInterface) {

My environment: Grav v1.7.18 - Admin v1.10.18

w00fz commented 3 years ago

What PHP version are you running?

MattAppleton commented 3 years ago

PHP Version 7.4.21

MattAppleton commented 3 years ago

I can try downgrading through serverpilot... the CLI and app are both using 7.4 atm.

MattAppleton commented 3 years ago

Grav admin crashes if I downgrade to 7.3...

/srv/users/chrisbrooks/apps/chrisbrooks/public/vendor/doctrine/cache/lib/Doctrine/Common/Cache/FilesystemCache.php
        $resource = fopen($filename, 'r');
        $line     = fgets($resource);

        if ($line !== false) {
            $lifetime = (int) $line;
        }

        if ($lifetime !== 0 && $lifetime < time()) {
            fclose($resource);

            return false;
        }

        while (($line = fgets($resource)) !== false) {
            $data .= $line;
        }

        fclose($resource);

        return unserialize($data);
    }

    /**
     * {@inheritdoc}
     */
    protected function doContains($id)
    {
        $lifetime = -1;
        $filename = $this->getFilename($id);

        if (! is_file($filename)) {
            return false;
        }

        $resource = fopen($filename, 'r');
        $line     = fgets($resource);

        if ($line !== false) {
            $lifetime = (int) $line;
        }
Arguments
"Erroneous data format for unserializing 'Grav\Common\Flex\Types\Users\UserObject'"
MattAppleton commented 3 years ago

Admin is OK at first sight on php 8.0 - -but still the same license manager crash...

Halite-screenshot-2021-07-20-9

rhukster commented 3 years ago

I can't seem to replicate this. I've clicked on it in plugins list and also in the sidebar, and it works fine with latest Grav + Admin (previous versions worked fine too) using PHP 8 and 7.4

rhukster commented 3 years ago

I would also try clearing your cache completely.

MattAppleton commented 3 years ago

hmmm... tried that... maybe I can just add the warm-cache plugin manually, and register the license another way?

mahagr commented 3 years ago

I think the issue is coming from here: https://github.com/getgrav/grav-plugin-license-manager/blob/develop/license-manager.php#L104

MattAppleton commented 3 years ago

Thanks @mahagr for looking... is there something I can try on this file do you think?

MattAppleton commented 3 years ago

Happy to share admin login / repo of the site in question if that helps?

MattAppleton commented 3 years ago

I think I found the problem... I guess it might have happened due to internet outage which was plaguing us the other day...

Basically I looked at the license.yaml and compared it to a site where everything was working well. The problem site had a license but no prefix (?!) — see redacted screenshot.

Screenshot-Zeolite-2021-07-22

As soon as I added warm-cache before the license key it seemed to solve the issue.

Might be a problem that can be triggered again by mis-spelling the slug or saving issues, not sure if it counts as an on-going bug :) ?

w00fz commented 3 years ago

The misspelling shouldn't affect it, you can still save it. I am not sure if you can save it without it though. If you can save without the slug part, perhaps that's what happened