|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* balloon |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com) |
|
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Balloon\Migration\Delta; |
|
13
|
|
|
|
|
14
|
|
|
use Balloon\Server; |
|
15
|
|
|
use MongoDB\Database; |
|
16
|
|
|
|
|
17
|
|
|
class CoreInstallation implements DeltaInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Database. |
|
21
|
|
|
* |
|
22
|
|
|
* @var Database |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $db; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Server. |
|
28
|
|
|
* |
|
29
|
|
|
* @var Server |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $server; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Construct. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(Database $db, Server $server) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->db = $db; |
|
39
|
|
|
$this->server = $server; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Initialize database. |
|
44
|
|
|
*/ |
|
45
|
|
|
public function start(): bool |
|
46
|
|
|
{ |
|
47
|
|
|
$collections = []; |
|
48
|
|
|
foreach ($this->db->listCollections() as $collection) { |
|
49
|
|
|
$collections[] = $collection->getName(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->db->user->createIndex(['username' => 1], ['unique' => true]); |
|
53
|
|
|
$this->db->group->createIndex(['member' => 1]); |
|
54
|
|
|
|
|
55
|
|
|
$this->db->selectCollection('fs.files')->createIndex(['md5' => 1], [ |
|
56
|
|
|
'unique' => true, |
|
57
|
|
|
'partialFilterExpression' => [ |
|
58
|
|
|
'md5' => ['$exists' => true], |
|
59
|
|
|
], |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
$this->db->selectCollection('fs.chunks')->createIndex( |
|
63
|
|
|
['files_id' => 1, 'n' => 1], |
|
64
|
|
|
['unique' => true] |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$this->db->storage->createIndexes([ |
|
68
|
|
|
['key' => ['acl.id' => 1]], |
|
69
|
|
|
['key' => ['hash' => 1]], |
|
70
|
|
|
['key' => ['parent' => 1, 'owner' => 1]], |
|
71
|
|
|
['key' => ['reference' => 1]], |
|
72
|
|
|
['key' => ['shared' => 1]], |
|
73
|
|
|
['key' => ['deleted' => 1]], |
|
74
|
|
|
['key' => [ |
|
75
|
|
|
'owner' => 1, |
|
76
|
|
|
'directory' => 1, |
|
77
|
|
|
'delete' => 1, |
|
78
|
|
|
]], |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$this->db->delta->createIndexes([ |
|
82
|
|
|
['key' => ['owner' => 1]], |
|
83
|
|
|
['key' => ['timestamp' => 1]], |
|
84
|
|
|
['key' => ['node' => 1]], |
|
85
|
|
|
['key' => ['share' => 1]], |
|
86
|
|
|
]); |
|
87
|
|
|
|
|
88
|
|
|
if (!in_array('queue', $collections, true)) { |
|
89
|
|
|
$this->db->createCollection( |
|
90
|
|
|
'queue', |
|
91
|
|
|
[ |
|
92
|
|
|
'capped' => true, |
|
93
|
|
|
'size' => 100000, ] |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$this->server->addUser('admin', [ |
|
98
|
|
|
'password' => 'admin', |
|
99
|
|
|
'mail' => '[email protected]', |
|
100
|
|
|
'admin' => true, |
|
101
|
|
|
]); |
|
102
|
|
|
|
|
103
|
|
|
return true; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|