How to implement correctly depencies between different extensions

Discussion forum for Extension Writers regarding Extension Development.
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

How to implement correctly depencies between different extensions

Post by javiexin »

Hi,

Here is the problem I have.

For a project I am working on, I need a "library" that is going to be used by a number of my extensions. It would be kind of a new "vendor" library if you wish, but loaded from an extension (because I understand that requiring the user to load something to the vendor folder is a no-no, right?).

Then, I have a core extension, that uses the above library, adding extra functionalities to the phpbb core. This would be a "normal" (ie conventional) extension.

And finally, I have sample use cases of the above extension that, in itself, are also extensions (mostly GUI oriented if not exclusively so).

So my question is: how do I make my "sample use case" extension depend on my "core functionality" extension, that in turn depends on the "library" extension?

These should all be enabled/disabled independently, but safely and in the right order.

My first guess is that I need to use migrations, although I might not have any need for a migration in some of these "extensions" (not in the library, nor in the samples). Also, I could use ext.php? maybe. Also, dependencies from services, even if some of these do not need any use for services.

Anyhow, the question is what is the "correct" way of doing this (for phpBB at least). And, even better, if you could point me in the direction of some (set of) extensions that does this (correctly), that would be awesome.

I know this is not a me-only problem, as other extensions add new events, and therefore they are "required" for any downstream extension that uses them...

Thanks a lot in advance!
-javiexin

PD: Just in case you wonder, the case in point is
- JS library to perform DOM modifications based on jQuery
- Advanced Profile Fields (including new types of CPFs, such as image selector, image upload, and some more; but no perceivable changes)
- Examples of real functional cases of the above, such as Multiple Ranks or Game Team Membership, that would use an Image Selector CPF, or a Profile Picture that would use am Image Upload CPF

Then, the Advanced Polls extension would also use the same JS library, and therefore would need to be decoupled from both extensions... as duplicates are BAD :evil:

Another example that I am NOT working on right now, but I might do later on, is the creation of a "Page" (from the Pages extension) that includes some specific content, such as a MAP with user locations, that would be stored in an specific CPF. So, it would need Pages and Advanced CPFs as mandatory extensions before being able to enable such an extension.
User avatar
MarkDHamill
Registered User
Posts: 4268
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: How to implement correctly depencies between different extensions

Post by MarkDHamill »

As I've learned, ext.php in your extension is used to enforce any constraints you might have, so potentially you could have is_enableable() in it not allow the extension to be installed if these constraints aren't met. Have it return false if the these are not installed.

In addition, your migration programs can have a depends_on() function. It could be set to check to see if some migration for a particular extension other than your own is installed:

Code: Select all

	static public function depends_on()
	{
		return array('\anothervendor\extension\migrations\release_1_0_0');
	}
This basically searches the migrations table to see if this migration is a row in the table. If it is, it is assumed to have been installed correctly.

Your use cases should be fine if the above is done, since your installation and migration programs will ensure correct version of the dependencies are installed.
Need phpBB services or a phpBB consultant? I offer most phpBB services. Getting lost managing phpBB? Buy my book, Mastering phpBB Administration. Kindle and paper versions available.
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to implement correctly depencies between different extensions

Post by 3Di »

@ Mark
That's not actually what the OP he's asking for. Actually ext.php seems to be the way to go for.

@ javexin almost of your questions have been already answered in this forum, a simple search this forum will help.

Regards.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to implement correctly depencies between different extensions

Post by 3Di »

Hello,
I did some search and finally I got what I knew you are looking for. Hopefully.
The use of packagist seems to be not an option for you, here we go then.

As Mark above said the ext.php is involved here... how?

There is an user (ForumHulp) that's used to do that for all of his extensions.
I link you to the github repositories of him
https://github.com/ForumHulp

The extension that's needed by the others is
https://github.com/ForumHulp/helper

An example of the ext.php file of an extension that requires it
https://github.com/ForumHulp/statistics ... er/ext.php

Hope this solves you question or at least helps.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: How to implement correctly depencies between different extensions

Post by javiexin »

This seems that may work. Only issue is that ForumHulp is relying on the fact that the extensions dependent from the helper one are only "forumhulp" extensions... But certainly a way to go!

The "problem" here is that there is no? way to know from the depended-on extension that there are other extensions that depend on it, and therefore either block the "disable" step of the depended-on, or auto-disable de dependent extension(s). As I said, forumhulp relies on the fact that all forumhulp extensions require the helper... Not generic, but definitely, a big step forward!

Thanks a lot,
-javiexin
PD: I have been running some of forumhulp's extensions... Specifically, the cronstatus one, but I believe it does not use this helper.
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to implement correctly depencies between different extensions

Post by 3Di »

Well, it seems to me. Maybe has been updated since?¿
https://github.com/ForumHulp/cronstatus ... er/ext.php

About the relationship between vendors, well... I think there is a solution somewhere.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 26812
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: How to implement correctly depencies between different extensions

Post by Paul »

Once there is proper dependency management in phpBB ( Hopefully in 3.3) then this can be properly fixed. Until then you will need to kinda hack around it badly enough
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to implement correctly depencies between different extensions

Post by 3Di »

When the going gets tough, the tough get going. :geek:

See: [Archimede docet] "Give me a fulcrum and I will lift the world".

Anyway, in the meantime that hopefully 3.3 will be out with this so expected feature, what should we do? Sit-down and roll our fingers? Is there a valid and more elegant alternative?
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: How to implement correctly depencies between different extensions

Post by javiexin »

3Di wrote:Well, it seems to me. Maybe has been updated since?¿
https://github.com/ForumHulp/cronstatus ... er/ext.php
Ah, I know now... I am NOT using the "forumhulp" cronstatus, but the "boardtools" cronstatus (co-authored by forumhulp). I think the forumhulp version is a "private" custom version of the CDB cronstatus (boardtools).
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 26812
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: How to implement correctly depencies between different extensions

Post by Paul »

3Di wrote:When the going gets tough, the tough get going. :geek:

See: [Archimede docet] "Give me a fulcrum and I will lift the world".

Anyway, in the meantime that hopefully 3.3 will be out with this so expected feature, what should we do? Sit-down and roll our fingers? Is there a valid and more elegant alternative?
Like I said, there is currently no good way of doing so. You can use a dependency, and include that in all your extensions, and it will work, but might cause issues if different versions are in different extensions. Or you do a ext.php check with another extension, however that has disavantages as well.

As far as I know the composer management will be managed pretty early in development process of 3.3, so I am kinda sure it will be in there on that is released. However, I have no idea on when that it will be ofcourse.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to implement correctly depencies between different extensions

Post by 3Di »

Indeed.
Here I am seeing Javiexin doesn't want to rely on Packagist, no more chances but ext.php. Atm.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: How to implement correctly depencies between different extensions

Post by javiexin »

I have taken a look at packagist, and I think it might be used for extension-to-library dependencies, but not for extension-to-extension dependencies. It might work when enabling (depended-on must be enabled to enable the depending extension), but what would happen with disabling (disabling depended-on does nothing to depending extension, so it might fail next time it is invoked, as the dependecy is not there...). Please, correct me if this is not the way it would work...

I think I will try to use a combination of what 3Di suggested from ForumHulp and a strict naming for extensions that will allow me to identify depending extensions from the depended-on one... Not ideal, hacky, but probably the only viable solution before 3.3.

Thanks a lot,
-javiexin
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to implement correctly depencies between different extensions

Post by 3Di »

This one, it is an add-on for another extension (phpbb/pages), checks for the existence (is enabled?) of it.. https://github.com/ForumHulp/pageaddon/ ... er/ext.php
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: How to implement correctly depencies between different extensions

Post by javiexin »

Precisely what I was saying: you can check whether pages is enabled at enable time, but what happens if you disable pages without disabling add-on?
-javiexin
User avatar
3Di
Former Team Member
Posts: 16032
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: How to implement correctly depencies between different extensions

Post by 3Di »

Javiexin, I remember a discussion where I did partecipate that talks about what you above posted, I am searching it with no succes though. It is here in this forum. The idea after all was that the childs extensions should act as a library/helper and once the main extension is disabled those should remain like "hidden".. burried there and doing nothing, more or less.

If I find it I will post the link, now I have to work a bit
(unfortunately I can say, today it's one of those blondes here.. :) )
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
Looking for a specific feature or alternative option? We will rock you! 🚀
Post Reply

Return to “Extension Writers Discussion”