Skip to content

Commit 4aea311

Browse files
author
daniel-abbey
committed
Merge pull request #688 from LearningLocker/issue/684
Fix #684
2 parents 5f1ccab + f68808b commit 4aea311

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

app/locker/repository/Statement/EloquentInserter.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/locker/repository/Statement/EloquentStorer.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,9 @@ private function activateStatements(array $ids, StoreOptions $opts) {
104104

105105
/**
106106
* Generates a UUID.
107-
* @param $excludes An array of ids to check that the new id is unique against
108107
* @return String
109108
*/
110-
private function getUUID($exclude=[]) {
111-
$remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'LL';
112-
mt_srand(crc32(serialize([microtime(true), $remote_addr, 'ETC'])));
109+
private function getUUID() {
113110

114111
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
115112
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
@@ -118,11 +115,8 @@ private function getUUID($exclude=[]) {
118115
mt_rand(0, 0x3fff) | 0x8000,
119116
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
120117
);
121-
122-
if( in_array($uuid, $exclude)){
123-
return $this->getUUID($exclude);
124-
} else {
125-
return $uuid;
126-
}
118+
119+
return $uuid;
120+
127121
}
128122
}

0 commit comments

Comments
 (0)