You are here

function hosting_ssl_clean_keys in Hosting 6.2

Same name and namespace in other branches
  1. 7.4 web_server/ssl/hosting_ssl.nodeapi.inc \hosting_ssl_clean_keys()
  2. 7.3 web_server/ssl/hosting_ssl.nodeapi.inc \hosting_ssl_clean_keys()

Remove unused SSL keys from the system (but not from the backend).

This is designed to be ran on a site's delete task or the site node's deletion.

2 calls to hosting_ssl_clean_keys()
hosting_ssl_nodeapi_site_delete in web_server/ssl/hosting_ssl.nodeapi.inc
hosting_ssl_nodeapi_site_update in web_server/ssl/hosting_ssl.nodeapi.inc

File

web_server/ssl/hosting_ssl.nodeapi.inc, line 326

Code

function hosting_ssl_clean_keys($node) {

  // check if there are still sites using this site's certificate
  if (!db_result(db_query("SELECT * FROM hosting_ssl_site siteA\n                             INNER JOIN hosting_ssl_site siteB ON siteA.ssl_key = siteB.ssl_key \n                             INNER JOIN hosting_site s ON s.nid = siteA.nid\n                               WHERE siteA.nid <> siteB.nid\n                                 AND siteA.ssl_enabled = 1\n                                 AND s.status <> %d\n                                 AND siteB.nid = %d;", HOSTING_SITE_DELETED, $node->nid))) {

    // we need to fetch the ssl_key field from the DB because the object comes from the node edit, so it's gone
    $ssl_key = db_result(db_query('SELECT ssl_key FROM {hosting_ssl_site} WHERE nid = %d', $node->nid));
    drupal_set_message(t("cleaning up unused certificate %cert associated with site %site", array(
      '%cert' => $ssl_key,
      '%site' => $node->nid,
    )));
    db_query("DELETE FROM {hosting_ssl_cert} WHERE cid = %d", $ssl_key);
    db_query("DELETE FROM {hosting_ssl_cert_ips} WHERE cid = %d", $ssl_key);
  }
}