stats/import-stats.php
changeset 22 04c2f743c6ec
equal deleted inserted replaced
21:d86ea89358ec 22:04c2f743c6ec
       
     1 <?php
       
     2 
       
     3 require('../config.php');
       
     4 require('../database.php');
       
     5 require('../hooks.php');
       
     6 require('../libprogress.php');
       
     7 require('../statsincludes/stats_core.php');
       
     8 mysql_reconnect();
       
     9 
       
    10 // PASS 1 - build file list
       
    11 $filelist = array();
       
    12 if ( $dr = @opendir('.') )
       
    13 {
       
    14   while ( $dh = @readdir($dr) )
       
    15   {
       
    16     if ( preg_match('/^stats-data-[0-9]{8}\.php$/', $dh) )
       
    17     {
       
    18       $filelist[] = $dh;
       
    19     }
       
    20   }
       
    21   closedir($dr);
       
    22 }
       
    23 
       
    24 asort($filelist);
       
    25 
       
    26 // PASS 2 - import
       
    27 $pbar = new ProgressBar('Importing: [', ']', '');
       
    28 $pbar->start();
       
    29 $pbar->set(0);
       
    30 $i = 0;
       
    31 foreach ( $filelist as $dh )
       
    32 {
       
    33   $pbar->update_text_quiet($dh);
       
    34   $pbar->set(++$i, count($filelist));
       
    35   require($dh);
       
    36   foreach ( $stats_data['messages'] as $channel => &$data )
       
    37   {
       
    38     foreach ( $data as &$message )
       
    39     {
       
    40       stats_log_message($channel, $message['nick'], $message['time']);
       
    41     }
       
    42   }
       
    43   if ( isset($stats_data['anonymous']) )
       
    44   {
       
    45     foreach ( $stats_data['anonymous'] as $user => $_ )
       
    46     {
       
    47       stats_anonymize_user_now($user);
       
    48     }
       
    49   }
       
    50 }
       
    51 
       
    52 $pbar->end();
       
    53