Skip to content

Commit 1eda4f5

Browse files
committed
[ticket/15142] Merge branch 'ticket/15142' into 32x
PHPBB3-15142
2 parents f80b238 + d7c89ea commit 1eda4f5

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

extension/manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public function is_configured($name)
573573
* @param bool $force_update Ignores cached data. Defaults to false.
574574
* @param bool $force_cache Force the use of the cache. Override $force_update.
575575
* @param string $stability Force the stability (null by default).
576-
* @return string
576+
* @return array
577577
* @throws runtime_exception
578578
*/
579579
public function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false, $stability = null)
@@ -592,7 +592,7 @@ public function version_check(\phpbb\extension\metadata_manager $md_manager, $fo
592592
$version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename'], isset($version_check['ssl']) ? $version_check['ssl'] : false);
593593
$version_helper->force_stability($stability);
594594

595-
return $updates = $version_helper->get_suggested_updates($force_update, $force_cache);
595+
return $version_helper->get_ext_update_on_branch($force_update, $force_cache);
596596
}
597597

598598
/**

version_helper.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,69 @@ public function get_update_on_branch($force_update = false, $force_cache = false
240240
return $update_info === null ? array() : $update_info;
241241
}
242242

243+
/**
244+
* Gets the latest extension update for the current phpBB branch the user is on
245+
* Will suggest versions from newer branches when EoL has been reached
246+
* and/or version from newer branch is needed for having all known security
247+
* issues fixed.
248+
*
249+
* @param bool $force_update Ignores cached data. Defaults to false.
250+
* @param bool $force_cache Force the use of the cache. Override $force_update.
251+
* @return array Version info or empty array if there are no updates
252+
* @throws \RuntimeException
253+
*/
254+
public function get_ext_update_on_branch($force_update = false, $force_cache = false)
255+
{
256+
$versions = $this->get_versions_matching_stability($force_update, $force_cache);
257+
258+
$self = $this;
259+
$current_version = $this->current_version;
260+
261+
// Get current phpBB branch from version, e.g.: 3.2
262+
preg_match('/^(\d+\.\d+).*$/', $this->config['version'], $matches);
263+
$current_branch = $matches[1];
264+
265+
// Filter out any versions less than the current version
266+
$versions = array_filter($versions, function($data) use ($self, $current_version) {
267+
return $self->compare($data['current'], $current_version, '>=');
268+
});
269+
270+
// Filter out any phpbb branches less than the current version
271+
$branches = array_filter(array_keys($versions), function($branch) use ($self, $current_branch) {
272+
return $self->compare($branch, $current_branch, '>=');
273+
});
274+
if (!empty($branches))
275+
{
276+
$versions = array_intersect_key($versions, array_flip($branches));
277+
}
278+
else
279+
{
280+
// If branches are empty, it means the current phpBB branch is newer than any branch the
281+
// extension was validated against. Reverse sort the versions array so we get the newest
282+
// validated release available.
283+
krsort($versions);
284+
}
285+
286+
// Get the first available version from the previous list.
287+
$update_info = array_reduce($versions, function($value, $data) use ($self, $current_version) {
288+
if ($value === null && $self->compare($data['current'], $current_version, '>='))
289+
{
290+
if (!$data['eol'] && (!$data['security'] || $self->compare($data['security'], $data['current'], '<=')))
291+
{
292+
return $self->compare($data['current'], $current_version, '>') ? $data : array();
293+
}
294+
else
295+
{
296+
return null;
297+
}
298+
}
299+
300+
return $value;
301+
});
302+
303+
return $update_info === null ? array() : $update_info;
304+
}
305+
243306
/**
244307
* Obtains the latest version information
245308
*

0 commit comments

Comments
 (0)