Conditions | 2 |
Paths | 2 |
Total Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
36 | public function start(): bool |
||
37 | { |
||
38 | $pipeline = [ |
||
39 | ['$group' => [ |
||
40 | '_id' => [ |
||
41 | 'name' => '$name', |
||
42 | 'parent' => '$parent', |
||
43 | 'owner' => '$owner', |
||
44 | 'deleted' => '$deleted', |
||
45 | ], |
||
46 | 'count' => [ |
||
47 | '$sum' => 1, |
||
48 | ], |
||
49 | 'nodes' => [ |
||
50 | '$addToSet' => '$_id', |
||
51 | ], |
||
52 | ]], |
||
53 | ['$match' => [ |
||
54 | '_id' => ['$ne' => null], |
||
55 | 'count' => ['$gt' => 1], |
||
56 | ]], |
||
57 | ]; |
||
58 | |||
59 | $cursor = $this->db->storage->aggregate($pipeline, [ |
||
60 | 'allowDiskUse' => true, |
||
61 | ]); |
||
62 | |||
63 | foreach ($cursor as $object) { |
||
64 | $id = array_pop($object['nodes']); |
||
65 | $this->db->storage->deleteOne(['_id' => $id]); |
||
66 | } |
||
67 | |||
68 | $this->db->storage->createIndex([ |
||
69 | 'name' => 1, |
||
70 | 'owner' => 1, |
||
71 | 'parent' => 1, |
||
72 | 'deleted' => 1, |
||
73 | ], [ |
||
74 | 'unique' => true, |
||
75 | ]); |
||
76 | |||
77 | return true; |
||
78 | } |
||
79 | } |
||
80 |