function closedb($conn_handler) { if (@mysql_close($conn_handler)) { return; } else { send_err("Cannot close SQL server connection!"); exit; } }
#!/usr/bin/php -q <?php //////////////////////////////////////////////////////////////////////////// // $Id$ // // Description: statistics cleanup // //////////////////////////////////////////////////////////////////////////// include "cleanup-functions.php"; include "cleanup-config.php"; // ************* PRELIMINARY TASKS, DATA INIT ************* set_time_limit(0); // get for which revision we generate stats if ($argv[1] == "") { $rev = "HEAD"; } else { $rev = $argv[1]; } // open database connection $dbh = initdb($sql_host, $sql_user, $sql_pass, $sql_db); debug(10, "cleanup statistics"); $res = @mysql_query("DELETE FROM essential WHERE rev='{$rev}' AND " . "sdate < DATE_SUB(NOW(),INTERVAL '60' DAY)", $dbh); if (!$res) { send_err("SQL error: delete by sdate for {$rev} branch."); die; } $deleted = @mysql_affected_rows($dbh); debug(10, "deleted {$deleted} records for {$rev} branch"); closedb($dbh); // send_ok("Deleted $deleted records for $rev branch.");
send_err("SQL error: group by package"); exit; } while ($row = @mysql_fetch_row($res)) { array_push($m_packages, $row[0]); } // make dirpath for $rev if (!is_dir("{$outdir}/{$rev}")) { if (!@mkdir("{$outdir}/{$rev}", 0755)) { send_err("Cannot make {$outdir}/{$rev} directory!"); exit; } } make_historybyrev($outbyrev1, $outbyrev2); // render historic graphics by team for level 2 foreach ($m_teams as $teamcode => $teamname) { if ($teamcode == "templates") { continue; } debug(10, "render historic graphics for '{$teamcode}' team"); // make dirpath for $rev & current teamcode if (!is_dir("{$outdir}/{$rev}/{$teamcode}")) { if (!@mkdir("{$outdir}/{$rev}/{$teamcode}", 0755)) { send_err("Cannot make {$outdir}/{$rev}/{$teamcode} directory!"); exit; } } make_historybyteam($teamcode); } closedb($dbh); // send_ok("Success generating history graphs for $rev branch.");
$total_total = $total_translated + $total_fuzzy + $total_untranslated; $res = @mysql_query("INSERT INTO sum SET rev='{$rev}', " . " team='{$teamcode}', package='{$package}', " . " translated='{$total_translated}', fuzzy='{$total_fuzzy}', " . " untranslated='{$total_untranslated}', total='{$total_total}', " . " error='{$total_error}'", $dbh); if (!$res) { send_err("SQL error: sum PO grabbing team={$teamcode}; package={$package}"); exit; } // build essential packages stats if (in_array($package, array_keys($ess_p))) { $essential_p[$package] = array($total_translated, $total_total); } } // insert in database associative array for essential files foreach (array_keys($ess_f) as $file) { list($translated, $total) = $essential_f[$file]; $res = @mysql_query("INSERT INTO essential SET rev='{$rev}', " . " sdate='{$currdate}', team='{$teamcode}', " . " filename='{$file}', translated='{$translated}', " . " total='{$total}' ", $dbh); if (!$res) { send_err("SQL error: essential PO grabbing 1 team={$teamcode}; filename={$file}"); exit; } } foreach (array_keys($ess_p) as $package) { list($translated, $total) = $essential_p[$package]; $res = @mysql_query("INSERT INTO essential SET rev='{$rev}', " . " sdate='{$currdate}', team='{$teamcode}', " . " filename='{$package}', translated='{$translated}', " . " total='{$total}' ", $dbh); if (!$res) { send_err("SQL error: essential PO grabbing 2 team={$teamcode}; filename={$package}"); exit; } } } closedb($dbh); // send_ok("Success grabbing statistics for $rev branch.");
$sound = ""; } if ($other > 0) { $other = "{$other} other(s),"; } else { $other = ""; } $br = ""; if ($images || $video || $sound || $other || $layout) { $br = "<br />"; } $e2t = mysql_query("SELECT e2t.* FROM core_entry2tag e2t WHERE e2t.entry_id = {$entry_id}") or send_err(mysql_error(), 1, true); $tagstr = ""; while ($n = @mysql_fetch_array($e2t)) { $tag_id = $n["tag_id"]; $tags = mysql_query("SELECT t.* FROM core_tags t WHERE t.tag_id = {$tag_id}") or send_err(mysql_error(), 1, true); while ($t = @mysql_fetch_array($tags)) { $tag_text = $t["tag_text"]; $tagstr = "{$tagstr} {$tag_text}, "; } } $tagstr = substr($tagstr, 0, strlen($str) - 2); if ($tagstr) { $tagstr = $tagstr . "<br />"; } echo "<div class=\"list-item\" id=\"listItem_" . $entry_id . "\">\n\t\t\t<span class=\"arr\"><img src=\"arr.jpg\" /></span> <span class=\"list-link\" onclick=\"get_data('get_edit_entry',{'id':{$entry_id}})\"><b>{$entry_title}</b> #{$entry_id} —{$entry_hits} hits</span>\n\t\t\t<p class=\"extra\">\n\t\t\t" . $tagstr . " " . $images . " " . $video . " " . $sound . " " . $other . " " . $layout . " " . $br . "\n\t\t\t</p>\n\t\t\t</div>"; } ?> </div> </fieldset>