diff --git a/lib/Sharing.php b/lib/Sharing.php index b676599ad..00f96c4f9 100644 --- a/lib/Sharing.php +++ b/lib/Sharing.php @@ -133,6 +133,7 @@ Class Sharing $this->matchComments(); if ($this->siteSettings['posting']) { $this->postAll(); + $this->postSC(); } } @@ -165,14 +166,14 @@ Class Sharing */ protected function postAll() { - // Get all comments that we have no posted yet. + // Get all comments that we have not posted yet. $newComments = $this->pdo->query( sprintf( 'SELECT rc.text, rc.id, %s, u.username, r.nzb_guid FROM releasecomment rc INNER JOIN users u ON rc.userid = u.id INNER JOIN releases r on rc.releaseid = r.id - WHERE rc.shared = 0 LIMIT %d', + WHERE (rc.shared = 0 or issynced = 1) LIMIT %d', $this->pdo->unix_timestamp_column('rc.createddate'), $this->siteSettings['max_push'] ) @@ -197,6 +198,40 @@ Class Sharing } + /** + * Post all new comments to usenet. + */ + protected function postSC() + { + // Get all comments from spotnab that we have not posted yet. + $newComments = $this->pdo->query( + sprintf( + 'SELECT id, text, UNIX_TIMESTAMP(createddate) AS unix_time, + username, nzb_guid FROM releasecomment + WHERE issynced = 1 AND shared = 1 AND shareid IS NULL + ORDER BY id DESC' + ) + ); + + // Check if we have any comments to push. + if (count($newComments) === 0) { + return; + } + + + echo '(Sharing) Starting to upload spotnab comments.' . PHP_EOL; + + + // Loop over the comments. + foreach ($newComments as $comment) { + $this->postComment($comment); + } + + + echo PHP_EOL . '(Sharing) Finished uploading spotnab comments.' . PHP_EOL; + + } + /** * Post a comment to usenet. * diff --git a/lib/copy_this/www/lib/spotnab.php b/lib/copy_this/www/lib/spotnab.php index d0e09d896..7ddf00120 100644 --- a/lib/copy_this/www/lib/spotnab.php +++ b/lib/copy_this/www/lib/spotnab.php @@ -985,9 +985,12 @@ class SpotNab { # Batch update for comment table $usql = 'UPDATE releasecomment, releases ' - .'SET releasecomment.GID = releases.GID ' + .'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 '; $affected = $db->exec(sprintf($usql)); @@ -1329,11 +1332,11 @@ class SpotNab { // Comments $sql_new_cmt = "INSERT INTO releasecomment (". "id, sourceID, username, userid, gid, cid, isvisible, ". - "releaseid, `text`, createddate, issynced) VALUES (". - "NULL, %d, %s, 0, %s, %s, %d, 0, %s, %s, 1)"; + "releaseid, `text`, createddate, issynced, nzb_guid) VALUES (". + "NULL, %d, %s, 0, %s, %s, %d, 0, %s, %s, 1, %s)"; $sql_upd_cmt = "UPDATE releasecomment SET ". "isvisible = %d, `text` = %s". - "WHERE sourceID = %d AND gid = %s AND cid = %s"; + "WHERE sourceID = %d AND gid = %s AND cid = %s AND nzb_guid = %s"; $sql_fnd_cmt = "SELECT count(id) as cnt FROM releasecomment ". "WHERE sourceID = %d AND gid = %s AND cid = %s"; @@ -1472,7 +1475,8 @@ class SpotNab { $db->escapeString($comment['comment']), $hash['id'], $db->escapeString($comment['gid']), - $db->escapeString($comment['cid']) + $db->escapeString($comment['cid']), + $db->escapeString($comment['gid']) ))>0)?1:0; }else{ // Make some noise @@ -1487,7 +1491,8 @@ class SpotNab { $db->escapeString($comment['comment']), // Convert createddate to Local $db->escapeString($this->utc2local( - $comment['postdate_utc'])) + $comment['postdate_utc'])), + $db->escapeString($comment['gid']) )); $inserts += 1; }