Web based family history software

Question Custom module errors with webtrees 2.2.0: Call to undefined function app/make

  • Jefferson49
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 week 6 days ago - 1 week 6 days ago #1 by Jefferson49
After installing the new webtrees 2.2.0 version, several custom modules throw error messages:
  1. Call to undefined function Jefferson49\Webtrees\Module\ExtendedImportExport\app()
  2. Call to undefined method Fisharebest\Webtrees\Webtrees::make()

ExtendedImportExport, FancyResearchLinks, FancyTreeview, RepositoryHierarchy, webtrees-branch-statistics:

Fatal error in module: extended_import_export
Error: Call to undefined function Jefferson49\Webtrees\Module\ExtendedImportExport\app() in C:\wamp64\www\webtrees\modules_v4\extended_import_export\DownloadGedcomWithURL.php:221 Stack trace: #0 C:\wamp64\www\webtrees\modules_v4\extended_import_export\module.php(57): Jefferson49\Webtrees\Module\ExtendedImportExport\DownloadGedcomWithURL->__construct() #1 C:\wamp64\www\webtrees\app\Services\ModuleService.php(722): include('C:\\wamp64\\www\\w...') #2 C:\wamp64\www\webtrees\app\Services\ModuleService.php(702): Fisharebest\Webtrees\Services\ModuleService::load('C:\\wamp64\\www\\w...') #3 [internal function]: Fisharebest\Webtrees\Services\ModuleService::Fisharebest\Webtrees\Services\{closure}('C:\\wamp64\\www\\w...', 1)


GV Export:

Fatal error in module: GVExport
Error: Call to undefined method Fisharebest\Webtrees\Webtrees::make() in C:\wamp64\www\webtrees\modules_v4\GVExport\module.php:414 Stack trace: #0 C:\wamp64\www\webtrees\app\Services\ModuleService.php(722): include() #1 C:\wamp64\www\webtrees\app\Services\ModuleService.php(702): Fisharebest\Webtrees\Services\ModuleService::load('C:\\wamp64\\www\\w...') #2 [internal function]: Fisharebest\Webtrees\Services\ModuleService::Fisharebest\Webtrees\Services\{closure}('C:\\wamp64\\www\\w...', 2)


Does webtrees 2.2 include some changes in the custom module API, which need to be adopted? Or is it a bug? 
Last edit: 1 week 6 days ago by Jefferson49. Reason: Added question

Please Log in or Create an account to join the conversation.

  • fisharebest
  • Away
  • Administrator
  • Administrator
More
1 week 6 days ago #2 by fisharebest
This is a change in the core code, and will need a small change in the module.

webtrees uses a number of libraries and conventions from the Laravel framework. One of these is that the function app() is used to access the dependency-injection container.

i.e. if you want to create an object of type Foo, you would previously have used app(Foo::class).

Firstly, this has issues with testing, and secondly it is considered bad practice to create functions in the global namespace.

So, in 2.2, the container is accessed via a "service-locator/registry" system.

In short,

app(Foo::class) becomes Registery::container()->get(Foo::class)

Greg Roach - greg@subaqua.co.uk - @fisharebest@phpc.social - fisharebest.webtrees.net

Please Log in or Create an account to join the conversation.

  • Jefferson49
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 week 6 days ago #3 by Jefferson49

So, in 2.2, the container is accessed via a "service-locator/registry" system.

In short,

app(Foo::class) becomes Registery::container()->get(Foo::class)
Thank you Greg for the fast explanation. I agree that it is easy to change. It took only some minutes to fix it in my modules. However, it seems to work only in 2.2. To be still compatible with 2.1., it seems that the webtrees version needs to be checked.
Code:
if (version_compare(Webtrees::VERSION, '2.2.0', '>=')) {     return Registry::container()->get(SourcesReferenceNumbersList::class); } else {     return app(SourcesReferenceNumbersList::class); }

Is this the right way to go?
 

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #4 by kiwi
2.2 also requires a minimum version of php (8.3).
So perhaps better to create a “2.2 compatible “ version and leave the 2.1 version alone?

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago #5 by ric2015

2.2 also requires a minimum version of php (8.3).
So perhaps better to create a “2.2 compatible “ version and leave the 2.1 version alone?
 

When adjusting the Vesta modules for webtrees 2.2, I didn't encounter any backwards-incompatible php issues, so apart from the issue mentioned by Jefferson49 it's not too problematic to create a custom module release that works with both 2.1.21 and 2.2 (and php 8.2 - 8.4).

I ended up putting all calls to the container (including that version check) into separate helper methods (webtrees itself had those helper methods in 2.1.x: app/Webtrees::make() and app/Webtrees::set() - it would have been very helpful for custom modules if those had been kept at least in initial 2.2 releases as deprecated methods).
 

Richard

webtrees 2.2.0 at cissee.de/webtrees2
Vesta custom modules (Classic Look & Feel, Gov4webtrees, Shared Places, Extended Relationships) available at cissee.de

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago - 1 week 5 days ago #6 by RickM
Richard

Are you saying that Vesta Modules are compatible with WebTrees 2.2.0??

I get errors similar to attached image for all Vesta Modules and they DO NOT show up in the Control Panel >> Other or >> All Modules

 

Rick M
Tauranga
New Zealand - Nu Tirani

alineofmalkins.com/wt-malkins
Webtrees v2.2.1
Hosted by HostAmarada on litespeed Server, PHP v8.3
Last edit: 1 week 5 days ago by RickM.

Please Log in or Create an account to join the conversation.

More
1 week 5 days ago - 1 week 5 days ago #7 by ric2015

Richard

Are you saying that Vesta Modules are compatible with WebTrees 2.2.0??

I get errors similar to attached image for all Vesta Modules


 

Yes, the latest Vesta version (released yesterday) is compatible - In general, you can always determine this by checking the Readme files on github (or see the version number). As usual, the previous Vesta releases 2.1.20.x are not compatible with a higher webtrees version (normally the modules would just be made inactive internally in such a case, but this particular change in webtrees prevents this and causes the error message).
 

Richard

webtrees 2.2.0 at cissee.de/webtrees2
Vesta custom modules (Classic Look & Feel, Gov4webtrees, Shared Places, Extended Relationships) available at cissee.de
Last edit: 1 week 5 days ago by ric2015.

Please Log in or Create an account to join the conversation.

More
1 week 4 days ago - 4 days 8 hours ago #8 by Mperates
Hi all, I have now published a new version of GVexport that supports webtrees 2.2.0. I would have done the update earlier but I had a bit of trouble with the update. It seems the PHP module Imagick can have issues with PHP8.3, but I managed to get webtrees 2.2.0 running by disabling it.

Because of this breaking change in webtrees, the latest version of GVExport will only support webtrees 2.2.0 and up. I have also published a release with some recent unreleased changes to be the last release for 2.1.X.  I've now published a version that should support both 2.1.X and 2.2.X

See the releases section on github to grab the latest releases.
Last edit: 4 days 8 hours ago by Mperates.

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #9 by maalik
I have the same issue with several modules.

Is this something we can fix by ourself? Where does the Code need to be changed? Only a few files or a lot?

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago - 1 week 3 days ago #10 by maalik
Okay, figured it out by myself. As stated above: Edit all occurrences of
Code:
app(Foo::class)
to
Code:
Registry::container()->get(Foo::class)

Watch out for trailing semicolon, in very few cases there is none (e.g. jc-fancy-treeview/FancyTreeviewModule.php line 1872.)

You also have to add 
Code:
use Fisharebest\Webtrees\Registry;
somewhere (recommended somewhere to the other in the top).
Last edit: 1 week 3 days ago by maalik.

Please Log in or Create an account to join the conversation.

More
1 week 2 days ago #11 by jcnventura
Added a pull request to JustCarmen's webtrees-fancy-research-links module at  github.com/JustCarmen/webtrees-fancy-res...links/pull/104/files

João Ventura - venturas.org/familytree

Please Log in or Create an account to join the conversation.

  • Jefferson49
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 week 2 hours ago #12 by Jefferson49
By adding a helper function to support the different handling in webtrees 2.1 and 2.2, I created new releases for the following custom modules: 
  •   Extended Import/Export (Advanced GEDCOM import, export, and filter operations. Also supports remote downloads/uploads via URL requests)
  •   Repository Hierarchy  (... to present the structure of a repository and its sources in a hierarchical manner; also including advanced features to improve the handling of source citations)
The following modules can be used in webtrees 2.2 without any changes:
  • Change Language with URL  (... to change the webtrees language by URL requests with the language provided as an URL parameter)
  • My Custom Tags  (... to provide custom tags, custom types, custom relationship descriptors, and custom roles in events)

The latest versions of the custom modules can be used in both, webtrees 2.1 and 2.2

Please Log in or Create an account to join the conversation.

More
4 days 12 hours ago #13 by miqrogroove

Please Log in or Create an account to join the conversation.

More
4 days 10 hours ago #14 by UksusoFF
Please post this to blog on webtrees.net

Please Log in or Create an account to join the conversation.

More
4 days 59 minutes ago #15 by Didier
So you have to replace app(Foo::class) with Registry::container()->get(Foo::class)
Okay. but I can't find the file(s) in which app(Foo::class) would be.
Can you tell me their path? (forgive my lack of skills). Thanks in advance

Please Log in or Create an account to join the conversation.

More
4 days 57 minutes ago #16 by maalik
Which module are you talking about?
You have to replace "Foo" with the corresponding variable.

Please Log in or Create an account to join the conversation.

More
4 days 47 minutes ago #17 by Didier
My error message is Error: Call to undefined function MyArtJaub\Webtrees\Module\app() in /homepages/29/d169090331/htdocs/webtrees/modules_v4/myartjaub_ruraltheme/module.php:170 so I guess it's about myartjaub_ruraltheme. The problem is that in module.php I can't find any app(Foo::class)

Please Log in or Create an account to join the conversation.

More
4 days 45 minutes ago #18 by miqrogroove
Just search for "app(" and remember if this is 3rd-party code it might need other changes.

Please Log in or Create an account to join the conversation.

More
4 days 44 minutes ago #19 by maalik
What is in module.php on line 170?

Please Log in or Create an account to join the conversation.

More
4 days 43 minutes ago - 4 days 42 minutes ago #20 by maalik
You can't just search for "app(Foo::class)", since the "Foo" is a Placeholder, for whatever variable is there.
So if there is e.g.
Code:
app(Didier::class)
you have to change it to
Code:
Registry::container()->get(Didier::class)
Last edit: 4 days 42 minutes ago by maalik.

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum