function statspro_update_6101 in Statistics Pro 6.2
Same name and namespace in other branches
- 6 statspro.install \statspro_update_6101()
Moves the data from the old statspro table which has the column 'day' as TIMESTAMP to the temporary statspro_temp table which already has the 'day' column as DATE.
Return value
array
File
- ./
statspro.install, line 227 - Install file for statistics pro module
Code
function statspro_update_6101() {
$qt_per_call = 20;
// See if we are being called for the first time
if (!isset($_SESSION['statspro_update_6101_current'])) {
// These variables keep track of our progress
$_SESSION['statspro_update_6101_current'] = 0;
$_SESSION['statspro_update_6101_max'] = db_result(db_query('SELECT COUNT(*) FROM {statspro}')) - 1;
}
// Fetch the next $qt_per_call nodes
$result = db_query_range('SELECT *, DATE(FROM_UNIXTIME(day)) AS day_date FROM {statspro} ORDER BY day', $_SESSION['statspro_update_6101_current'], $_SESSION['statspro_update_6101_current'] + $qt_per_call);
while ($row = db_fetch_array($result)) {
$found = db_result(db_query("SELECT * FROM {statspro_day_to_date_temp} WHERE day = '%s'", $row['day_date']));
$_SESSION['statspro_update_6101_current']++;
if ($found) {
db_query("UPDATE {statspro_day_to_date_temp}\n SET nuser = nuser + %d,\n auser = auser + %d,\n nnode = nnode + %d,\n cnode = cnode + %d,\n comment = comment + %d,\n pi = pi + %d,\n upi = upi + %d,\n error = error + %d,\n uerror = uerror + %d,\n warning = warning + %d,\n uwarning = uwarning + %d\n WHERE day = '%s'", $row['nuser'], $row['auser'], $row['nnode'], $row['cnode'], $row['comment'], $row['pi'], $row['upi'], $row['error'], $row['uerror'], $row['warning'], $row['uwarning'], $row['day_date']);
}
else {
db_query("INSERT INTO {statspro_day_to_date_temp}\n (nuser, auser, nnode, cnode, comment, pi, upi, error, uerror, warning,\n uwarning, day)\n VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%s')", $row['nuser'], $row['auser'], $row['nnode'], $row['cnode'], $row['comment'], $row['pi'], $row['upi'], $row['error'], $row['uerror'], $row['warning'], $row['uwarning'], $row['day_date']);
}
}
// See if we are done
if ($_SESSION['statspro_update_6101_current'] < $_SESSION['statspro_update_6101_max']) {
// Not done yet. Return the progress.
return array(
'#finished' => $_SESSION['statspro_update_6101_current'] / $_SESSION['statspro_update_6101_max'],
);
}
else {
// Done. Clean up and indicate we're finished.
unset($_SESSION['statspro_update_6101_current']);
unset($_SESSION['statspro_update_6101_max']);
return array(
'#finished' => 1,
);
}
}