public function test_getServerVisitCustomVariables_shouldReturnSystemReport() { FakeAccess::clearAccess($superUser = true); for ($i = 1; $i < 15; $i++) { if (!Fixture::siteCreated($i)) { Fixture::createWebsite('2014-01-01 00:00:00'); } } for ($i = 1; $i < 9; $i++) { UsersApi::getInstance()->addUser($login = '******' . $i, 'password0815', "lorem{$i}@piwik.org"); } for ($i = 1; $i < 5; $i++) { SegmentApi::getInstance()->add('Segment' . $i, 'pageUrl%3D@inde'); } $customVars = array(array('id' => 1, 'name' => 'Piwik Version', 'value' => '2.14.3'), array('id' => 2, 'name' => 'PHP Version', 'value' => '5.5.27'), array('id' => 3, 'name' => 'Num Users', 'value' => 8), array('id' => 4, 'name' => 'Num Websites', 'value' => 14), array('id' => 5, 'name' => 'Num Segments', 'value' => 4), array('id' => 6, 'name' => 'MySQL Version', 'value' => Db::get()->getServerVersion())); $this->assertSame($customVars, $this->customVars->getServerVisitCustomVariables()); }
/** * To test execute the following command: * `./console core:run-scheduled-tasks "Piwik\Plugins\AnonymousPiwikUsageMeasurement\Tasks.sendSystemReport"` * * @throws \Exception */ public function sendSystemReport() { $trackers = $this->trackers->makeTrackers(); $customVars = $this->customVars->getServerVisitCustomVariables(); $profiles = $this->profiles->popAll(); foreach ($trackers as $tracker) { $tracker->enableBulkTracking(); foreach ($customVars as $customVar) { $tracker->setCustomVariable($customVar['id'], $customVar['name'], $customVar['value'], 'visit'); } $tracker->setAnonymousUrl('/system-report'); $tracker->doTrackPageView('System-Report'); foreach ($profiles as $profile) { $countAppendix = ' (count)'; $tracker->doTrackEvent($profile['category'] . $countAppendix, $profile['action'] . $countAppendix, $profile['name'] . $countAppendix, $profile['count']); if ($profile['count'] > 0) { $speedAppendix = ' (speed)'; $wallTimeAvg = round($profile['wall_time'] / $profile['count'], 1); $tracker->doTrackEvent($profile['category'] . $speedAppendix, $profile['action'] . $speedAppendix, $profile['name'] . $speedAppendix, $wallTimeAvg); } } $tracker->doBulkTrack(); } }