forked from ovh/php-ovh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteAttachedDomain.php
70 lines (57 loc) · 2.1 KB
/
deleteAttachedDomain.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;
use GuzzleHttp\Client;
// Informations about your application
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumer_key = "your_consumer_key";
// Information about API and rights asked
$endpoint = 'ovh-eu';
// Informations about your web hosting and the attached domain (compulsory)
$domain = 'mydomain.ovh'; // Web hosting id (often domain order with it)
$domainToAttach = 'myotherdomaintoattach.ovh';
$http_client = new Client([
'timeout' => 30,
'connect_timeout' => 5,
]);
// Create a new attached domain
$conn = new Api( $applicationKey,
$applicationSecret,
$endpoint,
$consumer_key,
$http_client);
try {
// This call will create a "task". The task is the status of the attached domain deletion.
// You can follow the task on /hosting/web/{serviceName}/tasks/{id}
$task = $conn->delete('/hosting/web/' . $domain . '/attachedDomain/' . $domainToDetach);
echo "Task #" . $task['id'] . " is created" . PHP_EOL;
// we check every 5 seconds if task is done
// When the task disappears, the task is done
while ( 1 ) {
try {
$wait = $conn->get('/hosting/web/' . $domain . '/tasks/' . $task['id']);
if ( strcmp( $wait['status'], 'error' ) === 0 ) {
// The task is in error state. Please check your parameters, retry or contact support.
echo "An error has occured during the task" . PHP_EOL;
break;
} elseif ( strcmp( $wait['status'], 'cancelled' ) === 0 ) {
// The task is in cancelled state. Please check your parameters, retry or contact support.
echo "Task has been cancelled during the task" . PHP_EOL;
break;
}
echo "Status of task #". $wait['id'] . " is '". $wait['status'] ."'" . PHP_EOL;
} catch ( \GuzzleHttp\Exception\ClientException $ex) {
$response = $ex->getResponse();
if ( $response && $response->getStatusCode() === 404 ) {
echo "Domain detached from the web hosting" . PHP_EOL;
break;
}
throw $ex;
}
sleep(5);
}
} catch ( Exception $ex ) {
print_r( $ex->getMessage() );
}
?>