diff --git a/bin/monitor.php b/bin/monitor.php index db1472a8a..4f6e6bb33 100644 --- a/bin/monitor.php +++ b/bin/monitor.php @@ -5,7 +5,7 @@ require(WWW_DIR.'/lib/postprocess.php'); require_once (WWW_DIR.'/lib/site.php'); require_once("../test/ColorCLI.php"); -$version="0.3r598"; +$version="0.3r600"; $db = new DB(); $s = new Sites(); diff --git a/test/db_updates/db.sql b/test/db_updates/db.sql index e914b0bef..7b861ec1c 100644 --- a/test/db_updates/db.sql +++ b/test/db_updates/db.sql @@ -1,13 +1,13 @@ ALTER TABLE `predb` - ADD `hash` VARCHAR( 32 ) NULL, - ADD INDEX (`hash`); + ADD `md5` VARCHAR( 32 ) NULL, + ADD INDEX (`md5`); ALTER TABLE `releases` ADD `dehashstatus` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `haspreview`, ADD `nfostatus` TINYINT NOT NULL DEFAULT 0 after `dehashstatus`, ADD `reqidstatus` TINYINT(1) NOT NULL DEFAULT '0' AFTER `dehashstatus`, ADD `bitwise` SMALLINT UNSIGNED NOT NULL DEFAULT 0 AFTER `reqidstatus`, - ADD INDEX `ix_releases_nfostatus` (`nfostatus` ASC) USING HASH, - ADD INDEX `ix_releases_reqidstatus` (`reqidstatus` ASC) USING HASH, + ADD INDEX `ix_releases_nfostatus` (`nfostatus` ASC) USING md5, + ADD INDEX `ix_releases_reqidstatus` (`reqidstatus` ASC) USING md5, ADD INDEX `ix_releases_status` (`ID`, `nfostatus`, `bitwise`, `passwordstatus`, `dehashstatus`, `reqidstatus`, `musicinfoID`, `consoleinfoID`, `bookinfoID`, `haspreview`, `categoryID`); DELIMITER $$ diff --git a/test/db_updates/db_update_13_01_2014.sql b/test/db_updates/db_update_13_01_2014.sql new file mode 100644 index 000000000..294c4411a --- /dev/null +++ b/test/db_updates/db_update_13_01_2014.sql @@ -0,0 +1,3 @@ +DROP INDEX ix_prehash_releaseID ON prehash; +ALTER TABLE `prehash` change hash md5 VARCHAR(255) NOT NULL DEFAULT '0'; +ALTER TABLE `predb` change hash md5 VARCHAR( 32 ) NULL; diff --git a/test/dump_prehash.php b/test/dump_prehash.php index 9bc718da3..b5fc9abbc 100644 --- a/test/dump_prehash.php +++ b/test/dump_prehash.php @@ -3,69 +3,71 @@ require_once(dirname(__FILE__)."/../bin/config.php"); require_once(WWW_DIR."/lib/framework/db.php"); require_once("ColorCLI.php"); -$c = new ColorCLI; +$db = new DB(); +$c = new ColorCLI(); -if (isset($argv[2])) -{ - if (!preg_match('/^\//', $argv[2])) +if (isset($argv[2])) { + if (!preg_match('/^\//', $argv[2])) { $path = getcwd() . '/' . $argv[2]; - else + } else { $path = $argv[2]; + } } -if (isset($argv[1]) && $argv[1] == 'export' && isset($argv[2])) -{ - if (!preg_match('/\.csv$/', $path)) - $path = dirname($path).'/'.basename($path).'/predb_dump.csv'; - else +if (isset($argv[1]) && $argv[1] == 'export' && isset($argv[2])) { + if (!preg_match('/\.csv$/', $path)) { + $path = dirname($path) . '/' . basename($path) . '/prebd_dump.csv'; + } else { $path = $path; - if (!preg_match('/^\//', $path)) + } + if (!preg_match('/^\//', $path)) { $path = getcwd() . '/' . $path; + } - if (file_exists($path) && is_file($path)) + if (file_exists($path) && is_file($path)) { unlink($path); - if (isset($argv[3])) + } + if (isset($argv[3])) { $table = $argv[3]; - else + } else { $table = 'prehash'; - $db = new DB(); - $db->queryDirect("SELECT title, nfo, size, category, predate, adddate, source, hash, requestID, groupID INTO OUTFILE '".$path."' FROM ".$table); -} -else if (isset($argv[1]) && ($argv[1] == 'local' || $argv[1] == 'remote') && isset($argv[2]) && is_file($argv[2])) -{ - if (!preg_match('/^\//', $path)) + } + $db->queryDirect("SELECT title, nfo, size, category, predate, adddate, source, md5, requestID, g.name FROM " . $table . " p LEFT OUTER JOIN groups g ON p.groupID = g.ID INTO OUTFILE '" . $path . "' FIELDS TERMINATED BY '\t\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\r\n'"); +} else if (isset($argv[1]) && ($argv[1] == 'local' || $argv[1] == 'remote') && isset($argv[2]) && is_file($argv[2])) { + if (!preg_match('/^\//', $path)) { $path = require_once getcwd() . '/' . $argv[2]; - if (isset($argv[3])) + } + if (isset($argv[3])) { $table = $argv[3]; - else + } else { $table = 'prehash'; - - $db = new DB(); + } // Create temp table to allow updating - $db->exec('DROP TABLE IF EXISTS tmp_pre'); - $db->exec('CREATE TABLE tmp_pre LIKE prehash'); + echo $c->info("Creating temporary table"); + $db->query('DROP TABLE IF EXISTS tmp_pre'); + $db->query('CREATE TABLE tmp_pre LIKE prehash'); // Drop indexes on tmp_pre - $db->exec('ALTER TABLE tmp_pre DROP INDEX `ix_prehash_md5`, DROP INDEX `ix_prehash_nfo`, DROP INDEX `ix_prehash_predate`, DROP INDEX `ix_prehash_adddate`, DROP INDEX `ix_prehash_source`, DROP INDEX `ix_prehash_title`, DROP INDEX `ix_prehash_requestid`'); + $db->query('ALTER TABLE tmp_pre DROP INDEX `ix_prehash_md5`, DROP INDEX `ix_prehash_nfo`, DROP INDEX `ix_prehash_predate`, DROP INDEX `ix_prehash_adddate`, DROP INDEX `ix_prehash_source`, DROP INDEX `ix_prehash_title`, DROP INDEX `ix_prehash_requestid`'); + $db->query('ALTER TABLE tmp_pre ADD COLUMN groupname VARCHAR (255)'); // Import file into tmp_pre - if ($argv[1] == 'remote') - { - $db->queryDirect("LOAD DATA LOCAL INFILE '".$path."' IGNORE into table tmp_pre (title, nfo, size, category, predate, adddate, source, hash, requestID, groupID)"); - } - else - { - $db->queryDirect("LOAD DATA INFILE '".$path."' IGNORE into table tmp_pre (title, nfo, size, category, predate, adddate, source, hash, requestID, groupID)"); + if ($argv[1] == 'remote') { + $db->queryDirect("LOAD DATA LOCAL INFILE '" . $path . "' IGNORE INTO TABLE tmp_pre FIELDS TERMINATED BY '\t\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\r\n' (title, nfo, size, category, predate, adddate, source, md5, requestID, groupname)"); + } else { + $db->queryDirect("LOAD DATA INFILE '" . $path . "' IGNORE INTO TABLE tmp_pre FIELDS TERMINATED BY '\t\t' ENCLOSED BY \"'\" LINES TERMINATED BY '\r\n' (title, nfo, size, category, predate, adddate, source, md5, requestID, groupname)"); } // Insert and update table - $db->queryDirect('INSERT INTO '.$table.' (title, nfo, size, category, predate, adddate, source, hash, requestID, groupID) SELECT t.title, t.nfo, t.size, t.category, t.predate, t.adddate, t.source, t.hash, t.requestID, t.groupID FROM tmp_pre t ON DUPLICATE KEY UPDATE prehash.nfo = IF(prehash.nfo is null, t.nfo, prehash.nfo), prehash.size = IF(prehash.size is null, t.size, prehash.size), prehash.category = IF(prehash.category is null, t.category, prehash.category), prehash.requestID = IF(prehash.requestID = 0, t.requestID, prehash.requestID), prehash.groupID = IF(prehash.groupID = 0, t.groupID, prehash.groupID)'); + $db->queryDirect('INSERT INTO ' . $table . ' (title, nfo, size, category, predate, adddate, source, md5, requestID, groupID) SELECT t.title, t.nfo, t.size, t.category, t.predate, t.adddate, t.source, t.md5, t.requestID, IF(g.ID IS NOT NULL, g.ID, 0) FROM tmp_pre t LEFT OUTER JOIN groups g ON t.groupname = g.name ON DUPLICATE KEY UPDATE prehash.nfo = IF(prehash.nfo is null, t.nfo, prehash.nfo), prehash.size = IF(prehash.size is null, t.size, prehash.size), prehash.category = IF(prehash.category is null, t.category, prehash.category), prehash.requestID = IF(prehash.requestID = 0, t.requestID, prehash.requestID), prehash.groupID = IF(g.ID IS NOT NULL, g.ID, 0)'); // Drop tmp_pre table - $db->exec('DROP TABLE IF EXISTS tmp_pre'); + $db->queryExec('DROP TABLE IF EXISTS tmp_pre'); +} else { + exit($c->error("\nThis script can export or import a prehash dump file. You may use the full path, or a relative path.\n" + . "For importing, the script insert new rows and update existing matched rows. For databases not on the local system, use remote, else use local.\n" + . "For exporting, the path must be writeable by mysql, any existing file[prebd_dump.csv] will be overwritten.\n\n" + . "php $argv[0] export /path/to/write/to ...: To export.\n" + . "php $argv[0] [remote | local] /path/to/filename ...: To import.\n")); } -else - exit($c->error("\nThis script can export or import a predb dump file. You may use the full path, or a relative path.". - "\nFor importing, the script insert new rows and update existing matched rows. For databases not on the local system, use remote, else use local.". - "\nFor exporting, the path must be writeable by mysql, any existing file[prebd_dump.csv] will be overwritten.\nTo export:\nphp dump_predb.php export /path/to/write/to\n\nTo import:\nphp dump_predb.php [remote | local] /path/to/filename")); diff --git a/test/hash_decrypt.php b/test/hash_decrypt.php index 5459ef2f2..b7c464956 100755 --- a/test/hash_decrypt.php +++ b/test/hash_decrypt.php @@ -13,9 +13,9 @@ require_once ("ColorCLI.php"); $c = new ColorCLI(); if (!isset($argv[1]) || ( $argv[1] != "all" && $argv[1] != "full" && !is_numeric($argv[1]))) exit($c->error("\nThis script tries to match an MD5 of the releases.name or releases.searchname to predb.md5.\n" - ."php hash_decrypt.php 1000 ...: to limit to 1000 sorted by newest postdate.\n" - ."php hash_decrypt.php full ...: to run on full database.\n" - ."php hash_decrypt.php all ...: to run on all hashed releases(including previously renamed).\n")); + ."php md5_decrypt.php 1000 ...: to limit to 1000 sorted by newest postdate.\n" + ."php md5_decrypt.php full ...: to run on full database.\n" + ."php md5_decrypt.php all ...: to run on all hashed releases(including previously renamed).\n")); echo $c->header ("\nHash Decryption Started at ".date("H:i:s")."\nMatching prehash MD5 to md5(releases.name or releases.searchname)"); preName($argv); @@ -49,7 +49,7 @@ function preName($argv) $success = false; if (preg_match('/([0-9a-fA-F]{32})/', $row['searchname'], $match) || preg_match('/([0-9a-fA-F]{32})/', $row['name'], $match)) { - $pre = $db->queryOneRow(sprintf("SELECT title, source FROM prehash WHERE hash = %s", $db->escapeString($match[1]))); + $pre = $db->queryOneRow(sprintf("SELECT title, source FROM prehash WHERE md5 = %s", $db->escapeString($match[1]))); if ($pre !== false) { $determinedcat = $category->determineCategory($row["groupID"], $pre['title']); diff --git a/test/initial_setup/create_prehash_table.sql b/test/initial_setup/create_prehash_table.sql index 45d58169a..eea7be85d 100755 --- a/test/initial_setup/create_prehash_table.sql +++ b/test/initial_setup/create_prehash_table.sql @@ -1,26 +1,23 @@ -DROP TABLE IF EXISTS `prehash`; -CREATE TABLE `prehash` -( -`ID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, -`title` VARCHAR(255) NOT NULL DEFAULT '', -`nfo` VARCHAR(500) NULL, -`size` VARCHAR(50) NULL, -`category` VARCHAR(255) NULL, -`predate` DATETIME DEFAULT NULL, -`adddate` DATETIME DEFAULT NULL, -`source` VARCHAR(50) NOT NULL DEFAULT '', -`hash` VARCHAR(255) NOT NULL DEFAULT '0', -`releaseID` INT NULL, -`requestID` INT NOT NULL DEFAULT '0', -`groupID` INT NOT NULL DEFAULT '0', -PRIMARY KEY (`ID`) +DROP TABLE IF EXISTS prehash; +CREATE TABLE prehash ( + ID INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + title VARCHAR(255) NOT NULL DEFAULT '', + nfo VARCHAR(255) NULL, + size VARCHAR(50) NULL, + category VARCHAR(255) NULL, + predate DATETIME DEFAULT NULL, + adddate DATETIME DEFAULT NULL, + source VARCHAR(50) NOT NULL DEFAULT '', + md5 VARCHAR(255) NOT NULL DEFAULT '0', + requestID INT(10) UNSIGNED NOT NULL DEFAULT '0', + groupID INT(10) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (ID) ) ENGINE=MYISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci AUTO_INCREMENT=1 ; -CREATE INDEX ix_prehash_title ON prehash(`title`); -CREATE INDEX ix_prehash_nfo ON prehash(`nfo`); -CREATE INDEX ix_prehash_predate ON prehash(`predate`); -CREATE INDEX ix_prehash_adddate ON prehash(`adddate`); -CREATE INDEX ix_prehash_source ON prehash(`source`); -CREATE UNIQUE INDEX ix_prehash_md5 ON prehash(`hash`); -CREATE INDEX ix_prehash_releaseID ON prehash(`releaseID`); -CREATE INDEX ix_prehash_requestid on prehash(requestID, groupID); \ No newline at end of file +CREATE INDEX ix_prehash_title ON prehash(title); +CREATE INDEX ix_prehash_nfo ON prehash(nfo); +CREATE INDEX ix_prehash_predate ON prehash(predate); +CREATE INDEX ix_prehash_adddate ON prehash(adddate); +CREATE INDEX ix_prehash_source ON prehash(source); +CREATE INDEX ix_prehash_requestid on prehash(requestID, groupID); +CREATE UNIQUE INDEX ix_prehash_md5 ON prehash(md5); \ No newline at end of file diff --git a/test/namecleaner.php b/test/namecleaner.php index 7dc0351a0..7577835b5 100755 --- a/test/namecleaner.php +++ b/test/namecleaner.php @@ -308,7 +308,7 @@ class nameCleaning //Die.Nacht.Der.Creeps.THEATRICAL.GERMAN.1986.720p.BluRay.x264-GH - "gh-notcreepskf720.nfo" yEnc //The.Fast.and.the.Furious.Tokyo.Drift.2006.German.1080p.BluRay.x264.iNTERNAL-MWS - "mws-tfatftd-1080p.nfo" yEnc else if (preg_match('/^([\w.-]+)\s+-\s+".+?" yEnc$/', $subject, $match)) - return $cleansubject["hash"] = $match[1]; + return $cleansubject["md5"] = $match[1]; //CorelDRAW Technical Suite X6-16.3.0.1114 x32-x64<><>DRM<><> - (10/48) "CorelDRAW Technical Suite X6-16.3.0.1114 x32-x64.part09.rar" - 2,01 GB - yEnc //AnyDVD_7.1.9.3_-_HD-BR - Beta<>give-me-all.org<>DRM<><> - (1/3) "AnyDVD_7.1.9.3_-_HD-BR - Beta.par2" - 14,53 MB - yEnc //Android Softarchive.net Collection Pack 27^^give-me-all.org^^^^DRM^^^^ - (01/26) "Android Softarchive.net Collection Pack 27.par2" - 1,01 GB - yEnc diff --git a/test/namefixer.php b/test/namefixer.php index 563466cb9..c98b08339 100644 --- a/test/namefixer.php +++ b/test/namefixer.php @@ -321,7 +321,7 @@ class Namefixer $category = new Category(); $this->matched = false; $n = "\n"; - $res = $db->queryDirect(sprintf("SELECT title, source FROM prehash WHERE hash = %s", $db->escapeString($md5))); + $res = $db->queryDirect(sprintf("SELECT title, source FROM prehash WHERE md5 = %s", $db->escapeString($md5))); $total = $res->rowCount(); if ($total > 0) { foreach ($res as $row) diff --git a/test/predb_hash_decrypt.php b/test/predb_hash_decrypt.php index 0c716eb6a..187087bd4 100644 --- a/test/predb_hash_decrypt.php +++ b/test/predb_hash_decrypt.php @@ -12,12 +12,12 @@ require_once ("ColorCLI.php"); //this script is adapted from nZEDb decrypt_hashes.php $c = new ColorCLI(); if (!isset($argv[1]) || ( $argv[1] != "all" && $argv[1] != "full" && !is_numeric($argv[1]))) - exit($c->error("\nThis script tries to match an MD5 of the releases.name or releases.searchname to predb.md5.\n" - ."php predb_hash_decrypt.php 1000 ...: to limit to 1000 sorted by newest postdate.\n" - ."php predb_hash_decrypt.php full ...: to run on full database.\n" - ."php predb_hash_decrypt.php all ...: to run on all hashed releases(including previously renamed).\n")); + exit($c->error("\nThis script tries to match an MD5 of the releases.name or releases.searchname to prehash.md5.\n" + ."php predb_md5_decrypt.php 1000 ...: to limit to 1000 sorted by newest postdate.\n" + ."php predb_md5_decrypt.php full ...: to run on full database.\n" + ."php predb_md5_decrypt.php all ...: to run on all hashed releases(including previously renamed).\n")); -echo $c->header ("\nHash Decryption Started at ".date("H:i:s")."\nMatching preDB MD5 to md5(releases.name or releases.searchname)"); +echo $c->header ("\nHash Decryption Started at ".date("H:i:s")."\nMatching prehash MD5 to md5(releases.name or releases.searchname)"); preName($argv); function preName($argv) @@ -49,7 +49,7 @@ function preName($argv) $success = false; if (preg_match('/([0-9a-fA-F]{32})/', $row['searchname'], $match) || preg_match('/([0-9a-fA-F]{32})/', $row['name'], $match)) { - $pre = $db->queryOneRow(sprintf("SELECT dirname FROM predb WHERE hash = %s", $db->escapeString($match[1]))); + $pre = $db->queryOneRow(sprintf("SELECT dirname FROM predb WHERE md5 = %s", $db->escapeString($match[1]))); if ($pre !== false) { $determinedcat = $category->determineCategory($row["groupID"], $pre['dirname']); diff --git a/test/prehash.php b/test/prehash.php index 0858118e3..eb52dd5d9 100755 --- a/test/prehash.php +++ b/test/prehash.php @@ -161,7 +161,7 @@ Class Predb else $nfo = $db->escapeString("http://nzb.isasecret.com/".$matches2["nfo"]); - $db->exec(sprintf("INSERT IGNORE INTO prehash (title, nfo, size, category, predate, adddate, source, hash) VALUES (%s, %s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $nfo, $size, $db->escapeString($matches2["category"]), $db->escapeString("womble"), $db->escapeString(md5($matches2["title"])))); + $db->exec(sprintf("INSERT IGNORE INTO prehash (title, nfo, size, category, predate, adddate, source, md5) VALUES (%s, %s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $nfo, $size, $db->escapeString($matches2["category"]), $db->escapeString("womble"), $db->escapeString(md5($matches2["title"])))); $newnames++; } } @@ -214,7 +214,7 @@ Class Predb { $size = $db->escapeString(round($matches2["size1"]).$matches2["size2"]); $title = preg_replace("/ - omgwtfnzbs.org/", "", $matches2["title"]); - $db->exec(sprintf("INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, hash) VALUES (%s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($title), $size, $db->escapeString($matches2["category"]), $db->escapeString("omgwtfnzbs"), $db->escapeString($md5))); + $db->exec(sprintf("INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, md5) VALUES (%s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($title), $size, $db->escapeString($matches2["category"]), $db->escapeString("omgwtfnzbs"), $db->escapeString($md5))); $newnames++; } } @@ -251,7 +251,7 @@ Class Predb $predate = $db->escapeString($matches2['predate']); $md5 = $db->escapeString(md5($matches2['title'])); $title = $db->escapeString($matches2['title']); - $oldname = $db->queryOneRow(sprintf('SELECT hash FROM prehash WHERE hash = %s', $db->escapeString($md5))); + $oldname = $db->queryOneRow(sprintf('SELECT md5 FROM prehash WHERE md5 = %s', $db->escapeString($md5))); if ($oldname !== false && $oldname["md5"] == $md5) continue; else @@ -266,7 +266,7 @@ Class Predb else $category = 'NULL'; - $run = $db->queryInsert(sprintf('INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, hash) VALUES (%s, %s, %s, %s, now(), %s, %s)', $title, $size, $category, $predate, $db->escapeString('zenet'), $md5)); + $run = $db->queryInsert(sprintf('INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, md5) VALUES (%s, %s, %s, %s, now(), %s, %s)', $title, $size, $category, $predate, $db->escapeString('zenet'), $md5)); if ($run) $newnames++; } @@ -311,7 +311,7 @@ Class Predb else $size = $db->escapeString(round($matches2["size"])); - $db->exec(sprintf("INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, hash) VALUES (%s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $size, $db->escapeString($matches2["category"]), $db->escapeString("prelist"), $db->escapeString($md5))); + $db->exec(sprintf("INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, md5) VALUES (%s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $size, $db->escapeString($matches2["category"]), $db->escapeString("prelist"), $db->escapeString($md5))); $newnames++; } } @@ -325,7 +325,7 @@ Class Predb { $category = $db->escapeString($matches2["category"].", ".$matches2["category1"]); - $db->exec(sprintf("INSERT IGNORE INTO prehash (title, category, predate, adddate, source, hash) VALUES (%s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $category, $db->escapeString("prelist"), $db->escapeString($md5))); + $db->exec(sprintf("INSERT IGNORE INTO prehash (title, category, predate, adddate, source, md5) VALUES (%s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $category, $db->escapeString("prelist"), $db->escapeString($md5))); $newnames++; } } @@ -371,7 +371,7 @@ Class Predb else $size = $db->escapeString($matches2["size"]); - $db->exec(sprintf("INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, hash) VALUES (%s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $size, $db->escapeString($matches2["category"]), $db->escapeString("orlydb"), $db->escapeString($md5))); + $db->exec(sprintf("INSERT IGNORE INTO prehash (title, size, category, predate, adddate, source, md5) VALUES (%s, %s, %s, FROM_UNIXTIME(".strtotime($matches2["date"])."), now(), %s, %s)", $db->escapeString($matches2["title"]), $size, $db->escapeString($matches2["category"]), $db->escapeString("orlydb"), $db->escapeString($md5))); $newnames++; } } @@ -414,12 +414,12 @@ Class Predb foreach ($releases->channel->item as $release) { $md5 = md5($release->title); - $oldname = $db->queryOneRow(sprintf('SELECT hash FROM prehash WHERE hash = %s', $db->escapeString($md5))); - if ($oldname !== false && $oldname['hash'] == $md5) + $oldname = $db->queryOneRow(sprintf('SELECT md5 FROM prehash WHERE md5 = %s', $db->escapeString($md5))); + if ($oldname !== false && $oldname['md5'] == $md5) continue; else { - $db->exec(sprintf('INSERT IGNORE INTO prehash (title, predate, adddate, source, hash) VALUES (%s, %s, now(), %s, %s)', $db->escapeString($release->title), $f->from_unixtime(strtotime($release->pubDate)), $db->escapeString('srrdb'), $db->escapeString($md5)));$newnames++; + $db->exec(sprintf('INSERT IGNORE INTO prehash (title, predate, adddate, source, md5) VALUES (%s, %s, now(), %s, %s)', $db->escapeString($release->title), $f->from_unixtime(strtotime($release->pubDate)), $db->escapeString('srrdb'), $db->escapeString($md5)));$newnames++; } } } @@ -454,7 +454,7 @@ Class Predb continue; else { - $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, hash) VALUES (%s, now(), now(), %s, %s)", $db->escapeString($release->title), $db->escapeString("predbme"), $db->escapeString($md5))); + $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, md5) VALUES (%s, now(), now(), %s, %s)", $db->escapeString($release->title), $db->escapeString("predbme"), $db->escapeString($md5))); $newnames++; } } @@ -492,7 +492,7 @@ Class Predb $md5 = $db->escapeString(md5($matches2["title"])); $predate = $db->escapeString($matches2["predate"]); $source = $db->escapeString('allfilled'); - $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, hash, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); + $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, md5, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); $newnames++; } } @@ -529,7 +529,7 @@ Class Predb $md5 = $db->escapeString(md5($matches2["title"])); $predate = $db->escapeString($matches2["predate"]); $source = $db->escapeString('allfilled'); - $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, hash, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); + $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, md5, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); $newnames++; } } @@ -566,7 +566,7 @@ Class Predb $md5 = $db->escapeString(md5($matches2["title"])); $predate = $db->escapeString($matches2["predate"]); $source = $db->escapeString('allfilled'); - $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, hash, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); + $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, md5, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); $newnames++; } } @@ -603,7 +603,7 @@ Class Predb $md5 = $db->escapeString(md5($matches2["title"])); $predate = $db->escapeString($matches2["predate"]); $source = $db->escapeString('allfilled'); - $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, hash, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); + $run = $db->exec(sprintf("INSERT IGNORE INTO prehash (title, predate, adddate, source, md5, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %s, %d) ON DUPLICATE KEY UPDATE requestID = %d, groupID = %d", $title, $predate, $source, $md5, $requestID, $groupID, $requestID, $groupID)); $newnames++; } } @@ -648,16 +648,16 @@ Class Predb $md5 = md5($title[1]); $predate = $title[2]; - $oldname = $db->queryOneRow(sprintf('SELECT hash, requestID, groupID FROM prehash WHERE hash = %s', $db->escapeString($md5))); - if ($oldname !== false && $oldname['hash'] == $md5) + $oldname = $db->queryOneRow(sprintf('SELECT md5, requestID, groupID FROM prehash WHERE md5 = %s', $db->escapeString($md5))); + if ($oldname !== false && $oldname['md5'] == $md5) { $oldrequestid = $oldname['requestID']; $oldgroupid = $oldname['groupID']; - $db->exec(sprintf('UPDATE prehash SET requestID = IF(%d = 0, %d, 0), groupid = IF(%d = 0, %d, 0) WHERE hash = %s', $oldrequestid, $requestid, $oldgroupid, $groupid, $db->escapeString($md5))); + $db->exec(sprintf('UPDATE prehash SET requestID = IF(%d = 0, %d, 0), groupid = IF(%d = 0, %d, 0) WHERE md5 = %s', $oldrequestid, $requestid, $oldgroupid, $groupid, $db->escapeString($md5))); } else { - if ($db->exec(sprintf('INSERT INTO prehash (title, predate, adddate, source, hash, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %d, %d)', $db->escapeString($title[1]), $functions->from_unixtime(strtotime($predate)), $db->escapeString('abgx'), $db->escapeString($md5), $requestid, $groupid))) + if ($db->exec(sprintf('INSERT INTO prehash (title, predate, adddate, source, md5, requestID, groupID) VALUES (%s, %s, now(), %s, %s, %d, %d)', $db->escapeString($title[1]), $functions->from_unixtime(strtotime($predate)), $db->escapeString('abgx'), $db->escapeString($md5), $requestid, $groupid))) { $newnames++; } diff --git a/test/update_prehash_md5.php b/test/update_prehash_md5.php index a1ef1019d..6aed39354 100644 --- a/test/update_prehash_md5.php +++ b/test/update_prehash_md5.php @@ -12,7 +12,7 @@ $c = new ColorCLI(); if (!isset($argv[1]) || $argv[1] != 'true') { exit($c->error("\nThis script will recalculate and update the MD5 column for each pre.\n\n" - . "php $argv[0] true ...: To reset every predb MD5.\n")); + . "php $argv[0] true ...: To reset every prehash MD5.\n")); } // Drop the unique index @@ -25,17 +25,17 @@ if ($has_index->rowCount() > 0) { $res = $db->queryDirect("SELECT ID, title FROM prehash"); $total = $res->rowCount(); $deleted = $count = 0; -echo $c->header("Updating MD5's on $total preDB's."); +echo $c->header("Updating MD5's on $total prehash's."); foreach ($res as $row) { $name = trim($row['title']); $md5 = $db->escapeString(md5($name)); $title = $db->escapeString($name); - $db->queryDirect(sprintf("UPDATE prehash SET title = %s, hash = %s WHERE ID = %d", $title, $md5, $row['ID'])); + $db->queryDirect(sprintf("UPDATE prehash SET title = %s, md5 = %s WHERE ID = %d", $title, $md5, $row['ID'])); $consoletools->overWriteHeader("Reset MD5s: " . $consoletools->percentString(++$count, $total)); } //Re-create the unique index, dropping dupes echo $c->info("\nCreating index ix_prehash_md5."); -$db->queryDirect("ALTER IGNORE TABLE prehash ADD CONSTRAINT ix_prehash_md5 UNIQUE (hash)"); +$db->queryDirect("ALTER IGNORE TABLE prehash ADD CONSTRAINT ix_prehash_md5 UNIQUE (md5)"); echo $c->header("\nDone.");