blob: 263c80abbf581482b7e785836427f7ad4b1e0d13 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\SitesManager\Tracker;
use Piwik\Date;
use Piwik\Tracker\Cache;
use Piwik\Tracker\Request;
use Piwik\Tracker\RequestProcessor;
use Piwik\Tracker\Visit\VisitProperties;
use Piwik\Plugins\SitesManager\Model as SitesManagerModel;
/**
* Handles site specific logic during tracking.
*/
class SitesManagerRequestProcessor extends RequestProcessor
{
/**
* @var SitesManagerModel
*/
private $sitesManagerModel;
public function __construct(SitesManagerModel $sitesManagerModel)
{
$this->sitesManagerModel = $sitesManagerModel;
}
public function recordLogs(VisitProperties $visitProperties, Request $request)
{
// if we successfully record some data and the date is older than the site's created time,
// update the created time so the data will be viewable in the UI
$idSite = $request->getIdSite();
$createdTimeTimestamp = $this->getSiteCreatedTime($idSite);
if (empty($createdTimeTimestamp)) {
return;
}
$requestTimestamp = Date::factory((int) $request->getCurrentTimestamp());
// replicating old Piwik logic, see:
// https://github.com/piwik/piwik/blob/baa6da86266c7c44bc2d65821c7ffe042c2f4716/core/Archive/ArchiveInvalidator.php#L150
// before when this was done during archive invalidation, the date would not have an attached time and
// one extra day was subtracted from the minimum.
// I am not sure why this is required or if it is still required, but some tests that check the contents
// of archive tables will fail w/o this.
$requestTimestamp = $requestTimestamp->subDay(1)->setTime('00:00:00');
if ($requestTimestamp->isEarlier($createdTimeTimestamp)) {
$this->updateSiteCreatedTime($idSite, $requestTimestamp);
}
}
private function getSiteCreatedTime($idSite)
{
$attributes = Cache::getCacheWebsiteAttributes($idSite);
if (!isset($attributes['ts_created'])) {
return null;
}
return Date::factory($attributes['ts_created']);
}
private function updateSiteCreatedTime($idSite, Date $timestamp)
{
$this->sitesManagerModel->updateSiteCreatedTime(array($idSite), $timestamp->getDatetime());
Cache::deleteCacheWebsiteAttributes($idSite);
}
}
|