Skip Navigation

[Resolved] Fatal error: Uncaught Error: Call to a member function can_be_used_in_relationship() on null in controller.php on line 268 with Types beta and WPML

This thread is resolved. Here is a description of the problem and solution.

Problem:
In some cases, when installing Toolset and migrating Post Relationships built with Toolset Types lower than version 3.0, and then deleting them, can produce a PHP fatal error that stops a Toolset powered website from working properly.

The PHP error is

Fatal error: Uncaught Error: Call to a member function can_be_used_in_relationship() on null in controller.php on line 268

Solution:
Update Toolset to its latest versions

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 14 replies, has 2 voices.

Last updated by Beda 6 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#630200

I am trying to: Open the settings page

Link to a page where the issue can be seen:

.../wp-admin/admin.php?page=toolset-settings

I expected to see:

The settings

Instead, I got:

This error message
Fatal error: Uncaught Error: Call to a member function can_be_used_in_relationship() on null in .../wp-content/plugins/types/vendor/toolset/toolset-common/inc/m2m/migration/controller.php:268 Stack trace: #0 .../wp-content/plugins/types/application/controllers/page/extension/m2m_migration_dialog.php(230): Toolset_Relationship_Migration_Controller->get_legacy_relationship_post_type_pairs() #1 .../wp-content/plugins/types/application/controllers/page/extension/m2m_migration_dialog.php(187): Types_Page_Extension_M2m_Migration_Dialog->has_translatable_post_types_in_relationships() #2 .../wp-includes/class-wp-hook.php(286): Types_Page_Extension_M2m_Migration_Dialog->on_admin_enqueue_scripts('toolset_page_to...') #3 .../wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #4 .../wp-includes/plugin.php(453): WP_Hook->do_action(Array) in .../wp-content/plugins/types/vendor/toolset/toolset-common/inc/m2m/migration/controller.php on line 268

I installed the latest beta and then migrated my old post relationships. After that I decided to not use them und removed my old post-types completely. Now I can not open the settings page anymore.

#630229

I repeated those steps but I could not produce the error.

Can you provide us with a copy of the site before you migrated, or if you do not have any copy anymore, one of the actual site?

We can then analyse this and fix it.

I see that the code itself has the potential to fail.

$child_post_type_obj = $this->post_type_repository->get( $child_post_type );

We do $child_post_type_obj->can_be_used_in_relationship() later and if $child_post_type_obj is not what we expect, it may fail.

Classic "unsafe code" at first glimpse, but this is always tricky, then the code is expected to have certain values and it's not good to just remove the issue by "checking if the value is as expected" before proceeding.

This may hide errors, which now show as in your example.
So I will immediately involve the DEV after I have a copy of your site

#630236
Bildschirmfoto 2018-03-31 um 10.21.57.png

The Link is not added.

Can you paste it again please, in the private reply?

#630241

Not added.

Please paste it into the normal post body.
Seems the forum is broken 🙁

Thank you a lot and please apologise this problem, I reported it and I hope this will be fixed ASAP.

#630243

Received and downloading

#630245

OK, this is not a clean Beta site.
The beta plugins version may conflict with some of your plugins.

I also cannot replicate the site, as the duplicator fails in a generic error 500.
Not even after I deactivate all plugins during the install steps it works.

I cannot build up the copy even manually, it doesn't allow me to import the database.
It's too large.
So I added it to the Terminal and adjusted it manually.

Finally, I was able to call wp-admin which shows an endless chain of errors.

Function create_function() is deprecated in .../plugins/real-media-library/inc/others/AdvertHandler.class.php on line 190
Warning: Cannot modify header information - headers already sent by (output started at .../plugins/real-media-library/inc/others/AdvertHandler.class.php:190) in .../wp-includes/pluggable.php on line 1216
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in .../plugins/sitepress-multilingual-cms/lib/dqml2tree.php on line 475
Notice: is_404 was called <strong>incorrectly</strong>. Conditional query tags do not work before the query is run. Before then, they always return false. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in .../wp-includes/functions.php on line 4147
Notice: is_home was called <strong>incorrectly</strong>. Conditional query tags do not work before the query is run. Before then, they always return false. Please see <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.) in .../wp-includes/functions.php on line 4147

This website cannot work properly at any cost, it does not surprise me that Types will fail.

Have you tried to solve these errors, disabling all NOT supported Plugins (which is everything but WPML) and try again?
The betas are not to be used on stable or production sites, and/or with other plugins not part of the OTGS products.
Only stable versions should be used like this.

#630253

I am aware of the beta state, but the site is not really live by now and I do need those repeatable field groups. I don't wanted to release it now with post relationships and later have to switch ?

The site works fine without any problems.You should see the link above, do you? Could it be a problem with the duplication progress? I can also give you access.

I will deactivate the plugins later, but I do feel like this it not the problem. The latest stable version of types worked fine, too.

#630256

Well, the duplicator shows errors that are present on the site, this is not related to the duplication.

The plugin basically should not be used like this just now.
It may conflict.

I can log in to the live site if you provide the data, but that won't help a lot since the errors will be the same.
But I can try, maybe I can find the solution on the fly.

Private conversation enabled.

#630263

In about a month, but do not take this as an ETA.
It may be less or more.

Can you enable WP debug on that site?

As well, I need to know more about this:

After that I decided to not use them and removed my old post-types completely.

Which were the exact slugs of those post types?
I need to check the Database for it.
Please also install the plugin "ARI Adminer – WordPress Database Manager" so I can peek into the database, and disable all non-Toolset plugins.

Then I will try to see if there are erroneous entries in the database, which is what I suspect.

#630290

Hi Beda,

now all Plugins except yours are deactivated, ARI Adminer is installed and debug mode is on ?

I have also installed "Twenty Seventeen".

The slugs were "anchor", "download" and "shoplink"

Thank you ?

#630299

It's strange but I still see all plugins active...

I also saw now that this is related to WPML, and that may be replicable, as I did not test that in my previous test, I used Toolset only.

I saw in the database no directly related lingering entry of the types, but there are entries along the lines of "post_shoplinks-group", which I assume to be leftovers from those posts.

This may conflict here as the error actually has a stack where WPML is involved.

I need to re-test this.

I saw in your FTP that you have a structure which duplicator may mess up.
Could I ask for this data:

- a database copy,
- the zipped up folder of "Website" from your FTP.

Can you share this with us in a google drive link (share with anyone who has the link).

Then we can go to the bottom of this.
I suspect translated remains of the posts are causing this issue, and it would help us greatly if we can put our hands on the "real" case.

I will notify my colleagues of this and your other thread, so it does not get missed in any case.

#631404

I deployed the site and again it fails with falls out of the box as soon you try to load /wp-admin and need to log in.

The errors are the same as previously mentioned.
I needed to remove the heavily customized .htaccess as well and regenerated it.

The first thing I did after logging in is to use Theme Twenty Seventeen so to exclude custom code issues.
I updated the Theme (2017) and re-enabled Toolset and WPML.

Finally, I was able to see the error in the Toolset Settings Screen, along with several others.
Deactivating WPML solved the issue, enabling just Types and WPML Multilingual CMS brings the error back.

I deleted all other plugins and restored the WordPress install as much I could.
Replaced the Plugins (Types and WPML) with the actual fresh copies from each download area.

The error is still visible.

I escalated this to the Developers, let's hope they can narrow the issue down.

#631588

Hi Beda,

have you seen the right login url I posted in this comment? Login via wp-admin is not be possible.
https://toolset.com/forums/topic/fatal-error-uncaught-error-call-to-a-member-function-can_be_used_in_relationsh/#post-630259

Thank you for testing. So it has something todo with wpml? Just this website, or every website using types + wpml?

#652176

This will be resolved in the coming 3.0 release of Toolset Types.

When WPML is active, Types is collecting a list of translatable relationship post types for the migration dialogue.

In your case, in the Database, the involved post types of the legacy relationship (old method) are no longer there
(We are not sure how it was possible to delete the post type, but the relationship wasn't updated).

We are now applying checks to the existence of the post types, additionally, so this cannot fail anymore even if an unexpected value is still present in the Database.

#921615

This was released with the 3.0 updates.