diff --git a/Repositories/statistics/scripts/eprints-usage_src.php b/Repositories/statistics/scripts/eprints-usage_src.php index fc8ee99..57d02b7 100755 --- a/Repositories/statistics/scripts/eprints-usage_src.php +++ b/Repositories/statistics/scripts/eprints-usage_src.php @@ -1,5 +1,30 @@ 0) { @@ -123,7 +151,7 @@ } $connect2 = mysql_connect($sqlserver2,$sqluser2,$sqlpass2); -$counter = 1; +$counter = 0; foreach($log_file as $archivename=>$archivelog) { $logf = $log_dir . $archivelog; $archive_name = $archivename; @@ -193,25 +221,18 @@ $date = $matches[2]; $archive = $matches[3]; $uniquebits = $buffer; - $date = preg_replace("/:.*/","",$date); - $date = preg_replace("/\//", " ", $date); - $when = getdate(strtotime($date)); - $request_date = $when["year"]."-".$when["mon"]."-".$when["mday"]; - $datetestB = strtotime($request_date); - /* NJS 2006-04-25 - IMPORTANT: if you run this script more than once per day, - it will count multiple times downloads whose - $request_date == $lastproc. For example, if you ran this - script five times per day, all the downloads that - occurred during that day would be counted EVERY TIME this - script ran, thus overinflating your stats by a factor of - up to five :( This happens because $lastproc has one day - as its base unit. - - If finer granularity for stats updates is desired, the - solution would be to use the full timestamp rather than - just the date. + /* NJS 2006-04-28 + Switched to timestamp rather than date-based comparison. + First, clean up the Apache request date into something + that strtotime understands. Note that the Apache log + dates include time zone info by default. */ + $date = preg_replace("/:/"," ",$date,1); // Change first ":" to " ". + $date = preg_replace("/\//", " ", $date); // Change all "/" to " ". + $datetestB = strtotime($date); + // Convert to properly formatted date string. + $request_date = date('Y-m-d H:i:s O', $datetestB); + if ($datetestB < $datetestA) continue; @@ -260,7 +281,8 @@ if the script is run more than once on the same log file */ -$query = "INSERT into lastproc (lastproc) values('".$request_date."')"; +// NJS 2006-04-28 Switched value inserted to $start_time instead of $request_date. +$query = "INSERT into lastproc (lastproc) values('".$start_time."')"; $result = mysql_query($query,$connect); #print "Records counted: $counter\n"; @@ -268,21 +290,35 @@ mysql_close($connect2); mysql_close($connect); +// Look up the title corresponding to the specified eprint id. function getePrintName($db,$eprintid) { global $connect2; $sqldatabase = $db; $db = mysql_select_db($sqldatabase,$connect2); $query3 = "select title from archive where eprintid = $eprintid"; $result3 = mysql_query($query3,$connect2); + $title = ''; + $suffix = ''; // NJS 2006-04-25 Added check for empty result, probably a deleted item. + // Look in the deletion table for details. if (mysql_num_rows($result3) == 0) { - return "Unknown item ($eprintid)"; - } else { + $query3 = "select title from deletion where eprintid = $eprintid"; + $result3 = mysql_query($query3,$connect2); + // If it's not in deletion, then we have no clue what it is. + if (mysql_num_rows($result3) == 0) { + $title = "Unknown item [$eprintid]"; + } + else { + $suffix = ' [deleted]'; + } + } + if ($title == '') { $row = mysql_fetch_assoc($result3); $row["title"] = trim($row["title"]); $row["title"] = preg_replace("/\s+/"," ",$row["title"]); - return $row["title"]; + $title = $row["title"]; } + return $title . $suffix; } ?>