Skip to content

Commit be336bf

Browse files
committed
Merge pull request #788 from LearningLocker/develop
v1.12.0
2 parents 86f3a30 + 911813d commit be336bf

40 files changed

+879
-656
lines changed

.github/issue_template.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
You need to replace the parts of this template where you see {{some text}}.
2+
3+
**Version**
4+
{{branch}} at {{commit}} on {{version - found in your copy of the VERSION file}}
5+
6+
**Steps to reproduce the bug**
7+
1. {{step 1}}
8+
2. {{step 2}}
9+
10+
**Expected behaviour**
11+
{{feature}} should be {{expectedResult}} because {{reason}}.
12+
13+
**Actual behaviour**
14+
{{feature}} is {{actualResult}}.
15+
16+
**Additional information**
17+
OS: {{operatingSystem}}
18+
Browser: {{browser}} version 1.0.1
19+
{{additionalInfo}}

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
- mongodb
88

99
install:
10+
- echo y | pecl install mongo
1011
- php -r "readfile('https://getcomposer.org/installer');" | php
1112
- php composer.phar install --no-interaction --dev
1213

@@ -16,8 +17,9 @@ before_script:
1617
- sudo chmod -R 777 ./uploads
1718
- php artisan migrate --env="testing"
1819

19-
script: ./vendor/bin/phpunit
20-
after_success: sh test.sh
20+
script:
21+
- ./vendor/bin/phpunit
22+
- sh test.sh
2123

2224
notifications:
2325
slack:

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.11.0
1+
1.12.0

app/commands/ConvertTimestamp.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public function fire()
4343
{
4444
Statement::chunk(1000, function($statements){
4545
foreach ($statements as $s){
46-
$s->timestamp = new \MongoDate(strtotime($s->statement['timestamp']));
46+
$timestamp = new Carbon\Carbon($s->statement['timestamp']);
47+
$s->timestamp = new \MongoDate($timestamp->timestamp, $timestamp->micro);
4748
$s->save();
4849
}
4950
$this->info(count($statements) . ' converted.');

app/config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
'JsLocalization\JsLocalizationServiceProvider',
121121
'locker\RequestServiceProvider',
122122
'Philo\Translate\TranslateServiceProvider',
123+
'Clockwork\Support\Laravel\ClockworkServiceProvider',
123124
),
124125

125126
/*

app/config/database.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
'default' => 'mongodb',
66
'connections' => [
77
'mongodb' => [
8-
'driver' => 'mongodb',
9-
'host' => 'localhost',
10-
'port' => 27017,
11-
'username' => '',
12-
'password' => '',
13-
'database' => 'll_staging' // Default name (removing this makes Travis fail).
14-
],
8+
'driver' => 'mongodb',
9+
'host' => 'localhost',
10+
'port' => 27017,
11+
'username' => '',
12+
'password' => '',
13+
'database' => 'll_staging' // Default name (removing this makes Travis fail).
14+
],
1515
],
1616
'migrations' => 'migrations',
1717
];

app/controllers/LrsController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public function show($lrs_id) {
134134
$dashboard = new \app\locker\data\dashboards\LrsDashboard($lrs_id);
135135
return View::make('partials.lrs.dashboard', array_merge($this->getLrs($lrs_id), [
136136
'stats' => $dashboard->getStats(),
137-
'graph_data' => $dashboard->getGraphData(),
138137
'dash_nav' => true,
139138
'client' => (new \Client)->where('lrs_id', $lrs_id)->first()
140139
]));
@@ -198,7 +197,7 @@ public function statements($lrs_id){
198197
'scopes' => ['all']
199198
]),
200199
'scopes' => ['all']
201-
]))->orderBy('statement.stored', 'DESC')->paginate(15);
200+
]))->orderBy('stored', 'DESC')->paginate(15);
202201
return View::make('partials.statements.list', array_merge($this->getLrs($lrs_id), [
203202
'statements' => $statements,
204203
'statement_nav' => true,

app/controllers/SiteController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function index(){
3838
'site' => $site,
3939
'list' => $list,
4040
'stats' => $admin_dashboard->getFullStats(),
41-
'graph_data' => $admin_dashboard->getGraphData()
41+
'dash_nav' => true
4242
]);
4343

4444
}
@@ -120,9 +120,12 @@ public function getGraphData(){
120120
public function lrs(){
121121
$opts = ['user' => \Auth::user()];
122122
$lrss = $this->lrs->index($opts);
123+
$lrs_repo = $this->lrs;
123124

124-
return Response::json(array_map(function ($lrs) {
125-
$lrs->statement_total = $this->statement->count(['lrs_id' => $lrs->_id, 'scopes' => ['all']]);
125+
$collection = \DB::getCollection('statements');
126+
127+
return Response::json(array_map(function ($lrs) use ($lrs_repo) {
128+
$lrs->statement_total = $lrs_repo->getStatementCount($lrs->_id);
126129
return $lrs;
127130
}, $lrss));
128131
}

app/controllers/api/Exports.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public function __construct(Export $export) {
2323
* @return StreamedResponse.
2424
*/
2525
public function showJson($id) {
26+
// should top timeouts on long queries
27+
set_time_limit(0);
28+
2629
$opts = $this->getOptions();
2730
$model = $this->repo->show($id, $opts);
2831

@@ -46,6 +49,9 @@ public function showJson($id) {
4649
* @return StreamedResponse.
4750
*/
4851
public function showCsv($id) {
52+
// should top timeouts on long queries
53+
set_time_limit(0);
54+
4955
$opts = $this->getOptions();
5056
$model = $this->repo->show($id, $opts);
5157

@@ -92,4 +98,4 @@ private function quoteCSV($field) {
9298
return $field;
9399
}
94100
}
95-
}
101+
}

app/controllers/api/Statements.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Controllers\API;
22

3+
use Carbon\Carbon;
34
use \Locker\Repository\Query\QueryRepository as QueryRepository;
45
use \Locker\Helpers\Exceptions as Exceptions;
56

@@ -29,7 +30,7 @@ public function where() {
2930
* @return Aggregate http://php.net/manual/en/mongocollection.aggregate.php#refsect1-mongocollection.aggregate-examples
3031
*/
3132
public function aggregate() {
32-
$pipeline = $this->getParam('pipeline');
33+
$pipeline = $this->getPipeline();
3334
return \Response::json($this->query->aggregate($this->getOptions(), $pipeline));
3435
}
3536

@@ -82,9 +83,43 @@ public function void() {
8283
return \Response::json($this->query->void($match, $this->getOptions()));
8384
}
8485

86+
private function convertDte($value) {
87+
if(is_array($value)) {
88+
if(isset($value['$dte'])) {
89+
$date = $value['$dte'];
90+
$parsedDate = new Carbon($date);
91+
if($parsedDate) return new \MongoDate($parsedDate->timestamp, $parsedDate->micro);
92+
else throw new Exceptions\Exception("`$date` is not a valid date.");
93+
}
94+
else
95+
return array_map([$this, __FUNCTION__], $value); // recursively apply this function to whole pipeline
96+
}
97+
98+
return $value;
99+
}
100+
101+
private function convertOid($value) {
102+
if(is_array($value)) {
103+
if(isset($value['$oid']))
104+
return new \MongoId($value['$oid']);
105+
else
106+
return array_map([$this, __FUNCTION__], $value); // recursively apply this function to whole pipeline
107+
}
108+
109+
return $value;
110+
}
111+
112+
private function getPipeline() {
113+
$pipeline = $this->getParam('pipeline');
114+
$pipeline = $this->convertDte($pipeline);
115+
$pipeline = $this->convertOid($pipeline);
116+
return $pipeline;
117+
}
118+
85119
private function getParam($param) {
86120
$param_value = \LockerRequest::getParam($param);
87121
$value = json_decode($param_value, true);
122+
88123
if ($value === null && $param_value === null) {
89124
throw new Exceptions\Exception("Expected `$param` to be defined as a URL parameter.");
90125
} else if ($value === null) {

0 commit comments

Comments
 (0)