private void MigrateUserNotifications() { try { var usersToNotify = UserNotifyRepo.GetAll(); var plexUsers = PlexUsers.GetAll().ToList(); var users = UserRepo.GetAll().ToList(); if (usersToNotify == null) { return; } foreach (var u in usersToNotify) { var selectedPlexUser = plexUsers.FirstOrDefault( x => x.Username.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase)); if (selectedPlexUser != null) { selectedPlexUser.Features += (int)Features.RequestAddedNotification; PlexUsers.Update(selectedPlexUser); } var selectedLocalUser = users.FirstOrDefault(x => x.UserName.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase)); if (selectedLocalUser != null) { selectedLocalUser.Features += (int)Features.RequestAddedNotification; UserRepo.Update(selectedLocalUser); } } } catch (Exception e) { Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateScheduledJobs)"); Logger.Fatal(e); } }
private void UpdatePlexUsers() { try { var settings = PlexSettings.GetSettings(); if (string.IsNullOrEmpty(settings.PlexAuthToken)) { return; } var plexUsers = PlexApi.GetUsers(settings.PlexAuthToken); if (plexUsers?.User == null) { return; } var prSettings = PlexRequestSettings.GetSettings(); var dbUsers = PlexUsers.GetAll().ToList(); foreach (var user in plexUsers.User) { if (dbUsers.FirstOrDefault(x => x.PlexUserId == user.Id) != null) { continue; } int permissions = 0; if (prSettings.SearchForMovies) { permissions = (int)Permissions.RequestMovie; } if (prSettings.SearchForTvShows) { permissions += (int)Permissions.RequestTvShow; } if (prSettings.SearchForMusic) { permissions += (int)Permissions.RequestMusic; } if (!prSettings.RequireMovieApproval) { permissions += (int)Permissions.AutoApproveMovie; } if (!prSettings.RequireTvShowApproval) { permissions += (int)Permissions.AutoApproveTv; } if (!prSettings.RequireMusicApproval) { permissions += (int)Permissions.AutoApproveAlbum; } // Add report Issues permissions += (int)Permissions.ReportIssue; var m = new PlexUsers { PlexUserId = user.Id, Permissions = permissions, Features = 0, UserAlias = string.Empty, EmailAddress = user.Email, Username = user.Username, LoginId = Guid.NewGuid().ToString() }; PlexUsers.Insert(m); } } catch (Exception e) { Logger.Fatal("Exception when migrating Version 1.10.0 (UpdatePlexUsers)"); Logger.Fatal(e); } }