You are here

function drd_server_key_remote in Drupal Remote Dashboard Server 6.2

Same name and namespace in other branches
  1. 7.2 drd_server.module \drd_server_key_remote()

This is called to update encryption keys on all domains.

Parameters

array $domainurls:

array $aes_keys:

3 calls to drd_server_key_remote()
drd_server_key in ./drd_server.module
This is called to update the excryption keys for this server and all it's domains hosted in the same Drupal installation.
drd_server_settings_keys_submit in ./drd_server.admin.inc
Submit handler for the AES key settings form.
drd_server_settings_submit in ./drd_server.admin.inc
Submit handler for the settings form.

File

./drd_server.module, line 623

Code

function drd_server_key_remote($domainurls, $aes_keys) {
  global $db_url, $db_prefix;
  if (is_string($db_url)) {
    $db_url = array(
      'default' => $db_url,
    );
  }
  $orig_db_prefix = $db_prefix;
  $used_extension = '';
  $i = 0;
  foreach ($domainurls as $url => $shortname) {
    $file = DRUPAL_ROOT . '/sites/' . $shortname . '/settings.php';
    if (file_exists($file)) {
      $i++;
      list($base_url, $url, $prefix) = _drd_server_read_settings($shortname, $file);
      if (empty($url)) {
        _drd_server_watchdog('Set AES key - Failed as url is empty: @shortname', array(
          '@shortname' => $shortname,
        ), WATCHDOG_ERROR);
        continue;
      }
      $extension = substr($url, 0, strpos($url, '://'));
      if (empty($used_extension)) {
        $used_extension = $extension;
      }
      elseif ($used_extension == $extension) {

        // Everything is fine, we can continue as is.
      }
      else {

        // We are having a problem here: the current domain uses a different db extension than the previous one.
        if (in_array(strtolower($used_extension), array(
          'mysql',
          'mysqli',
        )) && in_array(strtolower($extension), array(
          'mysql',
          'mysqli',
        ))) {

          // This is a case we can handle: use the same extension for the current domain as for the previous one.
          $url = str_replace($extension . '://', $used_extension . '://', $url);
        }
        else {

          // This is a case we can't handle and we produce a message and skip.
          _drd_server_watchdog('Set AES key - Failed because of mixed usage of @used and @current', array(
            '@used' => $used_extension,
            '@current' => $extension,
          ), WATCHDOG_ERROR);
          continue;
        }
      }
      $db_url['drd_' . $i] = $url;
      $db_prefix = $prefix;
      db_set_active('drd_' . $i);
      variable_set('drd_aes_keys', $aes_keys);
    }
  }

  // Reset to the default database
  $db_prefix = $orig_db_prefix;
  db_set_active();
}