r10193 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10192‎ | r10193 | r10194 >
Date:06:09, 18 July 2005
Author:kateturner
Status:old
Tags:
Comment:
generate all urls report
Modified paths:
  • /trunk/logwood/run_reports.php (modified) (history)

Diff [purge]

Index: trunk/logwood/run_reports.php
@@ -3,41 +3,77 @@
44
55 require_once('/etc/logwood-fe.conf');
66
7 -$dbh = mysql_connect($server, $username, $password);
8 -mysql_select_db($database, $dbh);
 7+$db = new mysqli($server, $username, $password, $database);
98
10 -mysql_query("DELETE FROM topurls", $dbh);
11 -mysql_query("DELETE FROM topagents", $dbh);
12 -mysql_query("DELETE FROM toprefs", $dbh);
 9+$stmt = $db->prepare("DELETE FROM topurls");
 10+$stmt->execute();
 11+$stmt = $db->prepare("DELETE FROM topagents");
 12+$stmt->execute();
 13+$stmt = $db->prepare("DELETE FROM toprefs");
 14+$stmt->execute();
1315
14 -$res = mysql_query("SELECT si_id FROM sites", $dbh);
15 -while ($row = mysql_fetch_assoc($res)) {
 16+$insert_topurls = $db->prepare("
 17+ INSERT INTO topurls(tu_site, tu_url, tu_count)
 18+ SELECT si_id, ur_id, uc_count
 19+ FROM sites, url_id, url_count
 20+ WHERE si_id=? AND ur_site=si_id AND uc_url_id=ur_id
 21+ ORDER BY uc_count DESC LIMIT 500
 22+ ");
 23+$qallurls = $db->prepare("
 24+ SELECT si_name, ur_path, uc_count
 25+ FROM sites, url_id, url_count
 26+ WHERE si_id=? AND ur_site=si_id AND uc_url_id=ur_id
 27+ ORDER BY uc_count DESC
 28+ ");
 29+$insert_topagents = $db->prepare("
 30+ INSERT INTO topagents(ta_site, ta_agent, ta_count)
 31+ SELECT si_id, ag_id, ac_count
 32+ FROM sites, agent_ids, agent_count
 33+ WHERE si_id=? AND ag_site=si_id AND ac_id=ag_id
 34+ ORDER BY ac_count DESC LIMIT 500
 35+ ");
 36+
 37+$insert_toprefs = $db->prepare("
 38+ INSERT INTO toprefs(tr_site, tr_ref, tr_count)
 39+ SELECT si_id, ref_ids.ref_id, ref_count
 40+ FROM sites, ref_ids, ref_count
 41+ WHERE si_id=? AND ref_site=si_id AND ref_count.ref_id=ref_ids.ref_id
 42+ ORDER BY ref_count DESC LIMIT 500
 43+ ");
 44+
 45+$si_id = $si_name = false;
 46+$qsites = $db->prepare("SELECT si_id, si_name FROM sites");
 47+$qsites->bind_result($si_id, $si_name);
 48+$qsites->execute();
 49+$qsites->store_result();
 50+while ($qsites->fetch()) {
1651 $site = $row["si_id"];
17 - mysql_query("
18 - INSERT INTO topurls(tu_site, tu_url, tu_count)
19 - SELECT si_id, ur_id, uc_count
20 - FROM sites, url_id, url_count
21 - WHERE si_id=$site AND ur_site=si_id AND uc_url_id=ur_id
22 - ORDER BY uc_count DESC LIMIT 500
23 - ", $dbh);
2452
25 - mysql_query("
26 - INSERT INTO topagents(ta_site, ta_agent, ta_count)
27 - SELECT si_id, ag_id, ac_count
28 - FROM sites, agent_ids, agent_count
29 - WHERE si_id=$site AND ag_site=si_id AND ac_id=ag_id
30 - ORDER BY ac_count DESC LIMIT 500
31 - ", $dbh);
 53+ $insert_topurls->bind_param("i", $site);
 54+ $insert_topurls->execute();
3255
33 - mysql_query("
34 - INSERT INTO toprefs(tr_site, tr_ref, tr_count)
35 - SELECT si_id, ref_ids.ref_id, ref_count
36 - FROM sites, ref_ids, ref_count
37 - WHERE si_id=$site AND ref_site=si_id AND ref_count.ref_id=ref_ids.ref_id
38 - ORDER BY ref_count DESC LIMIT 500
39 - ", $dbh);
 56+ $insert_topagents->bind_param("i", $site);
 57+ $insert_topagents->execute();
 58+
 59+ $insert_toprefs->bind_param("i", $site);
 60+ $insert_toprefs->execute();
 61+
 62+ $date = date('Y-m');
 63+ $fdate = date('Y-m-d H:i:s');
 64+ fwrite($fh, "# This is a list of all URLs for ". $row["si_name"] . "\n");
 65+ fwrite($fh, "# It was last updated on $fdate.\n");
 66+
 67+ $fh = fopen("$lwbase/$date.all_urls.txt");
 68+
 69+ $a_name = $a_path = $a_count = false;
 70+ $qallurls->bind_param("i", $site);
 71+ $qallurls->bind_result($a_name, $a_path, $a_count);
 72+ $qallurls->execute();
 73+ while ($qallurls->fetch())
 74+ fwrite($fh, "$a_count\t$a_name\t$a_path\n");
 75+ fclose($fh);
 76+ $qallurls->free_result();
4077 }
41 -mysql_free_result($res);
42 -
43 -mysql_close($dbh);
 78+$qsites->close();
 79+$db->close();
4480 ?>

Status & tagging log