protected function retrieveData($url)
 {
     if (strpos($url, '.kmz') !== false) {
         if (!class_exists('ZipArchive')) {
             throw new KurogoException("class ZipArchive (php-zip) not available");
         }
         $tmpDir = Kurogo::tempDirectory();
         if (!is_writable($tmpDir)) {
             throw new KurogoConfigurationException("Temporary directory {$tmpDir} not available");
         }
         $tmpFile = $tmpDir . '/tmp.kmz';
         copy($url, $tmpFile);
         $zip = new ZipArchive();
         $zip->open($tmpFile);
         $contents = $zip->getFromIndex(0);
         unlink($tmpFile);
         return $contents;
         // this is false on failure, same as file_get_contents
     }
     return parent::retrieveData($url);
 }
 /**
  * export the stats data to the database
  */
 public static function exportStatsData($startTimestamp = null)
 {
     $site = Kurogo::sharedInstance()->getSite();
     $baseLogDir = $site->getBaseLogDir();
     $logDir = $site->getLogDir();
     $statsLogFileName = Kurogo::getOptionalSiteVar('KUROGO_STATS_LOG_FILENAME', 'kurogo_stats_log_v1');
     //if the base dir is different then the log dir then get all files with the log file name
     if ($baseLogDir != $logDir) {
         $logFiles = glob($baseLogDir . DIRECTORY_SEPARATOR . "*" . DIRECTORY_SEPARATOR . $statsLogFileName);
     } else {
         $logFiles = array($logDir . DIRECTORY_SEPARATOR . $statsLogFileName);
     }
     //cycle through all log files
     foreach ($logFiles as $statsLogFile) {
         if (!file_exists($statsLogFile)) {
             continue;
         }
         $today = date('Ymd', time());
         //copy the log file
         $tempLogFolder = Kurogo::tempDirectory();
         $statsLogFileCopy = rtrim($tempLogFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . "stats_log_copy.{$today}";
         if (!is_writable($tempLogFolder)) {
             throw new Exception("Unable to write to Temporary Directory {$tempLogFolder}");
         }
         if (!rename($statsLogFile, $statsLogFileCopy)) {
             Kurogo::log(LOG_DEBUG, "Failed to rename {$statsLogFile} to {$statsLogFileCopy}", 'kurogostats');
             return;
         }
         $handle = fopen($statsLogFileCopy, 'r');
         $startDate = '';
         while (!feof($handle)) {
             $line = trim(fgets($handle, 1024));
             $value = explode("\t", $line);
             if (count($value) != count(self::validFields()) || !isset($value[0]) || intval($value[0]) <= 0) {
                 continue;
             }
             if (!$startDate) {
                 $startTimestamp = $value[0];
                 $startDate = date('Y-m-d', $startTimestamp);
                 // If startTimestamp is during today
                 // Set startTimestamp to the beginning of today
                 if ($startDate == date('Y-m-d')) {
                     list($year, $month, $day) = explode('-', $startDate);
                     $startTimestamp = mktime(0, 0, 0, $month, $day, $year);
                 }
             }
             //insert the raw data to the database
             $logData = array_combine(self::validFields(), $value);
             self::insertStatsToMainTable($logData);
         }
         fclose($handle);
         unlink($statsLogFileCopy);
         self::updateSummaryFromShards($startTimestamp);
     }
 }
Beispiel #3
0
 /**
  * export the stats data to the database
  */
 public static function exportStatsData($startTimestamp = null)
 {
     $statsLogFile = Kurogo::getOptionalSiteVar('KUROGO_STATS_LOG_FILE', LOG_DIR . "/kurogo_stats_log_v1");
     if (!file_exists($statsLogFile)) {
         Kurogo::log(LOG_DEBUG, "the stats log file not exists", 'kurogostats');
         return false;
     }
     /* need an condition for export the stats data */
     $today = date('Ymd', time());
     //copy the log file
     $tempLogFolder = Kurogo::tempDirectory();
     $statsLogFileCopy = rtrim($tempLogFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . "stats_log_copy.{$today}";
     if (!is_writable($tempLogFolder)) {
         throw new Exception("Unable to write to Temporary Directory {$tempLogFolder}");
     }
     if (!rename($statsLogFile, $statsLogFileCopy)) {
         Kurogo::log(LOG_DEBUG, "failed to rename {$statsLogFile} to {$statsLogFileCopy}", 'kurogostats');
         return;
     }
     $handle = fopen($statsLogFileCopy, 'r');
     $startDate = '';
     while (!feof($handle)) {
         $line = trim(fgets($handle, 1024));
         $value = explode("\t", $line);
         if (count($value) != count(self::validFields()) || !isset($value[0]) || intval($value[0]) <= 0) {
             continue;
         }
         if (!$startDate) {
             $startTimestamp = $value[0];
             $startDate = date('Y-m-d', $startTimestamp);
             // If startTimestamp is during today
             // Set startTimestamp to the beginning of today
             if ($startDate == date('Y-m-d')) {
                 list($year, $month, $day) = explode('-', $startDate);
                 $startTimestamp = mktime(0, 0, 0, $month, $day, $year);
             }
         }
         //insert the raw data to the database
         $logData = array_combine(self::validFields(), $value);
         self::insertStatsToMainTable($logData);
     }
     fclose($handle);
     unlink($statsLogFileCopy);
     self::updateSummaryFromShards($startTimestamp);
 }