@@ -17,25 +17,25 @@ discard block |
||
17 | 17 | 'timestamp' => 'deleted_date' |
18 | 18 | ]; |
19 | 19 | |
20 | - public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary){ |
|
20 | + public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary) { |
|
21 | 21 | $getOptions = $query->getOptions(); |
22 | 22 | if ( |
23 | - !array_key_exists('enableSoftDelete',$getOptions) || |
|
23 | + !array_key_exists('enableSoftDelete', $getOptions) || |
|
24 | 24 | $getOptions['enableSoftDelete'] == true |
25 | - ){ |
|
25 | + ) { |
|
26 | 26 | $modelName = $this->_table->alias(); |
27 | - if ($this->config('boolean') !== false){ |
|
28 | - $query->where([$modelName . '.' . $this->_config['boolean'] => false]); |
|
27 | + if ($this->config('boolean') !== false) { |
|
28 | + $query->where([$modelName.'.'.$this->_config['boolean'] => false]); |
|
29 | 29 | } |
30 | - if ($this->_config['boolean'] === false && $this->_config['timestamp'] !== false){ |
|
31 | - $query->where([$modelName . '.' . $this->_config['timestamp'].' IS' => null]); |
|
30 | + if ($this->_config['boolean'] === false && $this->_config['timestamp'] !== false) { |
|
31 | + $query->where([$modelName.'.'.$this->_config['timestamp'].' IS' => null]); |
|
32 | 32 | } |
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
36 | - public function softDelete($deleteEntity){ |
|
36 | + public function softDelete($deleteEntity) { |
|
37 | 37 | //データがぞんざいしない場合はエラー |
38 | - if (!$this->dataExist($deleteEntity->{$this->_table->primaryKey()})){ |
|
38 | + if (!$this->dataExist($deleteEntity->{$this->_table->primaryKey()})) { |
|
39 | 39 | return false; |
40 | 40 | } |
41 | 41 | |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | $now = Time::now(); |
45 | 45 | |
46 | 46 | $delete_data = []; |
47 | - if ($this->_config['boolean'] !== false){ |
|
47 | + if ($this->_config['boolean'] !== false) { |
|
48 | 48 | $delete_data[$this->_config['boolean']] = true; |
49 | 49 | } |
50 | - if ($this->_config['timestamp'] !== false){ |
|
50 | + if ($this->_config['timestamp'] !== false) { |
|
51 | 51 | $delete_data[$this->_config['timestamp']] = $now; |
52 | 52 | } |
53 | 53 | $saveEntity = $this->_table->patchEntity( |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | |
61 | 61 | $behavior = $this; |
62 | 62 | |
63 | - $result = $this->_table->connection()->transactional(function () use ($behavior, $saveEntity, $id) { |
|
63 | + $result = $this->_table->connection()->transactional(function() use ($behavior, $saveEntity, $id) { |
|
64 | 64 | //削除データの保存に失敗 |
65 | - if (!$behavior->_table->save($saveEntity,['atomic' => false])){ |
|
65 | + if (!$behavior->_table->save($saveEntity, ['atomic' => false])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | //最終的に存在していなければOK |
69 | - if ($behavior->dataExist($id)){ |
|
69 | + if ($behavior->dataExist($id)) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | return true; |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | return $result; |
76 | 76 | } |
77 | 77 | |
78 | - private function dataExist($id){ |
|
78 | + private function dataExist($id) { |
|
79 | 79 | //数値などのチェック |
80 | - if (!$id || !Validation::naturalNumber($id)){ |
|
80 | + if (!$id || !Validation::naturalNumber($id)) { |
|
81 | 81 | return false; |
82 | 82 | } |
83 | 83 | |
84 | 84 | $data = $this->_table->find() |
85 | - ->where([$this->_table->alias() . '.' . $this->_table->primaryKey() => $id]) |
|
85 | + ->where([$this->_table->alias().'.'.$this->_table->primaryKey() => $id]) |
|
86 | 86 | ->first(); |
87 | 87 | ; |
88 | 88 | return !empty($data); |