diff --git a/Changelog b/Changelog index 15f4231bb..bf15de323 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-07-19 DariusIII + * Chg: Remove Blacklight\db\DB class from many scripts in misc/testing folder * Chg: Update ReleaseExtra class constructor * Chg: Remove Blacklight\db\DB from ProcessAdditional class * Fix: Potential fix for ADM site processing error diff --git a/misc/testing/DB/mysqldump_tables.php b/misc/testing/DB/mysqldump_tables.php deleted file mode 100644 index f0d8180d0..000000000 --- a/misc/testing/DB/mysqldump_tables.php +++ /dev/null @@ -1,180 +0,0 @@ - 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 = '.env('DB_USER') - ."\n" - .'password = '.env('DB_PASSWORD') - ."\n[mysql]" - ."\n" - .'user = '.env('DB_USER') - ."\n" - .'password = '.env('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 = env('DB_HOST'); -$dbport = env('DB_PORT'); -$dbsocket = env('DB_SOCKET'); -$dbuser = env('DB_USER'); -$dbpass = env('DB_PASSWORD'); -$dbname = env(env('DB_NAME')); - -if (env('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); -} elseif ((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'); - } -} elseif ((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_'.env('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); - } -} elseif ((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_'.env('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'); -} elseif ((isset($argv[1]) && $argv[1] == 'test') && (isset($argv[2]) && $argv[2] == 'dump') && (isset($argv[3]) && file_exists($argv[3]))) { - $arr = ['parts', 'binaries', 'missed_parts', '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); - } -} elseif ((isset($argv[1]) && $argv[1] == 'test') && (isset($argv[2]) && $argv[2] == 'restore') && (isset($argv[3]) && file_exists($argv[3]))) { - $arr = ['parts', 'binaries', 'missed_parts', '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'); -} elseif ((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_'.env('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)); - } -} elseif ((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_'.env('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'); -} diff --git a/misc/testing/DB/populate_nzb_guid.php b/misc/testing/DB/populate_nzb_guid.php deleted file mode 100644 index b46d3f228..000000000 --- a/misc/testing/DB/populate_nzb_guid.php +++ /dev/null @@ -1,107 +0,0 @@ -error("\nThis script updates all releases with the guid (md5 hash of the first message-id) from the nzb file.\n\n" - ."php $argv[0] true ...: To create missing nzb_guids.\n" - ."php $argv[0] true delete ...: To create missing nzb_guids and delete invalid nzbs and releases.\n")); -} - -function create_guids($live, $delete = false) -{ - $pdo = new DB(); - $consoletools = new ConsoleTools(); - $timestart = time(); - $relcount = $deleted = $total = 0; - - $relrecs = false; - if ($live == 'true') { - $relrecs = $pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC')); - } elseif ($live == 'limited') { - $relrecs = $pdo->queryDirect(sprintf('SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC LIMIT 10000')); - } - if ($relrecs) { - $total = $relrecs->rowCount(); - } - if ($total > 0) { - echo $pdo->log->header('Creating nzb_guids for '.number_format($total).' releases.'); - $releases = new Releases(['Settings' => $pdo]); - $nzb = new NZB(); - $releaseImage = new ReleaseImage(); - $reccnt = 0; - if ($relrecs instanceof \Traversable) { - foreach ($relrecs as $relrec) { - $reccnt++; - $nzbpath = $nzb->NZBPath($relrec['guid']); - if ($nzbpath !== false) { - $nzbfile = Utility::unzipGzipFile($nzbpath); - if ($nzbfile) { - $nzbfile = @simplexml_load_string($nzbfile); - } - if (! $nzbfile) { - if (isset($delete) && $delete == 'delete') { - //echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n"; - $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); - $deleted++; - } - continue; - } - $binary_names = []; - foreach ($nzbfile->file as $file) { - $binary_names[] = $file['subject']; - } - if (count($binary_names) == 0) { - if (isset($delete) && $delete == 'delete') { - //echo "\n".$nzb->NZBPath($relrec['guid'])." has no binaries, deleting release.\n"; - $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); - $deleted++; - } - continue; - } - - asort($binary_names); - foreach ($nzbfile->file as $file) { - if ($file['subject'] == $binary_names[0]) { - $segment = $file->segments->segment; - $nzb_guid = md5($segment); - - $pdo->queryExec('UPDATE releases set nzb_guid = UNHEX('.$pdo->escapestring($nzb_guid).') WHERE id = '.$relrec['id']); - $relcount++; - $consoletools->overWritePrimary('Created: ['.$deleted.'] '.$consoletools->percentString($reccnt, $total).' Time:'.$consoletools->convertTimer(time() - $timestart)); - break; - } - } - } else { - if (isset($delete) && $delete == 'delete') { - //echo $pdo->log->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting."); - $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); - } - } - } - } - - if ($relcount > 0) { - echo "\n"; - } - echo $pdo->log->header('Updated '.$relcount.' release(s). This script ran for '.$consoletools->convertTime(time() - $timestart)); - } else { - echo $pdo->log->info('Query time: '.$consoletools->convertTime(time() - $timestart)); - exit($pdo->log->info('No releases are missing the guid.')); - } -} diff --git a/misc/testing/DB/reset_postprocessing.php b/misc/testing/DB/reset_postprocessing.php index dc97c63d9..9853faf6f 100755 --- a/misc/testing/DB/reset_postprocessing.php +++ b/misc/testing/DB/reset_postprocessing.php @@ -2,12 +2,12 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; -use Blacklight\db\DB; use App\Models\Category; use Blacklight\ColorCLI; use Blacklight\ConsoleTools; +use Illuminate\Support\Facades\DB; -$pdo = new DB(); +$pdo = DB::connection()->getPdo(); $consoletools = new ConsoleTools(); $ran = false; @@ -15,30 +15,30 @@ if ($argv[1] !== null && $argv[1] === 'all' && $argv[2] !== null && $argv[2] === $ran = true; $where = ''; if (isset($argv[3]) && $argv[3] === 'truncate') { - echo 'Truncating tables\n'; - $pdo->queryExec('TRUNCATE TABLE consoleinfo'); - $pdo->queryExec('TRUNCATE TABLE gamesinfo'); - $pdo->queryExec('TRUNCATE TABLE movieinfo'); - $pdo->queryExec('TRUNCATE TABLE video_data'); - $pdo->queryExec('TRUNCATE TABLE musicinfo'); - $pdo->queryExec('TRUNCATE TABLE bookinfo'); - $pdo->queryExec('TRUNCATE TABLE release_nfos'); - $pdo->queryExec('TRUNCATE TABLE releaseextrafull'); - $pdo->queryExec('TRUNCATE TABLE xxxinfo'); - $pdo->queryExec('TRUNCATE TABLE videos'); - $pdo->queryExec('TRUNCATE TABLE videos_aliases'); - $pdo->queryExec('TRUNCATE TABLE tv_info'); - $pdo->queryExec('TRUNCATE TABLE tv_episodes'); - $pdo->queryExec('TRUNCATE TABLE anidb_info'); - $pdo->queryExec('TRUNCATE TABLE anidb_episodes'); + echo 'Truncating tables'; + $pdo->exec('TRUNCATE TABLE consoleinfo'); + $pdo->exec('TRUNCATE TABLE gamesinfo'); + $pdo->exec('TRUNCATE TABLE movieinfo'); + $pdo->exec('TRUNCATE TABLE video_data'); + $pdo->exec('TRUNCATE TABLE musicinfo'); + $pdo->exec('TRUNCATE TABLE bookinfo'); + $pdo->exec('TRUNCATE TABLE release_nfos'); + $pdo->exec('TRUNCATE TABLE releaseextrafull'); + $pdo->exec('TRUNCATE TABLE xxxinfo'); + $pdo->exec('TRUNCATE TABLE videos'); + $pdo->exec('TRUNCATE TABLE videos_aliases'); + $pdo->exec('TRUNCATE TABLE tv_info'); + $pdo->exec('TRUNCATE TABLE tv_episodes'); + $pdo->exec('TRUNCATE TABLE anidb_info'); + $pdo->exec('TRUNCATE TABLE anidb_episodes'); } echo ColorCLI::header('Resetting all postprocessing'); - $qry = $pdo->queryDirect('SELECT id FROM releases'); + $qry = $pdo->query('SELECT id FROM releases'); $affected = 0; if ($qry instanceof \Traversable) { $total = $qry->rowCount(); foreach ($qry as $releases) { - $pdo->queryExec( + $pdo->exec( sprintf( ' UPDATE releases @@ -56,7 +56,7 @@ if ($argv[1] !== null && $argv[1] === 'all' && $argv[2] !== null && $argv[2] === if (isset($argv[1]) && ($argv[1] === 'consoles' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE consoleinfo'); + $pdo->exec('TRUNCATE TABLE consoleinfo'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all Console postprocessing'); @@ -66,7 +66,7 @@ if (isset($argv[1]) && ($argv[1] === 'consoles' || $argv[1] === 'all')) { $where = ' WHERE consoleinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::GAME_ROOT.' AND '.Category::GAME_OTHER; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); if ($qry !== false) { $total = $qry->rowCount(); } else { @@ -75,7 +75,7 @@ if (isset($argv[1]) && ($argv[1] === 'consoles' || $argv[1] === 'all')) { $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET consoleinfo_id = NULL WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET consoleinfo_id = NULL WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting Console Releases: '.$consoletools->percentString(++$concount, $total)); } } @@ -84,7 +84,7 @@ if (isset($argv[1]) && ($argv[1] === 'consoles' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'games' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE gamesinfo'); + $pdo->exec('TRUNCATE TABLE gamesinfo'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all Games postprocessing'); @@ -94,7 +94,7 @@ if (isset($argv[1]) && ($argv[1] === 'games' || $argv[1] === 'all')) { $where = ' WHERE gamesinfo_id IN (-2, 0) AND categories_id = 4050'; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); $total = 0; if ($qry !== false) { @@ -104,7 +104,7 @@ if (isset($argv[1]) && ($argv[1] === 'games' || $argv[1] === 'all')) { $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET gamesinfo_id = 0 WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET gamesinfo_id = 0 WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting Games Releases: '.$consoletools->percentString(++$concount, $total)); } echo ColorCLI::header(PHP_EOL.number_format($concount).' gameinfo_IDs reset.'); @@ -113,7 +113,7 @@ if (isset($argv[1]) && ($argv[1] === 'games' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'movies' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE movieinfo'); + $pdo->exec('TRUNCATE TABLE movieinfo'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all Movie postprocessing'); @@ -123,7 +123,7 @@ if (isset($argv[1]) && ($argv[1] === 'movies' || $argv[1] === 'all')) { $where = ' WHERE imdbid IN (-2, 0) AND categories_id BETWEEN '.Category::MOVIE_ROOT.' AND '.Category::MOVIE_OTHER; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); if ($qry !== false) { $total = $qry->rowCount(); } else { @@ -132,7 +132,7 @@ if (isset($argv[1]) && ($argv[1] === 'movies' || $argv[1] === 'all')) { $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET imdbid = NULL WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET imdbid = NULL WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting Movie Releases: '.$consoletools->percentString(++$concount, $total)); } } @@ -141,7 +141,7 @@ if (isset($argv[1]) && ($argv[1] === 'movies' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'music' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE musicinfo'); + $pdo->exec('TRUNCATE TABLE musicinfo'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all Music postprocessing'); @@ -151,12 +151,12 @@ if (isset($argv[1]) && ($argv[1] === 'music' || $argv[1] === 'all')) { $where = ' WHERE musicinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::MUSIC_ROOT.' AND '.Category::MUSIC_OTHER; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); $total = $qry->rowCount(); $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec(sprintf('UPDATE releases SET musicinfo_id = NULL WHERE id = %s ', $releases['id'])); + $pdo->exec(sprintf('UPDATE releases SET musicinfo_id = NULL WHERE id = %s ', $releases['id'])); $consoletools->overWritePrimary('Resetting Music Releases: '.$consoletools->percentString(++$concount, $total)); } } @@ -173,7 +173,7 @@ if (isset($argv[1]) && ($argv[1] === 'misc' || $argv[1] === 'all')) { } echo ColorCLI::primary('SELECT id FROM releases'.$where); - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); if ($qry !== false) { $total = $qry->rowCount(); } else { @@ -182,7 +182,7 @@ if (isset($argv[1]) && ($argv[1] === 'misc' || $argv[1] === 'all')) { $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET passwordstatus = -1, haspreview = -1, jpgstatus = 0, videostatus = 0, audiostatus = 0 WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET passwordstatus = -1, haspreview = -1, jpgstatus = 0, videostatus = 0, audiostatus = 0 WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting Releases: '.$consoletools->percentString(++$concount, $total)); } } @@ -191,9 +191,9 @@ if (isset($argv[1]) && ($argv[1] === 'misc' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'tv' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('DELETE v, va FROM videos v INNER JOIN videos_aliases va ON v.id = va.videos_id WHERE type = 0'); - $pdo->queryExec('TRUNCATE TABLE tv_info'); - $pdo->queryExec('TRUNCATE TABLE tv_episodes'); + $pdo->exec('DELETE v, va FROM videos v INNER JOIN videos_aliases va ON v.id = va.videos_id WHERE type = 0'); + $pdo->exec('TRUNCATE TABLE tv_info'); + $pdo->exec('TRUNCATE TABLE tv_episodes'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all TV postprocessing'); @@ -203,7 +203,7 @@ if (isset($argv[1]) && ($argv[1] === 'tv' || $argv[1] === 'all')) { $where = ' WHERE tv_episodes_id < 0 AND categories_id BETWEEN '.Category::TV_ROOT.' AND '.Category::TV_OTHER; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); if ($qry !== false) { $total = $qry->rowCount(); } else { @@ -212,7 +212,7 @@ if (isset($argv[1]) && ($argv[1] === 'tv' || $argv[1] === 'all')) { $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET videos_id = 0, tv_episodes_id = 0 WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET videos_id = 0, tv_episodes_id = 0 WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting TV Releases: '.$consoletools->percentString(++$concount, $total)); } } @@ -221,8 +221,8 @@ if (isset($argv[1]) && ($argv[1] === 'tv' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'anime' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE anidb_info'); - $pdo->queryExec('TRUNCATE TABLE anidb_episodes'); + $pdo->exec('TRUNCATE TABLE anidb_info'); + $pdo->exec('TRUNCATE TABLE anidb_episodes'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all Anime postprocessing'); @@ -232,7 +232,7 @@ if (isset($argv[1]) && ($argv[1] === 'anime' || $argv[1] === 'all')) { $where = ' WHERE anidbid BETWEEN -2 AND -1 AND categories_id = '.Category::TV_ANIME; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); if ($qry !== false) { $total = $qry->rowCount(); } else { @@ -241,7 +241,7 @@ if (isset($argv[1]) && ($argv[1] === 'anime' || $argv[1] === 'all')) { $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET anidbid = NULL WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET anidbid = NULL WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting Anime Releases: '.$consoletools->percentString(++$concount, $total)); } } @@ -250,7 +250,7 @@ if (isset($argv[1]) && ($argv[1] === 'anime' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'books' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE bookinfo'); + $pdo->exec('TRUNCATE TABLE bookinfo'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all Book postprocessing'); @@ -260,12 +260,12 @@ if (isset($argv[1]) && ($argv[1] === 'books' || $argv[1] === 'all')) { $where = ' WHERE bookinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::BOOKS_ROOT.' AND '.Category::BOOKS_UNKNOWN; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); $total = $qry->rowCount(); $concount = 0; if ($qry instanceof \Traversable) { foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET bookinfo_id = NULL WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET bookinfo_id = NULL WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting Book Releases: '.$consoletools->percentString(++$concount, $total)); } } @@ -274,7 +274,7 @@ if (isset($argv[1]) && ($argv[1] === 'books' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'xxx' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE xxxinfo'); + $pdo->exec('TRUNCATE TABLE xxxinfo'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all XXX postprocessing'); @@ -284,12 +284,12 @@ if (isset($argv[1]) && ($argv[1] === 'xxx' || $argv[1] === 'all')) { $where = ' WHERE xxxinfo_id IN (-2, 0) AND categories_id BETWEEN '.Category::XXX_ROOT.' AND '.Category::XXX_X264; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); $concount = 0; if ($qry instanceof \Traversable) { $total = $qry->rowCount(); foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET xxxinfo_id = 0 WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET xxxinfo_id = 0 WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting XXX Releases: '.$consoletools->percentString( ++$concount, $total @@ -301,7 +301,7 @@ if (isset($argv[1]) && ($argv[1] === 'xxx' || $argv[1] === 'all')) { if (isset($argv[1]) && ($argv[1] === 'nfos' || $argv[1] === 'all')) { $ran = true; if (isset($argv[3]) && $argv[3] === 'truncate') { - $pdo->queryExec('TRUNCATE TABLE release_nfos'); + $pdo->exec('TRUNCATE TABLE release_nfos'); } if (isset($argv[2]) && $argv[2] === 'true') { echo ColorCLI::header('Resetting all NFO postprocessing'); @@ -311,12 +311,12 @@ if (isset($argv[1]) && ($argv[1] === 'nfos' || $argv[1] === 'all')) { $where = ' WHERE nfostatus < -1'; } - $qry = $pdo->queryDirect('SELECT id FROM releases'.$where); + $qry = $pdo->query('SELECT id FROM releases'.$where); $concount = 0; if ($qry instanceof \Traversable) { $total = $qry->rowCount(); foreach ($qry as $releases) { - $pdo->queryExec('UPDATE releases SET nfostatus = -1 WHERE id = '.$releases['id']); + $pdo->exec('UPDATE releases SET nfostatus = -1 WHERE id = '.$releases['id']); $consoletools->overWritePrimary('Resetting NFO Releases: '.$consoletools->percentString(++$concount, $total)); } } diff --git a/misc/testing/DB/show_table_sizes.php b/misc/testing/DB/show_table_sizes.php deleted file mode 100644 index efb074802..000000000 --- a/misc/testing/DB/show_table_sizes.php +++ /dev/null @@ -1,93 +0,0 @@ -log->error("\nThis script will show table data, index and free space used. The argument needed is numeric.\n\n" - ."php $argv[0] 1 ...: To show all tables with data + index space used greater than 1MB or free space greater than 1MB.\n" - ."php $argv[0] .01 ...: To show all tables with data + index space used greater than .01MB or free space greater than .01MB.\n")); -} -passthru('clear'); -$data = $index = $total = $free = 0; - -$table_data = "SELECT TABLE_NAME AS 'Table', TABLE_ROWS AS 'Rows', " - ."ENGINE AS 'engine', " - ."CREATE_OPTIONS AS 'format', " - ."((DATA_LENGTH) / POWER(1024,2)) AS 'data', " - ."((INDEX_LENGTH) / POWER(1024,2)) AS 'index', " - ."((DATA_FREE) / POWER(1024,2)) AS 'free', " - ."((DATA_LENGTH + INDEX_LENGTH) / POWER(1024,2)) AS 'total' " - ."FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema = '".env('DB_NAME')."' " - .'ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC'; - -$run = $pdo->queryDirect($table_data); - -$mask = $pdo->log->headerOver('%-25.25s ').$pdo->log->primaryOver("%7.7s %10.10s %15.15s %15.15s %15.15s %15.15s\n"); -printf($mask, 'Table Name', 'Engine', 'Row_Format', 'Data Size', 'Index Size', 'Free Space', 'Total Size'); -printf($mask, '=========================', '=======', '==========', '===============', '===============', '===============', '==============='); -if ($run instanceof \Traversable) { - foreach ($run as $table) { - if ($table['total'] > $argv[1] || $table['free'] > $argv[1]) { - printf($mask, $table['table'], $table['engine'], str_replace('row_format=', '', $table['format']), number_format($table['data'], 2).' MB', number_format($table['index'], 2).' MB', number_format($table['free'], 2).' MB', number_format($table['total'], 2).' MB'); - } - $data += $table['data']; - $index += $table['index']; - $free += $table['free']; - $total += $table['total']; - } -} -printf($mask, '=========================', '=======', '==========', '===============', '===============', '===============', '==============='); -printf($mask, 'Table Name', 'Engine', 'Row_Format', 'Data Size', 'Index Size', 'Free Space', 'Total Size'); -printf($mask, '', '', '', number_format($data, 2).' MB', number_format($index, 2).' MB', number_format($free, 2).' MB', number_format($total, 2).' MB'); - -$myisam = $pdo->queryOneRow('SELECT CONCAT(ROUND(KBS/POWER(1024,IF(pw<0,0,IF(pw>3,0,pw)))+0.49999), ' - ."SUBSTR(' KMG',IF(pw<0,0,IF(pw>3,0,pw))+1,1)) recommended_key_buffer_size " - .'FROM (SELECT SUM(index_length) KBS ' - .'FROM information_schema.tables ' - ."WHERE engine='MyISAM' AND table_schema NOT IN ('information_schema','mysql')) A, (SELECT 3 pw) B;", false); - -$innodb = $pdo->queryOneRow('SELECT CONCAT(ROUND(KBS/POWER(1024,IF(pw<0,0,IF(pw>3,0,pw)))+0.49999), ' - ."SUBSTR(' KMG',IF(pw<0,0,IF(pw>3,0,pw))+1,1)) recommended_innodb_buffer_pool_size " - .'FROM (SELECT SUM(index_length) KBS ' - .'FROM information_schema.tables ' - ."WHERE engine='InnoDB') A,(SELECT 3 pw) B;", false); - -$a = $myisam['recommended_key_buffer_size']; -if ($myisam['recommended_key_buffer_size'] === null) { - $a = '12M'; -} -$b = $innodb['recommended_innodb_buffer_pool_size']; -if ($innodb['recommended_innodb_buffer_pool_size'] === null) { - $b = '12M'; -} - -// Get current variables -$aa = $pdo->queryOneRow("SHOW VARIABLES WHERE Variable_name = 'key_buffer_size'", false); -$bb = $pdo->queryOneRow("SHOW VARIABLES WHERE Variable_name = 'innodb_buffer_pool_size'", false); - -if ($aa['value'] >= 1073741824) { - $current_a = $aa['value'] / 1024 / 1024 / 1024; - $current_a .= 'G'; -} else { - $current_a = $aa['value'] / 1024 / 1024; - $current_a .= 'M'; -} -if ($bb['value'] >= 1073741824) { - $current_b = $bb['value'] / 1024 / 1024 / 1024; - $current_b .= 'G'; -} else { - $current_b = $bb['value'] / 1024 / 1024; - $current_b .= 'M'; -} - -echo $pdo->log->headerOver("\n\nThe recommended minimums are:\n"); -echo $pdo->log->primaryOver('MyISAM: key-buffer-size = ').$pdo->log->alternate($a); -echo $pdo->log->primaryOver('InnoDB: innodb_buffer_pool_size = ').$pdo->log->alternate($b); - -echo $pdo->log->headerOver("\nYour current setting are:\n"); -echo $pdo->log->primaryOver('MyISAM: key-buffer-size = ').$pdo->log->alternate($current_a); -echo $pdo->log->primaryOver('InnoDB: innodb_buffer_pool_size = ').$pdo->log->alternate($current_b); diff --git a/misc/testing/NZB/nzb-reorg.php b/misc/testing/NZB/nzb-reorg.php index 015ff3fb0..b19223c08 100755 --- a/misc/testing/NZB/nzb-reorg.php +++ b/misc/testing/NZB/nzb-reorg.php @@ -3,14 +3,14 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use Blacklight\NZB; -use Blacklight\db\DB; use Blacklight\ConsoleTools; +use Illuminate\Support\Facades\DB; if (! isset($argv[1]) || ! isset($argv[2])) { exit("ERROR: You must supply the level you want to reorganize it to, and the source directory (You would use: 3 .../newznab/resources/nzb/ to move it to 3 levels deep)\n"); } -$pdo = new DB(); +$pdo = DB::connection()->getPdo(); $nzb = new NZB(); $consoleTools = new ConsoleTools(); @@ -44,8 +44,7 @@ foreach ($objects as $filestoprocess => $nzbFile) { } } -$pdo->ping(true); -$pdo->queryExec(sprintf("UPDATE settings SET value = %s WHERE setting = 'nzbsplitlevel'", $argv[1])); +$pdo->exec(sprintf("UPDATE settings SET value = %s WHERE setting = 'nzbsplitlevel'", $argv[1])); $consoleTools->overWrite("Processed $iFilesProcessed nzbs in ".relativeTime($time)."\n"); function relativeTime($_time) @@ -65,7 +64,7 @@ function relativeTime($_time) $secondsLeft = $diff; for ($i = 4; $i > -1; $i--) { - $w[$i] = intval($secondsLeft / $d[$i][0]); + $w[$i] = (int) ($secondsLeft / $d[$i][0]); $secondsLeft -= ($w[$i] * $d[$i][0]); if ($w[$i] != 0) { $return .= $w[$i].' '.$d[$i][1].(($w[$i] > 1) ? 's' : '').' '; diff --git a/misc/testing/PostProc/check_covers.php b/misc/testing/PostProc/check_covers.php index 832f86524..03da542e6 100644 --- a/misc/testing/PostProc/check_covers.php +++ b/misc/testing/PostProc/check_covers.php @@ -5,17 +5,18 @@ // -------------------------------------------------------------- require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; -use Blacklight\db\DB; +use App\Models\Settings; use Blacklight\Movie; use Blacklight\ColorCLI; use Blacklight\utility\Utility; +use Illuminate\Support\Facades\DB; -$pdo = new DB(); -$movie = new Movie(['Echo' => true, 'Settings' => $pdo]); +$pdo = DB::connection()->getPdo(); +$movie = new Movie(['Echo' => true]); -$row = $pdo->queryOneRow("SELECT value FROM settings WHERE setting = 'coverspath'"); -if ($row !== false) { - Utility::setCoversConstant($row['value']); +$row = Settings::settingValue('site.main.coverspath'); +if ($row !== null) { + Utility::setCoversConstant($row); } else { die('Unable to determine covers path!'.PHP_EOL); } @@ -29,7 +30,7 @@ if (isset($argv[1]) && ($argv[1] === 'true' || $argv[1] === 'check')) { $limit = $argv[2]; } echo ColorCLI::header('Scanning for releases missing covers'); - $res = $pdo->queryDirect('SELECT r.id, r.imdbid + $res = $pdo->query('SELECT r.id, r.imdbid FROM releases r LEFT JOIN movieinfo m ON m.imdbid = r.imdbid WHERE nzbstatus = 1 AND m.cover = 1 AND adddate > (NOW() - INTERVAL 5 HOUR)'); @@ -42,7 +43,7 @@ if (isset($argv[1]) && ($argv[1] === 'true' || $argv[1] === 'check')) { if ($argv[1] === 'true') { $cover = $movie->updateMovieInfo($row['imdbid']); if ($cover === false || ! file_exists($nzbpath)) { - $pdo->queryExec('UPDATE movieinfo m SET m.cover = 0 WHERE m.imdbid = %d', $row['imdbid']); + $pdo->exec('UPDATE movieinfo m SET m.cover = 0 WHERE m.imdbid = %d', $row['imdbid']); } } } diff --git a/misc/testing/PostProc/check_previews.php b/misc/testing/PostProc/check_previews.php index 035829b1a..a93551025 100644 --- a/misc/testing/PostProc/check_previews.php +++ b/misc/testing/PostProc/check_previews.php @@ -5,18 +5,20 @@ // -------------------------------------------------------------- require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; +use App\Models\Settings; +use Blacklight\ColorCLI; use Blacklight\NZB; -use Blacklight\db\DB; use Blacklight\Releases; use Blacklight\ConsoleTools; use Blacklight\ReleaseImage; use Blacklight\utility\Utility; +use Illuminate\Support\Facades\DB; -$pdo = new DB(); +$pdo = DB::connection()->getPdo(); -$row = $pdo->queryOneRow("SELECT value FROM settings WHERE setting = 'coverspath'"); -if ($row !== false) { - Utility::setCoversConstant($row['value']); +$row = Settings::settingValue('site.main.coverspath'); +if ($row !== null) { + Utility::setCoversConstant($row); } else { die("Unable to determine covers path!\n"); } @@ -24,7 +26,7 @@ if ($row !== false) { $path2preview = NN_COVERS.'preview'.DS; if (isset($argv[1]) && ($argv[1] === 'true' || $argv[1] === 'check')) { - $releases = new Releases(['Settings' => $pdo]); + $releases = new Releases(); $nzb = new NZB(); $releaseImage = new ReleaseImage(); $consoletools = new ConsoleTools(); @@ -33,16 +35,16 @@ if (isset($argv[1]) && ($argv[1] === 'true' || $argv[1] === 'check')) { if (isset($argv[2]) && is_numeric($argv[2])) { $limit = $argv[2]; } - echo $pdo->log->header('Scanning for releases missing previews'); - $res = $pdo->queryDirect('SELECT id, guid FROM releases where nzbstatus = 1 AND haspreview = 1'); + echo ColorCLI::header('Scanning for releases missing previews'); + $res = $pdo->query('SELECT id, guid FROM releases where nzbstatus = 1 AND haspreview = 1'); if ($res instanceof \Traversable) { foreach ($res as $row) { $nzbpath = $path2preview.$row['guid'].'_thumb.jpg'; if (! file_exists($nzbpath)) { $counterfixed++; - echo $pdo->log->warning('Missing preview '.$nzbpath); + echo ColorCLI::warning('Missing preview '.$nzbpath); if ($argv[1] === 'true') { - $pdo->queryExec( + $pdo->exec( sprintf('UPDATE releases SET consoleinfo_id = NULL, gamesinfo_id = 0, imdbid = NULL, musicinfo_id = NULL, bookinfo_id = NULL, videos_id = 0, xxxinfo_id = 0, passwordstatus = -1, haspreview = -1, jpgstatus = 0, videostatus = 0, audiostatus = 0, nfostatus = -1 WHERE id = %s', $row['id']) ); } @@ -50,12 +52,12 @@ if (isset($argv[1]) && ($argv[1] === 'true' || $argv[1] === 'check')) { if (($limit > 0) && ($counterfixed >= $limit)) { break; - } // QUAD! + } } } - echo $pdo->log->header('Total releases missing previews that '.$couldbe.'reset for reprocessing= '.number_format($counterfixed)); + echo ColorCLI::header('Total releases missing previews that '.$couldbe.'reset for reprocessing= '.number_format($counterfixed)); } else { - exit($pdo->log->header("\nThis script checks if release previews actually exist on disk.\n\n" + exit(ColorCLI::header("\nThis script checks if release previews actually exist on disk.\n\n" ."Releases without previews may be reset for post-processing, thus regenerating them and related meta data.\n\n" ."Useful for recovery after filesystem corruption, or as an alternative re-postprocessing tool.\n\n" ."Optional LIMIT parameter restricts number of releases to be reset.\n\n" diff --git a/misc/testing/PostProc/getConsole.php b/misc/testing/PostProc/getConsole.php index cef00b9a9..04f7e651c 100644 --- a/misc/testing/PostProc/getConsole.php +++ b/misc/testing/PostProc/getConsole.php @@ -4,14 +4,15 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; -use Blacklight\db\DB; +use Blacklight\ColorCLI; use Blacklight\Console; use App\Models\Category; +use Illuminate\Support\Facades\DB; -$pdo = new DB(); -$console = new Console(['Echo' => true, 'Settings' => $pdo]); +$pdo = DB::connection()->getPdo(); +$console = new Console(['Echo' => true]); -$res = $pdo->queryDirect( +$res = $pdo->query( sprintf( 'SELECT searchname, id FROM releases WHERE consoleinfo_id IS NULL AND categories_id BETWEEN %s AND %s ORDER BY id DESC', @@ -20,7 +21,7 @@ $res = $pdo->queryDirect( ) ); if ($res instanceof \Traversable) { - echo $pdo->log->header('Updating console info for '.number_format($res->rowCount()).' releases.'); + echo ColorCLI::header('Updating console info for '.number_format($res->rowCount()).' releases.'); foreach ($res as $arr) { $starttime = microtime(true); @@ -28,14 +29,14 @@ if ($res instanceof \Traversable) { if ($gameInfo !== false) { $game = $console->updateConsoleInfo($gameInfo); if ($game === false) { - echo $pdo->log->primary($gameInfo['release'].' not found'); + echo ColorCLI::primary($gameInfo['release'].' not found'); } } // amazon limits are 1 per 1 sec $diff = floor((microtime(true) - $starttime) * 1000000); if (1000000 - $diff > 0) { - echo $pdo->log->alternate('Sleeping'); + echo ColorCLI::alternate('Sleeping'); usleep(1000000 - $diff); } } diff --git a/misc/testing/PostProc/getGameCovers.php b/misc/testing/PostProc/getGameCovers.php index a326628bf..da4e4a8ea 100644 --- a/misc/testing/PostProc/getGameCovers.php +++ b/misc/testing/PostProc/getGameCovers.php @@ -4,17 +4,16 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; -use Blacklight\db\DB; use Blacklight\Games; use Blacklight\ColorCLI; -$pdo = new DB(); -$game = new Games(['Echo' => true, 'Settings' => $pdo]); +$pdo = DB::connection()->getPdo(); +$game = new Games(['Echo' => true]); $res = $pdo->query( sprintf('SELECT id, title FROM gamesinfo WHERE cover = 0 ORDER BY id DESC LIMIT 100') ); -$total = count($res); +$total = $res->rowCount(); if ($total > 0) { echo ColorCLI::header('Updating game covers for '.number_format($total).' releases.'); @@ -28,7 +27,7 @@ if ($total > 0) { echo ColorCLI::primary($gameInfo['release'].' not found'); } else { if (file_exists(NN_COVERS.'games'.DS.$gameData.'.jpg')) { - $pdo->queryExec(sprintf('UPDATE gamesinfo SET cover = 1 WHERE id = %d', $arr['id'])); + $pdo->exec(sprintf('UPDATE gamesinfo SET cover = 1 WHERE id = %d', $arr['id'])); } } } diff --git a/misc/testing/PostProc/getImdb.php b/misc/testing/PostProc/getImdb.php index c32c205c8..79157135c 100644 --- a/misc/testing/PostProc/getImdb.php +++ b/misc/testing/PostProc/getImdb.php @@ -3,14 +3,14 @@ //This script will update all records in the movieinfo table require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; -use Blacklight\db\DB; use Blacklight\Movie; use Blacklight\ColorCLI; +use Illuminate\Support\Facades\DB; -$pdo = new DB(); -$movie = new Movie(['Echo' => true, 'Settings' => $pdo]); +$pdo = DB::connection()->getPdo(); +$movie = new Movie(['Echo' => true]); -$movies = $pdo->queryDirect('SELECT imdbid FROM movieinfo WHERE tmdbid = 0 ORDER BY id ASC'); +$movies = $pdo->query('SELECT imdbid FROM movieinfo WHERE tmdbid = 0 ORDER BY id ASC'); if ($movies instanceof \Traversable) { $count = $movies->rowCount(); if ($count > 0) { diff --git a/misc/testing/PostProc/getXXXCovers.php b/misc/testing/PostProc/getXXXCovers.php index 35d705042..eefbbb421 100644 --- a/misc/testing/PostProc/getXXXCovers.php +++ b/misc/testing/PostProc/getXXXCovers.php @@ -4,19 +4,17 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use Blacklight\XXX; -use Blacklight\db\DB; use Blacklight\ColorCLI; -$pdo = new DB(); $movie = new XXX(); $c = new ColorCLI(); -$movies = $pdo->queryDirect('SELECT title FROM xxxinfo WHERE cover = 0'); -if ($movies instanceof Traversable) { - echo $c->primary('Updating '.number_format($movies->rowCount()).' XXX movie covers.'); +$movies = DB::select('SELECT title FROM xxxinfo WHERE cover = 0'); + + echo $c->primary('Updating '.number_format(\count($movies)).' XXX movie covers.'); foreach ($movies as $mov) { $starttime = microtime(true); - $mov = $movie->updateXXXInfo($mov['title']); + $mov = $movie->updateXXXInfo($mov->title); // sleep so that it's not ddos' the site $diff = floor((microtime(true) - $starttime) * 1000000); @@ -26,4 +24,3 @@ if ($movies instanceof Traversable) { } } echo "\n"; -} diff --git a/misc/testing/Releases/fixReleaseNames.php b/misc/testing/Releases/fixReleaseNames.php index 1ae4becae..ad9b1d848 100755 --- a/misc/testing/Releases/fixReleaseNames.php +++ b/misc/testing/Releases/fixReleaseNames.php @@ -10,13 +10,11 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; use Blacklight\NNTP; -use Blacklight\db\DB; use App\Models\Settings; use Blacklight\ColorCLI; use Blacklight\NameFixer; -$pdo = new DB(); -$namefixer = new NameFixer(['Settings' => $pdo]); +$namefixer = new NameFixer(); if (isset($argv[1], $argv[2], $argv[3], $argv[4])) { $update = $argv[2] === 'true'; @@ -32,7 +30,7 @@ if (isset($argv[1], $argv[2], $argv[3], $argv[4])) { $nntp = null; if ($argv[1] === 7 || $argv[1] === 8) { - $nntp = new NNTP(['Settings' => $pdo]); + $nntp = new NNTP(); if ((Settings::settingValue('..alternate_nntp') === 1 ? $nntp->doConnect(true, true) : $nntp->doConnect()) !== true) { echo ColorCLI::error('Unable to connect to usenet.'.PHP_EOL); diff --git a/misc/testing/Releases/recategorize.php b/misc/testing/Releases/recategorize.php index 092242070..d69fd75c8 100644 --- a/misc/testing/Releases/recategorize.php +++ b/misc/testing/Releases/recategorize.php @@ -2,13 +2,12 @@ require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php'; -use Blacklight\db\DB; use App\Models\Category; use Blacklight\ColorCLI; use Blacklight\Categorize; use Blacklight\ConsoleTools; +use Illuminate\Support\Facades\DB; -$pdo = new DB(); if (! (isset($argv[1]) && ($argv[1] === 'all' || $argv[1] === 'misc' || preg_match('/\([\d, ]+\)/', $argv[1]) || is_numeric($argv[1])))) { exit(ColorCLI::error( @@ -27,7 +26,6 @@ reCategorize($argv); function reCategorize($argv) { - global $pdo; $where = ''; $othercats = implode(',', Category::OTHERS_GROUP); $update = true; @@ -69,20 +67,19 @@ function reCategorize($argv) // Returns the quantity of categorized releases. function categorizeRelease($where, $update = true, $echooutput = false) { - global $pdo; - $cat = new Categorize(['Settings' => $pdo]); - $pdo->log = new ColorCLI(); + + $cat = new Categorize(); $consoletools = new ConsoleTools(); $relcount = $chgcount = 0; echo ColorCLI::primary('SELECT id, searchname, fromname, groups_id, categories_id FROM releases '.$where); - $resrel = $pdo->queryDirect('SELECT id, searchname, fromname, groups_id, categories_id FROM releases '.$where); - $total = $resrel->rowCount(); + $resrel = DB::select('SELECT id, searchname, fromname, groups_id, categories_id FROM releases '.$where); + $total = \count($resrel); if ($total > 0) { foreach ($resrel as $rowrel) { - $catId = $cat->determineCategory($rowrel['groups_id'], $rowrel['searchname'], $rowrel['fromname']); - if ((int) $rowrel['categories_id'] !== $catId) { + $catId = $cat->determineCategory($rowrel->groups_id, $rowrel->searchname, $rowrel->fromname); + if ((int) $rowrel->categories_id !== $catId) { if ($update === true) { - $pdo->queryExec( + DB::update( sprintf( ' UPDATE releases @@ -99,7 +96,7 @@ function categorizeRelease($where, $update = true, $echooutput = false) categories_id = %d WHERE id = %d', $catId, - $rowrel['id'] + $rowrel->id ) ); } diff --git a/misc/testing/Tests/test_giantbomb_API.php b/misc/testing/Tests/test_giantbomb_API.php deleted file mode 100755 index 2157d3556..000000000 --- a/misc/testing/Tests/test_giantbomb_API.php +++ /dev/null @@ -1,45 +0,0 @@ -getSetting('giantbombkey'); -$cli = new ColorCLI(); -$obj = new GiantBomb($giantbombkey, $resp = 'json'); - -$searchgame = 'South Park The Stick of Truth'; -$resultsfound = 0; - -$e = null; -try { - $fields = [ - 'deck', 'description', 'original_game_rating', 'api_detail_url', 'image', 'genres', 'name', - 'platforms', 'publishers', 'original_release_date', 'reviews', 'site_detail_url', - ]; - $result = $obj->search($searchgame, $fields, 1); - $result = json_decode(json_encode($result), true); - if ($result['number_of_total_results'] != 0) { - $resultsfound = count($result['results']); - for ($i = 0; $i <= $resultsfound; $i++) { - similar_text($result['results'][$i]['name'], $searchgame, $p); - if ($p > 90) { - $result = $result['results'][$i]; - break; - } - } - } -} catch (\Exception $e) { - $result = false; -} - -if ($result !== false && ! empty($result)) { - print_r($result); - exit($cli->header("\nLooks like it is working alright.")); -} else { - print_r($e); - exit($cli->error("\nThere was a problem attempting to query giantbomb. Maybe your key is wrong, or you are being throttled.\n")); -}