@@ -240,6 +240,69 @@ public function get_update_on_branch($force_update = false, $force_cache = false
240
240
return $ update_info === null ? array () : $ update_info ;
241
241
}
242
242
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
+
243
306
/**
244
307
* Obtains the latest version information
245
308
*
0 commit comments