|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if (class_exists('AbstractQueuedJob')) { |
|
4
|
|
|
/** |
|
5
|
|
|
* Class AnalyticsUpdateJob |
|
6
|
|
|
* |
|
7
|
|
|
* Job to run in the QueuedJobs |
|
8
|
|
|
*/ |
|
9
|
|
|
class AnalyticsUpdateJob extends AbstractQueuedJob |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var GoogleAnalyticsReportService |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $service; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var PageUpdateService |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $updateService; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* AnalyticsUpdateJob constructor. |
|
23
|
|
|
* @param array $params |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct($params = []) |
|
26
|
|
|
{ |
|
27
|
|
|
parent::__construct($params); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getTitle() |
|
34
|
|
|
{ |
|
35
|
|
|
return 'Update Google Analytics information for the configured pages'; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Boot up the process |
|
40
|
|
|
* @throws \Google_Exception |
|
41
|
|
|
* @throws \LogicException |
|
42
|
|
|
* @throws \ValidationException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function process() |
|
45
|
|
|
{ |
|
46
|
|
|
$clientService = new GoogleClientService(); |
|
47
|
|
|
|
|
48
|
|
|
$this->getReport($clientService); |
|
49
|
|
|
|
|
50
|
|
|
$this->isComplete = true; |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Execute the whole part |
|
55
|
|
|
* |
|
56
|
|
|
* @param GoogleClientService $client |
|
57
|
|
|
* @throws \ValidationException |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getReport($client) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->service = new GoogleAnalyticsReportService($client); |
|
62
|
|
|
|
|
63
|
|
|
/** @var array $reports */ |
|
64
|
|
|
$reports = $this->service->getReport(); |
|
65
|
|
|
$count = 0; |
|
66
|
|
|
|
|
67
|
|
|
$this->updateService = new PageUpdateService(); |
|
68
|
|
|
foreach ($reports as $report) { |
|
69
|
|
|
/** @var array $rows */ |
|
70
|
|
|
$rows = $report->getData()->getRows(); |
|
71
|
|
|
$count += $this->updateService->updateVisits($rows); |
|
72
|
|
|
} |
|
73
|
|
|
$this->addMessage("$count Pages updated with Google Analytics visit count"); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* If needed, queue itself with |
|
78
|
|
|
*/ |
|
79
|
|
|
public function afterComplete() |
|
80
|
|
|
{ |
|
81
|
|
|
if ($this->service->batched && $this->updateService->batched) { |
|
82
|
|
|
/** @var AnalyticsUpdateJob $nextJob */ |
|
83
|
|
|
$nextJob = Injector::inst()->get('AnalyticsUpdateJob'); |
|
|
|
|
|
|
84
|
|
|
$nextJob->setJobData(1, 0, false, new stdClass(), ['Batched data from Google']); |
|
85
|
|
|
/** @var QueuedJobService $jobService */ |
|
86
|
|
|
$jobService = Injector::inst()->get(QueuedJobService::class); |
|
|
|
|
|
|
87
|
|
|
/* Queue immediately after this job */ |
|
88
|
|
|
$jobService->queueJob($nextJob, date('Y-m-d H:i:s')); |
|
89
|
|
|
} |
|
90
|
|
|
parent::afterComplete(); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths