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

SoftDelete::revert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
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 SoftDelete extends Delete
9
{
10
    private $entityId;
0 ignored issues
show
introduced by
The private property $entityId is not used, and could be removed.
Loading history...
11
    private $entityState;
0 ignored issues
show
introduced by
The private property $entityState is not used, and could be removed.
Loading history...
12
13
    protected function execute()
14
    {
15
        $entityId = $this->entity->getPk();
16
        if (! $entityId) {
17
            return;
18
        }
19
20
        $this->now = time();
0 ignored issues
show
Bug Best Practice introduced by
The property now does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
22
        $update = new \Sirius\Sql\Update($this->mapper->getWriteConnection());
23
        $update->table($this->mapper->getTable())
24
               ->columns([
25
                   $this->getOption('deleted_at_column') => $this->now
26
               ])
27
               ->where('id', $entityId);
28
        $update->perform();
29
    }
30
31
    public function onSuccess()
32
    {
33
        $this->mapper->setEntityAttribute($this->entity, $this->getOption('deleted_at_column'), $this->now);
34
        if ($this->entity->getPersistenceState() !== StateEnum::DELETED) {
35
            $this->entity->setPersistenceState(StateEnum::DELETED);
36
        }
37
    }
38
}
39