Skip to content

Commit 12f03ae

Browse files
Add migration to update tag permissions from old permission name
1 parent 066614c commit 12f03ae

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of fof/gamification.
5+
*
6+
* Copyright (c) 2020 FriendsOfFlarum.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Flarum\Group\Permission;
13+
use Illuminate\Database\Schema\Builder;
14+
use Illuminate\Support\Str;
15+
16+
return [
17+
'up' => function (Builder $schema) {
18+
Permission::query()
19+
->where('permission', 'like', '%.discussion.vote')
20+
->orderBy('permission')
21+
->each(function (Permission $item) use ($schema) {
22+
$schema->getConnection()->transaction(function () use ($item) {
23+
$item->delete();
24+
25+
$item->permission = $item->permission . 'Posts';
26+
27+
if (!Permission::query()->where($item->getAttributes())->exists()) {
28+
$item->save();
29+
}
30+
});
31+
});
32+
},
33+
'down' => function (Builder $schema) {
34+
Permission::query()
35+
->where('permission', 'like', '%.discussion.votePosts')
36+
->orderBy('permission')
37+
->each(function (Permission $item) use ($schema) {
38+
$schema->getConnection()->transaction(function () use ($item) {
39+
$item->delete();
40+
41+
$item->permission = Str::replaceLast('votePosts', 'vote', $item->permission);
42+
43+
if (!Permission::query()->where($item->getAttributes())->exists()) {
44+
$item->save();
45+
}
46+
});
47+
});
48+
},
49+
];

0 commit comments

Comments
 (0)