diff --git a/lib/copy_this/www/lib/book.php b/lib/copy_this/www/lib/book.php index b4d66aba7..ba6df909f 100644 --- a/lib/copy_this/www/lib/book.php +++ b/lib/copy_this/www/lib/book.php @@ -18,7 +18,7 @@ class Book * * @param bool $echooutput */ - public function __construct($echooutput=false) + public function __construct($echooutput = false) { $this->echooutput = $echooutput; $s = new Sites(); @@ -26,6 +26,7 @@ class Book $this->pubkey = $site->amazonpubkey; $this->privkey = $site->amazonprivkey; $this->asstag = $site->amazonassociatetag; + $this->pdo = new DB(); $this->imgSavePath = WWW_DIR.'covers/book/'; } @@ -35,8 +36,8 @@ class Book */ public function getBookInfo($id) { - $db = new DB(); - return $db->queryOneRow(sprintf("SELECT bookinfo.*, genres.title as genres FROM bookinfo left outer join genres on genres.id = bookinfo.genreID where bookinfo.id = %d ", $id)); + $query = $this->pdo->queryOneRow(sprintf("SELECT bookinfo.*, genres.title as genres FROM bookinfo left outer join genres on genres.id = bookinfo.genreID where bookinfo.id = %d ", $id)); + return $query; } /** @@ -44,8 +45,8 @@ class Book */ public function getBookInfoByName($author, $title) { - $db = new DB(); - return $db->queryOneRow(sprintf("SELECT * FROM bookinfo where author like %s and title like %s", $db->escapeString("%".$author."%"), $db->escapeString("%".$title."%"))); + $query = $this->pdo->queryOneRow(sprintf("SELECT * FROM bookinfo where author like %s and title like %s", $this->pdo->escapeString("%".$author."%"), $this->pdo->escapeString("%".$title."%"))); + return $query; } /** @@ -53,14 +54,14 @@ class Book */ public function getRange($start, $num) { - $db = new DB(); if ($start === false) $limit = ""; else $limit = " LIMIT ".$start.",".$num; - return $db->query(" SELECT * FROM bookinfo ORDER BY createddate DESC".$limit); + $query = $this->pdo->query(" SELECT * FROM bookinfo ORDER BY createddate DESC".$limit); + return $query; } /** @@ -68,8 +69,7 @@ class Book */ public function getCount() { - $db = new DB(); - $res = $db->queryOneRow("select count(id) as num from bookinfo"); + $res = $this->pdo->queryOneRow("select count(id) as num from bookinfo"); return $res["num"]; } @@ -78,8 +78,6 @@ class Book */ public function getBookCount($maxage=-1) { - $db = new DB(); - $browseby = $this->getBrowseBy(); if ($maxage > 0) @@ -89,7 +87,7 @@ class Book $sql = sprintf("select count(distinct r.bookinfoid) as num from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s", $browseby, $maxage); - $res = $db->queryOneRow($sql, true); + $res = $this->pdo->queryOneRow($sql, true); return $res["num"]; } @@ -98,8 +96,6 @@ class Book */ public function getBookRange($start, $num, $orderby, $maxage=-1) { - $db = new DB(); - $browseby = $this->getBrowseBy(); if ($start === false) @@ -113,7 +109,7 @@ class Book $order = $this->getBrowseOrder($orderby); $sql = sprintf(" SELECT r.bookinfoid, max(postdate), b.* from releases r inner join bookinfo b on b.id = r.bookinfoid and b.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') %s %s group by r.bookinfoid order by %s %s".$limit, $browseby, $maxagesql, $order[0], $order[1]); - $rows = $db->query($sql, true); + $rows = $this->pdo->query($sql, true); // //get a copy of all the bookinfoids @@ -130,8 +126,8 @@ class Book // get all releases matching these ids // $sql = sprintf("select r.*, releasenfo.id as nfoid, groups.name as grpname from releases r left outer join releasenfo on releasenfo.releaseid = r.id left outer join groups on groups.id = r.groupid where bookinfoid in (%s) %s order by r.postdate desc", $ids, $maxagesql); - $allrows = $db->query($sql, true); - $arr = array(); + $allrows = $this->pdo->query($sql, true); + $arr = []; // // build array indexed by bookinfoid @@ -228,7 +224,6 @@ class Book */ public function getBrowseBy() { - $db = new Db; $browseby = ' '; $browsebyArr = $this->getBrowseByOptions(); @@ -238,7 +233,7 @@ class Book if (preg_match('/id/i', $bbv)) { $browseby .= " and b.{$bbv} = $bbs "; } else { - $browseby .= " and b.$bbv LIKE(".$db->escapeString('%'.$bbs.'%').") "; + $browseby .= " and b.$bbv LIKE(".$this->pdo->escapeString('%'.$bbs.'%').") "; } } } @@ -252,8 +247,8 @@ class Book { $db = new DB(); - $db->queryExec(sprintf("update bookinfo SET title=%s, asin=%s, url=%s, author=%s, publisher=%s, publishdate='%s', cover=%d, updateddate=NOW() WHERE id = %d", - $db->escapeString($title), $db->escapeString($asin), $db->escapeString($url), $db->escapeString($author), $db->escapeString($publisher), $publishdate, $cover, $id)); + $this->pdo->queryExec(sprintf("update bookinfo SET title=%s, asin=%s, url=%s, author=%s, publisher=%s, publishdate='%s', cover=%d, updateddate=NOW() WHERE id = %d", + $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), $publishdate, $cover, $id)); } /** @@ -262,10 +257,8 @@ class Book */ public function updateBookInfo($author, $title) { - $db = new DB(); $ri = new ReleaseImage(); - $mus = array(); $amaz = $this->fetchAmazonProperties($author." ".$title); if (!$amaz) { @@ -277,7 +270,7 @@ class Book // // get album properties // - $item = array(); + $item = []; $item["asin"] = (string) $amaz->Items->Item->ASIN; $item["url"] = (string) $amaz->Items->Item->DetailPageURL; $item["coverurl"] = (string) $amaz->Items->Item->LargeImage->URL; @@ -369,17 +362,15 @@ class Book */ public function processBookReleases() { - $ret = 0; - $db = new DB(); $numlookedup = 0; - $res = $db->queryDirect(sprintf("SELECT searchname, id from releases where bookinfoid IS NULL and categoryid = %d ORDER BY postdate DESC LIMIT 100", Category::CAT_BOOK_EBOOK)); - if ($db->getNumRows($res) > 0) + $res = $this->pdo->queryDirect(sprintf("SELECT searchname, id from releases where bookinfoid IS NULL and categoryid = %d ORDER BY postdate DESC LIMIT 100", Category::CAT_BOOK_EBOOK)); + if ($this->pdo->getNumRows($res) > 0) { if ($this->echooutput) - echo "BookPrc : Processing " . $db->getNumRows($res) . " book releases\n"; + echo "BookPrc : Processing " . $this->pdo->getNumRows($res) . " book releases\n"; - while ($arr = $db->getAssocArray($res)) + while ($arr = $this->pdo->getAssocArray($res)) { if ($numlookedup > Book::NUMTOPROCESSPERTIME) return; @@ -411,7 +402,7 @@ class Book $bookId = $bookCheck["id"]; } } - $db->queryExec(sprintf("update releases SET bookinfoid = %d WHERE id = %d", $bookId, $arr["id"])); + $this->pdo->queryExec(sprintf("update releases SET bookinfoid = %d WHERE id = %d", $bookId, $arr["id"])); } } } @@ -421,7 +412,7 @@ class Book */ public function parseAuthor($releasename) { - $result = array(); + $result = []; $result['releasename'] = $releasename; $newName = $releasename; @@ -485,7 +476,6 @@ class Book */ public function addUpdateBookInfo($title, $asin, $url, $author, $publisher, $publishdate, $review, $cover, $dewey, $ean, $isbn, $pages) { - $db = new DB(); if ($pages == 0) $pages = "null"; @@ -495,23 +485,23 @@ class Book if ($publishdate == "") $publishdate = "null"; elseif (strlen($publishdate) == 4) - $publishdate = $db->escapeString($publishdate."-01-01"); + $publishdate = $this->pdo->escapeString($publishdate."-01-01"); elseif (strlen($publishdate) == 7) - $publishdate = $db->escapeString($publishdate."-01"); + $publishdate = $this->pdo->escapeString($publishdate."-01"); else - $publishdate = $db->escapeString($publishdate); + $publishdate = $this->pdo->escapeString($publishdate); $sql = sprintf("INSERT INTO bookinfo (title, asin, url, author, publisher, publishdate, review, cover, createddate, updateddate, dewey, ean, isbn, pages) VALUES (%s, %s, %s, %s, %s, %s, %s, %d, now(), now(), %s, %s, %s, %s) ON DUPLICATE KEY UPDATE title = %s, asin = %s, url = %s, author = %s, publisher = %s, publishdate = %s, review = %s, cover = %d, createddate = now(), updateddate = now(), dewey = %s, ean = %s, isbn = %s, pages = %s", - $db->escapeString($title), $db->escapeString($asin), $db->escapeString($url), - $db->escapeString($author), $db->escapeString($publisher), - $publishdate, $db->escapeString($review), $cover, $db->escapeString($dewey), $db->escapeString($ean), $db->escapeString($isbn), $pages, - $db->escapeString($title), $db->escapeString($asin), $db->escapeString($url), - $db->escapeString($author), $db->escapeString($publisher), - $db->escapeString($publishdate), $db->escapeString($review), $cover, $db->escapeString($dewey), $db->escapeString($ean), $db->escapeString($isbn), $pages ); + $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), + $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), + $publishdate, $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages, + $this->pdo->escapeString($title), $this->pdo->escapeString($asin), $this->pdo->escapeString($url), + $this->pdo->escapeString($author), $this->pdo->escapeString($publisher), + $this->pdo->escapeString($publishdate), $this->pdo->escapeString($review), $cover, $this->pdo->escapeString($dewey), $this->pdo->escapeString($ean), $this->pdo->escapeString($isbn), $pages ); - $bookId = $db->queryInsert($sql); + $bookId = $this->pdo->queryInsert($sql); return $bookId; } } \ No newline at end of file diff --git a/lib/copy_this/www/lib/framework/db.php b/lib/copy_this/www/lib/framework/db.php index 3d51581e6..36626ac81 100644 --- a/lib/copy_this/www/lib/framework/db.php +++ b/lib/copy_this/www/lib/framework/db.php @@ -689,20 +689,20 @@ class DB extends \PDO * Fetch a assoc row from a result set * * @param PDOStatement $result - * @return array + * @return array|PDOStatement */ - public function getAssocArray(PDOStatement $result) + public function getAssocArray($result) { - return $result->fetch(); + return $result->fetch(\PDO::FETCH_ASSOC); } /** * Get the total number of rows in the result set * * @param PDOStatement $result - * @return int + * @return int|PDOStatement */ - public function getNumRows(PDOStatement $result) + public function getNumRows($result) { return $result->rowCount(); } diff --git a/lib/copy_this/www/lib/nzbinfo.php b/lib/copy_this/www/lib/nzbinfo.php index c2d8d45f5..5a4a4100a 100644 --- a/lib/copy_this/www/lib/nzbinfo.php +++ b/lib/copy_this/www/lib/nzbinfo.php @@ -3,8 +3,8 @@ class nzbInfo { public $source = ''; - public $metadata = array(); - public $groups = array(); + public $metadata = []; + public $groups = []; public $filecount = 0; public $parcount = 0; public $rarcount = 0; @@ -24,18 +24,18 @@ class nzbInfo public $segmentactual = 0; public $gid = ''; - public $nzb = array(); - public $nfofiles = array(); - public $samplefiles = array(); - public $mediafiles = array(); - public $audiofiles = array(); - public $rarfiles = array(); - public $imgfiles = array(); - public $srrfiles = array(); - public $txtfiles = array(); - public $sfvfiles = array(); - public $segmentfiles = array(); - public $parfiles = array(); + public $nzb = []; + public $nfofiles = []; + public $samplefiles = []; + public $mediafiles = []; + public $audiofiles = []; + public $rarfiles = []; + public $imgfiles = []; + public $srrfiles = []; + public $txtfiles = []; + public $sfvfiles = []; + public $segmentfiles = []; + public $parfiles = []; private $isLoaded = false; private $loadAllVars = false; @@ -103,7 +103,7 @@ class nzbInfo public function summarize() { - $out = array(); + $out = []; $out[] = 'Reading from '.basename($this->source).'...'; if (!empty($this->nfofiles)) $out[] = ' -nfo detected'; @@ -170,16 +170,16 @@ class nzbInfo foreach($xmlObj->file as $file) { - $fileArr = array(); + $fileArr = []; $fileArr['subject'] = (string) $file->attributes()->subject; $fileArr['poster'] = (string) $file->attributes()->poster; $fileArr['posted'] = (int) $file->attributes()->date; - $fileArr['groups'] = array(); + $fileArr['groups'] = []; $fileArr['filesize'] = 0; $fileArr['segmenttotal'] = 0; $fileArr['segmentactual'] = 0; $fileArr['completion'] = 0; - $fileArr['segments'] = array(); + $fileArr['segments'] = []; //subject $subject = $fileArr['subject']; @@ -329,7 +329,7 @@ class nzbInfo if (!empty($this->metadata)) { $nzb .= "\n"; - $out = array(); + $out = []; foreach($this->metadata as $mk=>$mv) $out[] = ' '.$mv."\n"; $nzb .= "\n"; diff --git a/lib/copy_this/www/lib/releaseregex.php b/lib/copy_this/www/lib/releaseregex.php index faefe363d..3efd34dc8 100644 --- a/lib/copy_this/www/lib/releaseregex.php +++ b/lib/copy_this/www/lib/releaseregex.php @@ -15,18 +15,24 @@ class ReleaseRegex public function __construct() { $this->regexes = []; + $this->pdo = new DB(); } /** * Get all releaseregex rows matching filters. + * + * @param bool $activeonly + * @param string $groupname + * @param bool $blnIncludeReleaseCount + * @param null $userReleaseRegex + * + * @return array */ public function get($activeonly = true, $groupname = "-1", $blnIncludeReleaseCount = false, $userReleaseRegex = null) { if (!empty($this->regexes)) return $this->regexes; - $db = new DB(); - $where = ""; if ($activeonly) $where .= " and releaseregex.status = 1"; @@ -34,7 +40,7 @@ class ReleaseRegex if ($groupname == "all") $where .= " and releaseregex.groupname is null"; elseif ($groupname != "-1") - $where .= sprintf(" and releaseregex.groupname = %s", $db->escapeString($groupname)); + $where .= sprintf(" and releaseregex.groupname = %s", $this->pdo->escapeString($groupname)); if ($userReleaseRegex === true) { $where .= ' AND releaseregex.id >= 100000'; @@ -49,7 +55,7 @@ class ReleaseRegex $relcountjoin = " left outer join ( select regexid, max(adddate) adddate, count(id) as count from releases group by regexid) x on x.regexid = releaseregex.id "; } - $this->regexes = $db->query("SELECT releaseregex.id, releaseregex.categoryid, category.title as categoryTitle, releaseregex.status, releaseregex.description, releaseregex.groupname AS groupname, releaseregex.regex, + $this->regexes = $this->pdo->query("SELECT releaseregex.id, releaseregex.categoryid, category.title as categoryTitle, releaseregex.status, releaseregex.description, releaseregex.groupname AS groupname, releaseregex.regex, groups.id AS groupid, releaseregex.ordinal " . $relcountcol . " FROM releaseregex left outer JOIN groups ON groups.name = releaseregex.groupname @@ -68,8 +74,7 @@ class ReleaseRegex public function getGroupsForSelect() { - $db = new DB(); - $categories = $db->query("SELECT distinct coalesce(groupname,'all') as groupname from releaseregex order by groupname "); + $categories = $this->pdo->query("SELECT distinct coalesce(groupname,'all') as groupname from releaseregex order by groupname "); $temp_array = array(); $temp_array[-1] = "--Please Select--"; @@ -85,9 +90,8 @@ class ReleaseRegex */ public function getByID($id) { - $db = new DB(); - return $db->queryOneRow(sprintf("select * from releaseregex where id = %d ", $id)); + return $this->pdo->queryOneRow(sprintf("select * from releaseregex where id = %d ", $id)); } /** @@ -112,12 +116,15 @@ class ReleaseRegex /** * Delete a releaseregex row. + * + * @param $id + * + * @return bool|PDOStatement */ public function delete($id) { - $db = new DB(); - return $db->queryExec(sprintf("DELETE from releaseregex where id = %d", $id)); + return $this->pdo->queryExec(sprintf("DELETE from releaseregex where id = %d", $id)); } /** @@ -125,13 +132,12 @@ class ReleaseRegex */ public function update($regex) { - $db = new DB(); $groupname = $regex["groupname"]; if ($groupname == "") $groupname = "null"; else - $groupname = sprintf("%s", $db->escapeString($regex["groupname"])); + $groupname = sprintf("%s", $this->pdo->escapeString($regex["groupname"])); $catid = $regex["category"]; if ($catid == "-1") @@ -139,24 +145,27 @@ class ReleaseRegex else $catid = sprintf("%d", $regex["category"]); - $db->queryExec(sprintf("update releaseregex set groupname=%s, regex=%s, ordinal=%d, status=%d, description=%s, categoryid=%s where id = %d ", - $groupname, $db->escapeString($regex["regex"]), $regex["ordinal"], $regex["status"], $db->escapeString($regex["description"]), $catid, $regex["id"] + $this->pdo->queryExec(sprintf("update releaseregex set groupname=%s, regex=%s, ordinal=%d, status=%d, description=%s, categoryid=%s where id = %d ", + $groupname, $this->pdo->escapeString($regex["regex"]), $regex["ordinal"], $regex["status"], $this->pdo->escapeString($regex["description"]), $catid, $regex["id"] ) ); } /** * Add a releaseregex row. + * + * @param $regex + * + * @return bool|int */ public function add($regex) { - $db = new DB(); $groupname = $regex["groupname"]; if ($groupname == "") $groupname = "null"; else - $groupname = sprintf("%s", $db->escapeString($regex["groupname"])); + $groupname = sprintf("%s", $this->pdo->escapeString($regex["groupname"])); $catid = $regex["category"]; if ($catid == "-1") @@ -164,8 +173,8 @@ class ReleaseRegex else $catid = sprintf("%d", $regex["category"]); - return $db->queryInsert(sprintf("insert into releaseregex (groupname, regex, ordinal, status, description, categoryid) values (%s, %s, %d, %d, %s, %s) ", - $groupname, $db->escapeString($regex["regex"]), $regex["ordinal"], $regex["status"], $db->escapeString($regex["description"]), $catid + return $this->pdo->queryInsert(sprintf("insert into releaseregex (groupname, regex, ordinal, status, description, categoryid) values (%s, %s, %d, %d, %s, %s) ", + $groupname, $this->pdo->escapeString($regex["regex"]), $regex["ordinal"], $regex["status"], $this->pdo->escapeString($regex["description"]), $catid ) ); @@ -178,8 +187,7 @@ class ReleaseRegex $outcome = @preg_match($regexArr["regex"], $binarySubject, $matches); if ($outcome === false) { echo "ERROR: " . ($regexArr["id"] < 10000 ? "System" : "Custom") . " release regex '" . $regexArr["id"] . "' is not a valid regex.\n"; - $db = new DB(); - $db->queryExec(sprintf("update releaseregex set status=0 where id = %d and status=1", $regexArr["id"])); + $this->pdo->queryExec(sprintf("update releaseregex set status=0 where id = %d and status=1", $regexArr["id"])); return $ret; } @@ -250,7 +258,6 @@ class ReleaseRegex public function testRegex($regex, $groupname, $poster, $ignorematched, $matchagainstbins) { - $db = new Db(); $cat = new Categorize(); $s = new Sites(); $site = $s->get(); @@ -265,13 +272,13 @@ class ReleaseRegex $groupname = '.*'; if ($matchagainstbins !== '') - $sql = sprintf("select b.*, '0' as size, '0' as blacklistID, g.name as groupname from %s b left join groups g on g.id = b.groupid where b.groupid IN (select g.id from groups g where g.name REGEXP %s) order by b.date desc", $group['bname'], $db->escapeString('^' . $groupname . '$')); + $sql = sprintf("select b.*, '0' as size, '0' as blacklistID, g.name as groupname from %s b left join groups g on g.id = b.groupid where b.groupid IN (select g.id from groups g where g.name REGEXP %s) order by b.date desc", $group['bname'], $this->pdo->escapeString('^' . $groupname . '$')); else - $sql = sprintf("select rrt.* from releaseregextesting rrt where rrt.groupname REGEXP %s order by rrt.date desc", $db->escapeString('^' . $groupname . '$')); + $sql = sprintf("select rrt.* from releaseregextesting rrt where rrt.groupname REGEXP %s order by rrt.date desc", $this->pdo->escapeString('^' . $groupname . '$')); - $resbin = $db->queryDirect($sql); + $resbin = $this->pdo->queryDirect($sql); - while ($rowbin = $db->getAssocArray($resbin)) { + while ($rowbin = $this->pdo->getAssocArray($resbin)) { if ($ignorematched !== '' && ($rowbin['regexid'] != '' || $rowbin['blacklistID'] == 1)) continue; @@ -314,14 +321,13 @@ class ReleaseRegex public function fetchTestBinaries($groupname, $numarticles, $clearexistingbins) { - $db = new DB(); $nntp = new Nntp(); $binaries = new Binaries(); $groups = new Groups(); $ret = array(); if ($clearexistingbins == true) - $db->queryExec('truncate releaseregextesting'); + $this->pdo->queryExec('truncate releaseregextesting'); $nntp->doConnect(); @@ -342,7 +348,7 @@ class ReleaseRegex $group = $groupArr['name']; $data = $nntp->selectGroup($group); - if (PEAR::isError($data)) { + if (NNTP::isError($data)) { $ret[] = "Could not select group (doesnt exist on USP): {$group}"; continue; } else { @@ -363,7 +369,7 @@ class ReleaseRegex $msgs = $nntp->getXOver($rangeStart . "-" . $rangeEnd, true, false); - if (PEAR::isError($msgs)) { + if (NNTP::isError($msgs)) { $ret[] = "Error {$msgs->code}: {$msgs->message} on " . $group; continue 2; } @@ -455,11 +461,11 @@ class ReleaseRegex foreach ($binChunks as $binChunk) { foreach ($binChunk as $chunk) { - $binParams[] = sprintf("(%s, %s, FROM_UNIXTIME(%s), %s, %s, %s, %s, %s, %d, %d, now())", $db->escapeString($chunk['name']), $db->escapeString($chunk['fromname']), $db->escapeString($chunk['date']), $db->escapeString($chunk['binaryhash']), $db->escapeString($chunk['groupname']), $chunk['regexid'], $chunk['categoryid'], $chunk['reqid'], $chunk['blacklistID'], $chunk['size']); + $binParams[] = sprintf("(%s, %s, FROM_UNIXTIME(%s), %s, %s, %s, %s, %s, %d, %d, now())", $this->pdo->escapeString($chunk['name']), $this->pdo->escapeString($chunk['fromname']), $this->pdo->escapeString($chunk['date']), $this->pdo->escapeString($chunk['binaryhash']), $this->pdo->escapeString($chunk['groupname']), $chunk['regexid'], $chunk['categoryid'], $chunk['reqid'], $chunk['blacklistID'], $chunk['size']); } $binSql = "INSERT IGNORE INTO releaseregextesting (name, fromname, date, binaryhash, groupname, regexid, categoryid, reqid, blacklistID, size, dateadded) VALUES " . implode(', ', $binParams); //echo $binSql; - $db->queryExec($binSql); + $this->pdo->queryExec($binSql); } $ret[] = "Fetched " . number_format($numarticles) . " articles from " . $group; @@ -485,4 +491,4 @@ class ReleaseRegex return $ret; } -} +} \ No newline at end of file diff --git a/lib/copy_this/www/lib/spotnab.php b/lib/copy_this/www/lib/spotnab.php index fd01ccbd3..09ca4e979 100644 --- a/lib/copy_this/www/lib/spotnab.php +++ b/lib/copy_this/www/lib/spotnab.php @@ -5,6 +5,7 @@ require_once(WWW_DIR."/lib/nzb.php"); require_once(WWW_DIR."/lib/site.php"); require_once(WWW_DIR."/lib/releases.php"); require_once(WWW_DIR."/lib/releasecomments.php"); +require_once(WWW_DIR."/lib/releaseimage.php"); require_once(WWW_DIR."/lib/nzbinfo.php"); require_once(WWW_DIR."/lib/util.php"); require_once(WWW_DIR."/lib/users.php"); @@ -161,6 +162,8 @@ class SpotNab { public function __construct($post_user = Null, $post_email = Null, $post_group = Null) { $this->_pdo = new DB(); $this->_nntp = new NNTP(['Settings' => $this->_pdo]); + $this->releaseImage = new \ReleaseImage($this->_pdo); + $this->nzb = new \NZB($this->_pdo); $s = new Sites(); $this->_site = $s->get(); $this->_globals = $this->_site; @@ -943,7 +946,7 @@ class SpotNab { { if($delete_broken_releases){ $release = new Releases(); - $release->delete($r['id']); + $release->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage); // Free the variable in an attempt to recover memory unset($release); echo '-'; @@ -962,7 +965,7 @@ class SpotNab { if(!$gid){ if($delete_broken_releases){ $release = new Releases(); - $release->delete($r['id']); + $release->$release->deleteSingle(['g' => $r['guid'], 'i' => $r['id']], $this->nzb, $this->releaseImage); unset($release); echo '-'; }else{ @@ -973,7 +976,7 @@ class SpotNab { } // Update DB With Global Identifer - $ures = $db->queryExec(sprintf($usql, $gid, $r['id'])); + $ures = $db->queryExec(sprintf('UPDATE releases SET gid = %s WHERE id = %d', $gid, $r['id'])); if($ures < 0){ printf("\nPostPrc : Failed to update: %s\n", $r['name']); } @@ -984,18 +987,27 @@ class SpotNab { } # Batch update for comment table - $usql = 'UPDATE releasecomment, releases ' - .'SET releasecomment.GID = releases.GID, ' + /*$usql = 'UPDATE releasecomment, releases ' + .'SET releasecomment.gid = releases.gid, ' .'releasecomment.nzb_guid = releases.nzb_guid ' .'WHERE releases.id = releasecomment.releaseid ' - .'AND releasecomment.GID IS NULL ' + .'AND releasecomment.gid IS NULL ' .'AND releasecomment.nzb_guid = "" ' .'AND releases.nzb_guid IS NOT NULL ' - .'AND releases.GID IS NOT NULL '; + .'AND releases.gid IS NOT NULL ';*/ - $affected = $db->exec(sprintf($usql)); - if($affected > 0) - $processed += $affected; + $affected = $db->queryExec(sprintf('UPDATE releasecomment, releases SET releasecomment.gid = releases.gid, + releasecomment.nzb_guid = releases.nzb_guid + WHERE releases.id = releasecomment.releaseid + AND releasecomment.gid IS NULL + AND releasecomment.nzb_guid = "" + AND releases.nzb_guid IS NOT NULL + AND releases.gid IS NOT NULL ' + ) + ); + $rows = $affected->rowCount(); + if($rows > 0) + $processed += $rows; return $processed; }