diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-09-17 23:36:37 +0300 |
---|---|---|
committer | diosmosis <diosmosis@users.noreply.github.com> | 2019-09-17 23:36:37 +0300 |
commit | d1260617f4dea3d8366f2ca284e79affca46c8a0 (patch) | |
tree | fd277fb1e814a7f584be1218e1bb3eacd3795bb8 | |
parent | 42b4ab13bc36511fabbf376e098e07ffae0d674a (diff) |
Allow custom DB adapter in tracker mode (#14876)
In regular mode we already use the above logic see https://github.com/matomo-org/matomo/blob/3.x-dev/core/Db/Adapter.php#L68-L74
This means in regular mode any plugin can already define a custom adapter and configure it. This was not working in tracking mode where the two PDO and MySQLI modes were hard coded. This was likely because back in the days we weren't using auto loading in tracker mode which we are doing now already for many years.
-rw-r--r-- | core/Tracker/Db.php | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/core/Tracker/Db.php b/core/Tracker/Db.php index 3b1b7ec41c..c3d1eeb987 100644 --- a/core/Tracker/Db.php +++ b/core/Tracker/Db.php @@ -261,18 +261,13 @@ abstract class Db */ Piwik::postEvent('Tracker.getDatabaseConfig', array(&$configDb)); - switch ($configDb['adapter']) { - case 'PDO\MYSQL': - case 'PDO_MYSQL': // old format pre Piwik 2 - require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Db/Pdo/Mysql.php'; - return new Mysql($configDb); - - case 'MYSQLI': - require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Db/Mysqli.php'; - return new Mysqli($configDb); + $className = 'Piwik\Tracker\Db\\' . str_replace(' ', '\\', ucwords(str_replace(array('_', '\\'), ' ', strtolower($configDb['adapter'])))); + + if (!class_exists($className)) { + throw new Exception('Unsupported database adapter ' . $configDb['adapter']); } - throw new Exception('Unsupported database adapter ' . $configDb['adapter']); + return new $className($configDb); } public static function connectPiwikTrackerDb() |