@@ -16,11 +16,15 @@ class EloquentInserter extends EloquentReader implements Inserter {
1616 * @throws Exceptions\Conflict
1717 */
1818 public function insert (array $ statements , StoreOptions $ opts ) {
19- $ models = array_map (function (\stdClass $ statement ) use ($ opts ) {
20- $ this ->checkForConflict ($ statement , $ opts );
21- return $ this ->constructModel ($ statement , $ opts );
22- }, $ statements );
19+ $ models = [];
2320
21+ foreach ($ statements as $ statement ) {
22+ $ duplicate = $ this ->checkForConflict ($ statement , $ opts );
23+ if (!$ duplicate ) {
24+ $ models [] = $ this ->constructModel ($ statement , $ opts );
25+ }
26+ }
27+
2428 return $ this ->insertModels ($ models , $ opts );
2529 }
2630
@@ -36,8 +40,9 @@ private function checkForConflict(\stdClass $statement, StoreOptions $opts) {
3640 ->where ('active ' , true )
3741 ->first ();
3842
39- if ($ duplicate === null ) return ;
43+ if ($ duplicate === null ) return false ;
4044 $ this ->compareForConflict ($ statement , $ this ->formatModel ($ duplicate ));
45+ return true ;
4146 }
4247
4348 /**
@@ -68,6 +73,7 @@ public function compareForConflict(\stdClass $statement_x, \stdClass $statement_
6873 private function matchableStatement (\stdClass $ statement ) {
6974 $ statement = json_decode (json_encode ($ statement ));
7075 unset($ statement ->stored );
76+ unset($ statement ->timestamp );
7177 unset($ statement ->authority );
7278 return $ statement ;
7379 }
@@ -95,6 +101,9 @@ private function constructModel(\stdClass $statement, StoreOptions $opts) {
95101 * @param StoreOptions $opts
96102 */
97103 private function insertModels (array $ models , StoreOptions $ opts ) {
104+ if (empty ($ models )) {
105+ return ;
106+ }
98107 return $ this ->where ($ opts )->insert ($ models );
99108 }
100109}
0 commit comments