本文整理汇总了PHP中Piwik\Tracker::getDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP Tracker::getDatabase方法的具体用法?PHP Tracker::getDatabase怎么用?PHP Tracker::getDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Tracker
的用法示例。
在下文中一共展示了Tracker::getDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: outputResponse
public function outputResponse(Tracker $tracker)
{
if (!$tracker->shouldRecordStatistics()) {
$this->outputApiResponse($tracker);
Common::printDebug("Logging disabled, display transparent logo");
} elseif (!$tracker->hasLoggedRequests()) {
if (!$this->isHttpGetRequest() || !empty($_GET) || !empty($_POST)) {
Common::sendResponseCode(400);
}
Common::printDebug("Empty request => Piwik page");
echo "This resource is part of Piwik. Keep full control of your data with the leading free and open source <a href='https://piwik.org' target='_blank'>digital analytics platform</a> for web and mobile.";
} else {
$this->outputApiResponse($tracker);
Common::printDebug("Nothing to notice => default behaviour");
}
Common::printDebug("End of the page.");
if ($tracker->isDebugModeEnabled() && $tracker->isDatabaseConnected() && TrackerDb::isProfilingEnabled()) {
$db = Tracker::getDatabase();
$db->recordProfiling();
Profiler::displayDbTrackerProfile($db);
}
if ($tracker->isDebugModeEnabled()) {
Common::printDebug($_COOKIE);
Common::printDebug((string) $this->timer);
}
}
示例2: outputResponse
public function outputResponse(Tracker $tracker)
{
if (!$tracker->shouldRecordStatistics()) {
$this->outputApiResponse($tracker);
Common::printDebug("Logging disabled, display transparent logo");
} elseif (!$tracker->hasLoggedRequests()) {
if (!$this->isHttpGetRequest() || !empty($_GET) || !empty($_POST)) {
Common::sendResponseCode(400);
}
Common::printDebug("Empty request => Piwik page");
echo "<a href='/'>Piwik</a> is a free/libre web <a href='http://piwik.org'>analytics</a> that lets you keep control of your data.";
} else {
$this->outputApiResponse($tracker);
Common::printDebug("Nothing to notice => default behaviour");
}
Common::printDebug("End of the page.");
if ($tracker->isDebugModeEnabled() && $tracker->isDatabaseConnected() && TrackerDb::isProfilingEnabled()) {
$db = Tracker::getDatabase();
$db->recordProfiling();
Profiler::displayDbTrackerProfile($db);
}
if ($tracker->isDebugModeEnabled()) {
Common::printDebug($_COOKIE);
Common::printDebug((string) $this->timer);
}
}
示例3: outputResponse
public function outputResponse(Tracker $tracker)
{
if (!$tracker->shouldRecordStatistics()) {
$this->outputApiResponse($tracker);
Common::printDebug("Logging disabled, display transparent logo");
} elseif (!$tracker->hasLoggedRequests()) {
if (!$this->isHttpGetRequest() || !empty($_GET) || !empty($_POST)) {
Common::sendResponseCode(400);
}
Common::printDebug("Empty request => Piwik page");
//echo date('Y-m-d H:i:s');
} else {
$this->outputApiResponse($tracker);
Common::printDebug("Nothing to notice => default behaviour");
}
Common::printDebug("End of the page.");
if ($tracker->isDebugModeEnabled() && $tracker->isDatabaseConnected() && TrackerDb::isProfilingEnabled()) {
$db = Tracker::getDatabase();
$db->recordProfiling();
Profiler::displayDbTrackerProfile($db);
}
if ($tracker->isDebugModeEnabled()) {
Common::printDebug($_COOKIE);
Common::printDebug((string) $this->timer);
}
}
示例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 (SettingsServer::isTrackerApiRequest()) {
return Tracker::getDatabase();
}
if (!self::hasDatabaseObject()) {
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 (!empty($GLOBALS['PIWIK_TRACKER_MODE'])) {
return Tracker::getDatabase();
}
if (self::$connection === null) {
self::createDatabaseObject();
}
return self::$connection;
}
示例6: 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));
}
示例7: 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);
}
示例8: assertActionEquals
private function assertActionEquals($expected, $idaction)
{
$actionName = Tracker::getDatabase()->fetchOne("SELECT name FROM " . Common::prefixTable('log_action') . " WHERE idaction = ?", array($idaction));
$this->assertEquals($expected, $actionName);
}
示例9: getDb
private function getDb()
{
return Tracker::getDatabase();
}
示例10: getDb
protected function getDb()
{
return Tracker::getDatabase();
}
示例11: 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;
}
示例12: 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();
}
$tableName = Common::prefixTable('log_profiling');
$all = $db->fetchAll('SELECT * FROM ' . $tableName);
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);
}
示例13: updateExistingConversion
protected function updateExistingConversion($newGoal, $updateWhere)
{
$updateParts = $sqlBind = $updateWhereParts = array();
foreach ($newGoal as $name => $value) {
$updateParts[] = $name . " = ?";
$sqlBind[] = $value;
}
foreach ($updateWhere as $name => $value) {
$updateWhereParts[] = $name . " = ?";
$sqlBind[] = $value;
}
$sql = 'UPDATE ' . Common::prefixTable('log_conversion') . "\n\t\t\t\t\tSET " . implode($updateParts, ', ') . "\n\t\t\t\t\t\tWHERE " . implode($updateWhereParts, ' AND ');
try {
Tracker::getDatabase()->query($sql, $sqlBind);
} catch (Exception $e) {
Common::printDebug("There was an error while updating the Conversion: " . $e->getMessage());
return false;
}
return true;
}
示例14: recognize
/**
* This methods tries to see if the visitor has visited the website before.
*
* We have to split the visitor into one of the category
* - Known visitor
* - New visitor
*/
public function recognize()
{
$this->setIsVisitorKnown(false);
$configId = $this->configId;
$idVisitor = $this->request->getVisitorId();
$isVisitorIdToLookup = !empty($idVisitor);
if ($isVisitorIdToLookup) {
$this->visitorInfo['idvisitor'] = $idVisitor;
Common::printDebug("Matching visitors with: visitorId=" . bin2hex($this->visitorInfo['idvisitor']) . " OR configId=" . bin2hex($configId));
} else {
Common::printDebug("Visitor doesn't have the piwik cookie...");
}
$selectCustomVariables = '';
// No custom var were found in the request, so let's copy the previous one in a potential conversion later
if (!$this->customVariables) {
$maxCustomVariables = CustomVariables::getMaxCustomVariables();
for ($index = 1; $index <= $maxCustomVariables; $index++) {
$selectCustomVariables .= ', custom_var_k' . $index . ', custom_var_v' . $index;
}
}
$persistedVisitAttributes = self::getVisitFieldsPersist();
array_unshift($persistedVisitAttributes, 'visit_first_action_time');
array_unshift($persistedVisitAttributes, 'visit_last_action_time');
$persistedVisitAttributes = array_unique($persistedVisitAttributes);
$selectFields = implode(", ", $persistedVisitAttributes);
$select = "SELECT\n {$selectFields}\n {$selectCustomVariables}\n ";
$from = "FROM " . Common::prefixTable('log_visit');
list($timeLookBack, $timeLookAhead) = $this->getWindowLookupThisVisit();
$shouldMatchOneFieldOnly = $this->shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup);
// Two use cases:
// 1) there is no visitor ID so we try to match only on config_id (heuristics)
// Possible causes of no visitor ID: no browser cookie support, direct Tracking API request without visitor ID passed,
// importing server access logs with import_logs.py, etc.
// In this case we use config_id heuristics to try find the visitor in tahhhe past. There is a risk to assign
// this page view to the wrong visitor, but this is better than creating artificial visits.
// 2) there is a visitor ID and we trust it (config setting trust_visitors_cookies, OR it was set using &cid= in tracking API),
// and in these cases, we force to look up this visitor id
$whereCommon = "visit_last_action_time >= ? AND visit_last_action_time <= ? AND idsite = ?";
$bindSql = array($timeLookBack, $timeLookAhead, $this->request->getIdSite());
if ($shouldMatchOneFieldOnly) {
if ($isVisitorIdToLookup) {
$whereCommon .= ' AND idvisitor = ?';
$bindSql[] = $this->visitorInfo['idvisitor'];
} else {
$whereCommon .= ' AND config_id = ?';
$bindSql[] = $configId;
}
$sql = "{$select}\n {$from}\n WHERE " . $whereCommon . "\n ORDER BY visit_last_action_time DESC\n LIMIT 1";
} else {
// will use INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time)
$where = ' AND config_id = ?';
$bindSql[] = $configId;
$sqlConfigId = "{$select} ,\n 0 as priority\n {$from}\n WHERE {$whereCommon} {$where}\n ORDER BY visit_last_action_time DESC\n LIMIT 1\n ";
// will use INDEX index_idsite_idvisitor (idsite, idvisitor)
$bindSql[] = $timeLookBack;
$bindSql[] = $timeLookAhead;
$bindSql[] = $this->request->getIdSite();
$where = ' AND idvisitor = ?';
$bindSql[] = $this->visitorInfo['idvisitor'];
$sqlVisitorId = "{$select} ,\n 1 as priority\n {$from}\n WHERE {$whereCommon} {$where}\n ORDER BY visit_last_action_time DESC\n LIMIT 1\n ";
// We join both queries and favor the one matching the visitor_id if it did match
$sql = " ( {$sqlConfigId} )\n UNION\n ( {$sqlVisitorId} )\n ORDER BY priority DESC\n LIMIT 1";
}
$visitRow = Tracker::getDatabase()->fetch($sql, $bindSql);
$isNewVisitForced = $this->request->getParam('new_visit');
$isNewVisitForced = !empty($isNewVisitForced);
$newVisitEnforcedAPI = $isNewVisitForced && ($this->request->isAuthenticated() || !Config::getInstance()->Tracker['new_visit_api_requires_admin']);
$enforceNewVisit = $newVisitEnforcedAPI || Config::getInstance()->Debug['tracker_always_new_visitor'];
if (!$enforceNewVisit && $visitRow && count($visitRow) > 0) {
// These values will be used throughout the request
foreach ($persistedVisitAttributes as $field) {
$this->visitorInfo[$field] = $visitRow[$field];
}
$this->visitorInfo['visit_last_action_time'] = strtotime($visitRow['visit_last_action_time']);
$this->visitorInfo['visit_first_action_time'] = strtotime($visitRow['visit_first_action_time']);
// Custom Variables copied from Visit in potential later conversion
if (!empty($selectCustomVariables)) {
$maxCustomVariables = CustomVariables::getMaxCustomVariables();
for ($i = 1; $i <= $maxCustomVariables; $i++) {
if (isset($visitRow['custom_var_k' . $i]) && strlen($visitRow['custom_var_k' . $i])) {
$this->visitorInfo['custom_var_k' . $i] = $visitRow['custom_var_k' . $i];
}
if (isset($visitRow['custom_var_v' . $i]) && strlen($visitRow['custom_var_v' . $i])) {
$this->visitorInfo['custom_var_v' . $i] = $visitRow['custom_var_v' . $i];
}
}
}
$this->setIsVisitorKnown(true);
Common::printDebug("The visitor is known (idvisitor = " . bin2hex($this->visitorInfo['idvisitor']) . ",\n config_id = " . bin2hex($configId) . ",\n idvisit = {$this->visitorInfo['idvisit']},\n last action = " . date("r", $this->visitorInfo['visit_last_action_time']) . ",\n first action = " . date("r", $this->visitorInfo['visit_first_action_time']) . ",\n visit_goal_buyer' = " . $this->visitorInfo['visit_goal_buyer'] . ")");
//Common::printDebug($this->visitorInfo);
} else {
Common::printDebug("The visitor was not matched with an existing visitor...");
}
//.........这里部分代码省略.........
示例15: getIdVisit
private function getIdVisit($idVisit)
{
$LogVisit = Factory::getDAO('log_visit', Tracker::getDatabase());
return $LogVisit->getByIdvisit($idVisit);
}