本文整理汇总了PHP中app\Role::getAnonymousRoleForBoard方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::getAnonymousRoleForBoard方法的具体用法?PHP Role::getAnonymousRoleForBoard怎么用?PHP Role::getAnonymousRoleForBoard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Role
的用法示例。
在下文中一共展示了Role::getAnonymousRoleForBoard方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importInfinityRolesAndBoards
//.........这里部分代码省略.........
// Not identified!
default:
$this->error("\t\tMod {$user->username} has invalid mod type {$mod->type}.");
break;
}
}
}
}
});
$this->info("\tImported {$usersImported} users(s).");
if (!$userAdmin) {
$this->comment("\tFailed to import an admin. This may cause problems.");
}
unset($mods, $mod, $user);
# BEGIN BOARD IMPORT
$this->info("\tImporting Boards ...");
$boardsImported = 0;
$tBoardsTable->chunk(100, function ($boards) use(&$boardsImported, $userAdmin, $userBoardRelationships) {
$this->line("\t\tHandling 100 boards ...");
foreach ($boards as $tBoard) {
// We have an array like [board_uri => [ user_id => user_role ]] in the user import.
// This fetches the first key of the biggest item.
$boardOwner = [];
if (isset($userBoardRelationships[$tBoard->uri])) {
$boardOwner = array_keys($userBoardRelationships[$tBoard->uri], max($userBoardRelationships[$tBoard->uri]));
}
// Or it defaults to our admin.
if (!isset($boardOwner[0])) {
$this->comment("\t\t/{$tBoard->uri}/ has no known owner, assuming it is {$userAdmin->username}.");
$boardOwner = $userAdmin->user_id;
} else {
$boardOwner = isset($boardOwner) ? $boardOwner[0] : $userAdmin->user_id;
}
$hBoard = new Board(['board_uri' => $tBoard->uri, 'title' => $tBoard->title, 'description' => $tBoard->subtitle, 'created_at' => new Carbon($tBoard->time), 'created_by' => $boardOwner, 'operated_by' => $boardOwner, 'posts_total' => $tBoard->posts_total, 'is_indexed' => !!$tBoard->indexed, 'is_overboard' => !!$tBoard->indexed, 'is_worksafe' => !!$tBoard->sfw]);
if ($hBoard->save()) {
++$boardsImported;
if (!$tBoard->public_bans || !$tBoard->public_logs || $tBoard->public_logs == 2) {
$role = Role::getAnonymousRoleForBoard($hBoard);
$perms = [];
if (!$tBoard->public_bans) {
$perms[] = ['permission_id' => "board.bans", 'value' => false];
}
if (!$tBoard->public_logs || $tBoard->public_logs == 2) {
$perms[] = ['permission_id' => "board.logs", 'value' => false];
}
$role->permissionAssignments()->createMany($perms);
}
} else {
$this->error("Failed to save /{$hBoard->board_uri}/.");
}
}
});
$this->info("\tImported {$boardsImported} board(s).");
unset($boards, $tBoard, $hBoard);
# BEGIN ROLE CONFIGURATION
$this->info("\tCreating roles ...");
$roleBoardVols = 0;
$roleBoardOwners = 0;
$roleBoardSkips = 0;
// Okay, so apparently sometimes there are users that own boards that don't exist.
// We cannot crate roles for these boards, so lets prune useless data.
$boardsWeCareAbout = Board::select('board_uri')->whereIn('board_uri', array_keys($userBoardRelationships))->get()->pluck('board_uri');
if ($boardsWeCareAbout->count() != count($userBoardRelationships)) {
$this->comment("\t\tThere are " . (count($userBoardRelationships) - $boardsWeCareAbout->count()) . " board(s) which users own that do not exist!");
}
foreach ($boardsWeCareAbout as $board) {
$ownerRole = null;
$janitorRole = null;
$roles = $userBoardRelationships[$board];
foreach ($roles as $mod => $role) {
// TODO
// Pull these values from config when formal importer created.
switch ($role) {
// Board volunteer
case 19:
$janitorRole = $janitorRole ?: Role::getJanitorRoleForBoard($board);
$userRole = new UserRole(['user_id' => $mod, 'role_id' => $janitorRole->role_id]);
if ($userRole->save()) {
++$roleBoardVols;
}
break;
// Board owner
// Board owner
case 20:
$ownerRole = $ownerRole ?: Role::getOwnerRoleForBoard($board);
$userRole = new UserRole(['user_id' => $mod, 'role_id' => $ownerRole->role_id]);
if ($userRole->save()) {
++$roleBoardOwners;
}
break;
default:
$this->line("\t\tI don't know what to do with role {$role} for user id {$mod} in {$board}.");
break;
}
}
}
$this->info("\t\tCreated {$roleBoardOwners} owner(s) and {$roleBoardVols} janitor(s) ");
$this->info("\t\tPulled roles from " . count($userBoardRelationships) . " boards with relationships.");
unset($board, $roles, $mod, $role, $userRole, $janitorRole, $ownerRole);
}