Completed
Push — master ( ae3422...9751eb )
by Dmitry
02:51
created

Clear::run()   C

Complexity

Conditions 7
Paths 24

Size

Total Lines 39
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7.0099

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 39
ccs 16
cts 17
cp 0.9412
rs 6.7272
cc 7
eloc 16
nc 24
nop 2
crap 7.0099
1
<?php
2
3
namespace Basis\Job\Tarantool;
4
5
use Basis\Job;
6
use Tarantool\Client\Client;
7
use Tarantool\Client\Schema\Index;
8
use Basis\Filesystem;
9
10
class Clear extends Job
11
{
12 27
    public function run(Client $client, Filesystem $fs)
13
    {
14 27
        $space = $client->getSpace('_vspace');
15
16 27
        $client->evaluate("
17
            if box.space._queue ~= nil then
18
                if queue == nil then
19
                    queue = require('queue')
20
                end
21
                for i, q in box.space._queue:pairs() do
22
                    queue.tube[q.tube_name]:drop()
23
                end
24
            end
25
        ");
26
27 27
        $response = $space->select([], Index::SPACE_NAME);
28 27
        $data = $response->getData();
29
30 27
        foreach ($data as $row) {
31 27
            if ($row[1] == 0) {
32
                // user space
33 27
                if (strpos($row[2], '_queue') === false) {
34 27
                    $client->evaluate('box.space.'.$row[2].':drop()');
35
                }
36
            }
37
        }
38
39 27
        $schema = $client->getSpace('_schema')->select([], 0)->getData();
40 27
        foreach ($schema as $tuple) {
41 27
            if (strpos($tuple[0], 'mapper-once') === 0) {
42 27
                $client->getSpace('_schema')->delete([$tuple[0]]);
43
            }
44
        }
45
46 27
        $filename = $fs->getPath('.cache/mapper-meta.php');
47 27
        if (file_exists($filename)) {
48
            unlink($filename);
49
        }
50 27
    }
51
}
52