Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/Http/Controllers/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Jobs\ProvisionWikiDbJob;
use App\KnowledgeEquityResponse;
use App\QueryserviceNamespace;
use App\User;
use App\Wiki;
use App\WikiDb;
use App\WikiDomain;
Expand Down Expand Up @@ -87,6 +88,10 @@ public function create(Request $request): Response {

// TODO create with some sort of owner etc?
DB::transaction(function () use ($user, $request, &$wiki, &$dbAssignment, $submittedDomain, $rawProfile, $rawKnowledgeEquityResponse): void {
// Lock the user before any reads establish a repeatable-read snapshot.
// Creation always locks in this order: user, wiki DB, then QS namespace.
$user = User::whereKey($user->getKey())->lockForUpdate()->firstOrFail();

$dbVersion = Config::get('wbstack.wiki_db_use_version');
$wikiDbCondition = ['wiki_id' => null, 'version' => $dbVersion];

Expand All @@ -101,7 +106,7 @@ public function create(Request $request): Response {
$numWikis = $user->managesWikis()->count() + 1;
$maxWikis = config('wbstack.wiki_max_per_user');

if (config('wbstack.wiki_max_per_user') !== false && $numWikis > config('wbstack.wiki_max_per_user')) {
if ($maxWikis !== false && $numWikis > $maxWikis) {
abort(403, "Too many wikis. Your new total of {$numWikis} would exceed the limit of {$maxWikis} per user.");
}

Expand Down
Loading