Total Complexity | 3 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Insert extends Update |
||
9 | { |
||
10 | protected $entityId; |
||
11 | protected $entityState; |
||
12 | |||
13 | protected $extraColumns = []; |
||
14 | |||
15 | protected function execute() |
||
16 | { |
||
17 | $this->entityId = $this->mapper->getEntityPk($this->entity); |
||
18 | $this->entityState = $this->entity->getPersistenceState(); |
||
19 | |||
20 | $connection = $this->mapper->getWriteConnection(); |
||
21 | |||
22 | $columns = array_merge( |
||
23 | $this->mapper->extractFromEntity($this->entity), |
||
24 | $this->extraColumns, |
||
25 | $this->mapper->getGuards() |
||
26 | ); |
||
27 | $columns = Arr::except($columns, $this->mapper->getPrimaryKey()); |
||
28 | |||
29 | $insertSql = new \Sirius\Sql\Insert($connection); |
||
30 | $insertSql->into($this->mapper->getTable()) |
||
31 | ->columns($columns); |
||
32 | $insertSql->perform(); |
||
33 | $this->mapper->setEntityPk($this->entity, $connection->lastInsertId()); |
||
34 | } |
||
35 | |||
36 | public function revert() |
||
43 | } |
||
44 | } |
||
45 |