Passed
Push — master ( ea0818...92b4a6 )
by Adrian
01:28
created

Delete::revert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Action;
5
6
use Sirius\Orm\Entity\StateEnum;
7
8
class Delete extends BaseAction
9
{
10
    protected function execute()
11
    {
12
        $conditions = $this->getConditions();
13
14
        if (empty($conditions)) {
15
            return;
16
        }
17
18
        $delete = new \Sirius\Sql\Delete($this->mapper->getWriteConnection());
19
        $delete->from($this->mapper->getTable());
20
        $delete->whereAll($conditions, false);
21
22
        $delete->perform();
23
    }
24
25
    public function onSuccess()
26
    {
27
        if ($this->entity->getPersistenceState() !== StateEnum::DELETED) {
28
            $this->entity->setPk(null);
29
            $this->entity->setPersistenceState(StateEnum::DELETED);
30
        }
31
    }
32
}
33