Update comment sharing.

This commit is contained in:
Darko
2015-03-17 15:26:01 +01:00
parent 358e36e856
commit 3835310f8f
2 changed files with 48 additions and 8 deletions
+37 -2
View File
@@ -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.
*
+11 -6
View File
@@ -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;
}