backdrop-contrib / og

The Organic Groups module provides users the ability to create, manage, and delete 'groups' on a site.
GNU General Public License v2.0
1 stars 8 forks source link

`EntityPlusDefaultViewsController` not found when upgrading from D7 #138

Closed argiepiano closed 1 year ago

argiepiano commented 1 year ago

When upgrading from D7 WITHOUT first installing the D7 entity_plus stub module you get a fatal error Error: Class 'EntityPlusDefaultViewsController' not found.

This is happening even though Entity Plus is present in the modules folder, and it is being enabled during the update process (see https://github.com/backdrop/backdrop-issues/issues/5499, which added this feature to Backdrop's core).

It's unclear to me why this is happening. I tried adding the class to E+'s autoload function, but that doesn't make any difference.

BTW, if you try the upgrade again after the failure, it works the second time around. Step-debug is needed to see what's going on.

argiepiano commented 1 year ago

OK, the issue here is that there is a OG class that extends EntityDefaultExtraFieldsController. Apparently this class is needed right away, before Backdrop has had the opportunity to enable E+ in the upgrade process. It's unclear to me what the solution might be.

A quick solution is to always enable the stub D7 entity_plus module in the D7 site before attempting the upgrade.

argiepiano commented 1 year ago

OK, I've found the culprit. The class OgMembershipViewsController, which extends Entity Plus' EntityDefaultExtraFieldsController, is defined in og.views.inc. This file is included early during the upgrade process, way before Entity Plus is enabled.

To clarify, this class is not needed at this stage - it just happens to be present in a file that includes other functions that are needed at that moment. The problem is that, when you include a file that contains classes, PHP will verify that the parent classes exist (which they don't since Entity Plus is not enabled yet).

The solution is to move this class to its own file, and to include this file in the og_autoload_info(). This way PHP will not throw a fatal error, and the class is indeed found when needed. I've tested this solution and it works well. PR coming.

(BTW this class is a utility class that allows Entity Plus to create views fields for the fields provided by OG).

argiepiano commented 1 year ago

PR #139.

To test:

  1. Start out with a D7 site with OG. A simple vanilla site will work. Be sure NOT to enable the stub module entity_plus
  2. Follow the D7->B upgrade steps. This will generate the error reported here
  3. Patch the OG module with this PR
  4. Start the whole upgrade process again (be sure to trash the db and import the D7 original db again, remove all config files)
  5. This time the upgrade should proceed normally without the error.
argiepiano commented 1 year ago

We have a test failure not related to this PR. It looks like one of the tests is trying to install or include the contrib entityreference instead of using the core version?

argiepiano commented 1 year ago

Test failure fixed - it was produced by entityreference_prepopulate. Ready for testing!

laryn commented 1 year ago

I'm not able to test at the moment but it looks good to me, makes sense, and given your extensive testing and the relatively minor change (moving code and changing the location in the autoload) I'd be comfortable with it being merged. Great job!