You are here

function _notifications_update_fix_destinations in Notifications 6.4

Helper function. Fix subscription destinations

2 calls to _notifications_update_fix_destinations()
notifications_update_6007 in ./notifications.install
Create the destinations we need.
notifications_update_6016 in ./notifications.install
Update destination fields

File

./notifications.install, line 559

Code

function _notifications_update_fix_destinations($op) {
  $ret = array();
  $methods = $addresses = array();
  foreach (messaging_method_info() as $method => $info) {
    $type = isset($info['address_type']) ? $info['address_type'] : $info['group'];

    // Best guess, will work for most cases
    $type_method[$type][] = $method;
    $method_type[$method] = $type;
  }
  if ($op == 'create') {

    // First, fill in destination table with each address type
    foreach ($type_method as $type => $methods) {
      $ret[] = update_sql("INSERT INTO {messaging_destination} (uid, type, address) SELECT DISTINCT uid, '{$type}', destination FROM {notifications} WHERE send_method IN ('" . implode("','", $methods) . "')");
    }
  }
  elseif ($op == 'update') {

    // This should update notifications table with the new destinations created
    foreach ($method_type as $method => $type) {

      // First, registered users, we can do a better matching
      $ret[] = update_sql("UPDATE {notifications} n INNER JOIN {messaging_destination} d ON n.uid = d.uid AND d.type = '{$type}' SET n.mdid = d.mdid  WHERE n.uid > 0 AND n.send_method = '{$method}'");

      // Then anonymous users, we can just match using destination field
      $ret[] = update_sql("UPDATE {notifications} n INNER JOIN {messaging_destination} d ON d.uid = 0 AND d.type = '{$type}' AND n.destination = d.address SET n.mdid = d.mdid WHERE n.uid = 0 AND n.send_method = '{$method}'");
    }
  }

  // Mark to skip some updates
  return $ret;
}