You are here

function _hosting_ip_save in Hosting 7.3

Same name and namespace in other branches
  1. 7.4 server/hosting.ip.inc \_hosting_ip_save()

IP Utility function for hook_update/hook_insert.

2 calls to _hosting_ip_save()
hosting_server_insert in server/hosting_server.module
Implements hook_insert().
hosting_server_update in server/hosting_server.module
Implements hook_update().

File

server/hosting.ip.inc, line 25
General IP address CRUD routines.

Code

function _hosting_ip_save($node, $update = FALSE) {
  $ips = isset($node->ip_addresses) ? (array) $node->ip_addresses : array();
  foreach ($ips as $id => $ip) {
    $ip = trim($ip);
    if (empty($ip)) {

      // empty fields are considered removed
      db_delete('hosting_ip_addresses')
        ->condition('id', $id)
        ->execute();
    }
    else {
      $num_updated = db_update('hosting_ip_addresses')
        ->fields(array(
        'ip_address' => $ip,
      ))
        ->condition('id', $id)
        ->execute();
    }
  }
  $ips = isset($node->new_ip_addresses) ? (array) $node->new_ip_addresses : array();
  foreach ($ips as $id => $ip) {
    if (!empty($ip)) {

      // new entries are prefixed with the string 'new', insert those
      db_insert('hosting_ip_addresses')
        ->fields(array(
        'nid' => $node->nid,
        'ip_address' => $ip,
      ))
        ->execute();
    }
  }
}