public PublishContentContext(ContentItem contentItem, ContentItemVersionRecord previousItemVersionRecord) : base(contentItem) {
     PublishingItemVersionRecord = contentItem.VersionRecord;
     PreviousItemVersionRecord = previousItemVersionRecord;
 }
        protected async Task<ContentItem> BuildNewVersionAsync(ContentItem existingContentItem) {
            var contentItemRecord = existingContentItem.Record;

            // locate the existing and the current latest versions, allocate building version
            var existingItemVersionRecord = existingContentItem.VersionRecord;
            var buildingItemVersionRecord = new ContentItemVersionRecord {
                ContentItemId = contentItemRecord.Id,
                Latest = true,
                Published = false,
            };


            var latestVersion = await _session
                .QueryAsync<ContentItemVersionRecord, ContentItemVersionRecordIndex>(x => 
                    x.ContentItemId == contentItemRecord.Id && x.Latest)
                .FirstOrDefault();

            if (latestVersion != null) {
                latestVersion.Latest = false;
                buildingItemVersionRecord.Number = latestVersion.Number + 1;
            }
            else {
                var biggest = await _session.QueryIndexAsync<ContentItemVersionRecordIndex>(x => 
                x.ContentItemId == contentItemRecord.Id)
                .OrderByDescending(x => x.Number)
                .FirstOrDefault();
                buildingItemVersionRecord.Number = biggest.Number + 1;
            }

            buildingItemVersionRecord.ContentItemId = contentItemRecord.Id;
            _session.Save(buildingItemVersionRecord);

            var buildingContentItem = New(existingContentItem.ContentType);
            buildingContentItem.VersionRecord = buildingItemVersionRecord;

            var context = new VersionContentContext {
                Id = existingContentItem.Id,
                ContentType = existingContentItem.ContentType,
                ContentItemRecord = contentItemRecord,
                ExistingContentItem = existingContentItem,
                BuildingContentItem = buildingContentItem,
                ExistingItemVersionRecord = existingItemVersionRecord,
                BuildingItemVersionRecord = buildingItemVersionRecord,
            };

            Handlers.Invoke(handler => handler.Versioning(context), _logger);
            Handlers.Invoke(handler => handler.Versioned(context), _logger);

            return context.BuildingContentItem;
        }
 public bool SetContentItemVersionRecord(ContentItemVersionRecord record)
 {
     _contentItemVersionRepository.Update(record);
     return true;
 }
示例#4
0
        public void Weld(ContentPart part)
        {
            var contentVersionPart = part as ContentVersionPart;
            if (contentVersionPart != null)
            {
                if(VersionRecord == null)
                {
                    VersionRecord = new ContentItemVersionRecord();
                }

                VersionRecord.Parts.Add(contentVersionPart);
            }
            else
            {
                if (Record == null)
                {
                    Record = new ContentItemRecord();
                }

                Record.Parts.Add(part);
            }

            part.ContentItem = this;
        }
        protected virtual ContentItem BuildNewVersion(ContentItem existingContentItem)
        {
            ContentItemRecord contentItemRecord = existingContentItem.Record;

            // locate the existing and the current latest versions, allocate building version
            ContentItemVersionRecord existingItemVersionRecord = existingContentItem.VersionRecord;

            ContentItemVersionRecord buildingItemVersionRecord = new ContentItemVersionRecord
            {
                ContentItemRecord = contentItemRecord,
                Latest = true,
                Published = false,
                Data = existingItemVersionRecord.Data,
            };

            //get the latest version
            ContentItemVersionRecord latestVersion = contentItemRecord.Versions.SingleOrDefault(x => x.Latest);

            if (latestVersion != null)
            {
                latestVersion.Latest = false;
                buildingItemVersionRecord.Number = latestVersion.Number + 1;
            }
            else
            {
                buildingItemVersionRecord.Number = contentItemRecord.Versions.Max(x => x.Number) + 1;
            }

            //Add new version record
            contentItemRecord.Versions.Add(buildingItemVersionRecord);

            //Save the version record to the database
            _contentItemVersionRepository.Create(buildingItemVersionRecord);

            //Create a new contentitem record
            ContentItem buildingContentItem = _contentManager.New(existingContentItem.ContentType);
            buildingContentItem.VersionRecord = buildingItemVersionRecord;

            VersionContentContext context = new VersionContentContext
            {
                Id = existingContentItem.Id,
                ContentType = existingContentItem.ContentType,
                ContentItemRecord = contentItemRecord,
                ExistingContentItem = existingContentItem,
                BuildingContentItem = buildingContentItem,
                ExistingItemVersionRecord = existingItemVersionRecord,
                BuildingItemVersionRecord = buildingItemVersionRecord,
            };

            return context.BuildingContentItem;
        }
        private void RecordAuditTrailEvent(string eventName, IContent content, ContentItemVersionRecord previousContentItemVersion = null, XElement diffGram = null, XElement previousVersionXml = null) {
            var blackList = new[] {"Site"};

            if (blackList.Contains(content.ContentItem.ContentType))
                return;

            var properties = new Dictionary<string, object> {
                {"Content", content}
            };

            var metaData = _contentManager.GetItemMetadata(content);
            var eventData = new Dictionary<string, object> {
                {"ContentId", content.Id},
                {"ContentIdentity", metaData.Identity.ToString()},
                {"ContentType", content.ContentItem.ContentType},
                {"VersionId", content.ContentItem.Version},
                {"VersionNumber", content.ContentItem.VersionRecord != null ? content.ContentItem.VersionRecord.Number : 0},
                {"Published", content.ContentItem.VersionRecord != null && content.ContentItem.VersionRecord.Published},
                {"Title", metaData.DisplayText}
            };

            if (previousContentItemVersion != null) {
                eventData["PreviousVersionId"] = previousContentItemVersion.Id;
                eventData["PreviousVersionNumber"] = previousContentItemVersion.Number;
            }

            if (diffGram != null && previousVersionXml != null) {
                eventData["PreviousVersionXml"] = previousVersionXml.ToString(SaveOptions.DisableFormatting);
                eventData["DiffGram"] = diffGram.ToString(SaveOptions.DisableFormatting);
            }

            _auditTrailManager.CreateRecord<ContentAuditTrailEventProvider>(
                eventName, 
                _wca.GetContext().CurrentUser,
                properties, 
                eventData, 
                eventFilterKey: "content", 
                eventFilterData: content.Id.ToString(CultureInfo.InvariantCulture));
        }
示例#7
0
        protected virtual ContentItem BuildNewVersion(ContentItem existingContentItem)
        {
            var contentItemRecord = existingContentItem.Record;

            // locate the existing and the current latest versions, allocate building version
            var existingItemVersionRecord = existingContentItem.VersionRecord;
            var buildingItemVersionRecord = new ContentItemVersionRecord {
                ContentItemRecord = contentItemRecord,
                Latest = true,
                Published = false,
                Data = existingItemVersionRecord.Data,
            };

            var latestVersion = contentItemRecord.Versions.SingleOrDefault(x => x.Latest);

            if (latestVersion != null) {
                latestVersion.Latest = false;
                buildingItemVersionRecord.Number = latestVersion.Number + 1;
            }
            else {
                buildingItemVersionRecord.Number = contentItemRecord.Versions.Max(x => x.Number) + 1;
            }

            contentItemRecord.Versions.Add(buildingItemVersionRecord);
            _contentStorageManager.Store(buildingItemVersionRecord);

            var buildingContentItem = New(existingContentItem.ContentType);
            buildingContentItem.VersionRecord = buildingItemVersionRecord;

            var context = new VersionContentContext {
                Id = existingContentItem.Id,
                ContentType = existingContentItem.ContentType,
                ContentItemRecord = contentItemRecord,
                ExistingContentItem = existingContentItem,
                BuildingContentItem = buildingContentItem,
                ExistingItemVersionRecord = existingItemVersionRecord,
                BuildingItemVersionRecord = buildingItemVersionRecord,
            };
            Handlers.Invoke(handler => handler.Versioning(context), _logger);
            Handlers.Invoke(handler => handler.Versioned(context), _logger);

            return context.BuildingContentItem;
        }
        public ContentItem NewVersion(ContentItem existingContentItem)
        {
            var contentItemRecord = existingContentItem.Record;

            // locate the existing and the current latest versions, allocate building version
            var existingItemVersionRecord = existingContentItem.VersionRecord;
            var buildingItemVersionRecord = new ContentItemVersionRecord
            {
                ContentItemRecord = contentItemRecord,
                Latest = true,
                Published = false,
                Data = existingItemVersionRecord.Data,

                // Always set up version number to max from existing to avoid conflicts
                Number = contentItemRecord.Versions.Max(x => x.Number) + 1,
            };

            var latestVersion = contentItemRecord.Versions.SingleOrDefault(x => x.Latest);

            if (latestVersion != null) {
                latestVersion.Latest = false;
            }

            contentItemRecord.Versions.Add(buildingItemVersionRecord);
            _contentItemVersionRepository.Create(buildingItemVersionRecord);

            var buildingContentItem = _content.New(existingContentItem.ContentType);
            buildingContentItem.VersionRecord = buildingItemVersionRecord;

            var context = new VersionContentContext
            {
                Id = existingContentItem.Id,
                ContentType = existingContentItem.ContentType,
                ContentItemRecord = contentItemRecord,
                ExistingContentItem = existingContentItem,
                BuildingContentItem = buildingContentItem,
                ExistingItemVersionRecord = existingItemVersionRecord,
                BuildingItemVersionRecord = buildingItemVersionRecord,
            };
            Handlers.Invoke(handler => handler.Versioning(context), Logger);
            Handlers.Invoke(handler => handler.Versioned(context), Logger);

            return context.BuildingContentItem;
        }