You are here

function backup_migrate_destination_nodesquirrel::__xmlrpc in Backup and Migrate 6.2

Same name and namespace in other branches
  1. 8.3 includes/destinations.nodesquirrel.inc \backup_migrate_destination_nodesquirrel::__xmlrpc()
  2. 6.3 includes/destinations.nodesquirrel.inc \backup_migrate_destination_nodesquirrel::__xmlrpc()
  3. 7.2 includes/destinations.nodesquirrel.inc \backup_migrate_destination_nodesquirrel::__xmlrpc()

Get the form for the settings for this destination.

2 calls to backup_migrate_destination_nodesquirrel::__xmlrpc()
backup_migrate_destination_nodesquirrel::_get_endpoints in includes/destinations.nodesquirrel.inc
Retrieve the list of servers.
backup_migrate_destination_nodesquirrel::_xmlrpc in includes/destinations.nodesquirrel.inc
Get the form for the settings for this destination.

File

includes/destinations.nodesquirrel.inc, line 411
Functions to handle the NodeSquirrel backup destination.

Class

backup_migrate_destination_nodesquirrel
A destination for sending database backups to the NodeSquirel backup service.

Code

function __xmlrpc($method, $args, $servers, $retry = 3) {
  if ($servers && --$retry > 0) {

    // Add the key authentication arguments if we can.
    if ($this
      ->_sign_request($args)) {

      // Add the method and url to match the function signiture of xmlrpc().
      array_unshift($args, $method);
      $url = reset($servers);

      // Try each available server in order.
      while ($url) {
        $url = $this
          ->add_scheme($url);
        array_unshift($args, $url);
        $out = call_user_func_array('xmlrpc', $args);

        // Check for errors.
        $err = xmlrpc_error();
        if ($err && $err->is_error) {
          switch ($err->code) {
            case '500':
            case '503':
            case '404':

              // Some sort of server error. Try the next one.
              $url = next($servers);

              // If we're at the end of the line then try refetching the urls
              if (!$url) {
                $servers = $this
                  ->_get_endpoints(TRUE, $retry);
                return $this
                  ->__xmlrpc($method, $args, $servers, $retry);
              }
              break;
            case '300':

              // 'Multiple Choices' means that the existing server list needs to be refreshed.
              $servers = $this
                ->_get_endpoints(TRUE, $retry);
              return $this
                ->__xmlrpc($method, $args, $servers, $retry);
              break;
            case '401':
            case '403':

              // Authentication failed.
              _backup_migrate_message('Couldn\'t log in to NodeSquirrel. The server error was: %err', array(
                '%err' => $err->message,
              ), 'error');
              return FALSE;
              break;
            default:

              // Some sort of client error. Don't try the next server because it'll probably say the same thing.
              _backup_migrate_message('The NodeSquirrel server returned the following error: %err', array(
                '%err' => $err->message,
              ), 'error');
              return FALSE;
              break;
          }
        }
        else {
          return $out;
        }

        // Remove the current url so the next one can be added.
        array_shift($args);
      }
    }
  }
}