Skip to content

Commit 05c3fef

Browse files
committed
Merge pull request #674 from LearningLocker/issue/voiding-api
Fixes voiding API issues.
2 parents 40dcf61 + 9ca2597 commit 05c3fef

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

app/locker/repository/Query/EloquentQueryRepository.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ public function void(array $match, array $opts) {
149149

150150
$opts['authority'] = json_decode(json_encode($opts['client']['authority']));
151151

152-
return (new StatementsRepo())->store(json_decode(json_encode($statements)), [], $opts);
152+
if( count($statements) > 0 ){
153+
return (new StatementsRepo())->store(json_decode(json_encode($statements)), [], $opts);
154+
} else {
155+
return [];
156+
}
153157
}
154158

155159
/**

app/locker/repository/Statement/EloquentInserter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private function checkForConflict(\stdClass $statement, StoreOptions $opts) {
4747
* @param \stdClass $statement_y
4848
* @throws Exceptions\Conflict
4949
*/
50-
private function compareForConflict(\stdClass $statement_x, \stdClass $statement_y) {
50+
public function compareForConflict(\stdClass $statement_x, \stdClass $statement_y) {
5151
$matchable_x = $this->matchableStatement($statement_x);
5252
$matchable_y = $this->matchableStatement($statement_y);
5353
if ($matchable_x != $matchable_y) {

app/locker/repository/Statement/EloquentStorer.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function store(array $statements, array $attachments, StoreOptions $opts)
5252
* @return [String => \stdClass] Array of statements mapped to their UUIDs.
5353
*/
5454
private function constructValidStatements(array $statements, StoreOptions $opts) {
55+
$generated_ids = [];
5556
$constructed = [];
5657
$this->hashes = [];
5758

@@ -64,7 +65,8 @@ private function constructValidStatements(array $statements, StoreOptions $opts)
6465
}
6566

6667
if (!isset($statement->id)) {
67-
$statement->id = $this->getUUID();
68+
$statement->id = $this->getUUID($generated_ids);
69+
$generated_ids[] = $statement->id;
6870
}
6971

7072
// Validates statement.
@@ -102,18 +104,25 @@ private function activateStatements(array $ids, StoreOptions $opts) {
102104

103105
/**
104106
* Generates a UUID.
107+
* @param $excludes An array of ids to check that the new id is unique against
105108
* @return String
106109
*/
107-
private function getUUID() {
110+
private function getUUID($exclude=[]) {
108111
$remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'LL';
109112
mt_srand(crc32(serialize([microtime(true), $remote_addr, 'ETC'])));
110113

111-
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
114+
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
112115
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
113116
mt_rand(0, 0xffff),
114117
mt_rand(0, 0x0fff) | 0x4000,
115118
mt_rand(0, 0x3fff) | 0x8000,
116119
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
117120
);
121+
122+
if( in_array($uuid, $exclude)){
123+
return $this->getUUID($exclude);
124+
} else {
125+
return $uuid;
126+
}
118127
}
119128
}

app/tests/routes/StatementsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testAggregateObject() {
103103

104104
public function testWhere() {
105105
$response = $this->requestStatements('where', [
106-
'filter' => '[[{"active", true}]]',
106+
'filters' => '[[{"active", true}]]',
107107
'limit' => 1,
108108
'page' => 1
109109
]);

0 commit comments

Comments
 (0)