From 09e9d08bde62eb2a3be89f3d899c4887c9132bd7 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 2 Oct 2025 12:02:59 -0700 Subject: [PATCH 1/3] Only update composer/installers as needed --- contribution/extension/type.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/contribution/extension/type.php b/contribution/extension/type.php index 4ae327b78..e3ee5a70e 100644 --- a/contribution/extension/type.php +++ b/contribution/extension/type.php @@ -371,7 +371,15 @@ protected function update_phpbb_requirement(array $data) } // Composer installers must be required by all extensions in order to be installed correctly - $data['require']['composer/installers'] = '~1.0.0'; + if (!isset($data['require']['composer/installers'])) + { + $installers_version = '~1.0'; + if (isset($data['require']['phpbb/phpbb']) && $this->requires_phpbb_4_or_higher($data['require']['phpbb/phpbb'])) + { + $installers_version = '^1.0 || ^2.0'; + } + $data['require']['composer/installers'] = $installers_version; + } return $data; } @@ -387,6 +395,27 @@ protected function is_stable_version($version) return preg_match('#^\d+\.\d+\.\d+(-pl\d+)?$#i', $version) === 1 && phpbb_version_compare($version, '1.0.0', '>='); } + /** + * Check if phpBB requirement allows 4.0.0 or higher + * + * @param string $constraint Version constraint + * @return bool True if constraint allows phpBB 4.0.0+ + */ + protected function requires_phpbb_4_or_higher($constraint) + { + try + { + $parser = new \Composer\Semver\VersionParser(); + $constraintObj = $parser->parseConstraints($constraint); + // Check if the constraint excludes versions below 4.0.0 by testing if 3.9.9 does NOT satisfy the constraint + return !$constraintObj->matches(new \Composer\Semver\Constraint\Constraint('==', '3.9.9.0')); + } + catch (\Exception $e) + { + return false; + } + } + /** * Get prevalidator * From a60c6931d58a98318d85d4b395fc70f93348ffa2 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 2 Oct 2025 14:34:00 -0700 Subject: [PATCH 2/3] Improve constraint checking logic --- contribution/extension/type.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contribution/extension/type.php b/contribution/extension/type.php index e3ee5a70e..677820faa 100644 --- a/contribution/extension/type.php +++ b/contribution/extension/type.php @@ -396,19 +396,21 @@ protected function is_stable_version($version) } /** - * Check if phpBB requirement allows 4.0.0 or higher + * Check if phpBB requires 4.0.0 or higher * * @param string $constraint Version constraint - * @return bool True if constraint allows phpBB 4.0.0+ + * @return bool True if constraint requires phpBB 4.0.0+ */ protected function requires_phpbb_4_or_higher($constraint) { try { $parser = new \Composer\Semver\VersionParser(); - $constraintObj = $parser->parseConstraints($constraint); - // Check if the constraint excludes versions below 4.0.0 by testing if 3.9.9 does NOT satisfy the constraint - return !$constraintObj->matches(new \Composer\Semver\Constraint\Constraint('==', '3.9.9.0')); + $constraint_obj = $parser->parseConstraints($constraint); + $phpbb4_constraint = $parser->parseConstraints('>=4.0.0'); + $phpbb3_constraint = $parser->parseConstraints('<4.0.0'); + // Check if constraint allows 4.0.0+ and excludes all versions below 4.0.0 + return $constraint_obj->matches($phpbb4_constraint) && !$constraint_obj->matches($phpbb3_constraint); } catch (\Exception $e) { From 159621412d2206a1cf1b193e90504d972d7397f9 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 3 Oct 2025 11:16:41 -0700 Subject: [PATCH 3/3] Chech submission branch too if writing comp-installers --- contribution/extension/type.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/contribution/extension/type.php b/contribution/extension/type.php index 677820faa..eb7cf8645 100644 --- a/contribution/extension/type.php +++ b/contribution/extension/type.php @@ -280,7 +280,7 @@ protected function repack(package $package, \titania_contribution $contrib, \tit $ext_name = $data['name']; $data['type'] = 'phpbb-extension'; - $data = $this->update_phpbb_requirement($data); + $data = $this->update_phpbb_requirement($data, $revision); $data = $this->set_version_check($data, $contrib); $data = json_encode( @@ -352,9 +352,10 @@ protected function set_version_check(array $data, \titania_contribution $contrib * Updates phpBB requirements in composer.json * * @param array $data composer.json data + * @param \titania_revision $revision * @return array Returns $data array with phpBB requirement updated */ - protected function update_phpbb_requirement(array $data) + protected function update_phpbb_requirement(array $data, \titania_revision $revision) { if (!isset($data['require']['phpbb/phpbb'])) { @@ -374,7 +375,7 @@ protected function update_phpbb_requirement(array $data) if (!isset($data['require']['composer/installers'])) { $installers_version = '~1.0'; - if (isset($data['require']['phpbb/phpbb']) && $this->requires_phpbb_4_or_higher($data['require']['phpbb/phpbb'])) + if ($this->is_phpbb_4_branch($revision) || (isset($data['require']['phpbb/phpbb']) && $this->requires_phpbb_4($data['require']['phpbb/phpbb']))) { $installers_version = '^1.0 || ^2.0'; } @@ -401,7 +402,7 @@ protected function is_stable_version($version) * @param string $constraint Version constraint * @return bool True if constraint requires phpBB 4.0.0+ */ - protected function requires_phpbb_4_or_higher($constraint) + protected function requires_phpbb_4($constraint) { try { @@ -418,6 +419,17 @@ protected function requires_phpbb_4_or_higher($constraint) } } + /** + * Check if revision is submitted to phpBB 4.0+ branch + * + * @param \titania_revision $revision + * @return bool True if submitted to phpBB 4.0+ branch + */ + protected function is_phpbb_4_branch(\titania_revision $revision) + { + return max(array_column($revision->phpbb_versions, 'phpbb_version_branch')) >= 40; + } + /** * Get prevalidator *