How to specify two phpbb requirements

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

How to specify two phpbb requirements

Post by javiexin »

Hi,

With the publications of phpbb 3.2, now we find extensions that are valid in both 3.1 and 3.2.

The question is: is it possible to require specific versions for EACH individual version?

The situation now is that there are certain events (or core modifications/fixes) that are published in 3.2.0, but have not been published yet on 3.1.10 (will be there for 3.1.11). So an extension might want to require 3.1.11 or 3.2.0. Well, that could be ok, because 3.2.0 > 3.1.11... But what happens next? There will be events that are published in 3.1.11 and are NOT in 3.2.0, and they won't be until 3.2.1. So the requirement would be 3.1 >= 3.1.11 or 3.2 >= 3.2.1. And so on with following versions.

How should this be specified in the composer.json of the extension? Do we need to check this requirement in the extension code, and if yes, where, ext.php (only on enable)? Or anywhere else?

Thanks in advance,
-javiexin
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to specify two phpbb requirements

Post by 3Di »

That's something I solved with ext.php, here's an example that can be customized

ext.php

Code: Select all

	public function is_enableable()
	{
		/* @return bool */
		$bb3110 = ( phpbb_version_compare(PHPBB_VERSION, '3.1.10', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.2.0@dev', '<') );

		/* @return bool */
		$bb320 = ( phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=') );

		/**
		 * We rely on constants.php
		 */
		if ( ( ($bb320) || ($bb3110) ) && (function_exists('curl_version')) )
		{
			return true;
		}
		else
		{
			SELF::verbose_it();
		}
	}

	/**
	 * Let's tell the user what exactly is going on and provide a back-link.
	 * Using the User Object for BC.
	 */
	function verbose_it()
	{
		$this->container->get('user')->add_lang_ext('threedi/ipcf', 'ext_require');

		trigger_error($this->container->get('user')->lang['EXTENSION_REQUIREMENTS_NOTICE'] . adm_back_link(append_sid('index.' . $this->container->getParameter('core.php_ext'), 'i=acp_extensions&amp;mode=main')), E_USER_WARNING);
	}
language/en/ext_require.php

Code: Select all

$lang = array_merge($lang, array(
	'EXTENSION_REQUIREMENTS_NOTICE'	=>	'Your phpBB installation doesn\'t meet the requirements of <strong>IP Country Flag</strong> extension.<br />You need at least phpBB 3.1.10 or phpBB 3.2.0.<br />The presence of cURL is mandatory as well.',
));
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: How to specify two phpbb requirements

Post by nicofuma »

You can specify both version in the soft requirement this way: "phpbb/phpbb": "~3.1.10|~3.2.0" or "phpbb/phpbb": ">=3.1.10|>=3.2.0"
Member of phpBB Development-Team
No Support via PM
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5859
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: How to specify two phpbb requirements

Post by MattF »

Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to specify two phpbb requirements

Post by 3Di »

Way more elegant indeed.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: How to specify two phpbb requirements

Post by javiexin »

Thanks a lot to all, clear now!
-javiexin
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to specify two phpbb requirements

Post by 3Di »

nicofuma wrote: Fri Jan 20, 2017 7:35 am You can specify both version in the soft requirement this way: "phpbb/phpbb": "~3.1.10|~3.2.0" or "phpbb/phpbb": ">=3.1.10|>=3.2.0"
Thanks.

I am just curios to know what happens with travis.yml, how to amend it for test both versions and PHP versions too. But I think I should ask into the related topic that's not here as stickied anymore.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: How to specify two phpbb requirements

Post by javiexin »

nicofuma wrote: Fri Jan 20, 2017 7:35 am You can specify both version in the soft requirement this way: "phpbb/phpbb": "~3.1.10|~3.2.0" or "phpbb/phpbb": ">=3.1.10|>=3.2.0"
Sorry, one more question: if I read it right, what you are saying is that phpbb/phpbb must be either greater than 3.1.10, or greater than 3.2.0. This is exactly the same as saying it must be greater than 3.1.10, right?.

Probably, this should be something like: "phpbb/phpbb": ">=3.1.10,<3.2.0|>=3.2.0,<3.3.0" Not sure if I got the syntax right, but you get the idea. Probably, it would be more obvious with future versions: "phpbb/phpbb": ">=3.1.11,<3.2.0|>=3.2.1,<3.3.0"

Thanks a lot!
-javiexin

PS: This is the way it is checked in the code from VSE in the Skeleton extension, both minimum and maximum version checks:
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: How to specify two phpbb requirements

Post by kasimi »

I'm not sure about the second example with the | but here's what the ~ does: https://getcomposer.org/doc/articles/versions.md#tilde
nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: How to specify two phpbb requirements

Post by nicofuma »

I made a mistake indeed, "phpbb/phpbb": "~3.1.10|~3.2.0" is the best one (not sure about "phpbb/phpbb": ">=3.1.11,<3.2.0|>=3.2.1,<3.3.0", it should work I think, but...)
Member of phpBB Development-Team
No Support via PM
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: How to specify two phpbb requirements

Post by javiexin »

nicofuma wrote: Sun Jan 22, 2017 2:04 pm I made a mistake indeed, "phpbb/phpbb": "~3.1.10|~3.2.0" is the best one (not sure about "phpbb/phpbb": ">=3.1.11,<3.2.0|>=3.2.1,<3.3.0", it should work I think, but...)
kasimi wrote: Sun Jan 22, 2017 1:37 pm I'm not sure about the second example with the | but here's what the ~ does: https://getcomposer.org/doc/articles/versions.md#tilde
For completeness, I think that according to the documentation, these should be all equivalent:
  • "phpbb/phpbb": "~3.1.11||~3.2.1" - double pipe
  • "phpbb/phpbb": ">=3.1.11,<3.2.0||>=3.2.1,<3.3.0" - double pipe
  • "phpbb/phpbb": ">=3.1.11 <3.2.0 || >=3.2.1 <3.3.0" - space for and, same as ,
Definitely, the first one seems the best way to specify this. Thanks again!
-javiexin
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5859
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman

Re: How to specify two phpbb requirements

Post by MattF »

3Di wrote: Fri Jan 20, 2017 11:48 pm I am just curios to know what happens with travis.yml, how to amend it for test both versions and PHP versions too. But I think I should ask into the related topic that's not here as stickied anymore.
I wouldn't bother. phpBB 3.2.x usually has everything from 3.1.x in it. So if your 3.1/3.2 compat ext works in 3.2 it should work in 3.1. The main diffs between them with b.c. issues are really down to notifications.

At any rate, you can do it. But know that testing on each version is different. Testing in 3.2 uses the updated user and language classes, so you'd have to do version compares and generate separate code for each version of phpBB in your tests, which is ugly.

Anyway, in travis, assuming you're testing on 3.2.x already, to add a 3.1.x test:

Code: Select all

   - php: 5.4
     env: DB=mysqli
   - php: 5.4
     env: DB=mysqli;PHPBB_BRANCH=3.1.x
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to specify two phpbb requirements

Post by 3Di »

Thanks Matt. Gotcha.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “Extension Writers Discussion”