1 Star 0 Fork 19

dreawu/Discuz-Q-Update

forked from Discuz/Discuz-Q-Update 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
InitCategoryPermission.php 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
Luffy_龙 提交于 2020-08-25 11:12 . change descriptions
<?php
/**
* Discuz & Tencent Cloud
* This is NOT a freeware, use is subject to license terms
*/
namespace App\Console\Commands\Upgrades;
use App\Models\Category;
use App\Models\Group;
use App\Models\Permission;
use Discuz\Console\AbstractCommand;
use Illuminate\Support\Collection;
class InitCategoryPermission extends AbstractCommand
{
/**
* @var string
*/
protected $signature = 'upgrade:category-permission';
/**
* @var string
*/
protected $description = 'Initialize category permissions.';
/**
* {@inheritdoc}
*/
public function handle()
{
$categoryIds = Category::query()->pluck('id');
$groupIds = Group::query()->where('id', '>=', Group::MEMBER_ID)->pluck('id');
// 游客权限
$guestPermission = $categoryIds->map(function ($categoryId) {
return [
'group_id' => Group::GUEST_ID,
'permission' => "category{$categoryId}.viewThreads",
];
});
/** @var Collection $permissions */
$permissions = $groupIds->crossJoin($categoryIds)->reduce(function (Collection $carry, $idArray) {
[$groupId, $categoryId] = $idArray;
return $carry->merge([
[
'group_id' => $groupId,
'permission' => "category{$categoryId}.viewThreads",
],
[
'group_id' => $groupId,
'permission' => "category{$categoryId}.createThread",
],
[
'group_id' => $groupId,
'permission' => "category{$categoryId}.replyThread",
],
]);
}, $guestPermission);
Permission::query()->insertOrIgnore($permissions->toArray());
$this->info('success');
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dreawu/Discuz-Q-Update.git
git@gitee.com:dreawu/Discuz-Q-Update.git
dreawu
Discuz-Q-Update
Discuz-Q-Update
master

搜索帮助