Skip to content

Commit 3c43984

Browse files
author
daniel-abbey
committed
Merge pull request #687 from LearningLocker/develop
v1.6.1
2 parents 6ddb0ff + 1e6b707 commit 3c43984

File tree

9 files changed

+114
-43
lines changed

9 files changed

+114
-43
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ before_script:
1717
- php artisan migrate --env="testing"
1818

1919
script: ./vendor/bin/phpunit
20+
after_success: sh test.sh
2021

2122
notifications:
2223
slack:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.0
1+
1.6.1

app/config/local/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
'Jenssegers\Mongodb\Auth\ReminderServiceProvider',
66
)),
77

8-
'debug' => false,
8+
'debug' => true,
99
);

app/locker/data/dashboards/AdminDashboard.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,40 @@ public function lrsCount(){
5858
*
5959
**/
6060
public function actorCount(){
61-
$mbox = intval( \Statement::distinct('statement.actor.mbox')->remember(5)->count() );
62-
$openid = intval( \Statement::distinct('statement.actor.openid')->remember(5)->count() );
63-
$mbox_sha1sum = intval( \Statement::distinct('statement.actor.mbox_sha1sum')->remember(5)->count() );
64-
$account = intval( \Statement::distinct('statement.actor.account.name')->remember(5)->count() );
65-
return ($mbox + $openid + $mbox_sha1sum + $account);
61+
$count_array = ['mbox' => '', 'openid' => '', 'mbox_sha1sum' => '', 'account' => ''];
62+
63+
$count_array['mbox'] = $this->db->statements->aggregate([
64+
['$match' => ['statement.actor.mbox' => ['$exists' => true]]],
65+
['$group' => ['_id' => '$statement.actor.mbox']],
66+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
67+
]);
68+
69+
$count_array['openid'] = $this->db->statements->aggregate([
70+
['$match' => ['statement.actor.openid' => ['$exists' => true]]],
71+
['$group' => ['_id' => '$statement.actor.openid']],
72+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
73+
]);
74+
75+
$count_array['mbox_sha1sum'] = $this->db->statements->aggregate([
76+
['$match' => ['statement.actor.mbox_sha1sum' => ['$exists' => true]]],
77+
['$group' => ['_id' => '$statement.actor.mbox_sha1sum']],
78+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
79+
]);
80+
81+
$count_array['account'] = $this->db->statements->aggregate([
82+
['$match' => ['statement.actor.account' => ['$exists' => true]]],
83+
['$group' => ['_id' => ['accountName' => '$statement.actor.account.name', 'accountHomePage' => '$statement.actor.account.homePage']]],
84+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
85+
]);
86+
87+
$summary = 0;
88+
foreach ($count_array as $key => $val) {
89+
if( isset($val['result'][0]) ){
90+
$summary += $val['result'][0]['count'];
91+
}
92+
}
93+
94+
return $summary;
6695
}
6796

6897
/**

app/locker/data/dashboards/LrsDashboard.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,29 @@ public function statementCount(){
5454
public function actorCount(){
5555
$count_array = ['mbox' => '', 'openid' => '', 'mbox_sha1sum' => '', 'account' => ''];
5656

57-
$count_array['mbox'] = $this->db->statements->aggregate(
58-
['$match' => $this->getMatch( $this->lrs )],
59-
['$group' => ['_id' => '$statement.actor.mbox']],
60-
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
61-
);
57+
$count_array['mbox'] = $this->db->statements->aggregate([
58+
['$match' => ['lrs._id' => $this->lrs, 'statement.actor.mbox' => ['$exists' => true]]],
59+
['$group' => ['_id' => '$statement.actor.mbox']],
60+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
61+
]);
6262

63-
$count_array['openid'] = $this->db->statements->aggregate(
64-
['$match' => $this->getMatch( $this->lrs )],
65-
['$group' => ['_id' => '$statement.actor.openid']],
66-
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
67-
);
63+
$count_array['openid'] = $this->db->statements->aggregate([
64+
['$match' => ['lrs._id' => $this->lrs, 'statement.actor.openid' => ['$exists' => true]]],
65+
['$group' => ['_id' => '$statement.actor.openid']],
66+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
67+
]);
6868

69-
$count_array['mbox_sha1sum'] = $this->db->statements->aggregate(
70-
['$match' => $this->getMatch( $this->lrs )],
71-
['$group' => ['_id' => '$statement.actor.mbox_sha1sum']],
72-
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
73-
);
69+
$count_array['mbox_sha1sum'] = $this->db->statements->aggregate([
70+
['$match' => ['lrs._id' => $this->lrs, 'statement.actor.mbox_sha1sum' => ['$exists' => true]]],
71+
['$group' => ['_id' => '$statement.actor.mbox_sha1sum']],
72+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
73+
]);
7474

75-
$count_array['account'] = $this->db->statements->aggregate(
76-
['$match' => $this->getMatch( $this->lrs )],
77-
['$group' => ['_id' => ['accountName' => '$statement.actor.account.name', 'accountHomePage' => '$statement.actor.account.homePage']]],
78-
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
79-
);
75+
$count_array['account'] = $this->db->statements->aggregate([
76+
['$match' => ['lrs._id' => $this->lrs, 'statement.actor.account' => ['$exists' => true]]],
77+
['$group' => ['_id' => ['accountName' => '$statement.actor.account.name', 'accountHomePage' => '$statement.actor.account.homePage']]],
78+
['$group' => ['_id' => 1, 'count' => ['$sum' => 1]]]
79+
]);
8080

8181
$summary = 0;
8282
foreach ($count_array as $key => $val) {

app/locker/repository/Query/EloquentQueryRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use \Cache as IlluminateCache;
33
use \Carbon\Carbon as Carbon;
44
use \Locker\Helpers\Helpers as Helpers;
5+
use \Locker\Helpers\Exceptions as Exceptions;
56
use \Locker\Repository\Statement\EloquentRepository as StatementsRepo;
67

78
class EloquentQueryRepository implements QueryRepository {
@@ -154,7 +155,7 @@ public function aggregateObject($opts, array $match) {
154155
* @return [String] Ids of the inserted statements.
155156
*/
156157
public function insert(array $pipeline, array $opts) {
157-
$statements = $this->aggregate($opts['lrs_id'], $pipeline)['result'];
158+
$statements = $this->aggregate($opts, $pipeline)['result'];
158159

159160
if (count($statements) > 0) {
160161
$opts['authority'] = json_decode(json_encode($opts['client']['authority']));

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
}

test.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env sh
2+
3+
DEVELOP="develop"
4+
5+
if [ "${DEVELOP}" = "${TRAVIS_BRANCH}" ]; then
6+
echo "Running conformance tests."
7+
8+
# Starts the server.
9+
sudo chmod -R 777 *
10+
php artisan serve --env=testing --host 0.0.0.0 --port=8000 &
11+
12+
# Creates a new User.
13+
mongo ll_staging --eval 'db.users.insert({"name" : "Test User", "email" : "[email protected]", "verified" : "yes", "role" : "super", "password" : "$2y$10$MKDC2thihULF3fNuVj.DyORidVd.airmxZicEcSrpNQRsJMX3ZGBW"})'
14+
15+
# Creates a new LRS.
16+
mongo ll_staging --eval 'db.lrs.insert({"title" : "Conformance", "description" : "", "owner" : { "_id" : db.users.find()[0]._id}})'
17+
18+
# Creates a new Client.
19+
mongo ll_staging --eval 'db.client.insert({"api" : { "basic_key" : "1484c2ac05269b8c5479a1dd6a0d6370991fd6a1", "basic_secret" : "f0ef3d8062805c0fc1675beb8ac0715c75df13cb" }, "lrs_id" : db.lrs.find()[0]._id, "authority" : { "name" : "New Client", "mbox" : "mailto:[email protected]" }, "scopes" : [ "all" ]})'
20+
21+
# Runs the test suite.
22+
git clone https://github.com/ryansmith94/xAPI_LRS_Test.git conformance > /dev/null
23+
cd conformance
24+
git checkout travis > /dev/null
25+
cd src
26+
npm install -g grunt-cli > /dev/null
27+
npm install > /dev/null
28+
grunt --bail --reporter=dot --endpoint="http://0.0.0.0:8000/data/xAPI/" --username="1484c2ac05269b8c5479a1dd6a0d6370991fd6a1" --password="f0ef3d8062805c0fc1675beb8ac0715c75df13cb" --xapi-version="1.0.1"
29+
30+
# Stops the server.
31+
ps aux | grep [p]hp | awk '{print $2}' | xargs kill
32+
echo "Stopped the server."
33+
34+
echo "Completed conformance tests."
35+
else
36+
echo "Not running conformance tests."
37+
fi

0 commit comments

Comments
 (0)