diff --git a/framework/core/migrations/2018_07_16_003952_allow_hide_posts_for_moderators.php b/framework/core/migrations/2018_07_16_003952_allow_hide_posts_for_moderators.php deleted file mode 100644 index 57203b7b1..000000000 --- a/framework/core/migrations/2018_07_16_003952_allow_hide_posts_for_moderators.php +++ /dev/null @@ -1,17 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Flarum\Database\Migration; -use Flarum\Group\Group; - -return Migration::addPermissions([ - 'discussion.hidePosts' => Group::MODERATOR_ID -]); diff --git a/framework/core/migrations/2018_07_21_000000_seed_default_groups.php b/framework/core/migrations/2018_07_21_000000_seed_default_groups.php new file mode 100644 index 000000000..12566ba02 --- /dev/null +++ b/framework/core/migrations/2018_07_21_000000_seed_default_groups.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Flarum\Group\Group; +use Illuminate\Database\Schema\Builder; + +return [ + 'up' => function (Builder $schema) { + $db = $schema->getConnection(); + + $groups = [ + [Group::ADMINISTRATOR_ID, 'Admin', 'Admins', '#B72A2A', 'fas fa-wrench'], + [Group::GUEST_ID, 'Guest', 'Guests', null, null], + [Group::MEMBER_ID, 'Member', 'Members', null, null], + [Group::MODERATOR_ID, 'Mod', 'Mods', '#80349E', 'fas fa-bolt'] + ]; + + foreach ($groups as $group) { + if ($db->table('groups')->where('id', $group[0])->exists()) { + continue; + } + + $db->table('groups')->insert(array_combine(['id', 'name_singular', 'name_plural', 'color', 'icon'], $group)); + } + }, + + 'down' => function (Builder $schema) { + // do nothing so as to preserve user data + } +]; diff --git a/framework/core/migrations/2015_02_25_000000_setup_default_permissions.php b/framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php similarity index 100% rename from framework/core/migrations/2015_02_25_000000_setup_default_permissions.php rename to framework/core/migrations/2018_07_21_000100_seed_default_group_permissions.php diff --git a/framework/core/src/Database/Migration.php b/framework/core/src/Database/Migration.php index 6469b847f..58f23acba 100644 --- a/framework/core/src/Database/Migration.php +++ b/framework/core/src/Database/Migration.php @@ -137,11 +137,11 @@ abstract class Migration */ public static function addPermissions(array $permissions) { - $keys = []; + $rows = []; foreach ($permissions as $permission => $groups) { foreach ((array) $groups as $group) { - $keys[] = [ + $rows[] = [ 'group_id' => $group, 'permission' => $permission, ]; @@ -149,23 +149,27 @@ abstract class Migration } return [ - 'up' => function (Builder $schema) use ($keys) { + 'up' => function (Builder $schema) use ($rows) { $db = $schema->getConnection(); - foreach ($keys as $key) { - $instance = $db->table('permissions')->where($key)->first(); - - if (is_null($instance)) { - $db->table('permissions')->insert($key); + foreach ($rows as $row) { + if ($db->table('group_permission')->where($row)->exists()) { + continue; } + + if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) { + continue; + } + + $db->table('group_permission')->insert($row); } }, - 'down' => function (Builder $schema) use ($keys) { + 'down' => function (Builder $schema) use ($rows) { $db = $schema->getConnection(); - foreach ($keys as $key) { - $db->table('permissions')->where($key)->delete(); + foreach ($rows as $row) { + $db->table('group_permission')->where($row)->delete(); } } ]; diff --git a/framework/core/src/Install/Console/InstallCommand.php b/framework/core/src/Install/Console/InstallCommand.php index 758c1702c..b91ec48b6 100644 --- a/framework/core/src/Install/Console/InstallCommand.php +++ b/framework/core/src/Install/Console/InstallCommand.php @@ -193,8 +193,6 @@ class InstallCommand extends AbstractCommand $this->application->register(SearchServiceProvider::class); $this->application->register(PostServiceProvider::class); - $this->seedGroups(); - $this->createAdminUser(); $this->enableBundledExtensions(); @@ -280,28 +278,6 @@ class InstallCommand extends AbstractCommand } } - protected function seedGroups() - { - Group::unguard(); - - $groups = [ - [Group::ADMINISTRATOR_ID, 'Admin', 'Admins', '#B72A2A', 'fas fa-wrench'], - [Group::GUEST_ID, 'Guest', 'Guests', null, null], - [Group::MEMBER_ID, 'Member', 'Members', null, null], - [Group::MODERATOR_ID, 'Mod', 'Mods', '#80349E', 'fas fa-bolt'] - ]; - - foreach ($groups as $group) { - Group::create([ - 'id' => $group[0], - 'name_singular' => $group[1], - 'name_plural' => $group[2], - 'color' => $group[3], - 'icon' => $group[4], - ]); - } - } - protected function createAdminUser() { $admin = $this->adminUser;