You are here

function hosting_ssl_clean_keys in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 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
Implements hook_nodeapi_TYPE_OP().
hosting_ssl_nodeapi_site_update in web_server/ssl/hosting_ssl.nodeapi.inc
Implements hook_nodeapi_TYPE_OP().

File

web_server/ssl/hosting_ssl.nodeapi.inc, line 425
NodeAPI functions for the Hosting SSL module.

Code

function hosting_ssl_clean_keys($node) {

  // Check if there are still sites using this site's certificate.
  if (!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 (\n                         siteA.ssl_enabled = :ssl_enabled\n                         OR\n                         siteA.ssl_enabled = :ssl_required\n                       )\n                       AND siteB.nid = :siteB_nid;", array(
    ':ssl_enabled' => HOSTING_SSL_ENABLED,
    ':ssl_required' => HOSTING_SSL_REQUIRED,
    ':siteB_nid' => $node->nid,
  ))
    ->fetchField()) {

    // 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_query('SELECT ssl_key FROM {hosting_ssl_site} WHERE nid = :nid', array(
      ':nid' => $node->nid,
    ))
      ->fetchField();
    drupal_set_message(t("cleaning up unused certificate %cert associated with site %site", array(
      '%cert' => $ssl_key,
      '%site' => $node->nid,
    )));
    db_delete('hosting_ssl_cert')
      ->condition('cid', $ssl_key)
      ->execute();
    db_delete('hosting_ssl_cert_ips')
      ->condition('cid', $ssl_key)
      ->execute();
  }
}