Пример #1
0
        //    public virtual void Remove(ContentItem contentItem) {
        //        var activeVersions = _contentItemVersionRepository.Fetch(x => x.ContentItemRecord == contentItem.Record && (x.Published || x.Latest));
        //        var context = new RemoveContentContext(contentItem);
        //        Handlers.Invoke(handler => handler.Removing(context), Logger);
        //        foreach (var version in activeVersions) {
        //            if (version.Published) {
        //                version.Published = false;
        //            }
        //            if (version.Latest) {
        //                version.Latest = false;
        //            }
        //        }
        //        Handlers.Invoke(handler => handler.Removed(context), Logger);
        //    }
        //    public virtual void Destroy(ContentItem contentItem) {
        //        var session = _sessionLocator.Value.For(typeof(ContentItemVersionRecord));
        //        var context = new DestroyContentContext(contentItem);
        //        // Give storage filters a chance to delete content part records.
        //        Handlers.Invoke(handler => handler.Destroying(context), Logger);
        //        // Delete content item version and content item records.
        //        session
        //            .CreateQuery("delete from Orchard.ContentManagement.Records.ContentItemVersionRecord civ where civ.ContentItemRecord.Id = (:id)")
        //            .SetParameter("id", contentItem.Id)
        //            .ExecuteUpdate();
        //        // Delete the content item record itself.
        //        session
        //            .CreateQuery("delete from Orchard.ContentManagement.Records.ContentItemRecord ci where ci.Id = (:id)")
        //            .SetParameter("id", contentItem.Id)
        //            .ExecuteUpdate();
        //        Handlers.Invoke(handler => handler.Destroyed(context), Logger);
        //    }
        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));
            Handlers.Invoke(handler => handler.Versioned(context));

            return context.BuildingContentItem;
        }
Пример #2
0
 public PublishContentContext(ContentItem contentItem, ContentItemVersionRecord previousItemVersionRecord)
     : base(contentItem)
 {
     PublishingItemVersionRecord = contentItem.VersionRecord;
     PreviousItemVersionRecord = previousItemVersionRecord;
 }