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

Clear::run()   B

Complexity

Conditions 7
Paths 24

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7.0119

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 15
cts 16
cp 0.9375
rs 8.3786
c 0
b 0
f 0
cc 7
nc 24
nop 2
crap 7.0119
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