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

Clear   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 94.12%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 0
cbo 5
dl 0
loc 42
ccs 16
cts 17
cp 0.9412
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C run() 0 39 7
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