private function invalidateArchivesUsingActionDuplicates($archivesAffected, OutputInterface $output) { $output->write("Invalidating archives affected by duplicates fixed..."); foreach ($archivesAffected as $archiveInfo) { $this->archiveInvalidator->markArchivesAsInvalidated(array($archiveInfo['idsite']), $archiveInfo['server_time'], $period = false); } $output->writeln("Done."); }
public function test_markArchivesAsInvalidated_shouldForgetInvalidatedSitesAndDates() { $this->rememberReportsForManySitesAndDates(); $idSites = array(2, 10, 7, 5); $dates = '2014-04-05,2014-04-08,2010-10-10'; $this->invalidator->markArchivesAsInvalidated($idSites, $dates, false); $reports = $this->invalidator->getRememberedArchivedReportsThatShouldBeInvalidated(); $expected = array('2014-04-05' => array(1, 4), '2014-05-05' => array(2, 5), '2014-04-06' => array(3), '2014-05-08' => array(7)); $this->assertSame($expected, $reports); }
/** * When tracking data in the past (using Tracking API), this function * can be used to invalidate reports for the idSites and dates where new data * was added. * DEV: If you call this API, the UI should display the data correctly, but will process * in real time, which could be very slow after large data imports. * After calling this function via REST, you can manually force all data * to be reprocessed by visiting the script as the Super User: * http://example.net/piwik/misc/cron/archive.php?token_auth=$SUPER_USER_TOKEN_AUTH_HERE * REQUIREMENTS: On large piwik setups, you will need in PHP configuration: max_execution_time = 0 * We recommend to use an hourly schedule of the script. * More information: http://piwik.org/setup-auto-archiving/ * * @param string $idSites Comma separated list of idSite that have had data imported for the specified dates * @param string $dates Comma separated list of dates to invalidate for all these websites * @param string $period If specified (one of day, week, month, year, range) it will only invalidates archives for this period. * Note: because week, month, year, range reports aggregate day reports then you need to specifically invalidate day reports to see * other periods reports processed.. * @throws Exception * @return array * @hideExceptForSuperUser */ public function invalidateArchivedReports($idSites, $dates, $period = false) { $idSites = Site::getIdSitesFromIdSitesString($idSites); if (empty($idSites)) { throw new Exception("Specify a value for &idSites= as a comma separated list of website IDs, for which your token_auth has 'admin' permission"); } Piwik::checkUserHasAdminAccess($idSites); $invalidator = new ArchiveInvalidator(); $output = $invalidator->markArchivesAsInvalidated($idSites, $dates, $period); Site::clearCache(); return $output; }
/** * Invalidates report data, forcing it to be recomputed during the next archiving run. * * Note: This is done automatically when tracking or importing visits in the past. * * @param string $idSites Comma separated list of site IDs to invalidate reports for. * @param string $dates Comma separated list of dates of periods to invalidate reports for. * @param string|bool $period The type of period to invalidate: either 'day', 'week', 'month', 'year', 'range'. * The command will automatically cascade up, invalidating reports for parent periods as * well. So invalidating a day will invalidate the week it's in, the month it's in and the * year it's in, since those periods will need to be recomputed too. * @param string|bool $segment Optional. The segment to invalidate reports for. * @param bool $cascadeDown If true, child periods will be invalidated as well. So if it is requested to invalidate * a month, then all the weeks and days within that month will also be invalidated. But only * if this parameter is set. * @throws Exception * @return array * @hideExceptForSuperUser */ public function invalidateArchivedReports($idSites, $dates, $period = false, $segment = false, $cascadeDown = false) { $idSites = Site::getIdSitesFromIdSitesString($idSites); if (empty($idSites)) { throw new Exception("Specify a value for &idSites= as a comma separated list of website IDs, for which your token_auth has 'admin' permission"); } Piwik::checkUserHasAdminAccess($idSites); if (!empty($segment)) { $segment = new Segment($segment, $idSites); } else { $segment = null; } list($dateObjects, $invalidDates) = $this->getDatesToInvalidateFromString($dates); $invalidationResult = $this->invalidator->markArchivesAsInvalidated($idSites, $dateObjects, $period, $segment, (bool) $cascadeDown); $output = $invalidationResult->makeOutputLogs(); if ($invalidDates) { $output[] = 'Warning: some of the Dates to invalidate were invalid: ' . implode(", ", $invalidDates) . ". Piwik simply ignored those and proceeded with the others."; } Site::clearCache(); // TODO: is this needed? it shouldn't be needed... return $invalidationResult->makeOutputLogs(); }
/** * When tracking data in the past (using Tracking API), this function * can be used to invalidate reports for the idSites and dates where new data * was added. * DEV: If you call this API, the UI should display the data correctly, but will process * in real time, which could be very slow after large data imports. * After calling this function via REST, you can manually force all data * to be reprocessed by visiting the script as the Super User: * http://example.net/piwik/misc/cron/archive.php?token_auth=$SUPER_USER_TOKEN_AUTH_HERE * REQUIREMENTS: On large piwik setups, you will need in PHP configuration: max_execution_time = 0 * We recommend to use an hourly schedule of the script. * More information: http://piwik.org/setup-auto-archiving/ * * @param string $idSites Comma separated list of idSite that have had data imported for the specified dates * @param string $dates Comma separated list of dates to invalidate for all these websites * @param string $period If specified (one of day, week, month, year, range) it will only invalidates archives for this period. * Note: because week, month, year, range reports aggregate day reports then you need to specifically invalidate day reports to see * other periods reports processed.. * @throws Exception * @return array * @hideExceptForSuperUser */ public function invalidateArchivedReports($idSites, $dates, $period = false) { $idSites = Site::getIdSitesFromIdSitesString($idSites); if (empty($idSites)) { throw new Exception("Specify a value for &idSites= as a comma separated list of website IDs, for which your token_auth has 'admin' permission"); } Piwik::checkUserHasAdminAccess($idSites); list($dateObjects, $invalidDates) = $this->getDatesToInvalidateFromString($dates); $invalidator = new ArchiveInvalidator(); $output = $invalidator->markArchivesAsInvalidated($idSites, $dateObjects, $period); if ($invalidDates) { $output[] = 'Warning: some of the Dates to invalidate were invalid: ' . implode(", ", $invalidDates) . ". Piwik simply ignored those and proceeded with the others."; } Site::clearCache(); return $output; }
private function invalidatedReportsIfNeeded() { $siteIdsRequested = $this->getSiteIdsThatAreRequestedInThisArchiveButWereNotInvalidatedYet(); if (empty($siteIdsRequested)) { return; // all requested site ids were already handled } $sitesPerDays = $this->invalidator->getRememberedArchivedReportsThatShouldBeInvalidated(); foreach ($sitesPerDays as $date => $siteIds) { if (empty($siteIds)) { continue; } $siteIdsToActuallyInvalidate = array_intersect($siteIds, $siteIdsRequested); if (empty($siteIdsToActuallyInvalidate)) { continue; // all site ids that should be handled are already handled } try { $this->invalidator->markArchivesAsInvalidated($siteIdsToActuallyInvalidate, array(Date::factory($date)), false); } catch (\Exception $e) { Site::clearCache(); throw $e; } } Site::clearCache(); }