You are here

function simplenews_subscriber_save in Simplenews 7

Same name and namespace in other branches
  1. 7.2 simplenews.module \simplenews_subscriber_save()

Store subscriber object in the database.

Related topics

8 calls to simplenews_subscriber_save()
simplenews_confirmation_send_combined in ./simplenews.module
Send collected confirmations.
simplenews_confirm_multi_form_submit in includes/simplenews.subscription.inc
simplenews_confirm_subscription in includes/simplenews.subscription.inc
Menu callback: confirm the user's (un)subscription request
simplenews_subscribe_user in ./simplenews.module
Subscribe a user to a newsletter or send a confirmation mail.
simplenews_subscriptions_admin_form_submit in includes/simplenews.subscription.inc
FAPI ADMIN subscription form_submit.

... See full list

File

./simplenews.module, line 1660
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_subscriber_save(&$subscriber) {
  if (!empty($subscriber->snid)) {
    db_update('simplenews_subscriber')
      ->condition('snid', $subscriber->snid)
      ->fields(array(
      'snid' => $subscriber->snid,
      'activated' => (int) $subscriber->activated,
      'mail' => $subscriber->mail,
      'uid' => $subscriber->uid,
      'language' => $subscriber->language,
      'changes' => serialize(isset($subscriber->changes) ? $subscriber->changes : array()),
    ))
      ->execute();
    module_invoke_all('simplenews_subscriber_update', $subscriber);
  }
  elseif (empty($subscriber->snid)) {
    $query = db_insert('simplenews_subscriber')
      ->fields(array(
      'activated' => $subscriber->activated,
      'mail' => $subscriber->mail,
      'uid' => $subscriber->uid,
      'language' => $subscriber->language,
      'changes' => serialize(isset($subscriber->changes) ? $subscriber->changes : array()),
      'created' => REQUEST_TIME,
    ));
    $last_insert_id = $query
      ->execute();
    if ($last_insert_id !== FALSE) {
      $subscriber->snid = $last_insert_id;
      module_invoke_all('simplenews_subscriber_insert', $subscriber);
    }
  }
}