From 5bc0f4b3d49ed1bea45464beece42906646eb026 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 00:24:32 +0100 Subject: [ticket/11015] Move db driver class name fixing to function PHPBB3-11015 --- phpBB/includes/functions.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 804d89d1a2..045a28672b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5412,3 +5412,19 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } + +/** +* Convert 3.0 dbms to 3.1 db driver class name +* +* @param string $dbms dbms parameter +* @return db driver class +*/ +function phpbb_convert_30_dbms_to_31($dbms) +{ + if (!preg_match('#^phpbb_db_driver_#', $dbms)) + { + return 'phpbb_db_driver_'.$dbms; + } + + return $dbms; +} -- cgit v1.2.1 From 0372ecf14141ba2c174782f29d4fb079b4dd56c3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:40:32 +0100 Subject: [ticket/11015] Make phpbb_convert_30_dbms_to_31 more future proof It should allow any class name in the future, as long as that class exists. And it should give a useful error message otherwise. PHPBB3-11015 --- phpBB/includes/functions.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 045a28672b..57136a43ff 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5421,10 +5421,15 @@ function phpbb_to_numeric($input) */ function phpbb_convert_30_dbms_to_31($dbms) { - if (!preg_match('#^phpbb_db_driver_#', $dbms)) + if (class_exists($dbms)) { - return 'phpbb_db_driver_'.$dbms; + return $dbms; } - return $dbms; + if (class_exists('phpbb_db_driver_' . $dbms)) + { + return 'phpbb_db_driver_' . $dbms; + } + + throw new \RuntimeException('You have specified an invalid dbms driver.'); } -- cgit v1.2.1 From e765ccd075a19be7ec9c60970677d62dc75f0845 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 04:22:10 -0500 Subject: [ticket/11015] Include dbms name in exception message. PHPBB3-11015 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 57136a43ff..501257956a 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5431,5 +5431,5 @@ function phpbb_convert_30_dbms_to_31($dbms) return 'phpbb_db_driver_' . $dbms; } - throw new \RuntimeException('You have specified an invalid dbms driver.'); + throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } -- cgit v1.2.1 From 9e3fd3bf8e8ff08b159d9151aef6f9bb6b9244ee Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 19:07:49 -0500 Subject: [ticket/11015] Fix 3.0 to 3.1 dbms conversion for mysqli. PHPBB3-11015 --- phpBB/includes/functions.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4bf991ca9e..5c08d457b6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5550,23 +5550,39 @@ function phpbb_to_numeric($input) } /** -* Convert 3.0 dbms to 3.1 db driver class name +* Convert either 3.0 dbms or 3.1 db driver class name to 3.1 db driver class name. +* +* If $dbms is a valid 3.1 db driver class name, returns it unchanged. +* Otherwise prepends phpbb_db_driver_ to the dbms to convert a 3.0 dbms +* to 3.1 db driver class name. * * @param string $dbms dbms parameter * @return db driver class */ function phpbb_convert_30_dbms_to_31($dbms) { - if (class_exists($dbms)) + // Note: this check is done first because mysqli extension + // supplies a mysqli class, and class_exists($dbms) would return + // true for mysqli class. + // However, per the docblock any valid 3.1 driver name should be + // recognized by this function, and have priority over 3.0 dbms. + if (class_exists('phpbb_db_driver_' . $dbms)) { - return $dbms; + return 'phpbb_db_driver_' . $dbms; } - if (class_exists('phpbb_db_driver_' . $dbms)) + if (class_exists($dbms)) { - return 'phpbb_db_driver_' . $dbms; + return $dbms; } + // Additionally we could check that $dbms extends phpbb_db_driver. + // http://php.net/manual/en/class.reflectionclass.php + // Beware of possible performance issues: + // http://stackoverflow.com/questions/294582/php-5-reflection-api-performance + // We could check for interface implementation in all paths or + // only when we do not prepend phpbb_db_driver_. + throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } -- cgit v1.2.1 From ee7dc9e5a061038eadce40ed295d47f978b9e567 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 14 Dec 2012 01:08:09 +0100 Subject: [ticket/11015] Correctly transform 'mysqli' etc. in phpbb_convert_30_dbms_to_31 PHPBB3-11015 --- phpBB/includes/functions.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 5c08d457b6..575dd11388 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5573,6 +5573,15 @@ function phpbb_convert_30_dbms_to_31($dbms) if (class_exists($dbms)) { + /* + $reflection = new \ReflectionClass($dbms); + + if ($reflection->isSubclassOf('phpbb_db_driver')) + { + return $dbms; + } + */ + return $dbms; } -- cgit v1.2.1 From 89f069637cd95f584db924407378b64df9910243 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 19:21:23 -0500 Subject: [ticket/11015] Move comment in the right place. PHPBB3-11015 --- phpBB/includes/functions.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 575dd11388..8ef5284134 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5573,6 +5573,13 @@ function phpbb_convert_30_dbms_to_31($dbms) if (class_exists($dbms)) { + // Additionally we could check that $dbms extends phpbb_db_driver. + // http://php.net/manual/en/class.reflectionclass.php + // Beware of possible performance issues: + // http://stackoverflow.com/questions/294582/php-5-reflection-api-performance + // We could check for interface implementation in all paths or + // only when we do not prepend phpbb_db_driver_. + /* $reflection = new \ReflectionClass($dbms); @@ -5585,13 +5592,6 @@ function phpbb_convert_30_dbms_to_31($dbms) return $dbms; } - // Additionally we could check that $dbms extends phpbb_db_driver. - // http://php.net/manual/en/class.reflectionclass.php - // Beware of possible performance issues: - // http://stackoverflow.com/questions/294582/php-5-reflection-api-performance - // We could check for interface implementation in all paths or - // only when we do not prepend phpbb_db_driver_. - throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } -- cgit v1.2.1