Completed
Push — master ( c70864...b6d4e5 )
by Dmitry
03:30 queued 27s
created

Clear   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 41
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 38 7
1
<?php
2
3
namespace Basis\Job\Tarantool;
4
5
use Basis\Job;
6
use Tarantool\Client\Client;
7
use Tarantool\Client\Schema\IndexIds;
8
use Tarantool\Client\Schema\Criteria;
9
use Basis\Filesystem;
10
11
class Clear extends Job
12
{
13 45
    public function run(Client $client, Filesystem $fs)
14
    {
15 45
        $space = $client->getSpace('_vspace');
16
17 45
        $client->evaluate("
18
            if box.space._queue ~= nil then
19
                if queue == nil then
20
                    queue = require('queue')
21
                end
22
                for i, q in box.space._queue:pairs() do
23
                    queue.tube[q.tube_name]:drop()
24
                end
25
            end
26
        ");
27
        
28 45
        $data = $space->select(Criteria::key([]));
29
30 45
        foreach ($data as $row) {
31 45
            if ($row[0] >= 512) {
32
                // user space
33 45
                if (strpos($row[2], '_queue') === false) {
34 45
                    $client->evaluate('box.space.'.$row[2].':drop()');
35
                }
36
            }
37
        }
38
39 45
        $schema = $client->getSpace('_schema')->select(Criteria::key([]));
40 45
        foreach ($schema as $tuple) {
41 45
            if (strpos($tuple[0], 'mapper-once') === 0) {
42 10
                $client->getSpace('_schema')->delete([$tuple[0]]);
43
            }
44
        }
45
46 45
        $filename = $fs->getPath('.cache/mapper-meta.php');
47 45
        if (file_exists($filename)) {
48
            unlink($filename);
49
        }
50 45
    }
51
}
52