Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 113615 Details for
Bug 157543
torrents is dead
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
PHP script to fix database schema
fix_tracker_tables.php (text/plain), 2.99 KB, created by
Daniel Frey
on 2007-03-18 03:27:40 UTC
(
hide
)
Description:
PHP script to fix database schema
Filename:
MIME Type:
Creator:
Daniel Frey
Created:
2007-03-18 03:27:40 UTC
Size:
2.99 KB
patch
obsolete
>#!/usr/bin/php ><?php > /* > * fix_tracker_tables.php - This will fix the PHPBTTracker+ database schema and truncate the peer tables. > * Set the database values below, and specify whether or not locking should be used (default on.) > */ > > $db_name = ""; > $db_user = ""; > $db_password = ""; > $db_host = "localhost"; > > $use_table_locks = true; > > /* > * Parameter check > */ > if (!isset($db_name) || !isset($db_password) || !isset($db_host) || !isset($db_user) || > strlen($db_name) == 0 || strlen($db_password) == 0 || strlen($db_host) == 0 || strlen($db_user) == 0) { > echo "Please check the required parameters in this script.\n"; > die(); > } > > /* > * Check for prescence of table locks variable > */ > if (!isset($use_table_locks)) { > // Assume true > $use_table_locks = true; > } > > echo "fix_tracker_tables v1.0\n\n"; > > /* > * Announce table locking status > */ > if (!$use_table_locks) { > echo " NOT using table locks.\n\n"; > } else { > echo " Using table locks.\n\n"; > } > > /* > * Attempt a connection to the database > */ > $db = @mysql_connect($db_host, $db_user, $db_password) or die(" FATAL: Cannot connect to database '$db_host' - " . mysql_error() . "\n"); > > /* > * Open the database > */ > @mysql_select_db($db_name, $db) or die(" FATAL: Can't open the database '$db_name' - " . mysql_error() . "\n"); > > /* > * Get a list of tables to update > */ > $rstInfoHash = mysql_query("SELECT `info_hash` FROM `namemap`"); > > /* > * Check to see if there are results > */ > if (!$rstInfoHash) { > echo " FATAL: Cannot get list of hashes from database '$db_name' - " . mysql_error() . "\n"; > mysql_close($db); > } > > /* > * Figure out how many need to be updated. > */ > $number_to_process = mysql_num_rows($rstInfoHash); > if ($number_to_process === false || $number_to_process == 0) { > echo " Nothing to process. Exiting.\n"; > mysql_close($db); > } > > echo " Processing $number_to_process tables."; > > /* > * Start updating the tables. A dot (.) for every 10 records will be displayed. > */ > $dotcounter = 0; > $errorcount = 0; > > while ($rowHash = mysql_fetch_array($rstInfoHash)) { > if ($dotcounter == 10) { > echo "."; > $dotcounter = 0; > } > > if ($use_table_locks) { > @mysql_query("LOCK TABLES y${rowHash['info_hash']} WRITE"); > } > > /* > * Change the database structure > */ > @mysql_query("ALTER TABLE `y${rowHash['info_hash']}` CHANGE `compact` `compact` BINARY(6) NOT NULL DEFAULT ''") or $errorcount++; > > if ($use_table_locks) { > @mysql_query("UNLOCK TABLES"); > } > > /* > * Purge all peers from both peer tables, and reset the stuff in the summary table > */ > @mysql_query("TRUNCATE TABLE `y${rowHash['info_hash']}") or $errorcount++; > @mysql_query("TRUNCATE TABLE `x${rowHash['info_hash']}") or $errorcount++; > @mysql_query("UPDATE `summary` SET `seeds`=0, `leechers`=0 WHERE `info_hash`='${rowHash['info_hash']}'") or $errorcount++; > $dotcounter++; > } > > echo " done! $errorcount errors.\n"; > > /* > * Close connection to database > */ > mysql_close($db); > > echo "Database update successful.\n"; >?> >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 157543
: 113615