getgrav / grav-plugin-problems

Grav Problems Plugin
https://getgrav.org
MIT License
10 stars 8 forks source link

Use of undefined constant GRAV_SYSTEM_PATH - assumed 'GRAV_SYSTEM_PATH' (this will throw an Error in a future version of PHP) #34

Closed vedranmiletic closed 3 years ago

vedranmiletic commented 3 years ago

PHP 7.4.16 Grav 1.7.12 Problems 2.1.1

The code shown in the stack trace is:

{
    public function __construct()
    {
        $this->id = 'Essential Folders';
        $this->class = get_class($this);
        $this->order = 100;
        $this->level = Problem::LEVEL_CRITICAL;
        $this->status = false;
        $this->help = 'https://learn.getgrav.org/basics/folder-structure';
    }

    /**
     * @return $this
     */
    public function process()
    {
        $essential_folders = [
            GRAV_ROOT => false,
            GRAV_ROOT . '/vendor' => false,
            GRAV_SYSTEM_PATH => false,
            GRAV_CACHE_PATH => true,
            GRAV_LOG_PATH => true,
            GRAV_TMP_PATH => true,
            GRAV_BACKUP_PATH => true,
            GRAV_WEBROOT => false,
            GRAV_WEBROOT . '/images' => true,
            GRAV_WEBROOT . '/assets' => true,
            GRAV_WEBROOT . '/' . GRAV_USER_PATH .'/accounts' => true,
            GRAV_WEBROOT . '/' . GRAV_USER_PATH .'/data' => true,
            GRAV_WEBROOT . '/' . GRAV_USER_PATH .'/pages' => false,
            GRAV_WEBROOT . '/' . GRAV_USER_PATH .'/config' => false,
            GRAV_WEBROOT . '/' . GRAV_USER_PATH .'/plugins/error' => false,
            GRAV_WEBROOT . '/' . GRAV_USER_PATH .'/plugins' => false,
            GRAV_WEBROOT . '/' . GRAV_USER_PATH .'/themes' => false,
        ];

        // Check for essential files & perms
        $file_errors = [];
        $file_success = [];

Everything works if I revert to Problems 2.0.3.

mahagr commented 3 years ago

Where are you getting this as the const is always defined: https://github.com/getgrav/grav/blob/develop/system/defines.php#L45

vedranmiletic commented 3 years ago

Upon attempting to load any page.

mahagr commented 3 years ago

Have you modified the files? Check the contents of the above file, it should match what you have in your local.

vedranmiletic commented 3 years ago

No, I have not. That file looks exactly the same. I have added the stack trace below, hope it helps.

Stack frames (10):

9
Whoops\Exception\ErrorException
…/user/plugins/problems.new/classes/Problems/EssentialFolders.php31
8
Grav\Common\Debugger deprecatedErrorHandler
…/user/plugins/problems.new/classes/Problems/EssentialFolders.php31
7
Grav\Plugin\Problems\EssentialFolders process
…/user/plugins/problems/classes/Problems/Base/ProblemChecker.php88
6
Grav\Plugin\Problems\Base\ProblemChecker check
…/user/plugins/problems/problems.php128
5
Grav\Plugin\ProblemsPlugin problemsFound
…/user/plugins/problems/problems.php47
4
Grav\Plugin\ProblemsPlugin onFatalException
…/vendor/symfony/event-dispatcher/EventDispatcher.php264
3
Symfony\Component\EventDispatcher\EventDispatcher doDispatch
…/vendor/symfony/event-dispatcher/EventDispatcher.php239
2
Symfony\Component\EventDispatcher\EventDispatcher callListeners
…/vendor/symfony/event-dispatcher/EventDispatcher.php73
1
Symfony\Component\EventDispatcher\EventDispatcher dispatch
…/system/src/Grav/Common/Grav.php556
0
Grav\Common\Grav fireEvent
…/index.php63
mahagr commented 3 years ago

I have no idea how Grav can run but problems cannot as both use the same constant. The defines file is loaded by autoloader way before anything else and is required to bootstrap Grav.

Basically, it looks like it's defined before plugins run, but somehow doesn't work in plugin anymore, which is impossible (constants cannot be unset or updated) unless there's either a bug in PHP or your Grav installation has a mixed set of files from multiple versions.

Can you check this line, as it's being run before any plugins and should fail, too: https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Config/Setup.php#L167

vedranmiletic commented 3 years ago

How can I do that?

FWIW, I added at the beginning of the file:

define('GRAV_SYSTEM_PATH', '/var/www/example.com/system');
define('GRAV_WEBROOT', '/var/www/example.com/html');

And everything works now. So these are the only two constants that don't get defined for some reason.

mahagr commented 3 years ago

The first path should be just 'system'. I really cannot see them not being defined unless the define.php isn't being called or if it is the old version of the file. Did you try to reinstall Grav?

vedranmiletic commented 3 years ago

I did and it didn't help.

vedranmiletic commented 3 years ago

Do you want me to try to bisect this?

vedranmiletic commented 3 years ago

After playing with it for some time going back and forward, it seems that clearing OPcache by restarting PHP-FPM, which I randomly thought of, actually did the job. (FWIW I cleaned Grav cache on every version change.) Everything works now. Thanks for your help and apologies for wasting your time. Keep up the good work!

mahagr commented 3 years ago

I'm wondering why opcahe wasn't cleared when Grav was updated -- the installation process contains a call to clear the opcache. Grav cache also automatically clears when you install updates.

fembuelita commented 3 years ago

I had the same issue running bin/grav install on a Grav 1.6.31 install. Our server is only running PHP 7.2 so we couldn't install yet Grav 1.7, which the latest version of the problems plugin requires (as of April 2021). I'm instead manually installing problems 2.0.3 to resolve this.

(To install 2.0.3, use direct-install command available in bin/gpm, eg: bin/gpm direct-install https://getgrav.org/download/plugins/problems/2.0.3)

mahagr commented 3 years ago

The latest version of the problems plugin requires Grav 1.7, not sure why the installer didn't stop the installation.

fembuelita commented 3 years ago

Yes @mahagr that's what I'm saying as well. Looks like the installer is not correctly checking software versions before installing. When trying to install other plugins the bin/gpm tool has a red error message stating it can't proceed due to missing requirements. I'm not sure where it checks those dependencies -- maybe composer? Probably a simple fix.