@@ -209,7 +209,6 @@ protected function processRelations(\Magento\Framework\Model\AbstractModel $obje
209
209
* @param \Magento\Framework\Model\AbstractModel $object
210
210
* @return $this
211
211
* @throws \Exception
212
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
213
212
*/
214
213
public function save (\Magento \Framework \Model \AbstractModel $ object )
215
214
{
@@ -232,38 +231,12 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
232
231
$ this ->objectRelationProcessor ->validateDataIntegrity ($ this ->getMainTable (), $ object ->getData ());
233
232
if ($ object ->getId () !== null && (!$ this ->_useIsObjectNew || !$ object ->isObjectNew ())) {
234
233
$ condition = $ this ->_getWriteAdapter ()->quoteInto ($ this ->getIdFieldName () . '=? ' , $ object ->getId ());
235
- /**
236
- * Not auto increment primary key support
237
- */
238
- if ($ this ->_isPkAutoIncrement ) {
239
- $ data = $ this ->prepareDataForUpdate ($ object );
240
- if (!empty ($ data )) {
241
- $ this ->_getWriteAdapter ()->update ($ this ->getMainTable (), $ data , $ condition );
242
- }
243
- } else {
244
- $ select = $ this ->_getWriteAdapter ()->select ()->from (
245
- $ this ->getMainTable (),
246
- [$ this ->getIdFieldName ()]
247
- )->where (
248
- $ condition
249
- );
250
- if ($ this ->_getWriteAdapter ()->fetchOne ($ select ) !== false ) {
251
- $ data = $ this ->prepareDataForUpdate ($ object );
252
- if (!empty ($ data )) {
253
- $ this ->_getWriteAdapter ()->update ($ this ->getMainTable (), $ data , $ condition );
254
- }
255
- } else {
256
- $ this ->_getWriteAdapter ()->insert (
257
- $ this ->getMainTable (),
258
- $ this ->_prepareDataForSave ($ object )
259
- );
260
- }
261
- }
234
+ $ data = $ this ->_prepareDataForSave ($ object );
235
+ unset($ data [$ this ->getIdFieldName ()]);
236
+ $ this ->_getWriteAdapter ()->update ($ this ->getMainTable (), $ data , $ condition );
262
237
} else {
263
238
$ bind = $ this ->_prepareDataForSave ($ object );
264
- if ($ this ->_isPkAutoIncrement ) {
265
- unset($ bind [$ this ->getIdFieldName ()]);
266
- }
239
+ unset($ bind [$ this ->getIdFieldName ()]);
267
240
$ this ->_getWriteAdapter ()->insert ($ this ->getMainTable (), $ bind );
268
241
269
242
$ object ->setId ($ this ->_getWriteAdapter ()->lastInsertId ($ this ->getMainTable ()));
@@ -272,10 +245,9 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
272
245
$ object ->isObjectNew (false );
273
246
}
274
247
}
275
-
276
248
$ this ->unserializeFields ($ object );
277
249
$ this ->_afterSave ($ object );
278
-
250
+ $ this -> entitySnapshot -> registerSnapshot ( $ object );
279
251
$ object ->afterSave ();
280
252
$ this ->processRelations ($ object );
281
253
}
0 commit comments