You are here

function subscribed_user_import_after_save in User Import 5

Same name and namespace in other branches
  1. 8 supported/subscribed.inc \subscribed_user_import_after_save()
  2. 5.2 supported/subscribed.inc \subscribed_user_import_after_save()
  3. 6.4 supported/subscribed.inc \subscribed_user_import_after_save()
  4. 6.2 supported/subscribed.inc \subscribed_user_import_after_save()
  5. 7 supported/subscribed.inc \subscribed_user_import_after_save()
  6. 7.2 supported/subscribed.inc \subscribed_user_import_after_save()

Implementation of hook_user_import_after_save().

File

supported/subscribed.inc, line 72

Code

function subscribed_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
  $uid = $account->uid;
  $subscribed_settings = $settings['options']['subscribed'];
  $update_setting = $update_setting_per_module['subscribed'];
  if (!module_exists('publication') || !module_exists('schedule') || !module_exists('identity_hash')) {
    return;
  }
  if (empty($subscribed_settings) || !is_array($subscribed_settings)) {
    return;
  }
  if ($updated && $update_setting == UPDATE_NONE) {
    return;
  }
  if ($updated) {
    $subscribed = subscribed_subscriptions_user_all_select_db($uid);
  }
  foreach ($subscribed_settings as $type => $type_subscriptions) {
    $subscriptions = $type_subscriptions;
    foreach ($type_subscriptions as $publication_id => $schedule) {
      if (!$updated || $updated && $update_setting == UPDATE_REPLACE) {
        if (empty($schedule[0])) {
          unset($subscriptions[$publication_id]);
        }
      }
      elseif ($updated && $update_setting == UPDATE_ADD) {
        if (empty($subscribed[$type][$publication_id]) && !empty($subscriptions[$publication_id][0])) {
          $update_subscriptions = TRUE;
        }
        else {
          $subscriptions[$publication_id][0] = $subscribed[$type][$publication_id][$schedule[0]]['schedule_id'];
          if (empty($subscribed[$type][$publication_id][$schedule[0]])) {
            unset($subscriptions[$publication_id]);
          }
        }
      }
    }
    $publications = publication_select_publications_and_terms($type);
    if (!empty($publications) && !empty($subscriptions)) {
      if (!$updated || $updated && $update_setting == UPDATE_REPLACE || $updated && $update_setting == UPDATE_ADD && $update_subscriptions) {
        subscribed_set_subscriptions($type, $uid, $publications, $subscriptions);
        subscribed_set_subscriptions_terms($type, $uid, $publications, $subscriptions);
        identity_hash_set_hash($uid);
      }
    }
  }
  return;
}