From: Bartosz DziewoƄski Date: Wed, 11 Jan 2017 18:23:00 +0000 (-0800) Subject: MysqlInstaller: Restore missing function X-Git-Tag: 1.31.0-rc.0~4346^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=eb1e4bf240eebec7f572b323e8fb04810a872aee MysqlInstaller: Restore missing function Copied from rSVN45497. I'm not sure how to reproduce the circumstances in which this code gets called, so I didn't test it. But what we did before was clearly wrong. Bug: T154670 Change-Id: Id9b0282e7e65543999c9737950f5073ba2e81962 --- diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 5ff47e94f0..72697739c8 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -312,7 +312,7 @@ class MysqlInstaller extends DatabaseInstaller { 'IS_GRANTABLE' => 1, ], __METHOD__ ); foreach ( $res as $row ) { - $regex = $conn->likeToRegex( $row->TABLE_SCHEMA ); + $regex = $this->likeToRegex( $row->TABLE_SCHEMA ); if ( preg_match( $regex, $this->getVar( 'wgDBname' ) ) ) { unset( $grantOptions[$row->PRIVILEGE_TYPE] ); } @@ -325,6 +325,19 @@ class MysqlInstaller extends DatabaseInstaller { return true; } + /** + * Convert a wildcard (as used in LIKE) to a regex + * Slashes are escaped, slash terminators included + */ + protected function likeToRegex( $wildcard ) { + $r = preg_quote( $wildcard, '/' ); + $r = strtr( $r, [ + '%' => '.*', + '_' => '.' + ] ); + return "/$r/s"; + } + /** * @return string */