update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,11 +8,11 @@
|
|||
*/
|
||||
namespace Piwik\Tracker;
|
||||
|
||||
use Piwik\Access;
|
||||
use Piwik\ArchiveProcessor\Rules;
|
||||
use Piwik\CacheFile;
|
||||
use Piwik\Cache as PiwikCache;
|
||||
use Piwik\Common;
|
||||
use Piwik\Config;
|
||||
use Piwik\Log;
|
||||
use Piwik\Option;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Tracker;
|
||||
|
|
@ -23,19 +23,29 @@ use Piwik\Tracker;
|
|||
*/
|
||||
class Cache
|
||||
{
|
||||
private static $cacheIdGeneral = 'general';
|
||||
|
||||
/**
|
||||
* Public for tests only
|
||||
* @var CacheFile
|
||||
* @var \Piwik\Cache\Lazy
|
||||
*/
|
||||
static public $trackerCache = null;
|
||||
public static $cache;
|
||||
|
||||
static protected function getInstance()
|
||||
/**
|
||||
* @return \Piwik\Cache\Lazy
|
||||
*/
|
||||
private static function getCache()
|
||||
{
|
||||
if (is_null(self::$trackerCache)) {
|
||||
$ttl = Config::getInstance()->Tracker['tracker_cache_file_ttl'];
|
||||
self::$trackerCache = new CacheFile('tracker', $ttl);
|
||||
if (is_null(self::$cache)) {
|
||||
self::$cache = PiwikCache::getLazyCache();
|
||||
}
|
||||
return self::$trackerCache;
|
||||
|
||||
return self::$cache;
|
||||
}
|
||||
|
||||
private static function getTtl()
|
||||
{
|
||||
return Config::getInstance()->Tracker['tracker_cache_file_ttl'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,67 +54,68 @@ class Cache
|
|||
* @param int $idSite
|
||||
* @return array
|
||||
*/
|
||||
static function getCacheWebsiteAttributes($idSite)
|
||||
public static function getCacheWebsiteAttributes($idSite)
|
||||
{
|
||||
if($idSite == 'all') {
|
||||
return array();
|
||||
}
|
||||
$idSite = (int)$idSite;
|
||||
if($idSite <= 0) {
|
||||
if ('all' == $idSite) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$cache = self::getInstance();
|
||||
if (($cacheContent = $cache->get($idSite)) !== false) {
|
||||
$idSite = (int) $idSite;
|
||||
if ($idSite <= 0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$cache = self::getCache();
|
||||
$cacheId = $idSite;
|
||||
$cacheContent = $cache->fetch($cacheId);
|
||||
|
||||
if (false !== $cacheContent) {
|
||||
return $cacheContent;
|
||||
}
|
||||
|
||||
Tracker::initCorePiwikInTrackerMode();
|
||||
|
||||
// save current user privilege and temporarily assume Super User privilege
|
||||
$isSuperUser = Piwik::hasUserSuperUserAccess();
|
||||
Piwik::setUserHasSuperUserAccess();
|
||||
|
||||
$content = array();
|
||||
|
||||
/**
|
||||
* Triggered to get the attributes of a site entity that might be used by the
|
||||
* Tracker.
|
||||
*
|
||||
* Plugins add new site attributes for use in other tracking events must
|
||||
* use this event to put those attributes in the Tracker Cache.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* public function getSiteAttributes($content, $idSite)
|
||||
* {
|
||||
* $sql = "SELECT info FROM " . Common::prefixTable('myplugin_extra_site_info') . " WHERE idsite = ?";
|
||||
* $content['myplugin_site_data'] = Db::fetchOne($sql, array($idSite));
|
||||
* }
|
||||
*
|
||||
* @param array &$content Array mapping of site attribute names with values.
|
||||
* @param int $idSite The site ID to get attributes for.
|
||||
*/
|
||||
Piwik::postEvent('Tracker.Cache.getSiteAttributes', array(&$content, $idSite));
|
||||
Common::printDebug("Website $idSite tracker cache was re-created.");
|
||||
|
||||
// restore original user privilege
|
||||
Piwik::setUserHasSuperUserAccess($isSuperUser);
|
||||
Access::doAsSuperUser(function () use (&$content, $idSite) {
|
||||
/**
|
||||
* Triggered to get the attributes of a site entity that might be used by the
|
||||
* Tracker.
|
||||
*
|
||||
* Plugins add new site attributes for use in other tracking events must
|
||||
* use this event to put those attributes in the Tracker Cache.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* public function getSiteAttributes($content, $idSite)
|
||||
* {
|
||||
* $sql = "SELECT info FROM " . Common::prefixTable('myplugin_extra_site_info') . " WHERE idsite = ?";
|
||||
* $content['myplugin_site_data'] = Db::fetchOne($sql, array($idSite));
|
||||
* }
|
||||
*
|
||||
* @param array &$content Array mapping of site attribute names with values.
|
||||
* @param int $idSite The site ID to get attributes for.
|
||||
*/
|
||||
Piwik::postEvent('Tracker.Cache.getSiteAttributes', array(&$content, $idSite));
|
||||
Common::printDebug("Website $idSite tracker cache was re-created.");
|
||||
});
|
||||
|
||||
// if nothing is returned from the plugins, we don't save the content
|
||||
// this is not expected: all websites are expected to have at least one URL
|
||||
if (!empty($content)) {
|
||||
$cache->set($idSite, $content);
|
||||
$cache->save($cacheId, $content, self::getTtl());
|
||||
}
|
||||
|
||||
Tracker::restoreTrackerPlugins();
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear general (global) cache
|
||||
*/
|
||||
static public function clearCacheGeneral()
|
||||
public static function clearCacheGeneral()
|
||||
{
|
||||
self::getInstance()->delete('general');
|
||||
self::getCache()->delete(self::$cacheIdGeneral);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -113,12 +124,12 @@ class Cache
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
static public function getCacheGeneral()
|
||||
public static function getCacheGeneral()
|
||||
{
|
||||
$cache = self::getInstance();
|
||||
$cacheId = 'general';
|
||||
$cache = self::getCache();
|
||||
$cacheContent = $cache->fetch(self::$cacheIdGeneral);
|
||||
|
||||
if (($cacheContent = $cache->get($cacheId)) !== false) {
|
||||
if (false !== $cacheContent) {
|
||||
return $cacheContent;
|
||||
}
|
||||
|
||||
|
|
@ -131,26 +142,29 @@ class Cache
|
|||
/**
|
||||
* Triggered before the [general tracker cache](/guides/all-about-tracking#the-tracker-cache)
|
||||
* is saved to disk. This event can be used to add extra content to the cache.
|
||||
*
|
||||
*
|
||||
* Data that is used during tracking but is expensive to compute/query should be
|
||||
* cached to keep tracking efficient. One example of such data are options
|
||||
* that are stored in the piwik_option table. Querying data for each tracking
|
||||
* request means an extra unnecessary database query for each visitor action. Using
|
||||
* a cache solves this problem.
|
||||
*
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
*
|
||||
* public function setTrackerCacheGeneral(&$cacheContent)
|
||||
* {
|
||||
* $cacheContent['MyPlugin.myCacheKey'] = Option::get('MyPlugin_myOption');
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @param array &$cacheContent Array of cached data. Each piece of data must be
|
||||
* mapped by name.
|
||||
*/
|
||||
Piwik::postEvent('Tracker.setTrackerCacheGeneral', array(&$cacheContent));
|
||||
self::setCacheGeneral($cacheContent);
|
||||
Common::printDebug("General tracker cache was re-created.");
|
||||
|
||||
Tracker::restoreTrackerPlugins();
|
||||
|
||||
return $cacheContent;
|
||||
}
|
||||
|
||||
|
|
@ -160,12 +174,11 @@ class Cache
|
|||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
static public function setCacheGeneral($value)
|
||||
public static function setCacheGeneral($value)
|
||||
{
|
||||
$cache = self::getInstance();
|
||||
$cacheId = 'general';
|
||||
$cache->set($cacheId, $value);
|
||||
return true;
|
||||
$cache = self::getCache();
|
||||
|
||||
return $cache->save(self::$cacheIdGeneral, $value, self::getTtl());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,11 +186,12 @@ class Cache
|
|||
*
|
||||
* @param array|int $idSites Array of idSites to clear cache for
|
||||
*/
|
||||
static public function regenerateCacheWebsiteAttributes($idSites = array())
|
||||
public static function regenerateCacheWebsiteAttributes($idSites = array())
|
||||
{
|
||||
if (!is_array($idSites)) {
|
||||
$idSites = array($idSites);
|
||||
}
|
||||
|
||||
foreach ($idSites as $idSite) {
|
||||
self::deleteCacheWebsiteAttributes($idSite);
|
||||
self::getCacheWebsiteAttributes($idSite);
|
||||
|
|
@ -189,17 +203,16 @@ class Cache
|
|||
*
|
||||
* @param string $idSite (website ID of the site to clear cache for
|
||||
*/
|
||||
static public function deleteCacheWebsiteAttributes($idSite)
|
||||
public static function deleteCacheWebsiteAttributes($idSite)
|
||||
{
|
||||
$idSite = (int)$idSite;
|
||||
self::getInstance()->delete($idSite);
|
||||
self::getCache()->delete((int) $idSite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all Tracker cache files
|
||||
*/
|
||||
static public function deleteTrackerCache()
|
||||
public static function deleteTrackerCache()
|
||||
{
|
||||
self::getInstance()->deleteAll();
|
||||
self::getCache()->flushAll();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue