-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimport.php
67 lines (46 loc) · 1.3 KB
/
import.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
<?php
require_once 'includes/core.php';
$hasExports = false;
foreach (FAVORITE_TYPES as $type) {
$file = EXPORT_PATH . '/' . $type . '.json';
if (file_exists($file)) {
$hasExports = true;
break;
}
}
if (!$hasExports) {
print 'No exports found.' . PHP_EOL;
exit(0);
}
setup();
foreach (FAVORITE_TYPES as $type) {
print 'Reading ' . $type . '... ';
$nonPluralType = substr($type, 0, -1);
$file = EXPORT_PATH . '/' . $type . '.json';
if (!file_exists($file)) {
print 'No ' . $type . ' found.' . PHP_EOL;
continue;
}
$favorites = json_decode(file_get_contents($file), true);
print 'OK!' . PHP_EOL;
if ($favorites) {
foreach ($favorites as $favorite) {
print '=> ' . $favorite['id'] . ': ' . ($favorite['title'] ?? $favorite['name']) . '... ';
$result = request('/favorite/create', 'POST', [
$nonPluralType . '_ids' => $favorite['id']
]);
if (
isset($result['status'])
&&
$result['status'] == 'success'
) {
print 'OK!' . PHP_EOL;
} else {
print 'FAIL! - ' . $result['status'] . PHP_EOL;
}
}
}
}
print 'Done.' . PHP_EOL;
exit(0);
?>