本文整理汇总了PHP中Piwik\Tracker类的典型用法代码示例。如果您正苦于以下问题:PHP Tracker类的具体用法?PHP Tracker怎么用?PHP Tracker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tracker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendRequest
protected function sendRequest($url, $method = 'GET', $data = null, $force = false)
{
// if doing a bulk request, store the url
if ($this->doBulkRequests && !$force) {
$this->storedTrackingActions[] = $url;
return true;
}
if ($method == 'POST') {
$requests = array();
foreach ($this->storedTrackingActions as $action) {
$requests[] = $this->parseUrl($action);
}
$testEnvironmentArgs = array();
} else {
$testEnvironmentArgs = $this->parseUrl($url);
$requests = array($testEnvironmentArgs);
}
// unset cached values
Cache::$trackerCache = null;
Tracker::setForceIp(null);
Tracker::setForceDateTime(null);
// save some values
$plugins = Config::getInstance()->Plugins['Plugins'];
$oldTrackerConfig = Config::getInstance()->Tracker;
\Piwik\Plugin\Manager::getInstance()->unloadPlugins();
// modify config
$GLOBALS['PIWIK_TRACKER_MODE'] = true;
$GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true;
Tracker::$initTrackerMode = false;
Tracker::setTestEnvironment($testEnvironmentArgs, $method);
// set language
$oldLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage;
// set user agent
$oldUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$_SERVER['HTTP_USER_AGENT'] = $this->userAgent;
// set cookie
$oldCookie = $_COOKIE;
// parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE);
// do tracking and capture output
ob_start();
$localTracker = new Tracker();
$localTracker->main($requests);
$output = ob_get_contents();
ob_end_clean();
// restore vars
Config::getInstance()->Tracker = $oldTrackerConfig;
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang;
$_SERVER['HTTP_USER_AGENT'] = $oldUserAgent;
$_COOKIE = $oldCookie;
$GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false;
$GLOBALS['PIWIK_TRACKER_MODE'] = false;
unset($_GET['bots']);
// reload plugins
\Piwik\Plugin\Manager::getInstance()->loadPlugins($plugins);
return $output;
}
示例2: shouldRun
public function shouldRun(Tracker $tracker)
{
if (Common::isPhpCliMode()) {
// don't run scheduled tasks in CLI mode from Tracker, this is the case
// where we bulk load logs & don't want to lose time with tasks
return false;
}
return $tracker->shouldRecordStatistics();
}
示例3: process
public function process(Tracker $tracker, RequestSet $requestSet)
{
$queueManager = $this->getQueueManager();
$queueManager->addRequestSetToQueues($requestSet);
$tracker->setCountOfLoggedRequests($requestSet->getNumberOfRequests());
$this->sendResponseNow($tracker, $requestSet);
if ($this->isAllowedToProcessInTrackerMode() && $queueManager->canAcquireMoreLocks()) {
$this->processQueue($queueManager);
}
}
示例4: get
/**
* Returns the database connection and creates it if it hasn't been already.
*
* @return \Piwik\Tracker\Db|\Piwik\Db\AdapterInterface|\Piwik\Db
*/
public static function get()
{
if (!empty($GLOBALS['PIWIK_TRACKER_MODE'])) {
return Tracker::getDatabase();
}
if (self::$connection === null) {
self::createDatabaseObject();
}
return self::$connection;
}
示例5: get
/**
* Returns the database connection and creates it if it hasn't been already.
*
* @return \Piwik\Tracker\Db|\Piwik\Db\AdapterInterface|\Piwik\Db
*/
public static function get()
{
if (SettingsServer::isTrackerApiRequest()) {
return Tracker::getDatabase();
}
if (!self::hasDatabaseObject()) {
self::createDatabaseObject();
}
return self::$connection;
}
示例6: loadTrackerPlugins
/**
* @return array names of plugins that have been loaded
*/
public function loadTrackerPlugins()
{
$this->unloadPlugins();
$pluginsTracker = PiwikConfig::getInstance()->Plugins_Tracker['Plugins_Tracker'];
if (empty($pluginsTracker)) {
return array();
}
$pluginsTracker = array_diff($pluginsTracker, Tracker::getPluginsNotToLoad());
$this->doNotLoadAlwaysActivatedPlugins();
$this->loadPlugins($pluginsTracker);
return $pluginsTracker;
}
示例7: loadTrackerPlugins
/**
* @return array names of plugins that have been loaded
*/
public function loadTrackerPlugins()
{
$this->unloadPlugins();
$pluginsTracker = PiwikConfig::getInstance()->Plugins_Tracker['Plugins_Tracker'];
if (empty($pluginsTracker)) {
return array();
}
$pluginsTracker = array_diff($pluginsTracker, Tracker::getPluginsNotToLoad());
if (defined('PIWIK_TEST_MODE')) {
$pluginsTracker = array_intersect($pluginsTracker, $this->getPluginsToLoadDuringTests());
}
$this->doNotLoadAlwaysActivatedPlugins();
$this->loadPlugins($pluginsTracker);
return $pluginsTracker;
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$systemCheck = new SystemCheck();
$systemCheck->checkRedisIsInstalled();
$trackerEnvironment = new Environment('tracker');
$trackerEnvironment->init();
Log::unsetInstance();
$trackerEnvironment->getContainer()->get('Piwik\\Access')->setSuperUserAccess(false);
$trackerEnvironment->getContainer()->get('Piwik\\Plugin\\Manager')->setTrackerPluginsNotToLoad(array('Provider'));
Tracker::loadTrackerEnvironment();
if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
$GLOBALS['PIWIK_TRACKER_DEBUG'] = true;
}
$backend = Queue\Factory::makeBackend();
$queueManager = Queue\Factory::makeQueueManager($backend);
if (!$queueManager->canAcquireMoreLocks()) {
$trackerEnvironment->destroy();
$this->writeSuccessMessage($output, array("Nothing to proccess. Already max number of workers in process."));
return;
}
$shouldProcess = false;
foreach ($queueManager->getAllQueues() as $queue) {
if ($queue->shouldProcess()) {
$shouldProcess = true;
break;
}
}
if (!$shouldProcess) {
$trackerEnvironment->destroy();
$this->writeSuccessMessage($output, array("No queue currently needs processing"));
return;
}
$output->writeln("<info>Starting to process request sets, this can take a while</info>");
register_shutdown_function(function () use($queueManager) {
$queueManager->unlock();
});
$startTime = microtime(true);
$processor = new Processor($queueManager);
$processor->setNumberOfMaxBatchesToProcess(1000);
$tracker = $processor->process();
$neededTime = microtime(true) - $startTime;
$numRequestsTracked = $tracker->getCountOfLoggedRequests();
$requestsPerSecond = $this->getNumberOfRequestsPerSecond($numRequestsTracked, $neededTime);
Piwik::postEvent('Tracker.end');
$trackerEnvironment->destroy();
$this->writeSuccessMessage($output, array(sprintf('This worker finished queue processing with %sreq/s (%s requests in %02.2f seconds)', $requestsPerSecond, $numRequestsTracked, $neededTime)));
}
示例9: test_rowCount_whenUpdating_returnsAllMatchedRowsNotOnlyUpdatedRows
public function test_rowCount_whenUpdating_returnsAllMatchedRowsNotOnlyUpdatedRows()
{
$db = Tracker::getDatabase();
// insert one record
$db->query("INSERT INTO `" . Common::prefixTable('option') . "` VALUES ('rowid', '1', false)");
// We will now UPDATE this table and check rowCount() value
$sqlUpdate = "UPDATE `" . Common::prefixTable('option') . "` SET option_value = 2";
// when no record was updated, return 0
$result = $db->query($sqlUpdate . " WHERE option_name = 'NOT FOUND'");
$this->assertSame(0, $db->rowCount($result));
// when one record was found and updated, returns 1
$result = $db->query($sqlUpdate . " WHERE option_name = 'rowid'");
$this->assertSame(1, $db->rowCount($result));
// when one record was found but NOT actually updated (as values have not changed), we make sure to return 1
// testing for MYSQLI_CLIENT_FOUND_ROWS and MYSQL_ATTR_FOUND_ROWS
$result = $db->query($sqlUpdate . " WHERE option_name = 'rowid'");
$this->assertSame(1, $db->rowCount($result));
}
示例10: runScheduledTasks
/**
* Tracker requests will automatically trigger the Scheduled tasks.
* This is useful for users who don't setup the cron,
* but still want daily/weekly/monthly PDF reports emailed automatically.
*
* This is similar to calling the API CoreAdminHome.runScheduledTasks
*/
public function runScheduledTasks()
{
$now = time();
// Currently, there are no hourly tasks. When there are some,
// this could be too aggressive minimum interval (some hours would be skipped in case of low traffic)
$minimumInterval = TrackerConfig::getConfigValue('scheduled_tasks_min_interval');
// If the user disabled browser archiving, he has already setup a cron
// To avoid parallel requests triggering the Scheduled Tasks,
// Get last time tasks started executing
$cache = Cache::getCacheGeneral();
if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerEnabled'])) {
Common::printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled.");
return;
}
$nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval;
if (defined('DEBUG_FORCE_SCHEDULED_TASKS') && DEBUG_FORCE_SCHEDULED_TASKS || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) {
$cache['lastTrackerCronRun'] = $now;
Cache::setCacheGeneral($cache);
Tracker::initCorePiwikInTrackerMode();
Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']);
Common::printDebug('-> Scheduled Tasks: Starting...');
// save current user privilege and temporarily assume Super User privilege
$isSuperUser = Piwik::hasUserSuperUserAccess();
// Scheduled tasks assume Super User is running
Piwik::setUserHasSuperUserAccess();
$tokens = CronArchive::getSuperUserTokenAuths();
$tokenAuth = reset($tokens);
$invokeScheduledTasksUrl = SettingsPiwik::getPiwikUrl() . "?module=API&format=csv&convertToUnicode=0&method=CoreAdminHome.runScheduledTasks&trigger=archivephp&token_auth={$tokenAuth}";
$cliMulti = new CliMulti();
$responses = $cliMulti->request(array($invokeScheduledTasksUrl));
$resultTasks = reset($responses);
// restore original user privilege
Piwik::setUserHasSuperUserAccess($isSuperUser);
Common::printDebug($resultTasks);
Common::printDebug('Finished Scheduled Tasks.');
} else {
Common::printDebug("-> Scheduled tasks not triggered.");
}
Common::printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC');
}
示例11: getDb
private function getDb()
{
return Tracker::getDatabase();
}
示例12: Tracker
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Base.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/Generic.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogVisit.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogVisit.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Mysql/LogLinkVisitAction.php';
require_once PIWIK_INCLUDE_PATH . '/core/Db/DAO/Pgsql/LogLinkVisitAction.php';
// TODO should move to Tracker application class later. currently needed for environment validation.
SettingsServer::setIsTrackerApiRequest();
$environment = new \Piwik\Application\Environment('tracker');
$environment->init();
Tracker::loadTrackerEnvironment();
$tracker = new Tracker();
$requestSet = new RequestSet();
ob_start();
try {
$handler = Handler\Factory::make();
$response = $tracker->main($handler, $requestSet);
if (!is_null($response)) {
echo $response;
}
} catch (Exception $e) {
echo "Error:" . $e->getMessage();
exit(1);
}
if (ob_get_level() > 1) {
ob_end_flush();
}
示例13: queryIdsAction
private static function queryIdsAction($actionsNameAndType)
{
$sql = TableLogAction::getSqlSelectActionId();
$bind = array();
$i = 0;
foreach ($actionsNameAndType as &$actionNameType) {
list($name, $type, $urlPrefix) = $actionNameType;
if (empty($name)) {
continue;
}
if ($i > 0) {
$sql .= " OR ( hash = CRC32(?) AND name = ? AND type = ? ) ";
}
$bind[] = $name;
$bind[] = $name;
$bind[] = $type;
$i++;
}
// Case URL & Title are empty
if (empty($bind)) {
return false;
}
$actionIds = Tracker::getDatabase()->fetchAll($sql, $bind);
return $actionIds;
}
示例14: outputApiResponse
private function outputApiResponse(Tracker $tracker)
{
if ($tracker->isDebugModeEnabled()) {
return;
}
if ($this->hasAlreadyPrintedOutput()) {
return;
}
$request = $_GET + $_POST;
if (array_key_exists('send_image', $request) && $request['send_image'] === '0') {
Common::sendResponseCode(204);
return;
}
$this->outputTransparentGif();
}
示例15: displayDbTrackerProfile
/**
* Print profiling report for the tracker
*
* @param \Piwik\Db $db Tracker database object (or null)
*/
public static function displayDbTrackerProfile($db = null)
{
if (is_null($db)) {
$db = Tracker::getDatabase();
}
$LogProfiling = Factory::getDAO('log_profiling', $db);
$all = $LogProfiling->getAll();
if ($all === false) {
return;
}
uasort($all, 'self::maxSumMsFirst');
$infoIndexedByQuery = array();
foreach ($all as $infoQuery) {
$query = $infoQuery['query'];
$count = $infoQuery['count'];
$sum_time_ms = $infoQuery['sum_time_ms'];
$infoIndexedByQuery[$query] = array('count' => $count, 'sumTimeMs' => $sum_time_ms);
}
self::getSqlProfilingQueryBreakdownOutput($infoIndexedByQuery);
}