summaryrefslogtreecommitdiff
path: root/actions/finishremotesubscribe.php
diff options
context:
space:
mode:
Diffstat (limited to 'actions/finishremotesubscribe.php')
-rw-r--r--actions/finishremotesubscribe.php22
1 files changed, 20 insertions, 2 deletions
diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php
index 97f972043..58040683f 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;
}