-
Notifications
You must be signed in to change notification settings - Fork 0
/
transfer-treatments.php
59 lines (41 loc) · 1.28 KB
/
transfer-treatments.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
<?php
$today = date("Y-m-d", time() + 3600*24);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $oldSecureDomain .'/api/v1/treatments.json?count=all&find[created_at][$lte]=' . $toDate . '&find[created_at][$gte]=' . $fromDate);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
if(!empty($_POST['oldApi'])) {
$headers = array();
$headers[] = 'api-secret: ' . $oldHash;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$arr = json_decode($result, true);
$newArray = [];
foreach($arr as $item) {
unset($item['_id']);
array_push($newArray, $item);
}
$newJSON = json_encode($newArray);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $newSecureDomain . '/api/v1/treatments');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $newJSON);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'api-secret: ' . $hashedSecret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
?>
<script>
window.location.href = '/?s=y';
</script>