Skip to content

Commit 0540a29

Browse files
committed
Refactor compatibility check to a new function
1 parent c05a7ea commit 0540a29

3 files changed

Lines changed: 39 additions & 23 deletions

File tree

includes/qi.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,4 +866,39 @@ public static function phpbb_version_compare($version1, $version2, $operator = n
866866
}
867867
return version_compare($version1, $version2, $operator);
868868
}
869+
870+
/**
871+
* Check phpBB compatibility with the PHP environment
872+
*
873+
* phpBB 3.1.x is not compat with PHP >= 7 (700000)
874+
* phpBB 3.2.0-3.2.1 is not compat with PHP >= 7.2 (702000)
875+
* phpBB 3.2.x is not compat with PHP >= 7.3 (703000)
876+
* phpBB 3.3.x is not compat with PHP < 7.1.3 (70103)
877+
* phpBB 4.0.x is not compat with PHP < 7.3 (703000)
878+
*
879+
* @param string $phpbb_version Check a given phpBB version. If none given, will check QI's loaded phpBB.
880+
*
881+
* @return bool
882+
*/
883+
public static function php_phpbb_incompatible($phpbb_version = '')
884+
{
885+
if ($phpbb_version)
886+
{
887+
return
888+
(PHP_VERSION_ID >= 70000 && self::phpbb_version_compare($phpbb_version, '3.2', '<')) ||
889+
(PHP_VERSION_ID >= 70200 && self::phpbb_version_compare($phpbb_version, '3.2.2', '<')) ||
890+
(PHP_VERSION_ID >= 70300 && self::phpbb_version_compare($phpbb_version, '3.3', '<')) ||
891+
(PHP_VERSION_ID < 70103 && self::phpbb_version_compare($phpbb_version, '3.3', '>=')) ||
892+
(PHP_VERSION_ID < 70300 && self::phpbb_version_compare($phpbb_version, '4.0', '>='))
893+
;
894+
}
895+
896+
return
897+
(PHP_VERSION_ID >= 70000 && !defined('PHPBB_32')) ||
898+
(PHP_VERSION_ID >= 70200 && self::phpbb_version_compare(PHPBB_VERSION, '3.2.2', '<')) ||
899+
(PHP_VERSION_ID >= 70300 && !defined('PHPBB_33')) ||
900+
(PHP_VERSION_ID < 70103 && defined('PHPBB_33')) ||
901+
(PHP_VERSION_ID < 70300 && defined('PHPBB_40'))
902+
;
903+
}
869904
}

includes/settings.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,11 @@ public function validate()
166166
$validation_errors[] = ['BOARDS_DIR_MISSING', $this->get_boards_dir()];
167167
}
168168

169-
// Validate alt environment boards
169+
// Validate alt environment board's compatibility with current PHP environment
170170
if ($this->settings['alt_env'])
171171
{
172172
$phpbb_version = get_phpbb_version($this->qi_path . 'sources/phpBB3_alt/' . $this->settings['alt_env']);
173-
// phpBB 3.1.x is not compat with PHP >= 7 (700000)
174-
// phpBB 3.2.0-3.2.1 is not compat with PHP >= 7.2 (702000)
175-
// phpBB 3.2.x is not compat with PHP >= 7.3 (703000)
176-
// phpBB 3.3.x is not compat with PHP < 7.1.3 (70103)
177-
// phpBB 4.0.x is not compat with PHP < 7.3 (703000)
178-
if ((PHP_VERSION_ID >= 70000 && qi::phpbb_version_compare($phpbb_version, '3.2', '<')) ||
179-
(PHP_VERSION_ID >= 70200 && qi::phpbb_version_compare($phpbb_version, '3.2.2', '<')) ||
180-
(PHP_VERSION_ID >= 70300 && qi::phpbb_version_compare($phpbb_version, '3.3', '<')) ||
181-
(PHP_VERSION_ID < 70103 && qi::phpbb_version_compare($phpbb_version, '3.3', '>=')) ||
182-
(PHP_VERSION_ID < 70300 && qi::phpbb_version_compare($phpbb_version, '4.0', '>='))
183-
)
173+
if (qi::php_phpbb_incompatible($phpbb_version))
184174
{
185175
$validation_errors[] = ['PHP_INCOMPATIBLE', $phpbb_version, PHP_VERSION];
186176
}

modules/qi_create.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,8 @@ public function run()
2222
// postgres uses remove_comments function which is defined in functions_admin
2323
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
2424

25-
// phpBB 3.1.x is not compat with PHP 7 (700000)
26-
// phpBB 3.2.0-3.2.1 is not compat with PHP 7.2 (702000)
27-
// phpBB 3.2.x is not compat with PHP 7.3 (703000)
28-
// phpBB 3.3.x is not compat with PHP < 7.1.3 (70103)
29-
// phpBB 4.0.x is not compat with PHP < 7.3 (703000)
30-
if ((PHP_VERSION_ID >= 70000 && !defined('PHPBB_32')) ||
31-
(PHP_VERSION_ID >= 70200 && qi::phpbb_version_compare(PHPBB_VERSION, '3.2.2', '<')) ||
32-
(PHP_VERSION_ID >= 70300 && !defined('PHPBB_33')) ||
33-
(PHP_VERSION_ID < 70103 && defined('PHPBB_33')) ||
34-
(PHP_VERSION_ID < 70300 && defined('PHPBB_40'))
35-
)
25+
// Validate board's compatibility with current PHP environment
26+
if (qi::php_phpbb_incompatible())
3627
{
3728
trigger_error(qi::lang('PHP_INCOMPATIBLE', PHPBB_VERSION, PHP_VERSION));
3829
}

0 commit comments

Comments
 (0)