Esempio n. 1
0
        public static ArchivedArtistVersion Create(Artist artist, ArtistDiff diff, AgentLoginData author, ArtistArchiveReason reason, string notes)
        {
            var contract = new ArchivedArtistContract(artist, diff);
            var data     = XmlHelper.SerializeToXml(contract);

            return(artist.CreateArchivedVersion(data, diff, author, reason, notes));
        }
Esempio n. 2
0
        /// <summary>
        /// Reverts an album to an earlier archived version.
        /// </summary>
        /// <param name="archivedArtistVersionId">Id of the archived version to be restored.</param>
        /// <returns>Result of the revert operation, with possible warnings if any. Cannot be null.</returns>
        /// <remarks>Requires the RestoreRevisions permission.</remarks>
        public async Task <EntryRevertedContract> RevertToVersion(int archivedArtistVersionId)
        {
            PermissionContext.VerifyPermission(PermissionToken.RestoreRevisions);

            return(await HandleTransactionAsync(async session => {
                var archivedVersion = await session.LoadAsync <ArchivedArtistVersion>(archivedArtistVersionId);

                if (archivedVersion.Hidden)
                {
                    PermissionContext.VerifyPermission(PermissionToken.ViewHiddenRevisions);
                }

                var artist = archivedVersion.Artist;

                session.AuditLogger.SysLog("reverting " + artist + " to version " + archivedVersion.Version);

                var fullProperties = ArchivedArtistContract.GetAllProperties(archivedVersion);
                var warnings = new List <string>();
                var diff = new ArtistDiff();

                artist.ArtistType = fullProperties.ArtistType;
                artist.Description.Original = fullProperties.Description;
                artist.Description.English = fullProperties.DescriptionEng ?? string.Empty;
                artist.TranslatedName.DefaultLanguage = fullProperties.TranslatedName.DefaultLanguage;
                artist.BaseVoicebank = DatabaseContextHelper.RestoreWeakRootEntityRef(session, warnings, fullProperties.BaseVoicebank);

                // Picture
                var versionWithPic = archivedVersion.GetLatestVersionWithField(ArtistEditableFields.Picture);

                if (versionWithPic != null)
                {
                    artist.Picture = versionWithPic.Picture;
                    artist.PictureMime = versionWithPic.PictureMime;

                    if (versionWithPic.Picture != null)
                    {
                        var thumbGenerator = new ImageThumbGenerator(imagePersister);
                        using (var stream = new MemoryStream(versionWithPic.Picture.Bytes)) {
                            var thumb = new EntryThumb(artist, versionWithPic.PictureMime, ImagePurpose.Main);
                            thumbGenerator.GenerateThumbsAndMoveImage(stream, thumb, ImageSizes.Thumb | ImageSizes.SmallThumb | ImageSizes.TinyThumb);
                        }
                    }
                }
                else
                {
                    artist.Picture = null;
                    artist.PictureMime = null;
                }

                // Assume picture was changed if there's a version between the current version and the restored version where the picture was changed.
                diff.Picture.Set(!Equals(artist.ArchivedVersionsManager.GetLatestVersionWithField(ArtistEditableFields.Picture, artist.Version), versionWithPic));

                // Groups
                DatabaseContextHelper.RestoreObjectRefs(
                    session, warnings, artist.AllGroups, fullProperties.Groups, (a1, a2) => (a1.Parent.Id == a2.Id),
                    (grp, grpRef) => (!artist.HasGroup(grp) ? artist.AddGroup(grp, grpRef.LinkType) : null),
                    groupForArtist => groupForArtist.Delete());

                // Names
                if (fullProperties.Names != null)
                {
                    var nameDiff = artist.Names.SyncByContent(fullProperties.Names, artist);
                    await session.SyncAsync(nameDiff);
                }

                // Weblinks
                if (fullProperties.WebLinks != null)
                {
                    var webLinkDiff = WebLink.SyncByValue(artist.WebLinks, fullProperties.WebLinks, artist);
                    await session.SyncAsync(webLinkDiff);
                }

                await ArchiveAsync(session, artist, diff, ArtistArchiveReason.Reverted, string.Format("Reverted to version {0}", archivedVersion.Version));
                await AuditLogAsync(string.Format("reverted {0} to revision {1}", entryLinkFactory.CreateEntryLink(artist), archivedVersion.Version), session);

                return new EntryRevertedContract(artist, warnings);
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// Reverts an album to an earlier archived version.
        /// </summary>
        /// <param name="archivedArtistVersionId">Id of the archived version to be restored.</param>
        /// <returns>Result of the revert operation, with possible warnings if any. Cannot be null.</returns>
        /// <remarks>Requires the RestoreRevisions permission.</remarks>
        public EntryRevertedContract RevertToVersion(int archivedArtistVersionId)
        {
            PermissionContext.VerifyPermission(PermissionToken.RestoreRevisions);

            return(HandleTransaction(session => {
                var archivedVersion = session.Load <ArchivedArtistVersion>(archivedArtistVersionId);
                var artist = archivedVersion.Artist;

                SysLog("reverting " + artist + " to version " + archivedVersion.Version);

                var fullProperties = ArchivedArtistContract.GetAllProperties(archivedVersion);
                var warnings = new List <string>();

                artist.ArtistType = fullProperties.ArtistType;
                artist.Description = fullProperties.Description;
                artist.TranslatedName.DefaultLanguage = fullProperties.TranslatedName.DefaultLanguage;

                // Picture
                var versionWithPic = archivedVersion.GetLatestVersionWithField(ArtistEditableFields.Picture);

                if (versionWithPic != null)
                {
                    artist.Picture = versionWithPic.Picture;
                }

                /*
                 * // Albums
                 * SessionHelper.RestoreObjectRefs<ArtistForAlbum, Album>(
                 *      session, warnings, artist.AllAlbums, fullProperties.Albums, (a1, a2) => (a1.Album.Id == a2.Id),
                 *      album => (!artist.HasAlbum(album) ? artist.AddAlbum(album) : null),
                 *      albumForArtist => albumForArtist.Delete());
                 */

                // Groups
                SessionHelper.RestoreObjectRefs <GroupForArtist, Artist>(
                    session, warnings, artist.AllGroups, fullProperties.Groups, (a1, a2) => (a1.Group.Id == a2.Id),
                    grp => (!artist.HasGroup(grp) ? artist.AddGroup(grp) : null),
                    groupForArtist => groupForArtist.Delete());

                /*
                 * // Members
                 * SessionHelper.RestoreObjectRefs<GroupForArtist, Artist>(
                 *      session, warnings, artist.AllMembers, fullProperties.Members, (a1, a2) => (a1.Member.Id == a2.Id),
                 *      member => (!artist.HasMember(member) ? artist.AddMember(member) : null),
                 *      groupForArtist => groupForArtist.Delete());
                 */

                // Names
                if (fullProperties.Names != null)
                {
                    var nameDiff = artist.Names.SyncByContent(fullProperties.Names, artist);
                    SessionHelper.Sync(session, nameDiff);
                }

                // Weblinks
                if (fullProperties.WebLinks != null)
                {
                    var webLinkDiff = WebLink.SyncByValue(artist.WebLinks, fullProperties.WebLinks, artist);
                    SessionHelper.Sync(session, webLinkDiff);
                }

                Archive(session, artist, ArtistArchiveReason.Reverted);
                AuditLog(string.Format("reverted {0} to revision {1}", EntryLinkFactory.CreateEntryLink(artist), archivedVersion.Version), session);

                return new EntryRevertedContract(artist, warnings);
            }));
        }