diff -u -r -N yasuck-0.0.6.orig/docs/ChangeLog yasuck-0.0.6/docs/ChangeLog --- yasuck-0.0.6.orig/docs/ChangeLog 2004-10-04 14:29:03.296779200 -0500 +++ yasuck-0.0.6/docs/ChangeLog 2004-10-04 14:38:50.440519784 -0500 @@ -4,6 +4,15 @@ *yasuck-0.0.6 (29 Sep 2004) + 04 Oct 2004: Mike Green docs/ChangeLog, + includes/app.functions.php, patch-0.0.6-03: + + Got rid of the poorly implemented last_msg column and replaced it with + num_msg column. This upgrade will break any version of yaview prior + to version 0.0.5. Cleaned up the counter and poster statistics code. + Started to modularize any code that performs database updates/inserts/deletes + so that DRYRUN can be utilized easier. Bumped version up to 0.0.7. + 29 Sep 2004: Mike Green docs/ChangeLog, includes/app.functions.php, yasuck, patch-0.0.6-02: diff -u -r -N yasuck-0.0.6.orig/includes/app.functions.php yasuck-0.0.6/includes/app.functions.php --- yasuck-0.0.6.orig/includes/app.functions.php 2004-10-04 14:29:03.297779048 -0500 +++ yasuck-0.0.6/includes/app.functions.php 2004-10-04 14:22:55.980619744 -0500 @@ -293,7 +293,6 @@ $ticker_id = $info_ar['ticker_id']; $low_msg = $info_ar['low_msg']; $high_msg = $info_ar['high_msg']; -$last_msg = $info_ar['last_msg']; if (checkLock($board_id)) { $locked = "locked"; } else { @@ -321,7 +320,6 @@ lock: $locked get index: $getIndex get message: $getmsg -last message: $last_msg Database Actual low_msg $low_msg $actual_low @@ -338,6 +336,8 @@ *****************************************************************************/ function createPosterId($poster_name='') { +if (defined('DRYRUN') and DRYRUN === true) { return true; } + if ($poster_name == '') { return false; } $poster_name = addslashes($poster_name); @@ -372,6 +372,12 @@ * * *****************************************************************************/ function dropBoard($board_name='') { + +if (defined('DRYRUN') and DRYRUN === true) { + echo "DRYRUN: skipping dropBoard()\n"; + return true; + } + if ($board_name == '') { echo "What board do you want to ditch?"; return false; @@ -417,6 +423,39 @@ /***************************************************************************** * * *****************************************************************************/ +function dumpHtml($page='',$message_id='') { + +if (!defined('DUMPHTML') or DUMPHTML !== true) { + return true; + } + +if (!is_array($page) or !is_numeric($message_id)) { return false; } + +$file = "$message_id.html"; +if (!$fd = fopen($file,"w")) { + echo "WARNING: cannot open file: $file\n"; + return false; + } + +foreach($page as $line) { + if (!fwrite($fd,$line . "\n")) { + echo "WARNING: could not write to file: $file\n"; + fclose($fd); + return false; + } + } + +fclose($fd); +if (QUIET !== true) { + echo "INFO: wrote $file\n"; + } + +return true; + +} +/***************************************************************************** + * * + *****************************************************************************/ function getUa() { $randomize = false; @@ -538,6 +577,8 @@ *****************************************************************************/ function initializeBoard($board_name='') { +if (defined(DRYRUN) and DRYRUN === true) { return true; } + if ($board_name == '') { return false; } // Don't initialize if it already exists, make the admin wipe it. @@ -566,7 +607,7 @@ $board_id = addslashes($board_id); $ticker_id = addslashes($ticker_id); $start = $start - 1; -$fl = "board_id,board_name,ticker_id,low_msg,high_msg,last_msg"; +$fl = "board_id,board_name,ticker_id,low_msg,high_msg,num_msg"; $vl = "$board_id,'$board_name','$ticker_id',$start,$end,$start"; $sql = "insert into board_ids($fl) values($vl)"; if (!db_query($sql)) { @@ -599,7 +640,7 @@ ticker_id varchar(5) NOT NULL default '', low_msg int(10) unsigned NOT NULL default '0', high_msg int(10) unsigned NOT NULL default '0', -last_msg int(10) unsigned NOT NULL default '0', +num_msg int(10) unsigned NOT NULL default '0', locked tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (board_id), UNIQUE KEY board_name (board_name))"; @@ -610,13 +651,6 @@ PRIMARY KEY (poster_id), UNIQUE KEY poster_name (poster_name))"; -//$thread_ids = "create table " . DBN . ".thread_ids ( -//thread_id int(10) unsigned NOT NULL default '0', -//board_id int(10) unsigned NOT NULL default '0', -//parent_id int(10) unsigned NOT NULL default '0', -//thread_name varchar(100) NOT NULL default '', -//PRIMARY KEY (thread_id,board_id,parent_id))"; - $message_ids = "create table " . DBN . ".message_ids ( message_id int(10) unsigned NOT NULL default '0', board_id int(10) unsigned NOT NULL default '0', @@ -936,38 +970,29 @@ } else { $rpid = $real_poster_ar[$merge_poster_name]; } + if (QUIET !== true) { + echo "ID: $mid P:$merge_poster_name S:$ms R:$mr\n"; + } + + if (defined('DRYRUN') and DRYRUN === true) { continue; } + $sql = "insert into message_ids(message_id,board_id,poster_id,parent_id,"; $sql .= "thread_id,message_date,message_subject,message_recs,"; $sql .= "message_text) values($mid,$board_id,$rpid,$parent,$tid,'$md',"; $sql .= "'$ms',$mr,'$mt')"; - if (QUIET !== true) { - echo "ID: $mid P:$merge_poster_name S:$ms R:$mr\n"; - } - if (DRYRUN !== true) { - if (!db_query($sql)) { - $msg = "\nMessage $mid SQL Error: " . mysql_error() . "\n\n"; - $msg .= "$sql\n\n"; - die($msg); - } + if (!db_query($sql)) { + $msg = "\nMessage $mid SQL Error: " . mysql_error() . "\n\n"; + $msg .= "$sql\n\n"; + die($msg); } } // update counters -if (DRYRUN !== true) { - $sql = "select max(message_id) from message_ids"; - if (!$qid = db_query($sql)) { - echo "WARNING: could not update counters\n"; - } else { - $high = db_result($qid,0,0); - if (!updateCounters($board_id,$high)) { - echo "WARNING: could not update counters\n"; - } else { - echo "Updated counters\n"; - } - if (!refreshStats($board_name)) { - echo "Failed to update stats\n"; - } - } +if (!updateCounters($board_id)) { + echo "WARNING: could not update counters\n"; + } +if (!refreshStats($board_name)) { + echo "Failed to update stats\n"; } // unlock everything @@ -1501,44 +1526,40 @@ echo "ERROR: ID: $message_id: msgdate\n"; } -if (DRYRUN !== true) { - $message_id = addslashes($message_id); - $board_id = addslashes($board_id); - $poster_id = addslashes($poster_id); - $parent_id = addslashes($parent_id); - $thread_id = addslashes($thread_id); - $ds = addslashes($ds); - $subject = addslashes($subject); - $msgtext = addslashes($msgtext); - if ($insert_msg) { - $fl = "message_id,board_id,poster_id,parent_id,thread_id,"; - $fl .= "message_date,message_subject,message_recs,message_text"; - $vl = "$message_id,$board_id,$poster_id,$parent_id,$thread_id,"; - $vl .= "'$ds','$subject',$msg_recs,'$msgtext'"; - $sql = "insert into message_ids($fl)\nvalues($vl)"; - if (!db_query($sql)) { - echo "ERROR: ID: $message_id: insert\n"; - return false; - } - } else { - $sql = "update message_ids set board_id=$board_id"; - $sql .= ",poster_id=$poster_id,parent_id=$parent_id,"; - $sql .= "thread_id=$thread_id,message_date='$ds',"; - $sql .= "message_text='$msgtext',message_subject='$subject',"; - $sql .= "message_recs=$msg_recs "; - $sql .= "where board_id=$board_id and message_id=$message_id "; - $sql .= "limit 1"; - if (!db_query($sql)) { - echo "ERROR: ID: $message_id: update\n"; - return false; - } - } - if (!updateCounters($board_id,$message_id)) { - echo "WARNING: ID: $message_id: updateCounters()\n"; - } - if (QUIET !== true) { +$message_id = addslashes($message_id); +$board_id = addslashes($board_id); +$poster_id = addslashes($poster_id); +$parent_id = addslashes($parent_id); +$thread_id = addslashes($thread_id); +$ds = addslashes($ds); +$subject = addslashes($subject); +$msgtext = addslashes($msgtext); + +if (QUIET !== true) { echo "ID: $message_id P:$author S:$subject R:$msg_recs\n"; } + +if (defined('DRYRUN') and DRYRUN === true) { return true; } + +if ($insert_msg) { + $fl = "message_id,board_id,poster_id,parent_id,thread_id,"; + $fl .= "message_date,message_subject,message_recs,message_text"; + $vl = "$message_id,$board_id,$poster_id,$parent_id,$thread_id,"; + $vl .= "'$ds','$subject',$msg_recs,'$msgtext'"; + $sql = "insert into message_ids($fl)\nvalues($vl)"; + } else { + $sql = "update message_ids set board_id=$board_id"; + $sql .= ",poster_id=$poster_id,parent_id=$parent_id,"; + $sql .= "thread_id=$thread_id,message_date='$ds',"; + $sql .= "message_text='$msgtext',message_subject='$subject',"; + $sql .= "message_recs=$msg_recs "; + $sql .= "where board_id=$board_id and message_id=$message_id "; + $sql .= "limit 1"; + } + +if (!db_query($sql)) { + echo "ERROR: ID: $message_id: insert\n"; + return false; } return true; @@ -1555,7 +1576,7 @@ if (!($initialize === true || $initialize === false)) { return false; } -$sql = "select board_id,ticker_id,low_msg,high_msg,last_msg,locked +$sql = "select board_id,ticker_id,low_msg,high_msg,num_msg,locked from board_ids where board_name='$board_name' limit 1"; if (!$qid = db_query($sql)) { die(mysql_error()); return false; } $num = db_num_rows($qid); @@ -1596,6 +1617,11 @@ *****************************************************************************/ function refreshStats($board_name='') { +if (defined('DRYRUN') and DRYRUN === true) { + echo "DRYRUN: skipping refreshStats()\n"; + return true; + } + if ($board_name == '') { echo "What board do you want to refresh stats for?"; return false; @@ -1641,8 +1667,7 @@ if ($recs_total > 0) { $sql = "select count(message_id) from message_ids "; - $sql .= "where board_id=$board_id and poster_id=$pid and "; - $sql .= "message_recs > 0"; + $sql .= "where board_id=$board_id and poster_id=$pid"; if (! $qid = db_query($sql) or db_num_rows($qid) !== 1) { echo "ERROR: $sql\n"; continue; @@ -1738,23 +1763,7 @@ echo "WARNING: ID: $j retrieval failure\n"; continue; } - if (DUMPHTML === true) { - if (!$fd = fopen("$j.html","w")) { - echo "WARNING: cannot open file: $j.html\n"; - } else { - foreach($page as $line) { - if (!fwrite($fd,$line . "\n")) { - echo "WARNING: could not write to file: $j.html\n"; - fclose($fd); - break; - } - } - fclose($fd); - if (QUIET !== true) { - echo "INFO: wrote $j.html\n"; - } - } - } + dumpHtml($page,$j); // account for yahoo outages $maxunavail = 0; $sleepmax = 3600; @@ -1790,10 +1799,8 @@ processMessage($board_id,$j,$page); } -if (DRYRUN !== true) { - if (!refreshStats($board_name)) { - echo "Failed to update stats\n"; - } +if (!refreshStats($board_name)) { + echo "Failed to update stats\n"; } return true; @@ -1843,6 +1850,11 @@ *****************************************************************************/ function runUpgrades() { +if (defined('DRYRUN') and DRYRUN === true) { + echo "DRYRUN: skipping runUpgrades()\n"; + return true; + } + // verify message_recs column exists when upgrading from // 0.0.4 checkDatabase(); @@ -1900,6 +1912,25 @@ } } +$has_col = false; +$fields = db_list_fields(DBN,"board_ids"); +$columns = db_num_fields($fields); +for($j=0; $j < $columns; $j++) { + if (db_field_name($fields,$j) == "num_msg") { + $has_col = true; + break; + } + } +if (!$has_col) { + echo "UPGRADE: Upgrading board_ids: renaming last_msg column to num_msg\n"; + $sql = "alter table " . DBN . ".board_ids change last_msg num_msg "; + $sql .= "int(10) unsigned default '0' not null"; + if (!db_query($sql)) { + echo "ERROR: Upgrade failure:\n$sql\n"; + return false; + } + } + return true; } @@ -1999,6 +2030,34 @@ /***************************************************************************** * * *****************************************************************************/ +function setRecs($board_id='',$message_id='',$msg_recs='') { + +if (defined('DRYRUN') and DRYRUN === true) { + echo "DRYRUN: skipping setRecs()\n"; + return true; + } + +$board_id = addslashes($board_id); +$message_id = addslashes($message_id); +$msg_recs = addslashes($msg_recs); + +if (!is_numeric($board_id) or !is_numeric($message_id) or + !is_numeric($msg_recs)) { return false; } + +$sql = "update message_ids set message_recs=$msg_recs "; +$sql .= "where board_id=$board_id and message_id=$message_id limit 1"; +if (!db_query($sql)) { + echo "ERROR: setRecs($board_id,$message_id,$msg_recs)\n"; + return false; + } + +return true; + +} + +/***************************************************************************** + * * + *****************************************************************************/ function suckMessages($board_name='',$start='',$end='') { if ($board_name == '') { @@ -2037,7 +2096,7 @@ // Figure out where to start/end if it was not specified on command line. if (!is_numeric($start)) { - $start = $info_ar['last_msg'] + 1; + $start = $info_ar['high_msg'] + 1; } if (!is_numeric($end)) { if (!$page = retrieveList($board_name)) { @@ -2067,23 +2126,7 @@ echo "WARNING: ID: $j retrieval failure\n"; continue; } - if (DUMPHTML === true) { - if (!$fd = fopen("$j.html","w")) { - echo "WARNING: cannot open file: $j.html\n"; - } else { - foreach($page as $line) { - if (!fwrite($fd,$line . "\n")) { - echo "WARNING: could not write to file: $j.html\n"; - fclose($fd); - break; - } - } - fclose($fd); - if (QUIET !== true) { - echo "INFO: wrote $j.html\n"; - } - } - } + dumpHtml($page,$j); // account for yahoo outages $maxunavail = 0; $sleepmax = 3600; @@ -2119,10 +2162,11 @@ processMessage($board_id,$j,$page); } -if (DRYRUN !== true) { - if (!refreshStats($board_name)) { - echo "Failed to update stats\n"; - } +if (!updateCounters($board_id)) { + echo "WARNING: updateCounters() failed\n"; + } +if (!refreshStats($board_name)) { + echo "Failed to update stats\n"; } return true; @@ -2169,7 +2213,7 @@ // be updated on yahoo boards, go back 500 messages as an arbitrary // number. if (!is_numeric($start) and !is_numeric($end)) { - $end = $info_ar['last_msg']; + $end = $info_ar['high_msg']; if ($end <= 500) { $start = 1; } else { @@ -2177,13 +2221,13 @@ } } if (!is_numeric($start)) { - $start = $info_ar['last_msg'] - 500; + $start = $info_ar['high_msg'] - 500; if ($start < 1) { $start = 1; } } if (!is_numeric($end)) { - $end = $info_ar['last_msg']; + $end = $info_ar['high_msg']; } -if (($start > $end) or ($end > $info_ar['last_msg'])) { +if (($start > $end) or ($end > $info_ar['high_msg'])) { echo "invalid start($start)/end($end)\n"; return false; } @@ -2213,23 +2257,7 @@ echo "WARNING: ID: $j retrieval failure\n"; continue; } - if (DUMPHTML === true) { - if (!$fd = fopen("$j.html","w")) { - echo "WARNING: cannot open file: $j.html\n"; - } else { - foreach($page as $line) { - if (!fwrite($fd,$line . "\n")) { - echo "WARNING: could not write to file: $j.html\n"; - fclose($fd); - break; - } - } - fclose($fd); - if (QUIET !== true) { - echo "INFO: wrote $j.html\n"; - } - } - } + dumpHtml($page,$j); // account for yahoo outages $maxunavail = 0; $sleepmax = 3600; @@ -2267,24 +2295,15 @@ continue; } - if (DRYRUN !== true) { - $msg_recs = addslashes($msg_recs); - $sql = "update " . DBN . ".message_ids "; - $sql .= "set message_recs=$msg_recs "; - $sql .= "where board_id=$board_id and message_id=$j limit 1"; - if (!db_query($sql)) { - echo "ERROR: ID: $j: update rec\n"; - } - } + setRecs($board_id,$j,$msg_recs); + if (QUIET !== true) { echo "ID: $j R: $msg_recs\n"; } } -if (DRYRUN !== true) { - if (!refreshStats($board_name)) { - echo "Failed to update stats\n"; - } +if (!refreshStats($board_name)) { + echo "Failed to update stats\n"; } return true; @@ -2296,6 +2315,11 @@ *****************************************************************************/ function toggleLock($board_id='',$lock=1) { +if (defined('DRYRUN') and DRYRUN === true) { + echo "DRYRUN: skipping toggleLock()\n"; + return true; + } + if ($board_id == '') { return false; } if (!$lock == 1 and !$lock == 0) { return false; } @@ -2319,34 +2343,34 @@ /***************************************************************************** * * *****************************************************************************/ -function updateCounters($board_id='',$message_id='') { +function updateCounters($board_id='') { -if (!is_numeric($board_id) or !is_numeric($message_id)) { return false; } +if (defined('DRYRUN') and DRYRUN === true) { + echo "DRYRUN: skipping updateCounters()\n"; + return true; + } + +if (!is_numeric($board_id)) { return false; } $board_id = addslashes($board_id); -$message_id = addslashes($message_id); -$sql = "select low_msg,high_msg from board_ids -where board_id=$board_id limit 1"; -if (!$qid = db_query($sql)) { return false; } +$sql = "select min(message_id),max(message_id),count(message_id) +from message_ids where board_id=$board_id limit 1"; +if (!$qid = db_query($sql)) { return false; } if (db_num_rows($qid) !== 1) { return false; } -$row_ar = db_fetch_array($qid); -$low = $row_ar['low_msg']; -$high = $row_ar['high_msg']; +$low_msg = db_result($qid,0,0); +$high_msg = db_result($qid,0,1); +$num_msg = db_result($qid,0,2); -$sql = "update board_ids set last_msg=$message_id"; -if ($message_id < $low or $low == 0) { - $sql .= ",low_msg=$message_id"; - } -if ($message_id > $high) { - $sql .= ",high_msg=$message_id"; - } -$sql .= " where board_id=$board_id limit 1"; +$sql = "update board_ids set low_msg=$low_msg,high_msg=$high_msg, +num_msg=$num_msg where board_id=$board_id limit 1"; if (!db_query($sql)) { $msg = "ABORT: SQL Error:\n" . mysql_error() . "\n"; echo $msg; return false; + } else { + echo "Message counters updated\n"; } return true;