From 9ef3f7cee601c80d93924eec2216a36bcbce73ef Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Dec 2008 08:48:24 -0500 Subject: [PATCH] correctly handle remote re-subscribe darcs-hash:20081215134824-84dde-de48c99b6cb45cc461125a7f8f382eb57de0bf28.gz --- actions/finishremotesubscribe.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php index 97f9720430..58040683fd 100644 --- a/actions/finishremotesubscribe.php +++ b/actions/finishremotesubscribe.php @@ -188,13 +188,31 @@ class FinishremotesubscribeAction extends Action { } $sub = new Subscription(); + $sub->subscriber = $remote->id; $sub->subscribed = $user->id; + + $sub_exists = false; + + if ($sub->find(true)) { + $sub_exists = true; + $orig_sub = clone($sub); + } else { + $sub_exists = false; + $sub->created = DB_DataObject_Cast::dateTime(); # current time + } + $sub->token = $newtok; $sub->secret = $newsecret; - $sub->created = DB_DataObject_Cast::dateTime(); # current time - if (!$sub->insert()) { + if ($sub_exists) { + $result = $sub->update($orig_sub); + } else { + $result = $sub->insert(); + } + + if (!$result) { + common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__); common_user_error(_('Couldn\'t insert new subscription.')); return; } -- 2.39.5