mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-09-01 02:38:55 +00:00
Add scripts to change USP, dump database and reset the database.
This commit is contained in:
@@ -878,7 +878,7 @@ class DB extends \PDO
|
||||
if ($myIsamTables instanceof \Traversable && $myIsamTables->rowCount()) {
|
||||
$tableNames = '';
|
||||
foreach ($myIsamTables as $table) {
|
||||
$tableNames .= $table['name'] . ',';
|
||||
$tableNames .= $table['Name'] . ',';
|
||||
}
|
||||
$tableNames = rtrim($tableNames, ',');
|
||||
$this->queryExec(sprintf('REPAIR %s TABLE %s', $local, $tableNames));
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
require_once(WWW_DIR . "/lib/framework/db.php");
|
||||
require_once(WWW_DIR . "/lib/nntp.php");
|
||||
require_once(WWW_DIR . "/lib/binaries.php");
|
||||
|
||||
|
||||
/* This script will update the groups table to get the new article numbers for each group you have activated.
|
||||
It will also truncate the parts, binaries, collections, and missed_parts tables.
|
||||
*/
|
||||
// TODO: Make this threaded so it goes faster.
|
||||
|
||||
$pdo = new DB();
|
||||
|
||||
if (!isset($argv[1]) || $argv[1] != 'true') {
|
||||
printf($pdo->log->setColor('Yellow') . "This script is used when you have switched UseNet Providers(USP) so you can pickup where you left off, rather than resetting all the groups.\nOnly use this script after you have updated your config.php file with your new USP info!!\nMake sure you " . $pdo->log->setColor('Red', 'Bold') . "DO NOT" . $pdo->log->setcolor('Yellow') . " have any update or postprocess scripts running when running this script!\n\n" . $pdo->log->setColor('Cyan') . "Usage: php change_USP_provider true\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$groups = $pdo->query("SELECT ID, name, first_record_postdate, last_record_postdate FROM groups WHERE active = 1");
|
||||
$numofgroups = count($groups);
|
||||
$guesstime = $numofgroups * 2;
|
||||
$totalstart = microtime(true);
|
||||
|
||||
echo "You have $numofgroups active, it takes about 2 minutes on average to processes each group.\n";
|
||||
foreach ($groups as $group) {
|
||||
$starttime = microtime(true);
|
||||
$nntp = new \NNTP(['Settings' => $pdo]);
|
||||
if ($nntp->doConnect() !== true) {
|
||||
return;
|
||||
}
|
||||
//printf("Updating group ".$group['name']."..\n");
|
||||
$bfdays = daysOldstr($group['first_record_postdate']);
|
||||
$currdays = daysOldstr($group['last_record_postdate']);
|
||||
$bfartnum = daytopost($nntp, $group['name'], $bfdays, true, true);
|
||||
echo "Our Current backfill postdate was: " . $pdo->log->setColor('Yellow') . date('r', strtotime($group['first_record_postdate'])) . $pdo->log->rsetcolor() . "\n";
|
||||
$currartnum = daytopost($nntp, $group['name'], $currdays, true, false);
|
||||
echo "Our Current current postdate was: " . $pdo->log->setColor('Yellow') . date('r', strtotime($group['last_record_postdate'])) . $pdo->log->rsetcolor() . "\n";
|
||||
$pdo->queryExec(sprintf("UPDATE groups SET first_record = %s, last_record = %s WHERE ID = %d", $pdo->escapeString($bfartnum), $pdo->escapeString($currartnum), $group['ID']));
|
||||
$endtime = microtime(true);
|
||||
echo $pdo->log->setColor('Gray', 'Dim') . "This group took " . gmdate("H:i:s", $endtime - $starttime) . " to process.\n";
|
||||
$numofgroups--;
|
||||
echo "There are " . $numofgroups . " left to process.\n\n" . $pdo->log->rsetcolor() . "";
|
||||
}
|
||||
|
||||
$totalend = microtime(true);
|
||||
echo $pdo->log->header('Total time to update all groups ' . gmdate("H:i:s", $totalend - $totalstart));
|
||||
|
||||
// Truncate tables to complete the change to the new USP.
|
||||
$arr = array("parts", "partrepair", "binaries");
|
||||
foreach ($arr as &$value) {
|
||||
$rel = $pdo->queryExec("TRUNCATE TABLE $value");
|
||||
if ($rel !== false) {
|
||||
echo $pdo->log->header("Truncating $value completed.");
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
|
||||
function daysOldstr($timestamp)
|
||||
{
|
||||
return round((time() - strtotime($timestamp)) / 86400, 5);
|
||||
}
|
||||
|
||||
function daysOld($timestamp)
|
||||
{
|
||||
return round((time() - $timestamp) / 86400, 5);
|
||||
}
|
||||
|
||||
// This function taken from lib/backfill.php, and modified to fit our needs.
|
||||
function daytopost($nntp, $group, $days, $debug = true, $bfcheck = true)
|
||||
{
|
||||
global $pdo;
|
||||
|
||||
$st = false;
|
||||
if ($debug && $bfcheck) {
|
||||
echo $pdo->log->primary('Finding start and end articles for ' . $group . '.');
|
||||
}
|
||||
|
||||
if (!isset($nntp)) {
|
||||
$nntp = new \NNTP(['Settings' => $pdo]);
|
||||
if ($nntp->doConnect(false) !== true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$st = true;
|
||||
}
|
||||
|
||||
$binaries = new \Binaries(['NNTP' => $nntp, 'Settings' => $pdo]);
|
||||
|
||||
$data = $nntp->selectGroup($group);
|
||||
if ($nntp->isError($data)) {
|
||||
$data = $nntp->dataError($nntp, $group, false);
|
||||
if ($data === false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Goal timestamp.
|
||||
$goaldate = date('U') - (86400 * $days);
|
||||
$totalnumberofarticles = $data['last'] - $data['first'];
|
||||
$upperbound = $data['last'];
|
||||
$lowerbound = $data['first'];
|
||||
|
||||
if ($debug && $bfcheck) {
|
||||
echo $pdo->log->header('Total Articles: ' . number_format($totalnumberofarticles) . ' Newest: ' . number_format($upperbound) . ' Oldest: ' . number_format($lowerbound));
|
||||
}
|
||||
|
||||
if ($data['last'] == PHP_INT_MAX) {
|
||||
exit($pdo->log->error("Group data is coming back as php's max value. You should not see this since we use a patched Net_NNTP that fixes this bug."));
|
||||
}
|
||||
|
||||
$firstDate = $binaries->postdate($data['first'], $data);
|
||||
$lastDate = $binaries->postdate($data['last'], $data);
|
||||
|
||||
if ($goaldate < $firstDate && $bfcheck) {
|
||||
if ($st === true) {
|
||||
$nntp->doQuit();
|
||||
}
|
||||
echo $pdo->log->warning("The oldest post indexed from $days day(s) ago is older than the first article stored on your news server.\nSetting to First available article of (date('r', $firstDate) or daysOld($firstDate) days).");
|
||||
return $data['first'];
|
||||
} else if ($goaldate > $lastDate && $bfcheck) {
|
||||
if ($st === true) {
|
||||
$nntp->doQuit();
|
||||
}
|
||||
echo $pdo->log->error("ERROR: The oldest post indexed from $days day(s) ago is newer than the last article stored on your news server.\nTo backfill this group you need to set Backfill Days to at least ceil(daysOld($lastDate)+1) days (date('r', $lastDate-86400).");
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($debug && $bfcheck) {
|
||||
echo $pdo->log->primary("Searching for postdates.\nGroup's Firstdate: " . $firstDate . ' (' . ((is_int($firstDate)) ? date('r', $firstDate) : 'n/a') . ").\nGroup's Lastdate: " . $lastDate . ' (' . date('r', $lastDate) . ").");
|
||||
}
|
||||
|
||||
$interval = floor(($upperbound - $lowerbound) * 0.5);
|
||||
$templowered = '';
|
||||
$dateofnextone = $lastDate;
|
||||
// Match on days not timestamp to speed things up.
|
||||
while (daysOld($dateofnextone) < $days) {
|
||||
while (($tmpDate = $binaries->postdate(($upperbound - $interval), $data)) > $goaldate) {
|
||||
$upperbound = $upperbound - $interval;
|
||||
}
|
||||
|
||||
if (!$templowered) {
|
||||
$interval = ceil(($interval / 2));
|
||||
}
|
||||
$dateofnextone = $binaries->postdate(($upperbound - 1), $data);
|
||||
while (!$dateofnextone) {
|
||||
$dateofnextone = $binaries->postdate(($upperbound - 1), $data);
|
||||
}
|
||||
}
|
||||
if ($st === true) {
|
||||
$nntp->doQuit();
|
||||
}
|
||||
if ($bfcheck) {
|
||||
echo $pdo->log->header("\nBackfill article determined to be " . $upperbound . " " . $pdo->log->setColor('Yellow') . "(" . date('r', $dateofnextone) . ")" . $pdo->log->rsetcolor());
|
||||
} // which is '.daysOld($dateofnextone)." days old.\n";
|
||||
else {
|
||||
echo $pdo->log->header('Current article determined to be ' . $upperbound . " " . $pdo->log->setColor('Yellow') . "(" . date('r', $dateofnextone) . ")" . $pdo->log->rsetcolor());
|
||||
} // which is '.daysOld($dateofnextone)." days old.\n";
|
||||
return $upperbound;
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
require_once(WWW_DIR . "/lib/framework/db.php");
|
||||
|
||||
|
||||
// This script can dump all tables or just collections/binaries/parts/partrepair/groups.
|
||||
|
||||
$pdo = new DB();
|
||||
|
||||
$exportopts = "";
|
||||
|
||||
//determine mysql platform Percona or Other
|
||||
$mysqlplatform = exec('mysqladmin version | grep "Percona"');
|
||||
if (strlen($mysqlplatform) > 0) {
|
||||
//Percona only has --innodb-optimize-keys
|
||||
$exportopts = "--opt --innodb-optimize-keys --complete-insert --skip-quick";
|
||||
} else {
|
||||
//generic (or unknown) instance of MySQL
|
||||
$exportopts = "--opt --complete-insert --skip-quick";
|
||||
}
|
||||
|
||||
|
||||
function newname($filename)
|
||||
{
|
||||
rename($filename, dirname($filename)."/".basename($filename,".gz")."_".date("Y_m_d_His", filemtime($filename)).".gz");
|
||||
}
|
||||
|
||||
function builddefaultsfile()
|
||||
{
|
||||
//generate file contents
|
||||
$filetext = "[mysqldump]"
|
||||
."\n"
|
||||
."user = " . DB_USER
|
||||
."\n"
|
||||
."password = " . DB_PASSWORD
|
||||
."\n[mysql]"
|
||||
."\n"
|
||||
."user = " . DB_USER
|
||||
."\n"
|
||||
."password = " . DB_PASSWORD;
|
||||
|
||||
$filehandle = fopen("mysql-defaults.txt", "w+");
|
||||
if(!$filehandle) {
|
||||
exit("Unable to write mysql defaults file! Exiting");
|
||||
} else {
|
||||
fwrite($filehandle, $filetext);
|
||||
fclose($filehandle);
|
||||
chmod("mysql-defaults.txt", 0600);
|
||||
}
|
||||
}
|
||||
|
||||
$dbhost = DB_HOST;
|
||||
$dbport = DB_PORT;
|
||||
$dbsocket = DB_SOCKET;
|
||||
$dbuser = DB_USER;
|
||||
$dbpass = DB_PASSWORD;
|
||||
$dbname = DB_NAME;
|
||||
|
||||
if (DB_SOCKET != '') {
|
||||
$use = "-S $dbsocket";
|
||||
} else {
|
||||
$use = "-P$dbport";
|
||||
}
|
||||
|
||||
//generate defaults file used to store database login information so it is not in cleartext in ps command for mysqldump
|
||||
builddefaultsfile();
|
||||
|
||||
if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) {
|
||||
$filename = $argv[3]."/".$dbname.".gz";
|
||||
echo $pdo->log->header("Dumping $dbname.");
|
||||
if (file_exists($filename)) {
|
||||
newname($filename);
|
||||
}
|
||||
$command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname | gzip -9 > $filename";
|
||||
system($command);
|
||||
} else if((isset($argv[1]) && $argv[1] == "db") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) {
|
||||
$filename = $argv[3]."/".$dbname.".gz";
|
||||
if (file_exists($filename)) {
|
||||
echo $pdo->log->header("Restoring $dbname.");
|
||||
$command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname";
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
|
||||
system($command);
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
|
||||
}
|
||||
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) {
|
||||
$sql = "SHOW tables";
|
||||
$tables = $pdo->query($sql);
|
||||
foreach($tables as $row) {
|
||||
$tbl = $row['Tables_in_'.DB_NAME];
|
||||
$filename = $argv[3]."/".$tbl.".gz";
|
||||
echo $pdo->log->header("Dumping $tbl.");
|
||||
if (file_exists($filename)) {
|
||||
newname($filename);
|
||||
}
|
||||
$command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname $tbl | gzip -9 > $filename";
|
||||
system($command);
|
||||
}
|
||||
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) {
|
||||
$sql = "SHOW tables";
|
||||
$tables = $pdo->query($sql);
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
|
||||
foreach($tables as $row) {
|
||||
$tbl = $row['Tables_in_'.DB_NAME];
|
||||
$filename = $argv[3]."/".$tbl.".gz";
|
||||
if (file_exists($filename)) {
|
||||
echo $pdo->log->header("Restoring $tbl.");
|
||||
$command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname";
|
||||
system($command);
|
||||
}
|
||||
}
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
|
||||
} else if((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "dump") && (isset($argv[3]) && file_exists($argv[3]))) {
|
||||
$arr = array("parts", "binaries", "partrepair", "groups");
|
||||
foreach ($arr as &$tbl) {
|
||||
$filename = $argv[3]."/".$tbl.".gz";
|
||||
echo $pdo->log->header("Dumping $tbl..");
|
||||
if (file_exists($filename)) {
|
||||
newname($filename);
|
||||
}
|
||||
$command = "mysqldump --defaults-file=mysql-defaults.txt $exportopts -h$dbhost $use "."$dbname $tbl | gzip -9 > $filename";
|
||||
system($command);
|
||||
}
|
||||
} else if((isset($argv[1]) && $argv[1] == "test") && (isset($argv[2]) && $argv[2] == "restore") && (isset($argv[3]) && file_exists($argv[3]))) {
|
||||
$arr = array("parts", "binaries", "partrepair", "groups");
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
|
||||
foreach ($arr as &$tbl) {
|
||||
$filename = $argv[3]."/".$tbl.".gz";
|
||||
if (file_exists($filename)) {
|
||||
echo $pdo->log->header("Restoring $tbl.");
|
||||
$command = "zcat < $filename | mysql --defaults-file=mysql-defaults.txt -h$dbhost $use $dbname";
|
||||
system($command);
|
||||
}
|
||||
}
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
|
||||
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "outfile") && (isset($argv[3]) && file_exists($argv[3]))) {
|
||||
$sql = "SHOW tables";
|
||||
$tables = $pdo->query($sql);
|
||||
foreach($tables as $row) {
|
||||
$tbl = $row['Tables_in_'.DB_NAME];
|
||||
$filename = $argv[3].$tbl.".csv";
|
||||
echo $pdo->log->header("Dumping $tbl.");
|
||||
if (file_exists($filename)) {
|
||||
newname($filename);
|
||||
}
|
||||
$pdo->queryDirect(sprintf("SELECT * INTO OUTFILE %s FROM %s", $pdo->escapeString($filename), $tbl));
|
||||
}
|
||||
} else if((isset($argv[1]) && $argv[1] == "all") && (isset($argv[2]) && $argv[2] == "infile") && (isset($argv[3]) && is_dir($argv[3]))) {
|
||||
$sql = "SHOW tables";
|
||||
$tables = $pdo->query($sql);
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=0");
|
||||
foreach($tables as $row) {
|
||||
$tbl = $row['Tables_in_'.DB_NAME];
|
||||
$filename = $argv[3].$tbl.".csv";
|
||||
if (file_exists($filename)) {
|
||||
echo $pdo->log->header("Restoring $tbl.");
|
||||
$pdo->queryExec(sprintf("LOAD DATA INFILE %s INTO TABLE %s", $pdo->escapeString($filename), $tbl));
|
||||
}
|
||||
}
|
||||
$pdo->queryExec("SET FOREIGN_KEY_CHECKS=1");
|
||||
} else {
|
||||
passthru("clear");
|
||||
echo $pdo->log->error("\nThis script can dump/restore all tables, compressed or OUTFILE/INFILE, or just collections/binaries/parts.\n\n"
|
||||
. "**Single File\n"
|
||||
. "php $argv[0] db dump /path/to/save/to ...: To dump the database.\n"
|
||||
. "php $argv[0] db restore /path/to/restore/from ...: To restore the database.\n\n"
|
||||
. "**Individual Table Files\n"
|
||||
. "php $argv[0] all dump /path/to/save/to ...: To dump all tables.\n"
|
||||
. "php $argv[0] all restore /path/to/restore/from ...: To restore all tables.\n\n"
|
||||
. "**Three Tables (collections, binaries, parts)\n"
|
||||
. "php $argv[0] test dump /path/to/save/to ...: To dump binaries and parts tables.\n"
|
||||
. "php $argv[0] test restore /path/to/restore/from ...: To restore binaries and parts tables.\n\n"
|
||||
. "**Individal Files - OUTFILE/INFILE - No schema\n"
|
||||
. "**MySQL MUST have write permissions to this path\n"
|
||||
. "php $argv[0] all outfile /path/to/save/to ...: To dump all tables, using OUTFILE.\n"
|
||||
. "php $argv[0] all infile /path/to/restore/from ...: To restore all tables, using INFILE.\n\n");
|
||||
}
|
||||
|
||||
if(file_exists("mysql-defaults.txt")) {
|
||||
@unlink("mysql-defaults.txt");
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . "/../../../bin/config.php");
|
||||
require_once(WWW_DIR . "/lib/framework/db.php");
|
||||
require_once(WWW_DIR . "/lib/releaseimage.php");
|
||||
require_once(WWW_DIR . "/lib/nzb.php");
|
||||
require_once(WWW_DIR . "/lib/ConsoleTools.php");
|
||||
require_once(WWW_DIR . "/lib/SphinxSearch.php");
|
||||
|
||||
passthru('clear');
|
||||
$pdo = new DB();
|
||||
|
||||
if (!isset($argv[1]) || (isset($argv[1]) && $argv[1] !== 'true'))
|
||||
exit($pdo->log->error("\nThis script removes all releases and release related files. To run:\nphp resetdb.php true\n"));
|
||||
|
||||
echo $pdo->log->warning("This script removes all releases, nzb files, samples, previews , nfos, truncates all article tables and resets all groups.");
|
||||
echo $pdo->log->header("Are you sure you want reset the DB? Type 'DESTROY' to continue: \n");
|
||||
echo $pdo->log->warningOver("\n");
|
||||
$line = fgets(STDIN);
|
||||
if (trim($line) != 'DESTROY')
|
||||
exit($pdo->log->error("This script is dangerous you must type DESTROY for it function."));
|
||||
|
||||
echo "\n";
|
||||
echo $pdo->log->header("Thank you, continuing...\n\n");
|
||||
|
||||
$timestart = time();
|
||||
$relcount = 0;
|
||||
$ri = new \ReleaseImage($pdo);
|
||||
$nzb = new \NZB($pdo);
|
||||
$consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]);
|
||||
|
||||
$pdo->queryExec("UPDATE groups SET first_record = 0, first_record_postdate = NULL, last_record = 0, last_record_postdate = NULL, last_updated = NULL");
|
||||
echo $pdo->log->primary("Reseting all groups completed.");
|
||||
|
||||
$arr = [
|
||||
"tvrage", "releasenfo", "releasecomment", 'sharing', 'sharing_sites',
|
||||
"usercart", "usermovies", "userseries", "movieinfo", "musicinfo", "releasefiles",
|
||||
"releaseaudio", "releasesubs", "releasevideo", "releaseextrafull", "parts",
|
||||
"partrepair", "binaries", "releases"
|
||||
];
|
||||
foreach ($arr as &$value) {
|
||||
$rel = $pdo->queryExec("TRUNCATE TABLE $value");
|
||||
if ($rel !== false)
|
||||
echo $pdo->log->primary("Truncating ${value} completed.");
|
||||
}
|
||||
unset($value);
|
||||
|
||||
$sql = "SHOW table status";
|
||||
|
||||
$tables = $pdo->query($sql);
|
||||
foreach ($tables as $row) {
|
||||
$tbl = $row['Name'];
|
||||
if (preg_match('/binaries_\d+/', $tbl) || preg_match('/parts_\d+/', $tbl) || preg_match('/partrepair_\d+/', $tbl) || preg_match('/\d+_binaries/', $tbl) || preg_match('/\d+_parts/', $tbl) || preg_match('/\d+_partrepair_\d+/', $tbl)) {
|
||||
$rel = $pdo->queryDirect(sprintf('DROP TABLE %s', $tbl));
|
||||
if ($rel !== false)
|
||||
echo $pdo->log->primary("Dropping ${tbl} completed.");
|
||||
}
|
||||
}
|
||||
|
||||
(new \SphinxSearch())->truncateRTIndex('releases_rt');
|
||||
|
||||
$pdo->optimise(false, 'full');
|
||||
$s = new Sites();
|
||||
$site = $s->get();
|
||||
|
||||
echo $pdo->log->header("Deleting nzbfiles subfolders.");
|
||||
try {
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($site->nzbpath, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($files as $file) {
|
||||
if (basename($file) != '.gitignore' && basename($file) != 'tmpunrar') {
|
||||
$todo = ($file->isDir() ? 'rmdir' : 'unlink');
|
||||
@$todo($file);
|
||||
}
|
||||
}
|
||||
} catch (UnexpectedValueException $e) {
|
||||
echo $pdo->log->error($e->getMessage());
|
||||
}
|
||||
|
||||
echo $pdo->log->header("Deleting all images, previews and samples that still remain.");
|
||||
try {
|
||||
$dirItr = new \RecursiveDirectoryIterator(NN_COVERS);
|
||||
$itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
|
||||
foreach ($itr as $filePath) {
|
||||
if (basename($filePath) != '.gitignore' && basename($filePath) != 'no-cover.jpg' && basename($filePath) != 'no-backdrop.jpg') {
|
||||
@unlink($filePath);
|
||||
}
|
||||
}
|
||||
} catch (UnexpectedValueException $e) {
|
||||
echo $pdo->log->error($e->getMessage());
|
||||
}
|
||||
|
||||
echo $pdo->log->header("Getting Updated List of TV Shows from TVRage.");
|
||||
$tvshows = @simplexml_load_file('http://services.tvrage.com/feeds/show_list.php');
|
||||
if ($tvshows !== false) {
|
||||
foreach ($tvshows->show as $rage) {
|
||||
if (isset($rage->id) && isset($rage->name) && !empty($rage->id) && !empty($rage->name))
|
||||
$pdo->queryInsert(sprintf('INSERT INTO tvrage (rageID, releasetitle, country) VALUES (%s, %s, %s)', $pdo->escapeString($rage->id), $pdo->escapeString($rage->name), $pdo->escapeString($rage->country)));
|
||||
}
|
||||
} else {
|
||||
echo $pdo->log->error("TVRage site has a hard limit of 400 concurrent api requests. At the moment, they have reached that limit. Please wait before retrying again.");
|
||||
}
|
||||
|
||||
echo $pdo->log->header("Deleted all releases, images, previews and samples. This script ran for " . $consoletools->convertTime(TIME() - $timestart));
|
||||
Reference in New Issue
Block a user