@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function getDtoCopy($cleanPk = false) { |
| 45 | 45 | $copy = clone $this->dto; |
| 46 | - if($cleanPk) { |
|
| 46 | + if ($cleanPk) { |
|
| 47 | 47 | $this->dto->resetPk(); |
| 48 | 48 | } |
| 49 | 49 | return $copy; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function save(Database $con = null) { |
| 61 | 61 | $saved = false; |
| 62 | - if(null === $con) { |
|
| 62 | + if (null === $con) { |
|
| 63 | 63 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 64 | 64 | } |
| 65 | 65 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $isInsert = $isUpdate = false; |
| 68 | 68 | $this->prepareData(); |
| 69 | 69 | $this->dto->setLastUpdate(); |
| 70 | - if($this->isNew()) { |
|
| 70 | + if ($this->isNew()) { |
|
| 71 | 71 | $this->preInsert($con); |
| 72 | 72 | $isInsert = true; |
| 73 | 73 | } elseif ($this->isModified()) { |
@@ -75,19 +75,19 @@ discard block |
||
| 75 | 75 | $isUpdate = true; |
| 76 | 76 | } |
| 77 | 77 | $result = $collection->insertOne($this->toArray()); |
| 78 | - if($result->getInsertedCount() > 0) { |
|
| 78 | + if ($result->getInsertedCount() > 0) { |
|
| 79 | 79 | $id = $result->getInsertedId(); |
| 80 | 80 | $this->dto->setPk($id->jsonSerialize()['$oid']); |
| 81 | - if($isInsert) { |
|
| 81 | + if ($isInsert) { |
|
| 82 | 82 | $this->postInsert($con); |
| 83 | - } elseif($isUpdate) { |
|
| 83 | + } elseif ($isUpdate) { |
|
| 84 | 84 | $this->postUpdate($con); |
| 85 | 85 | } |
| 86 | 86 | $saved = true; |
| 87 | 87 | $this->countAction(); |
| 88 | 88 | } |
| 89 | - } catch(\Exception $exception) { |
|
| 90 | - if($exception instanceof NOSQLValidationException) { |
|
| 89 | + } catch (\Exception $exception) { |
|
| 90 | + if ($exception instanceof NOSQLValidationException) { |
|
| 91 | 91 | throw $exception; |
| 92 | 92 | } else { |
| 93 | 93 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function update(Database $con = null) { |
| 104 | 104 | $updated = false; |
| 105 | - if(null === $con) { |
|
| 105 | + if (null === $con) { |
|
| 106 | 106 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 107 | 107 | } |
| 108 | 108 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | $this->postUpdate($con); |
| 117 | 117 | $updated = true; |
| 118 | 118 | $this->countAction(); |
| 119 | - } catch(\Exception $exception) { |
|
| 120 | - if($exception instanceof NOSQLValidationException) { |
|
| 119 | + } catch (\Exception $exception) { |
|
| 120 | + if ($exception instanceof NOSQLValidationException) { |
|
| 121 | 121 | throw $exception; |
| 122 | 122 | } else { |
| 123 | 123 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function bulkInsert(array $data, Database $con = null) { |
| 135 | 135 | $inserts = 0; |
| 136 | - if(null === $con) { |
|
| 136 | + if (null === $con) { |
|
| 137 | 137 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 138 | 138 | } |
| 139 | 139 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $ids = $result->getInsertedIds(); |
| 144 | 144 | $inserts = $this->parseInsertedDtos($con, $ids, $dtos); |
| 145 | 145 | $this->setActionCount($inserts); |
| 146 | - } catch(\Exception $exception) { |
|
| 146 | + } catch (\Exception $exception) { |
|
| 147 | 147 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 148 | 148 | } |
| 149 | 149 | return $inserts; |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | $upserts = 0; |
| 161 | 161 | $filters = $options = []; |
| 162 | 162 | |
| 163 | - if(null === $con) { |
|
| 163 | + if (null === $con) { |
|
| 164 | 164 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 165 | 165 | } |
| 166 | 166 | $collection = $con->selectCollection($this->getSchema()->name); |
| 167 | 167 | |
| 168 | - foreach($data as $item) { |
|
| 168 | + foreach ($data as $item) { |
|
| 169 | 169 | try { |
| 170 | 170 | $filters[$id] = ['$eq' => $item[$id]]; |
| 171 | 171 | $updateSet = []; |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function delete(Database $con = null) { |
| 193 | 193 | $deleted = false; |
| 194 | - if(null === $con) { |
|
| 194 | + if (null === $con) { |
|
| 195 | 195 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 196 | 196 | } |
| 197 | 197 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $deleted = true; |
| 203 | 203 | $this->dto = null; |
| 204 | 204 | $this->countAction(); |
| 205 | - } catch(\Exception $exception) { |
|
| 205 | + } catch (\Exception $exception) { |
|
| 206 | 206 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 207 | 207 | } |
| 208 | 208 | return $deleted; |
@@ -216,14 +216,14 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function bulkDelete(array $filters, Database $con = null) { |
| 218 | 218 | $deletedCount = 0; |
| 219 | - if(null === $con) { |
|
| 219 | + if (null === $con) { |
|
| 220 | 220 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 221 | 221 | } |
| 222 | 222 | $collection = $con->selectCollection($this->getSchema()->name); |
| 223 | 223 | try { |
| 224 | 224 | $result = $collection->deleteMany($filters); |
| 225 | 225 | $deletedCount = $result->getDeletedCount(); |
| 226 | - } catch(\Exception $exception) { |
|
| 226 | + } catch (\Exception $exception) { |
|
| 227 | 227 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 228 | 228 | } |
| 229 | 229 | return $deletedCount; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $dtos = []; |
| 241 | 241 | /** @var NOSQLModelDto $dto */ |
| 242 | 242 | foreach ($data as &$insertData) { |
| 243 | - if(is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
| 243 | + if (is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
| 244 | 244 | $dto = clone $insertData; |
| 245 | 245 | } else { |
| 246 | 246 | $dto = $this->getDtoCopy(true); |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | foreach ($ids as $index => $insertedId) { |
| 271 | 271 | $id = $insertedId->jsonSerialize(); |
| 272 | 272 | $dto = $dtos[$index]; |
| 273 | - if($dto instanceof NOSQLModelDto) { |
|
| 273 | + if ($dto instanceof NOSQLModelDto) { |
|
| 274 | 274 | $dto->setPk($id['$oid']); |
| 275 | 275 | } else { |
| 276 | 276 | |