From b503e1440b25e464ac41c287b1dc6ac70b0e269a Mon Sep 17 00:00:00 2001 From: Jamie McCarthy Date: Thu, 4 Oct 2007 15:47:38 +0000 Subject: [PATCH] Firehose row insert is now transaction-safe; if firehose sql insert(s) fail, emit warning and roll back. Also, fix bug that allowed logged-in user to submit the same URL multiple times. --- plugins/FireHose/FireHose.pm | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/plugins/FireHose/FireHose.pm b/plugins/FireHose/FireHose.pm index 3169aafc8..d5a2fa649 100644 --- a/plugins/FireHose/FireHose.pm +++ b/plugins/FireHose/FireHose.pm @@ -59,15 +59,31 @@ sub createFireHose { $text_data->{introtext} = delete $data->{introtext}; $text_data->{bodytext} = delete $data->{bodytext}; - $self->sqlInsert("firehose", $data); - $text_data->{id} = $self->getLastInsertId({ table => 'firehose', prime => 'id' }); + $self->sqlDo('SET AUTOCOMMIT=0'); + my $ok = $self->sqlInsert("firehose", $data); + if (!$ok) { + warn "could not create firehose row, '$ok'"; + } + if ($ok) { + $text_data->{id} = $self->getLastInsertId({ table => 'firehose', prime => 'id' }); - my $searchtoo = getObject('Slash::SearchToo'); - if ($searchtoo) { - $searchtoo->storeRecords(firehose => $text_data->{id}, { add => 1 }); + my $searchtoo = getObject('Slash::SearchToo'); + if ($searchtoo) { + $searchtoo->storeRecords(firehose => $text_data->{id}, { add => 1 }); + } + + $ok = $self->sqlInsert("firehose_text", $text_data); + if (!$ok) { + warn "could not create firehose_text row for id '$text_data->{id}'"; + } } - $self->sqlInsert("firehose_text", $text_data); + if ($ok) { + $self->sqlDo('COMMIT'); + } else { + $self->sqlDo('ROLLBACK'); + } + $self->sqlDo('SET AUTOCOMMIT=1'); return $text_data->{id}; } @@ -731,8 +747,8 @@ sub allowSubmitForUrl { if ($user->{is_anon}) { return !$self->sqlCount("firehose", "url_id=$url_id_q"); } else { - my $uid_q; - return !$self->sqlCount("firehose", "url_id=$url_id_q and uid != $uid_q"); + my $uid_q = $self->sqlQuote($user->{uid}); + return !$self->sqlCount("firehose", "url_id=$url_id_q AND uid != $uid_q"); } }