Skip to content

Commit 2882539

Browse files
committed
added support for utf8mb4 OC databases; updates #352
1 parent 47c931b commit 2882539

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

okapi/core.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public static function connect()
364364
if (mysql_connect(Settings::get('DB_SERVER'), Settings::get('DB_USERNAME'), Settings::get('DB_PASSWORD')))
365365
{
366366
mysql_select_db(Settings::get('DB_NAME'));
367-
mysql_query("set names 'utf8'");
367+
mysql_query("set names '" . Settings::get('DB_CHARSET') . "'");
368368
self::$connected = true;
369369
}
370370
else

okapi/services/caches/geocaches.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,8 @@ public static function call(OkapiRequest $request)
12001200
# Current OCPL table definitions use collation 'latin1' for parkipl
12011201
# and 'utf8' for np_areas. Union needs identical collations.
12021202
# To be sure, we convert both to utf8.
1203+
#
1204+
# TODO: use DB_CHARSET setting instead of literal 'utf8'
12031205
$rs = Db::query("
12041206
select
12051207
c.wp_oc as cache_code,

okapi/services/users/by_usernames.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use okapi\services\caches\search\SearchAssistant;
1111
use okapi\OkapiServiceRunner;
1212
use okapi\OkapiInternalRequest;
13+
use okapi\Settings;
1314

1415
class WebService
1516
{
@@ -38,7 +39,7 @@ public static function call(OkapiRequest $request)
3839
$rs = Db::query("
3940
select username, uuid
4041
from user
41-
where username collate utf8_general_ci in ('".implode("','", array_map('mysql_real_escape_string', $usernames))."')
42+
where username collate ".Settings::get('DB_CHARSET')."_general_ci in ('".implode("','", array_map('mysql_real_escape_string', $usernames))."')
4243
");
4344
$lower_username2useruuid = array();
4445
while ($row = mysql_fetch_assoc($rs))

okapi/settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ final class Settings
129129
'DB_NAME' => null,
130130
'DB_USERNAME' => null,
131131
'DB_PASSWORD' => null,
132+
'DB_CHARSET' => 'utf8',
132133

133134
/**
134135
* URL of this site (with slash, and without "/okapi"). If this is a
@@ -252,6 +253,10 @@ private static function verify(&$dict)
252253
throw new Exception("$key must end with a slash.");
253254
if ($dict['SITE_LOGO'] === null)
254255
$dict['SITE_LOGO'] = $dict['SITE_URL'] . 'okapi/static/oc_logo.png';
256+
257+
# The OKAPI code is only compatible with utf8 and utf8mb4 charsets.
258+
if (!in_array($dict['DB_CHARSET'], array('utf8', 'utf8mb4')))
259+
throw new exception("DB_CHARSET must be utf8 or utf8mb4.");
255260
}
256261

257262
/**

0 commit comments

Comments
 (0)