<?php

/**
 * This example gets the running DomainAction for a domain
 * and based on the status, retries it with new nameservers.
 *
 * @copyright Copyright 2011 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
require_once 'Transip/DomainService.php';
try {
    $currentDomainAction = Transip_DomainService::getCurrentDomainAction($domainName);
    $result = '';
    if (is_null($currentDomainAction)) {
        // There is currently no action running on this domain
        $result = "Currently no action for domain {$domainName}\n";
    }
    if ($currentDomainAction->hasFailed !== true) {
        // There is currently an action running, and it has not failed yet.
        $result = "Current action for domain is {$currentDomainAction->name}\n";
    } else {
        // There was an action running on the domain, and it has failed.
        // We retry with new nameservers for the domain.
        $result = "Current action for domain is {$currentDomainAction->name} and has failed with message {$currentDomainAction->message}\n";
        $result .= "Retrying....\n";
        $domain = Transip_DomainService::getInfo($domainName);
        // Create new nameserver entries we want
        $nameservers = array();
        $nameservers[] = new Transip_Nameserver('ns1.mydomain.com');
        $nameservers[] = new Transip_Nameserver('ns2.mydomain.com', '');
        // Since ns.thedomaintomodify.com is a subdomain of the domain we are saving,