Skip to content

Commit

Permalink
reimplemented caching; fixed detection of BOT 'os'
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed May 29, 2014
1 parent b826190 commit f85f7d6
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 22 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/CacheFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* It is for example used by the Tracker process to cache various settings and websites attributes in tmp/cache/tracker/*
*
*/
class CacheFile
class CacheFile implements \DeviceDetector\Cache\CacheInterface
{
// for testing purposes since tests run on both CLI/FPM (changes in CLI can't invalidate
// opcache in FPM, so we have to invalidate before reading)
Expand Down
12 changes: 9 additions & 3 deletions core/Tracker/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ protected function loadInfo()
$userAgent = $this->request->getUserAgent();

$deviceDetector = new DeviceDetector($userAgent);
#$deviceDetector->setCache(new CacheFile('tracker', 86400));
$deviceDetector->discardBotInformation();
$deviceDetector->setCache(new CacheFile('tracker', 86400));
$deviceDetector->parse();

$aBrowserInfo = $deviceDetector->getClient();
if ($aBrowserInfo['type'] != 'browser') {
// for now only track browsers
Expand All @@ -49,8 +51,12 @@ protected function loadInfo()
$browserName = !empty($aBrowserInfo['short_name']) ? $aBrowserInfo['short_name'] : 'UNK';
$browserVersion = !empty($aBrowserInfo['version']) ? $aBrowserInfo['version'] : '';

$os = $deviceDetector->getOS();
$os = empty($os['short_name']) ? 'UNK' : $os['short_name'];
if ($deviceDetector->isBot()) {
$os = 'BOT';
} else {
$os = $deviceDetector->getOS();
$os = empty($os['short_name']) ? 'UNK' : $os['short_name'];
}

$browserLang = substr($this->request->getBrowserLanguage(), 0, 20); // limit the length of this string to match db
$configurationHash = $this->getConfigHash(
Expand Down
3 changes: 3 additions & 0 deletions libs/UserAgentParser/UserAgentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,9 @@ static public function getOperatingSystemNameFromId($osId)
}

if(class_exists('DeviceDetector\\Parser\\OperatingSystem')) {
if ($osId == 'BOT') {
return 'Bot';
}
return DeviceDetector\Parser\OperatingSystem::getNameFromId($osId);
}
return false;
Expand Down
20 changes: 10 additions & 10 deletions piwik.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@

@ignore_user_abort(true);

/*
* Manually require needed vendor libraries, as composers autorequire would do too much
*/
if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')) {
$vendorDirectory = PIWIK_INCLUDE_PATH . '/vendor';
} else {
$vendorDirectory = PIWIK_INCLUDE_PATH . '/../..';
}
require_once $vendorDirectory . '/autoload.php';

require_once PIWIK_INCLUDE_PATH . '/core/Plugin/Controller.php';
require_once PIWIK_INCLUDE_PATH . '/core/Plugin/ControllerAdmin.php';

Expand Down Expand Up @@ -82,16 +92,6 @@
require_once PIWIK_INCLUDE_PATH . '/core/Cookie.php';
require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';

/*
* Manually require needed vendor libraries, as composers autorequire would do too much
*/
if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')) {
$vendorDirectory = PIWIK_INCLUDE_PATH . '/vendor';
} else {
$vendorDirectory = PIWIK_INCLUDE_PATH . '/../..';
}
require_once $vendorDirectory . '/autoload.php';

session_cache_limiter('nocache');
@date_default_timezone_set('UTC');

Expand Down
2 changes: 1 addition & 1 deletion plugins/DevicesDetection/DevicesDetection.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function parseMobileVisitData(&$visitorInfo, \Piwik\Tracker\Request $requ
$userAgent = $request->getUserAgent();

$UAParser = new DeviceDetector($userAgent);
#$UAParser->setCache(new CacheFile('tracker', 86400));
$UAParser->setCache(new CacheFile('tracker', 86400));
$UAParser->parse();
$deviceInfo['config_browser_name'] = $UAParser->getClient("type") == 'browser' ? $UAParser->getClient("short_name") : 'UNK';
$deviceInfo['config_browser_version'] = $UAParser->getClient("type") == 'browser' ? $UAParser->getClient("version") : 'UNK';
Expand Down
6 changes: 6 additions & 0 deletions plugins/DevicesDetection/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ function getModelName($label)

function getOSFamilyFullNameExtended($label)
{
if ($label == 'BOT') {
return 'Bot';
}
$label = OperatingSystemParser::getOsFamily($label);
if($label !== false) {
return $label;
Expand All @@ -183,6 +186,9 @@ function getOsFamilyLogoExtended($label)

function getOsFullNameExtended($label)
{
if ($label == 'BOT') {
return 'Bot';
}
if (!empty($label) && $label != ";") {
$os = substr($label, 0, 3);
$ver = substr($label, 4, 15);
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPUnit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
error_reporting(E_ALL | E_NOTICE);
@date_default_timezone_set('UTC');

require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')
? PIWIK_INCLUDE_PATH . '/vendor/autoload.php' // Piwik is the main project
: PIWIK_INCLUDE_PATH . '/../../autoload.php'; // Piwik is installed as a dependency

require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php';
Expand All @@ -37,9 +40,6 @@
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockPiwikOption.php';
require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php';
require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')
? PIWIK_INCLUDE_PATH . '/vendor/autoload.php' // Piwik is the main project
: PIWIK_INCLUDE_PATH . '/../../autoload.php'; // Piwik is installed as a dependency

\Piwik\Profiler::setupProfilerXHProf( $mainRun = true );

Expand Down
4 changes: 4 additions & 0 deletions tests/PHPUnit/proxy/includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
}

require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')
? PIWIK_INCLUDE_PATH . '/vendor/autoload.php' // Piwik is the main project
: PIWIK_INCLUDE_PATH . '/../../autoload.php'; // Piwik is installed as a dependency

require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
require_once PIWIK_INCLUDE_PATH . '/core/EventDispatcher.php';
require_once PIWIK_INCLUDE_PATH . '/core/Piwik.php';
Expand Down

0 comments on commit f85f7d6

Please sign in to comment.