stats/import-stats.php
author Dan
Sun, 04 Jan 2009 16:40:36 -0500
changeset 43 ce2e9caf2dfa
parent 22 04c2f743c6ec
permissions -rw-r--r--
Added support for different types of graphs; added a last 60 minutes line graph
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     1
<?php
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     2
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     3
require('../config.php');
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     4
require('../database.php');
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     5
require('../hooks.php');
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     6
require('../libprogress.php');
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     7
require('../statsincludes/stats_core.php');
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     8
mysql_reconnect();
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
     9
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    10
// PASS 1 - build file list
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    11
$filelist = array();
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    12
if ( $dr = @opendir('.') )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    13
{
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    14
  while ( $dh = @readdir($dr) )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    15
  {
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    16
    if ( preg_match('/^stats-data-[0-9]{8}\.php$/', $dh) )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    17
    {
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    18
      $filelist[] = $dh;
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    19
    }
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    20
  }
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    21
  closedir($dr);
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    22
}
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    23
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    24
asort($filelist);
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    25
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    26
// PASS 2 - import
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    27
$pbar = new ProgressBar('Importing: [', ']', '');
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    28
$pbar->start();
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    29
$pbar->set(0);
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    30
$i = 0;
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    31
foreach ( $filelist as $dh )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    32
{
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    33
  $pbar->update_text_quiet($dh);
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    34
  $pbar->set(++$i, count($filelist));
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    35
  require($dh);
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    36
  foreach ( $stats_data['messages'] as $channel => &$data )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    37
  {
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    38
    foreach ( $data as &$message )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    39
    {
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    40
      stats_log_message($channel, $message['nick'], $message['time']);
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    41
    }
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    42
  }
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    43
  if ( isset($stats_data['anonymous']) )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    44
  {
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    45
    foreach ( $stats_data['anonymous'] as $user => $_ )
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    46
    {
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    47
      stats_anonymize_user_now($user);
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    48
    }
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    49
  }
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    50
}
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    51
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    52
$pbar->end();
04c2f743c6ec Added script for importing stats databases
Dan
parents:
diff changeset
    53