Completed
Push — master ( 2aab0a...440703 )
by Raffael
19:06 queued 15:05
created

Postv1Cleanup::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 MongoDB\Database;
15
16
class Postv1Cleanup implements DeltaInterface
17
{
18
    /**
19
     * Database.
20
     *
21
     * @var Database
22
     */
23
    protected $db;
24
25
    /**
26
     * Construct.
27
     */
28
    public function __construct(Database $db)
29
    {
30
        $this->db = $db;
31
    }
32
33
    /**
34
     * Start.
35
     */
36
    public function start(): bool
37
    {
38
        $cursor = $this->db->user->find([
39
            '$or' => [
40
                ['groups' => ['$exists' => true]],
41
                ['ldapdn' => ['$exists' => true]],
42
                ['last_share_sync' => ['$exists' => true]],
43
            ],
44
        ]);
45
46
        foreach ($cursor as $user) {
47
            $this->db->user->updateOne(
48
                ['_id' => $user['_id']],
49
                [
50
                    '$unset' => [
51
                        'groups' => true,
52
                        'ldapdn' => true,
53
                        'last_share_sync' => true,
54
                    ],
55
                ]
56
            );
57
        }
58
59
        $cursor = $this->db->storage->find([
60
            ['migration' => ['$exists' => true]],
61
        ]);
62
63
        foreach ($cursor as $node) {
64
            $this->db->storage->updateOne(
65
                ['_id' => $node['_id']],
66
                [
67
                    '$unset' => [
68
                        'migration' => true,
69
                    ],
70
                ]
71
            );
72
        }
73
74
        return true;
75
    }
76
}
77