ReverseMove::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
ccs 23
cts 23
cp 1
rs 9.504
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Maketok\DataMigration\Action\Type;
4
5
use Maketok\DataMigration\Action\ActionInterface;
6
use Maketok\DataMigration\Unit\ExportDbUnitInterface;
7
use Maketok\DataMigration\Unit\ImportDbUnitInterface;
8
use Maketok\DataMigration\Unit\ImportFileUnitInterface;
9
use Maketok\DataMigration\Unit\UnitBagInterface;
10
use Maketok\DataMigration\Workflow\ResultInterface;
11
12
/**
13
 * Move data from main table to tmp one
14
 */
15
class ReverseMove extends AbstractDbAction implements ActionInterface
16
{
17
    /**
18
     * @var UnitBagInterface|ExportDbUnitInterface[]|ImportFileUnitInterface[]|ImportDbUnitInterface[]
19
     */
20
    protected $bag;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    public function process(ResultInterface $result)
26
    {
27 3
        $result->setActionStartTime($this->getCode(), new \DateTime());
28 3
        foreach ($this->bag as $unit) {
29 3
            $unit->setTmpTable($this->getTmpTableName($unit));
30 3
            $values = array_map(function () {
31 2
                return ['text', ['notnull' => false]];
32 3
            }, $unit->getMapping());
33 3
            $this->resource->createTmpTable(
34 3
                $unit->getTmpTable(),
35 3
                array_combine(array_keys($unit->getMapping()), $values)
36 3
            );
37 3
            $moved = $this->resource->move(
38 3
                $unit->getTable(),
39 3
                $unit->getTmpTable(),
40 3
                array_keys($unit->getMapping()),
41
                // set export filters
42 3
                $unit->getReverseMoveConditions(),
43
                // need to be able to set order, as assemble depends on that
44 3
                $unit->getReverseMoveOrder(),
45 3
                $unit->getReverseMoveDirection()
46 3
            );
47 3
            $result->incrementActionProcessed($this->getCode(), $moved);
48 3
        }
49 3
        $result->setActionEndTime($this->getCode(), new \DateTime());
50 3
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 4
    public function getCode()
56
    {
57 4
        return 'reverse_move';
58
    }
59
}
60