-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration to update tag permissions from old permission name
- Loading branch information
1 parent
066614c
commit 12f03ae
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
migrations/2020_08_25_000000_update_tag_permission_names.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/gamification. | ||
* | ||
* Copyright (c) 2020 FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Flarum\Group\Permission; | ||
use Illuminate\Database\Schema\Builder; | ||
use Illuminate\Support\Str; | ||
|
||
return [ | ||
'up' => function (Builder $schema) { | ||
Permission::query() | ||
->where('permission', 'like', '%.discussion.vote') | ||
->orderBy('permission') | ||
->each(function (Permission $item) use ($schema) { | ||
$schema->getConnection()->transaction(function () use ($item) { | ||
$item->delete(); | ||
|
||
$item->permission = $item->permission . 'Posts'; | ||
|
||
if (!Permission::query()->where($item->getAttributes())->exists()) { | ||
$item->save(); | ||
} | ||
}); | ||
}); | ||
}, | ||
'down' => function (Builder $schema) { | ||
Permission::query() | ||
->where('permission', 'like', '%.discussion.votePosts') | ||
->orderBy('permission') | ||
->each(function (Permission $item) use ($schema) { | ||
$schema->getConnection()->transaction(function () use ($item) { | ||
$item->delete(); | ||
|
||
$item->permission = Str::replaceLast('votePosts', 'vote', $item->permission); | ||
|
||
if (!Permission::query()->where($item->getAttributes())->exists()) { | ||
$item->save(); | ||
} | ||
}); | ||
}); | ||
}, | ||
]; |