/**
  * Print information about progress.
  * @param OutputInterface $output
  */
 protected function onVisitProcessed(OutputInterface $output)
 {
     ++$this->processed;
     $percent = ceil($this->processed / $this->amountOfVisits * 100);
     if ($percent > $this->processedPercent && $percent % $this->percentStep === 0) {
         $output->writeln(sprintf('%d%% processed. <comment>%s</comment>', $percent, $this->timer->__toString()));
         $this->processedPercent = $percent;
     }
 }
Example #2
0
 /**
  * @param $idSite
  * @param $period
  * @param $date
  * @param $segmentsCount
  * @param $visitsInLastPeriods
  * @param $visitsToday
  * @param $timer
  */
 private function logArchivedWebsite($idSite, $period, $date, $segmentsCount, $visitsInLastPeriods, $visitsToday, Timer $timer)
 {
     if (strpos($date, 'last') === 0 || strpos($date, 'previous') === 0) {
         $humanReadable = $this->formatReadableDateRange($date);
         $visitsInLastPeriods = (int) $visitsInLastPeriods . " visits in {$humanReadable} " . $period . "s, ";
         $thisPeriod = $period == "day" ? "today" : "this " . $period;
         $visitsInLastPeriod = (int) $visitsToday . " visits " . $thisPeriod . ", ";
     } else {
         $visitsInLastPeriods = (int) $visitsInLastPeriods . " visits in " . $period . "s included in: {$date}, ";
         $visitsInLastPeriod = '';
     }
     $this->logger->info("Archived website id = {$idSite}, period = {$period}, {$segmentsCount} segments, " . $visitsInLastPeriods . $visitsInLastPeriod . $timer->__toString());
 }
 private function fixDuplicateActionsInTable(OutputInterface $output, $table, $toIdAction, $fromIdActions)
 {
     $timer = new Timer();
     $archivesAffected = $this->duplicateActionRemover->getSitesAndDatesOfRowsUsingDuplicates($table, $fromIdActions);
     $this->duplicateActionRemover->fixDuplicateActionsInTable($table, $toIdAction, $fromIdActions);
     $output->writeln("\tFixed duplicates in " . Common::prefixTable($table) . ". <comment>" . $timer->__toString() . "</comment>.");
     return $archivesAffected;
 }
Example #4
0
 /**
  * @param $idSite
  * @param $period
  * @param $date
  * @param $visitsInLastPeriods
  * @param $visitsToday
  * @param $timer
  */
 private function logArchivedWebsite($idSite, $period, $date, $visitsInLastPeriods, $visitsToday, Timer $timer)
 {
     if (substr($date, 0, 4) === 'last') {
         $visitsInLastPeriods = (int) $visitsInLastPeriods . " visits in last " . $date . " " . $period . "s, ";
         $thisPeriod = $period == "day" ? "today" : "this " . $period;
         $visitsInLastPeriod = (int) $visitsToday . " visits " . $thisPeriod . ", ";
     } else {
         $visitsInLastPeriods = (int) $visitsInLastPeriods . " visits in " . $period . "s included in: {$date}, ";
         $visitsInLastPeriod = '';
     }
     $this->log("Archived website id = {$idSite}, period = {$period}, " . $visitsInLastPeriods . $visitsInLastPeriod . $timer->__toString());
 }
Example #5
0
 /**
  * Executes the given taks
  *
  * @param ScheduledTask $task
  * @return string
  */
 private static function executeTask($task)
 {
     try {
         $timer = new Timer();
         call_user_func(array($task->getObjectInstance(), $task->getMethodName()), $task->getMethodParameter());
         $message = $timer->__toString();
     } catch (Exception $e) {
         $message = 'ERROR: ' . $e->getMessage();
     }
     return $message;
 }
Example #6
0
 /**
  * Executes the given task
  *
  * @param Task $task
  * @return string
  */
 private function executeTask($task)
 {
     $this->logger->info("Scheduler: executing task {taskName}...", array('taskName' => $task->getName()));
     $this->isRunningTask = true;
     $timer = new Timer();
     try {
         $callable = array($task->getObjectInstance(), $task->getMethodName());
         call_user_func($callable, $task->getMethodParameter());
         $message = $timer->__toString();
     } catch (Exception $e) {
         $message = 'ERROR: ' . $e->getMessage();
     }
     $this->isRunningTask = false;
     $this->logger->info("Scheduler: finished. {timeElapsed}", array('timeElapsed' => $timer));
     return $message;
 }
Example #7
0
 /**
  * Executes the given task
  *
  * @param Task $task
  * @return string
  */
 private function executeTask($task)
 {
     $this->logger->debug('Running task {task}', array('task' => $task->getName()));
     try {
         $timer = new Timer();
         call_user_func(array($task->getObjectInstance(), $task->getMethodName()), $task->getMethodParameter());
         $message = $timer->__toString();
     } catch (Exception $e) {
         $message = 'ERROR: ' . $e->getMessage();
     }
     return $message;
 }
 /**
  * Will trigger API requests for the specified Website $idsite,
  * for the specified $period, for all segments that are pre-processed for this website.
  * Requests are triggered using cURL multi handle
  *
  * @param $idsite int
  * @param $period
  * @param $lastTimestampWebsiteProcessed
  * @param Timer $timerWebsite
  * @return bool True on success, false if some request failed
  */
 private function archiveVisitsAndSegments($idsite, $period, $lastTimestampWebsiteProcessed, Timer $timerWebsite = null)
 {
     $timer = new Timer();
     $aCurl = array();
     $mh = false;
     $url = $this->piwikUrl;
     $url .= $this->getVisitsRequestUrl($idsite, $period, $lastTimestampWebsiteProcessed);
     $url .= self::APPEND_TO_API_REQUEST;
     // already processed above for "day"
     if ($period != "day") {
         $ch = $this->getNewCurlHandle($url);
         $this->addCurlHandleToMulti($mh, $ch);
         $aCurl[$url] = $ch;
         $this->requests++;
     }
     $urlNoSegment = $url;
     foreach ($this->getSegmentsForSite($idsite) as $segment) {
         $segmentUrl = $url . '&segment=' . urlencode($segment);
         $ch = $this->getNewCurlHandle($segmentUrl);
         $this->addCurlHandleToMulti($mh, $ch);
         $aCurl[$segmentUrl] = $ch;
         $this->requests++;
     }
     $success = true;
     $visitsAllDaysInPeriod = false;
     if (!empty($aCurl)) {
         $running = null;
         do {
             usleep(1000);
             curl_multi_exec($mh, $running);
         } while ($running > 0);
         foreach ($aCurl as $url => $ch) {
             $content = curl_multi_getcontent($ch);
             $successResponse = $this->checkResponse($content, $url);
             $success = $successResponse && $success;
             if ($url == $urlNoSegment && $successResponse) {
                 $stats = @unserialize($content);
                 if (!is_array($stats)) {
                     $this->logError("Error unserializing the following response from {$url}: " . $content);
                 }
                 $visitsAllDaysInPeriod = @array_sum($stats);
             }
         }
         foreach ($aCurl as $ch) {
             curl_multi_remove_handle($mh, $ch);
         }
         curl_multi_close($mh);
     }
     $this->log("Archived website id = {$idsite}, period = {$period}, " . ($period != "day" ? (int) $visitsAllDaysInPeriod . " visits, " : "") . (!empty($timerWebsite) ? $timerWebsite->__toString() : $timer->__toString()));
     return $success;
 }
Example #9
0
 /**
  * @param $idSite
  * @param $period
  * @param $dateLast
  * @param $visitsInLastPeriods
  * @param $visitsToday
  * @param $timer
  */
 private function logArchivedWebsite($idSite, $period, $dateLast, $visitsInLastPeriods, $visitsToday, Timer $timer)
 {
     $thisPeriod = $period == "day" ? "today" : "this " . $period;
     $this->log("Archived website id = {$idSite}, period = {$period}, " . (int) $visitsInLastPeriods . " visits in last " . $dateLast . " " . $period . "s, " . (int) $visitsToday . " visits " . $thisPeriod . ", " . $timer->__toString());
 }
 private function performTimedPurging(OutputInterface $output, $startMessage, $callback)
 {
     $timer = new Timer();
     $output->write($startMessage);
     $callback();
     $output->writeln("Done. <comment>[" . $timer->__toString() . "]</comment>");
 }