Beispiel #1
0
 /**
  * Delete releases from the database.
  */
 protected function deleteReleases()
 {
     $deletedCount = 0;
     foreach ($this->result as $release) {
         if ($this->delete) {
             $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
             if ($this->echoCLI) {
                 echo $this->pdo->log->primary('Deleting: ' . $this->method . ': ' . $release['searchname']);
             }
         } elseif ($this->echoCLI) {
             echo $this->pdo->log->primary('Would be deleting: ' . $this->method . ': ' . $release['searchname']);
         }
         $deletedCount++;
     }
     $this->deletedCount += $deletedCount;
     return true;
 }
Beispiel #2
0
} else {
    $query = sprintf('SELECT max(id) AS id, id AS idx, guid FROM releases GROUP BY name, fromname, group_id,' . $size . 'HAVING COUNT(*) > 1');
}
do {
    $resrel = $pdo->queryDirect($query);
    if ($resrel instanceof \Traversable) {
        $total = $resrel->rowCount();
        echo $pdo->log->header(number_format($total) . " Releases have Duplicates");
        foreach ($resrel as $rowrel) {
            $nzbpath = $nzb->getNZBPath($rowrel['guid']);
            if (isset($argv[3]) && is_dir($argv[3])) {
                $path = $argv[3];
                if (substr($path, strlen($path) - 1) != '/') {
                    $path = $path . "/";
                }
                if (!file_exists($path . $rowrel['guid'] . ".nzb.gz") && file_exists($nzbpath)) {
                    if (@copy($nzbpath, $path . $rowrel['guid'] . ".nzb.gz") !== true) {
                        exit("\n" . $pdo->log->error("\nUnable to write " . $path . $rowrel['guid'] . ".nzb.gz"));
                    }
                }
            }
            if ($releases->deleteSingle(['g' => $rowrel['guid'], 'i' => $rowrel['idx']], $nzb, $ri) !== false) {
                $consoleTools->overWritePrimary('Deleted: ' . number_format(++$count) . " Duplicate Releases");
            }
        }
    }
    $all += $count;
    $count = 0;
    echo "\n\n";
} while ($total > 0);
echo $pdo->log->header("\nDeleted " . number_format($all) . " Duplicate Releases");
Beispiel #3
0
 /**
  * Purge a single group or all groups.
  *
  * @param int|string|bool $id The group ID. If false, purge all groups.
  */
 public function purge($id = false)
 {
     if ($id === false) {
         $this->resetall();
     } else {
         $this->reset($id);
     }
     $releaseArray = $this->pdo->queryDirect(sprintf("SELECT id, guid FROM releases %s", $id === false ? '' : 'WHERE group_id = ' . $id));
     if ($releaseArray instanceof \Traversable) {
         $releases = new Releases(['Settings' => $this->pdo, 'Groups' => $this]);
         $nzb = new NZB($this->pdo);
         $releaseImage = new ReleaseImage($this->pdo);
         foreach ($releaseArray as $release) {
             $releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $nzb, $releaseImage);
         }
     }
 }
Beispiel #4
0
 $couldbe = $argv[1] === "true" ? $couldbe = "could be " : "were ";
 echo $pdo->log->header('Getting List of nzbs to check against db.');
 $dirItr = new \RecursiveDirectoryIterator($pdo->getSetting('nzbpath'));
 $itr = new \RecursiveIteratorIterator($dirItr, \RecursiveIteratorIterator::LEAVES_ONLY);
 foreach ($itr as $filePath) {
     if (is_file($filePath) && preg_match('/([a-f-0-9]+)\\.nzb\\.gz/', $filePath, $guid)) {
         $nzbfile = Utility::unzipGzipFile($filePath);
         if ($nzbfile) {
             $nzbfile = @simplexml_load_string($nzbfile);
         }
         if ($nzbfile) {
             $res = $pdo->queryOneRow(sprintf("SELECT id, guid FROM releases WHERE guid = %s", $pdo->escapeString(stristr($filePath->getFilename(), '.nzb.gz', true))));
             if ($res === false) {
                 if ($argv[1] === "delete") {
                     @copy($filePath, nZEDb_ROOT . "pooped/" . $guid[1] . ".nzb.gz");
                     $releases->deleteSingle(['g' => $guid[1], 'i' => false], $nzb, $releaseImage);
                     $deleted++;
                 }
             } else {
                 if (isset($res)) {
                     $pdo->queryExec(sprintf("UPDATE releases SET nzbstatus = 1 WHERE id = %s", $res['id']));
                 }
             }
         } else {
             if ($argv[1] === "delete") {
                 @copy($filePath, nZEDb_ROOT . "pooped/" . $guid[1] . ".nzb.gz");
                 unlink($filePath);
                 $deleted++;
             }
         }
         $time = $consoletools->convertTime(time() - $timestart);
Beispiel #5
0
function create_guids($live, $delete = false)
{
    $pdo = new Settings();
    $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
    $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"));
    } else {
        if ($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($pdo);
        $releaseImage = new ReleaseImage($pdo);
        $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 = array();
                    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 = " . $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."));
    }
}
Beispiel #6
0
    /**
     * Delete releases using admin settings.
     * This deletes releases, regardless of group.
     *
     * @void
     * @access public
     */
    public function deleteReleases()
    {
        $startTime = time();
        $category = new Category(['Settings' => $this->pdo]);
        $genres = new Genres(['Settings' => $this->pdo]);
        $passwordDeleted = $duplicateDeleted = $retentionDeleted = $completionDeleted = $disabledCategoryDeleted = 0;
        $disabledGenreDeleted = $miscRetentionDeleted = $miscHashedDeleted = $categoryMinSizeDeleted = 0;
        // Delete old releases and finished collections.
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Delete old releases and passworded releases."));
        }
        // Releases past retention.
        if ($this->pdo->getSetting('releaseretentiondays') != 0) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE postdate < (NOW() - INTERVAL %d DAY)', $this->pdo->getSetting('releaseretentiondays')));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $retentionDeleted++;
                }
            }
        }
        // Passworded releases.
        if ($this->pdo->getSetting('deletepasswordedrelease') == 1) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE passwordstatus = %d', Releases::PASSWD_RAR));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $passwordDeleted++;
                }
            }
        }
        // Possibly passworded releases.
        if ($this->pdo->getSetting('deletepossiblerelease') == 1) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE passwordstatus = %d', Releases::PASSWD_POTENTIAL));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $passwordDeleted++;
                }
            }
        }
        if ($this->crossPostTime != 0) {
            // Crossposted releases.
            do {
                $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE adddate > (NOW() - INTERVAL %d HOUR) GROUP BY name HAVING COUNT(name) > 1', $this->crossPostTime));
                $total = 0;
                if ($releases && $releases->rowCount()) {
                    $total = $releases->rowCount();
                    foreach ($releases as $release) {
                        $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                        $duplicateDeleted++;
                    }
                }
            } while ($total > 0);
        }
        if ($this->completion > 0) {
            $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE completion < %d AND completion > 0', $this->completion));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $completionDeleted++;
                }
            }
        }
        // Disabled categories.
        $disabledCategories = $category->getDisabledIDs();
        if (count($disabledCategories) > 0) {
            foreach ($disabledCategories as $disabledCategory) {
                $releases = $this->pdo->queryDirect(sprintf('SELECT SQL_NO_CACHE id, guid FROM releases WHERE categoryid = %d', $disabledCategory['id']));
                if ($releases instanceof \Traversable) {
                    foreach ($releases as $release) {
                        $disabledCategoryDeleted++;
                        $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    }
                }
            }
        }
        // Delete smaller than category minimum sizes.
        $categories = $this->pdo->queryDirect('
			SELECT SQL_NO_CACHE c.id AS id,
			CASE WHEN c.minsize = 0 THEN cp.minsize ELSE c.minsize END AS minsize
			FROM category c
			INNER JOIN category cp ON cp.id = c.parentid
			WHERE c.parentid IS NOT NULL');
        if ($categories instanceof \Traversable) {
            foreach ($categories as $category) {
                if ($category['minsize'] > 0) {
                    $releases = $this->pdo->queryDirect(sprintf('
							SELECT SQL_NO_CACHE r.id, r.guid
							FROM releases r
							WHERE r.categoryid = %d
							AND r.size < %d LIMIT 1000', $category['id'], $category['minsize']));
                    if ($releases instanceof \Traversable) {
                        foreach ($releases as $release) {
                            $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                            $categoryMinSizeDeleted++;
                        }
                    }
                }
            }
        }
        // Disabled music genres.
        $genrelist = $genres->getDisabledIDs();
        if (count($genrelist) > 0) {
            foreach ($genrelist as $genre) {
                $releases = $this->pdo->queryDirect(sprintf('
						SELECT SQL_NO_CACHE id, guid
						FROM releases
						INNER JOIN (SELECT id AS mid FROM musicinfo WHERE musicinfo.genre_id = %d) mi
						ON musicinfoid = mid', $genre['id']));
                if ($releases instanceof \Traversable) {
                    foreach ($releases as $release) {
                        $disabledGenreDeleted++;
                        $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    }
                }
            }
        }
        // Misc other.
        if ($this->pdo->getSetting('miscotherretentionhours') > 0) {
            $releases = $this->pdo->queryDirect(sprintf('
					SELECT SQL_NO_CACHE id, guid
					FROM releases
					WHERE categoryid = %d
					AND adddate <= NOW() - INTERVAL %d HOUR', Category::CAT_OTHER_MISC, $this->pdo->getSetting('miscotherretentionhours')));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $miscRetentionDeleted++;
                }
            }
        }
        // Misc hashed.
        if ($this->pdo->getSetting('mischashedretentionhours') > 0) {
            $releases = $this->pdo->queryDirect(sprintf('
					SELECT SQL_NO_CACHE id, guid
					FROM releases
					WHERE categoryid = %d
					AND adddate <= NOW() - INTERVAL %d HOUR', Category::CAT_OTHER_HASHED, $this->pdo->getSetting('mischashedretentionhours')));
            if ($releases instanceof \Traversable) {
                foreach ($releases as $release) {
                    $this->releases->deleteSingle(['g' => $release['guid'], 'i' => $release['id']], $this->nzb, $this->releaseImage);
                    $miscHashedDeleted++;
                }
            }
        }
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary('Removed releases: ' . number_format($retentionDeleted) . ' past retention, ' . number_format($passwordDeleted) . ' passworded, ' . number_format($duplicateDeleted) . ' crossposted, ' . number_format($disabledCategoryDeleted) . ' from disabled categories, ' . number_format($categoryMinSizeDeleted) . ' smaller than category settings, ' . number_format($disabledGenreDeleted) . ' from disabled music genres, ' . number_format($miscRetentionDeleted) . ' from misc->other' . number_format($miscHashedDeleted) . ' from misc->hashed' . ($this->completion > 0 ? ', ' . number_format($completionDeleted) . ' under ' . $this->completion . '% completion.' : '.')));
            $totalDeleted = $retentionDeleted + $passwordDeleted + $duplicateDeleted + $disabledCategoryDeleted + $disabledGenreDeleted + $miscRetentionDeleted + $miscHashedDeleted + $completionDeleted + $categoryMinSizeDeleted;
            if ($totalDeleted > 0) {
                $this->pdo->log->doEcho($this->pdo->log->primary("Removed " . number_format($totalDeleted) . ' releases in ' . $this->consoleTools->convertTime(time() - $startTime)));
            }
        }
    }
use nzedb\Releases;
use nzedb\db\Settings;
$pdo = new Settings();
if (isset($argv[1]) && $argv[1] == "true") {
    $timestart = TIME();
    $releases = new Releases(['Settings' => $pdo]);
    $category = new Category(['Settings' => $pdo]);
    $nzb = new NZB($pdo);
    $releaseImage = new ReleaseImage($pdo);
    $catlist = $category->getDisabledIDs();
    $relsdeleted = 0;
    if (count($catlist > 0)) {
        foreach ($catlist as $cat) {
            $rels = $pdo->query(sprintf("SELECT id, guid FROM releases WHERE categoryid = %d", $cat['id']));
            if (count($rels)) {
                foreach ($rels as $rel) {
                    $relsdeleted++;
                    $releases->deleteSingle(['g' => $rel['guid'], 'i' => $rel['id']], $nzb, $releaseImage);
                }
            }
        }
    }
    $time = TIME() - $timestart;
    if ($relsdeleted > 0) {
        echo $pdo->log->header($relsdeleted . " releases deleted in " . $time . " seconds.");
    } else {
        exit($pdo->log->info("No releases to delete."));
    }
} else {
    exit($pdo->log->error("\nDeletes releases in categories you have disabled here : http://localhost/admin/category-list.php\n" . "php {$argv['0']} true    ...: run this script.\n"));
}