Skip to content

Commit 539459b

Browse files
author
Daniel Abbey
committed
Merges 714
2 parents 2b1b27d + 40f1bbb commit 539459b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+410
-246
lines changed

app/config/app.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,18 @@
108108
'Illuminate\Validation\ValidationServiceProvider',
109109
'Illuminate\View\ViewServiceProvider',
110110
'Illuminate\Workbench\WorkbenchServiceProvider',
111+
'Jenssegers\Mongodb\MongodbServiceProvider',
112+
'Jenssegers\Mongodb\Auth\ReminderServiceProvider',
113+
'Jenssegers\Mongodb\Session\SessionServiceProvider',
111114
'Locker\Repository\RepositoryServiceProvider',
112115
'Locker\Data\DataServiceProvider',
113116
'Locker\Graphing\GraphServiceProvider',
114-
'Jenssegers\Mongodb\MongodbServiceProvider',
115117
'DaveJamesMiller\Breadcrumbs\ServiceProvider',
116118
'Way\Generators\GeneratorsServiceProvider',
117119
'Barryvdh\Cors\CorsServiceProvider',
118120
'JsLocalization\JsLocalizationServiceProvider',
119121
'locker\RequestServiceProvider',
120122
'Philo\Translate\TranslateServiceProvider',
121-
'Jenssegers\Mongodb\Auth\ReminderServiceProvider',
122123
),
123124

124125
/*

app/config/session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
|
1919
*/
2020

21-
'driver' => 'file',
21+
'driver' => 'mongodb',
2222

2323
/*
2424
|--------------------------------------------------------------------------

app/controllers/LrsController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ public function destroy($lrs_id){
192192
public function statements($lrs_id){
193193
$site = \Site::first();
194194
$statements = (new StatementIndexer)->index(new IndexOptions([
195-
'lrs_id' => $lrs_id,
195+
'lrs_id' => new \MongoId($lrs_id),
196196
'limit' => $this->statement->count([
197-
'lrs_id' => $lrs_id,
197+
'lrs_id' => new \MongoId($lrs_id),
198198
'scopes' => ['all']
199199
]),
200200
'scopes' => ['all']

app/controllers/ReportingController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public function statements($lrs_id, $report_id) {
9191
return View::make("{$this->views}.statements", array_merge($this->getLrs($lrs_id), [
9292
'reporting_nav' => true,
9393
'statements' => $this->report->statements($report_id, [
94-
'lrs_id' => $lrs_id
94+
'lrs_id' => new \MongoId($lrs_id)
9595
])->select('statement')->paginate(20),
9696
'report' => $this->report->show($report_id, [
97-
'lrs_id' => $lrs_id
97+
'lrs_id' => new \MongoId($lrs_id)
9898
]),
9999
'lang' => $site->lang
100100
]));

app/controllers/api/Analytics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(AnalyticsData $analytics) {
1717

1818
// http://docs.learninglocker.net/analytics_api/
1919
public function index() {
20-
$data = $this->analytics->timedGrouping($this->lrs->_id, LockerRequest::getParams());
20+
$data = $this->analytics->timedGrouping($this->getOptions()['lrs_id'], LockerRequest::getParams());
2121
return $this->returnJson($data);
2222
}
2323
}

app/controllers/api/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct() {
3030
*/
3131
protected function getOptions() {
3232
return [
33-
'lrs_id' => $this->lrs->_id,
33+
'lrs_id' => new \MongoId($this->lrs->_id),
3434
'scopes' => $this->client->scopes,
3535
'client' => $this->client
3636
];

app/controllers/api/Statements.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(QueryRepository $query) {
2121
public function where() {
2222
$limit = \LockerRequest::getParam('limit', 100);
2323
$filters = $this->getParam('filters');
24-
return \Response::json($this->query->where($this->lrs->_id, $filters)->paginate($limit));
24+
return \Response::json($this->query->where($this->getOptions()['lrs_id'], $filters)->paginate($limit));
2525
}
2626

2727
/**
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
use Illuminate\Database\Schema\Blueprint;
3+
use Illuminate\Database\Migrations\Migration;
4+
5+
class ConsistentForeignKeyNames extends Migration {
6+
7+
public function up() {
8+
$db = \DB::getMongoDB();
9+
10+
Lrs::get()->each(function (Lrs $lrs) use ($db) {
11+
$convertToMongoId = function ($value) {
12+
return new \MongoId($value);
13+
};
14+
$this->changeForeignKey($db->statements, 'lrs._id', 'lrs_id', $lrs->_id, $convertToMongoId);
15+
$this->changeForeignKey($db->documentapi, 'lrs', 'lrs_id', $lrs->_id, $convertToMongoId);
16+
$this->changeForeignKey($db->reports, 'lrs', 'lrs_id', $lrs->_id, $convertToMongoId);
17+
$this->changeForeignKey($db->exports, 'lrs', 'lrs_id', $lrs->_id, $convertToMongoId);
18+
19+
$lrs->owner_id = $convertToMongoId($lrs->owner['_id']);
20+
$lrs->save();
21+
22+
echo 'Models for "'.$lrs->title.'" converted.'.PHP_EOL;
23+
});
24+
25+
echo 'All finished, hopefully!'.PHP_EOL;
26+
}
27+
28+
private function changeForeignKey($collection, $old_key, $new_key, $old_value, $modifier) {
29+
$collection->update([
30+
$old_key => $old_value
31+
], [
32+
'$set' => [
33+
$new_key => $modifier($old_value)
34+
]
35+
], [
36+
'multiple' => true
37+
]);
38+
}
39+
40+
public function down() {
41+
$db = \DB::getMongoDB();
42+
43+
Lrs::get()->each(function (Lrs $lrs) use ($db) {
44+
$convertToString = function ($value) {
45+
return (string) $value;
46+
};
47+
$this->changeForeignKey($db->statements, 'lrs_id', 'lrs._id', $lrs->_id, $convertToString);
48+
$this->changeForeignKey($db->documentapi, 'lrs_id', 'lrs', $lrs->_id, $convertToString);
49+
$this->changeForeignKey($db->reports, 'lrs_id', 'lrs', $lrs->_id, $convertToString);
50+
$this->changeForeignKey($db->exports, 'lrs_id', 'lrs', $lrs->_id, $convertToString);
51+
52+
$lrs->owner = [
53+
'_id' => $convertToString($lrs->owner_id)
54+
];
55+
$lrs->save();
56+
57+
echo 'Models for "'.$lrs->title.'" converted.'.PHP_EOL;
58+
});
59+
60+
echo 'All finished, hopefully!'.PHP_EOL;
61+
}
62+
63+
}
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\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class ChangeForeignKeyIndexes extends Migration {
7+
8+
public function up() {
9+
Schema::table('statements', function (Blueprint $table) {
10+
$table->index('lrs_id');
11+
$table->index(['lrs_id', 'statement.object.id']);
12+
$table->index(['lrs_id', 'statement.verb.id']);
13+
$table->index(['lrs_id', 'statement.actor.mbox']);
14+
$table->index(['lrs_id', 'timestamp']);
15+
$table->index(['statement.stored', 'lrs_id']);
16+
$table->index(['statement.id', 'lrs_id']);
17+
$table->dropIndex('lrs._id');
18+
$table->dropIndex(['lrs._id', 'statement.object.id']);
19+
$table->dropIndex(['lrs._id', 'statement.verb.id']);
20+
$table->dropIndex(['lrs._id', 'statement.actor.mbox']);
21+
$table->dropIndex(['lrs._id', 'timestamp']);
22+
$table->dropIndex(['statement.stored', 'lrs._id']);
23+
$table->dropIndex(['statement.id', 'lrs._id']);
24+
});
25+
}
26+
27+
public function down() {
28+
Schema::table('statements', function (Blueprint $table) {
29+
$table->index('lrs._id');
30+
$table->index(['lrs._id', 'statement.object.id']);
31+
$table->index(['lrs._id', 'statement.verb.id']);
32+
$table->index(['lrs._id', 'statement.actor.mbox']);
33+
$table->index(['lrs._id', 'timestamp']);
34+
$table->index(['statement.stored', 'lrs._id']);
35+
$table->index(['statement.id', 'lrs._id']);
36+
$table->dropIndex('lrs_id');
37+
$table->dropIndex(['lrs_id', 'statement.object.id']);
38+
$table->dropIndex(['lrs_id', 'statement.verb.id']);
39+
$table->dropIndex(['lrs_id', 'statement.actor.mbox']);
40+
$table->dropIndex(['lrs_id', 'timestamp']);
41+
$table->dropIndex(['statement.stored', 'lrs_id']);
42+
$table->dropIndex(['statement.id', 'lrs_id']);
43+
});
44+
}
45+
46+
}

app/filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
$lrs = Helpers::getLrsFromAuth();
7070

7171
//attempt login once
72-
if ( ! Auth::onceUsingId($lrs->owner['_id']) ) {
72+
if ( ! Auth::onceUsingId($lrs->owner_id) ) {
7373
throw new Exceptions\Exception('Unauthorized request.', 401);
7474
}
7575

0 commit comments

Comments
 (0)