diff options
Diffstat (limited to 'core/Option.php')
-rw-r--r-- | core/Option.php | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/core/Option.php b/core/Option.php index 0357865840..0b51d70286 100644 --- a/core/Option.php +++ b/core/Option.php @@ -47,10 +47,11 @@ class Option } /** - * Returns option values for options whose names are like a given pattern. + * Returns option values for options whose names are like a given pattern. Only `%` is supported as part of the + * pattern. * * @param string $namePattern The pattern used in the SQL `LIKE` expression - * used to SELECT options. + * used to SELECT options.`'%'` characters should be used as wildcard. Underscore match is not supported. * @return array Array mapping option names with option values. */ public static function getLike($namePattern) @@ -83,10 +84,10 @@ class Option } /** - * Deletes all options that match the supplied pattern. + * Deletes all options that match the supplied pattern. Only `%` is supported as part of the + * pattern. * - * @param string $namePattern Pattern of key to match. `'%'` characters should be used as wildcards, and literal - * `'_'` characters should be escaped. + * @param string $namePattern Pattern of key to match. `'%'` characters should be used as wildcard. Underscore match is not supported. * @param string $value If supplied, options will be deleted only if their value matches this value. */ public static function deleteLike($namePattern, $value = null) @@ -224,6 +225,8 @@ class Option protected function deleteNameLike($name, $value = null) { + $name = $this->getNameForLike($name); + $sql = 'DELETE FROM `' . Common::prefixTable('option') . '` WHERE option_name LIKE ?'; $bind[] = $name; @@ -237,8 +240,18 @@ class Option $this->clearCache(); } + private function getNameForLike($name) + { + $name = str_replace('\_', '###NOREPLACE###', $name); + $name = str_replace('_', '\_', $name); + $name = str_replace( '###NOREPLACE###', '\_', $name); + return $name; + } + protected function getNameLike($name) { + $name = $this->getNameForLike($name); + $sql = 'SELECT option_name, option_value FROM `' . Common::prefixTable('option') . '` WHERE option_name LIKE ?'; $bind = array($name); $rows = Db::fetchAll($sql, $bind); |