darrenjacoby / intervention

WordPress plugin to configure wp-admin and application state using a single config file.
MIT License
642 stars 51 forks source link

Fatal error #112

Closed tombroucke closed 2 years ago

tombroucke commented 2 years ago

Hi,

Automated updates on several website are failing since februari 20th because a fatal error:

[23-Feb-2022 19:21:46 UTC] PHP Fatal error:  Uncaught Error: Class 'Jacoby\Intervention\Illuminate\Support\Collection' not found in /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php:65
Stack trace:
#0 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php(32): Jacoby\Intervention\Support\Arr::collect(Array)
#1 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php(48): Jacoby\Intervention\Support\Arr::normalize(Array)
#2 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Intervention.php(33): Jacoby\Intervention\Support\Arr::normalizeTrue(Array)
#3 /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/intervention.php(85): Jacoby\Intervention\Intervention->__construct(Array, true)
#4 /Users/tombroucke/Local/adis/app/www/wp/wp-settings.php(418): include_once('/Users/tombrouc...')
#5 /Users/tombroucke/Local/adis/app/www/wp-config.php(9): require_once('/Users/tombrouc...')
#6 /Users/tombroucke/Local/adis/app/www/wp/wp-load.php(55): require_once('/Us in /Users/tombroucke/Local/adis/app/www/app/plugins/intervention/src/Support/Arr.php on line 65

All websites are running Bedrock & Sage 9 & latest tagged version of intervention (7377e42)

BSBjorn commented 2 years ago

Yeah, same here. Total crash of the site.

darrenjacoby commented 2 years ago

Shit, thanks for reporting.

It's because I'm trying to move it towards a WordPress plugin/wpackagist, so I need to compile third party code into vendor/. I imagine Composer is over-riding the prebuilt vendor file I have with the namespaced third party classes. I will try see how I can get this working in the meanwhile before the transfer to wpackagist. For now you can pull in version 2.0.0-rc.4 and it should work.

Sorry about this!

darrenjacoby commented 2 years ago

@tombroucke @BSBjorn I just ran composer require soberwp/intervention:dev-main and it seemed to keep the distributed vendor folder on my side.

On your side, could you check for me, under intervention/vendor/illuminate/collections/Collection.php is the namespace Jacoby\Intervention\Illuminate\Support?

tombroucke commented 2 years ago

@tombroucke @BSBjorn I just ran composer require soberwp/intervention:dev-main and it seemed to keep the distributed vendor folder on my side.

On your side, could you check for me, under intervention/vendor/illuminate/collections/Collection.php is the namespace Jacoby\Intervention\Illuminate\Support?

The vendor folder is present & namespace is correct. I will also try to debug the problem.

Screenshot 2022-02-24 at 10 28 45

darrenjacoby commented 2 years ago

Hmm, maybe something to do with the autoloader? Does it work if you just clone from GitHub?

BSBjorn commented 2 years ago

@tombroucke @BSBjorn I just ran composer require soberwp/intervention:dev-main and it seemed to keep the distributed vendor folder on my side.

On your side, could you check for me, under intervention/vendor/illuminate/collections/Collection.php is the namespace Jacoby\Intervention\Illuminate\Support?

just dit

Same her. Namespace is correct.

image

darrenjacoby commented 2 years ago

@tombroucke @BSBjorn what if you remove this in the root file intervention.php?

/**
 * Support for Bedrock/Composer
 */
if (!class_exists('Jacoby\Intervention\Intervention')) {
    if (is_file(__DIR__ . '/vendor/autoload.php')) {
        require_once __DIR__ . '/vendor/autoload.php';
    }

    // include file_exists($composer = __DIR__ . '/vendor/autoload.php') ? $composer : __DIR__ . '/build/vendor/autoload.php';
}

If you remove if (!class_exists('Jacoby\Intervention\Intervention')) { ?

Does the code run inside if (is_file(__DIR__ . '/vendor/autoload.php')) { ?

I think it may be Bedrock specific.

BSBjorn commented 2 years ago

Just tried cloning from github, same issue.

I tried removing the IF. Different error...

image

tombroucke commented 2 years ago

I assume the autoloader is looking for the Collection class in src/illuminate/support/Collection.php, which doesn't exist. The Collection class is located in vendor/illuminate/collections/Collection.php, in the Illuminate\Support namespace. You have prefixed the namespace with Jacoby\Intervention\, which makes the autoloader search for the class in src/Illuminate/Support/Collection.php.

darrenjacoby commented 2 years ago

@tombroucke Hm, any ideas on the best solution with php-scoper? Change the namespace of scoper so it's something different and doesn't conflict with PSR-4 loading? I'm a little stumped on the best solution.

"autoload": {
    "psr-4": {
      "Jacoby\\Intervention\\": "src/"
    }
  },
BSBjorn commented 2 years ago

Is there a way for me to get this working for now?

darrenjacoby commented 2 years ago

@BSBjorn falling back to 2.0.0-rc.4 should work.

BSBjorn commented 2 years ago

OK, sorry for my incompetence, but can you quickly explain how I do that with composer?

darrenjacoby commented 2 years ago

@BSBjorn try composer require soberwp/intervention:2.0.0-rc.4

BSBjorn commented 2 years ago

THANKS! :D learned something usefull right away. :) Just let me know if you need to test, I'm happy to help!

jeremydumaye commented 2 years ago

@tombroucke @BSBjorn what if you remove this in the root file intervention.php?

/**
 * Support for Bedrock/Composer
 */
if (!class_exists('Jacoby\Intervention\Intervention')) {
    if (is_file(__DIR__ . '/vendor/autoload.php')) {
        require_once __DIR__ . '/vendor/autoload.php';
    }

    // include file_exists($composer = __DIR__ . '/vendor/autoload.php') ? $composer : __DIR__ . '/build/vendor/autoload.php';
}

If you remove if (!class_exists('Jacoby\Intervention\Intervention')) { ?

Does the code run inside if (is_file(__DIR__ . '/vendor/autoload.php')) { ?

I think it may be Bedrock specific.

Hi @darrenjacoby so I have the same problem with the dev-main version, and if I downgrade to 2.0.0-rc.4 all my params not working well like 'application.discussion' => false not removed from admin panel menu. So I tried to remove (!class_exists('Jacoby\Intervention\Intervention')) { and now it is working well. So yes I think it comes from a problem of autoloader and your new folder vendor/ with src/ Hope you will find the solution and if you need I try other things, doesn't hesitate !

darrenjacoby commented 2 years ago

@jeremydumaye committed that change to dev-main. Could you give me more insight into your setup? Sage 9/10? Bedrock? Standard WP installation?

Thanks!

jeremydumaye commented 2 years ago

@darrenjacoby Perfect I update dev-main version and all working good thanks ! For my setup, I use Sage 9 and Bedrock

darrenjacoby commented 2 years ago

@jeremydumaye and you installed the plugin now with composer require soberwp/intervention:dev-main correct?

jeremydumaye commented 2 years ago

@darrenjacoby yes 👍

darrenjacoby commented 2 years ago

Closing for now!

BSBjorn commented 2 years ago

just did update as well to dev-main and is working as expected. Thanks