-
Notifications
You must be signed in to change notification settings - Fork 1
/
playground.php
102 lines (86 loc) · 2.65 KB
/
playground.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Playground for Migration Library Tests
*
* A place to test and debug the Migration Library stuff
*/
require_once __DIR__.'/vendor/autoload.php';
use Dotenv\Dotenv;
use Utopia\CLI\Console;
use Utopia\Migration\Destinations\Appwrite as AppwriteDestination;
use Utopia\Migration\Destinations\Local;
use Utopia\Migration\Sources\Appwrite;
use Utopia\Migration\Sources\Firebase;
use Utopia\Migration\Sources\NHost;
use Utopia\Migration\Sources\Supabase;
use Utopia\Migration\Transfer;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
/**
* Initialise All Source Adapters
*/
$sourceAppwrite = new Appwrite(
$_ENV['SOURCE_APPWRITE_TEST_PROJECT'],
$_ENV['SOURCE_APPWRITE_TEST_ENDPOINT'],
$_ENV['SOURCE_APPWRITE_TEST_KEY']
);
// $firebase = json_decode($_ENV['FIREBASE_TEST_ACCOUNT'], true);
// $sourceFirebase = new Firebase(
// $firebase,
// $firebase['project_id'] ?? '',
// );
// $sourceNHost = new NHost(
// $_ENV['NHOST_TEST_SUBDOMAIN'] ?? '',
// $_ENV['NHOST_TEST_REGION'] ?? '',
// $_ENV['NHOST_TEST_SECRET'] ?? '',
// $_ENV['NHOST_TEST_DATABASE'] ?? '',
// $_ENV['NHOST_TEST_USERNAME'] ?? '',
// $_ENV['NHOST_TEST_PASSWORD'] ?? '',
// );
// $sourceSupabase = new Supabase(
// $_ENV['SUPABASE_TEST_ENDPOINT'] ?? '',
// $_ENV['SUPABASE_TEST_KEY'] ?? '',
// $_ENV['SUPABASE_TEST_HOST'] ?? '',
// $_ENV['SUPABASE_TEST_DATABASE'] ?? '',
// $_ENV['SUPABASE_TEST_USERNAME'] ?? '',
// $_ENV['SUPABASE_TEST_PASSWORD'] ?? '',
// );
/**
* Initialise All Destination Adapters
*/
$destinationAppwrite = new AppwriteDestination(
$_ENV['DESTINATION_APPWRITE_TEST_PROJECT'],
$_ENV['DESTINATION_APPWRITE_TEST_ENDPOINT'],
$_ENV['DESTINATION_APPWRITE_TEST_KEY']
);
$destinationLocal = new Local(__DIR__.'/localBackup/');
/**
* Initialise Transfer Class
*/
$transfer = new Transfer(
$sourceAppwrite,
$destinationAppwrite
);
/**
* Run Transfer
*/
$transfer->run(
$sourceAppwrite->getSupportedResources(),
function (array $resources) use ($transfer) {
var_dump($transfer->getStatusCounters());
}
);
$report = [];
$cache = $transfer->getCache()->getAll();
if (count($sourceAppwrite->getErrors()) > 0) {
foreach ($sourceAppwrite->getErrors() as $error) {
/* @var \Utopia\Migration\Exception $error */
Console::error('[Source] ['.$error->getResourceType().'] '.$error->getMessage());
}
}
if (count($destinationAppwrite->getErrors()) > 0) {
foreach ($destinationAppwrite->getErrors() as $error) {
/* @var \Utopia\Migration\Exception $error */
Console::error('[Destination] ['.$error->getResourceType().'] '.$error->getMessage());
}
}