Skip to content

Commit 6887396

Browse files
authored
Merge pull request #827 from LearningLocker/develop
v.1.13.0
2 parents 627be8f + 305b7dd commit 6887396

File tree

13 files changed

+560
-315
lines changed

13 files changed

+560
-315
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Learning Locker Logo](http://learninglocker.net/wp-content/uploads/2013/12/ll-logo-sm.png)](http://learninglocker.net)
1+
[![Learning Locker Logo](http://i.imgur.com/w7SEoF6.png)](http://learninglocker.net)
22
> An open source Learning Record Store (LRS) implementing the [xAPI](https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md) ([Tin Can API](http://tincanapi.com/)).
33
44
[![Build Status](https://travis-ci.org/LearningLocker/learninglocker.svg?branch=master)](https://travis-ci.org/LearningLocker/learninglocker)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.12.1
1+
1.13.0

app/controllers/LrsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public function statements($lrs_id){
197197
'scopes' => ['all']
198198
]),
199199
'scopes' => ['all']
200-
]))->orderBy('stored', 'DESC')->paginate(15);
200+
]))->orderBy('stored', 'DESC')->paginate(15, ['*'], ['lrs_id'=>1], ['lrs_id'=>1, 'active'=>-1, 'voided'=>1]);
201+
201202
return View::make('partials.statements.list', array_merge($this->getLrs($lrs_id), [
202203
'statements' => $statements,
203204
'statement_nav' => true,

app/controllers/xapi/StatementStoreController.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use \Locker\XApi\IMT as XApiImt;
88
use \LockerRequest as LockerRequest;
99
use \Response as IlluminateResponse;
10+
use Seld\JsonLint\JsonParser as JsonParser;
1011

1112
class StatementStoreController {
1213

@@ -102,11 +103,21 @@ private function createStatements($options, Callable $modifier = null) {
102103
$content = $parts['content'];
103104

104105
// Decodes $statements from $content.
105-
$statements = json_decode($content);
106-
if ($statements === null && $content !== '') {
107-
throw new Exceptions\Exception('Invalid JSON');
108-
} else if ($statements === null) {
109-
$statements = [];
106+
$jsonParser = new JsonParser;
107+
try {
108+
$jsonParser->parse($content, JsonParser::DETECT_KEY_CONFLICTS); // this will catch any parsing issues
109+
110+
$statements = json_decode($content);
111+
if ($statements === null && $content !== '') {
112+
throw new Exceptions\Exception('Invalid JSON');
113+
} else if ($statements === null) {
114+
$statements = [];
115+
}
116+
} catch (\Seld\JsonLint\DuplicateKeyException $e) {
117+
$details = $e->getDetails();
118+
throw new Exceptions\Exception(sprintf('Invalid JSON: `%s` is a duplicate key on line %s', $details['key'], $details['line']));
119+
} catch (\Exception $e) { // some other parsing error occured
120+
throw new Exceptions\Exception('Invalid JSON: JSON could not be parsed');
110121
}
111122

112123
// Ensures that $statements is an array.

app/database/migrations/2015_12_23_093122_add_stored_to_statement_root.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function up()
5151
$timestamp = new Carbon\Carbon($refStatement['timestamp']);
5252
$query['u']['$set']['refs.'.$key.'.timestamp'] = new \MongoDate($timestamp->timestamp, $timestamp->micro);
5353
}
54-
if(isset($refStatement['stored']) && !$stored['stored'] instanceof MongoDate) {
54+
if(isset($refStatement['stored']) && !$refStatement['stored'] instanceof MongoDate) {
5555
$stored = new Carbon\Carbon($refStatement['stored']);
5656
$query['u']['$set']['refs.'.$key.'.stored'] = new \MongoDate($stored->timestamp, $stored->micro);
5757
}
@@ -127,4 +127,4 @@ public function down()
127127
}
128128
}
129129

130-
}
130+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
6+
class CreateStatementIndexes extends Migration {
7+
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up() {
14+
$db = \DB::getMongoDB();
15+
16+
$indexOptions = ['background'=>1, 'socketTimeoutMS'=>-1];
17+
$statements = new MongoCollection($db, 'statements');
18+
19+
$statements->createIndex(['statement.id' => 1, 'lrs_id' => 1], $indexOptions);
20+
$statements->createIndex(['statement.actor.mbox' => 1], $indexOptions);
21+
$statements->createIndex(['stored' => 1], $indexOptions);
22+
$statements->createIndex(['timestamp' => 1], $indexOptions);
23+
$statements->createIndex(['active' => 1], $indexOptions);
24+
$statements->createIndex(['voided' => 1], $indexOptions);
25+
$statements->createIndex(['lrs_id' => 1], $indexOptions);
26+
$statements->createIndex(['lrs_id' => 1, 'active' => -1, 'voided' => 1], $indexOptions);
27+
$statements->createIndex(['lrs_id' => 1, 'statement.actor.account.name' => 1, 'statement.actor.account.homePage' => 1], $indexOptions);
28+
$statements->createIndex(['lrs_id' => 1, 'statement.actor.mbox' => 1], $indexOptions);
29+
$statements->createIndex(['lrs_id' => 1, 'statement.verb.id' => 1], $indexOptions);
30+
$statements->createIndex(['lrs_id' => 1, 'statement.object.id' => 1], $indexOptions);
31+
$statements->createIndex(['lrs_id' => 1, 'stored' => -1], $indexOptions);
32+
$statements->createIndex(['lrs_id' => 1, 'timestamp' => -1], $indexOptions);
33+
}
34+
35+
36+
/**
37+
* Reverse the migrations.
38+
*
39+
* @return void
40+
*/
41+
public function down()
42+
{
43+
// we really don't want to remove this indexes
44+
}
45+
46+
}

app/locker/helpers/Attachments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static function setAttachments($content_type, $content) {
2424

2525
foreach ($parts as $count => $part) {
2626
// Stops at the end of the file.
27-
if ($part == "--") break;
27+
if (substr($part,0,2) == "--") break;
2828

2929
// Determines the delimiter.
3030
$delim = strpos($part, "\r\n") !== false ? "\r\n" : "\n";

app/locker/repository/Statement/EloquentIndexer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,6 @@ private function matchActivity($activity, Builder $builder, IndexOptions $opts)
234234
* @return Int Number of statements in Builder.
235235
*/
236236
public function count(Builder $builder, IndexOptions $opts) {
237-
return $builder->count();
237+
return $builder->count(['lrs_id' => 1], ['lrs_id'=>1, 'active'=>-1, 'voided'=>1]);
238238
}
239239
}

app/views/partials/lrs/backbone/templates.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@
135135
</script>
136136

137137
<script id="dashboardHeader" type="text/template">
138-
<h3>Statements <span><%= statement_count %></span></h3>
139-
<p class="averages">Your daily average is <span style="color:#00cc00;"> <%= statement_avg %> statements</span>.</p>
138+
<h3>Statements <span><%= statement_count.toLocaleString() %></span></h3>
139+
<p class="averages">Your daily average is <span style="color:#00cc00;"> <%= statement_avg.toLocaleString() %> statements</span>.</p>
140140
</script>
141141

142142
<script id="showLoading" type="text/template">

app/views/partials/site/backbone/templates.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
</div>
182182
<div class="col-xs-12 col-sm-4 col-lg-4">
183183
<div class="bordered stats-box">
184-
<span><%= statement_count %></span>
184+
<span><%= statement_count.toLocaleString() %></span>
185185
Total Statements
186186
</div>
187187
</div>
@@ -228,8 +228,8 @@
228228
<div class="row">
229229
<div class="col-xs-12 col-sm-12">
230230
<div class="statement-graph clearfix">
231-
<h3>Statements <span><%= statement_count %></span></h3>
232-
<p class="averages">Your daily average is <span style="color:#00cc00;"> <%= statement_avg %> statements</span>.</p>
231+
<h3>Statements <span><%= statement_count.toLocaleString() %></span></h3>
232+
<p class="averages">Your daily average is <span style="color:#00cc00;"> <%= statement_avg.toLocaleString() %> statements</span>.</p>
233233
</div>
234234
</div>
235235
</div>

0 commit comments

Comments
 (0)