Skip to content

Commit

Permalink
Add migration to update tag permissions from old permission name
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Aug 28, 2020
1 parent 066614c commit 12f03ae
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions migrations/2020_08_25_000000_update_tag_permission_names.php
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();
}
});
});
},
];

0 comments on commit 12f03ae

Please sign in to comment.