You are here

function hosting_server_update_6202 in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 server/hosting_server.install \hosting_server_update_6202()
  2. 7.3 server/hosting_server.install \hosting_server_update_6202()

Implements hook_update_N().

Migrate site-specific IPs to server-specific IPs.

We inject into the new certificate to IP mapping table the correct associations, by looking at the server IPs matching the IPs allocated to sites.

If SSL is not installed, this is a noop.

File

server/hosting_server.install, line 303
Define the database schema and update functions for the hosting_server module.

Code

function hosting_server_update_6202() {
  if (!db_table_exists('hosting_ssl_site')) {
    return array(
      array(
        'success' => TRUE,
      ),
    );
  }
  $ret = array();

  /* this is rather complicated:
   *
   * we need to first find the SSL certificate of the site, then look at the
   * IP of the sites with SSL certs, match that IP with the IP of a server (we
   * assume it's the same server!).
   *
   * Verification query:
   *
   * SELECT cert.cid,cert.ssl_key,server_ip.ip_address,server_ip.nid,server_ip.id FROM hosting_ssl_site ssl_site
   * INNER JOIN hosting_ssl_cert cert ON cert.cid = ssl_site.ssl_key
   * INNER JOIN hosting_ip_addresses site_ip ON site_ip.nid = ssl_site.nid
   * INNER JOIN hosting_site site ON site.nid = ssl_site.nid
   * INNER JOIN hosting_ip_addresses server_ip ON server_ip.ip_address = site_ip.ip_address
   * INNER JOIN hosting_platform p ON site.platform = p.nid AND p.web_server = server_ip.nid
   * WHERE ssl_enabled > 0 AND site.status > -2 GROUP BY cid ;
   *
   * This should show a meaningful list of SSL certificates -> IPs mappings.
   *
   */
  $ret[] = update_sql("INSERT INTO {hosting_ssl_cert_ips} (cid, ip_address)\n  SELECT cert.cid,server_ip.id FROM {hosting_ssl_site} ssl_site\n    INNER JOIN {hosting_ssl_cert} cert ON cert.cid = ssl_site.ssl_key\n    INNER JOIN {hosting_ip_addresses} site_ip ON site_ip.nid = ssl_site.nid\n    INNER JOIN {hosting_site} site ON site.nid = ssl_site.nid\n    INNER JOIN {hosting_ip_addresses} server_ip ON server_ip.ip_address = site_ip.ip_address\n    INNER JOIN {hosting_platform} p ON site.platform = p.nid AND p.web_server = server_ip.nid\n    WHERE ssl_enabled > %d AND site.status > %d GROUP BY cid", HOSTING_SSL_DISABLED, HOSTING_SITE_DELETED);
  return $ret;
}