void IContentPartHandler.Created(CreateContentContext context, ContentPart part)
 {
     if (part is TPart)
     {
         Created(context, (TPart)part);
     }
 }
Beispiel #2
0
 void IContentHandler.Created(CreateContentContext context)
 {
     if (context.ContentItem.Is <TPart>())
     {
         Created(context, context.ContentItem.As <TPart>());
     }
 }
Beispiel #3
0
 protected override void Created(CreateContentContext context)
 {
     // At this point the UpdateEditor hasn't been invoked on the content item yet,
     // so we don't have access to all of the information we might need (such as Title).
     // We set a flag which we will check in the Updated method (which is invoked when UpdateEditor is invoked).
     _contentItemCreated = true;
 }
Beispiel #4
0
 public void Created(CreateContentContext context)
 {
     if (!string.IsNullOrWhiteSpace(zone) && hostId != context.ContentItem.Id)
     {
         hostId = context.ContentItem.Id;
     }
 }
 void IContentStorageFilter.Created(CreateContentContext context)
 {
     if (context.ContentItem.Is <TPart>())
     {
         Created(context, context.ContentItem.As <TPart>());
     }
 }
 protected void AssignCreatingOwner(CreateContentContext context, CoeveryCommonPart part)
 {
     // and use the current user as Owner
     if (part.Record.OwnerId == 0)
     {
         part.Owner = _authenticationService.GetAuthenticatedUser();
     }
 }
        public virtual void Create(ContentItem contentItem, VersionOptions options)
        {
            if (contentItem.VersionRecord == null)
            {
                // produce root record to determine the model id
                contentItem.VersionRecord = new ContentItemVersionRecord {
                    ContentItemRecord = new ContentItemRecord {
                    },
                    Number            = 1,
                    Latest            = true,
                    Published         = true
                };
            }

            // add to the collection manually for the created case
            contentItem.VersionRecord.ContentItemRecord.Versions.Add(contentItem.VersionRecord);

            // version may be specified
            if (options.VersionNumber != 0)
            {
                contentItem.VersionRecord.Number = options.VersionNumber;
            }

            // draft flag on create is required for explicitly-published content items
            if (options.IsDraft)
            {
                contentItem.VersionRecord.Published = false;
            }

            _contentItemRepository.Create(contentItem.Record);
            _contentItemVersionRepository.Create(contentItem.VersionRecord);

            // build a context with the initialized instance to create
            var context = new CreateContentContext(contentItem);

            // invoke handlers to add information to persistent stores
            Handlers.Invoke(handler => handler.Creating(context), Logger);

            // deferring the assignment of ContentType as loading a Record might force NHibernate to AutoFlush
            // the ContentPart, and needs the ContentItemRecord to be created before (created in previous statement)
            contentItem.VersionRecord.ContentItemRecord.ContentType = AcquireContentTypeRecord(contentItem.ContentType);

            Handlers.Invoke(handler => handler.Created(context), Logger);


            if (options.IsPublished)
            {
                var publishContext = new PublishContentContext(contentItem, null);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Publishing(publishContext), Logger);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Published(publishContext), Logger);
            }
        }
Beispiel #8
0
        public override void Created(CreateContentContext context, FlowPart part)
        {
            foreach (var contentItem in part.Widgets)
            {
                // Update version number so that IsNew reflects the actual status
                contentItem.Number = 1;
            }

            // Reflect the changes back to the content item
            part.Apply();
        }
        public void Create(ContentItem contentItem)
        {
            _contentItemRepository.Create(contentItem.Record);

            // build a context with the initialized instance to create
            var context = new CreateContentContext(contentItem);

            // invoke handlers to add information to persistent stores
            Handlers.Invoke(handler => handler.Creating(context), Logger);
            Handlers.Invoke(handler => handler.Created(context), Logger);
        }
        public override Task CreatedAsync(CreateContentContext context)
        {
            base.CreatedAsync(context).GetAwaiter().GetResult();
            var httpContent = _httpContentAccessor.HttpContext;

            if (httpContent?.User?.Identity?.IsAuthenticated ?? false)
            {
                context.ContentItem.Author = _extensionService.FindUser(httpContent.User.Identity.Name)
                                             ?.NickName ?? context.ContentItem.Author;
            }
            return(Task.CompletedTask);
        }
        protected void AssignCreatingDates(CreateContentContext context, CoeveryCommonPart part)
        {
            // assign default create/modified dates
            part.Container = context.ContentItem;

            var utcNow = _clock.UtcNow;

            part.CreatedUtc         = utcNow;
            part.ModifiedUtc        = utcNow;
            part.VersionCreatedUtc  = utcNow;
            part.VersionModifiedUtc = utcNow;
        }
        public override void Creating(CreateContentContext context)
        {
            var infosetPart = context.ContentItem.As <InfosetPart>();

            if (infosetPart != null)
            {
                context.ContentItemRecord.Data        = infosetPart.Infoset.Data;
                context.ContentItemVersionRecord.Data = infosetPart.VersionInfoset.Data;

                infosetPart.Infoset        = context.ContentItemRecord.Infoset;
                infosetPart.VersionInfoset = context.ContentItemVersionRecord.Infoset;
            }
        }
Beispiel #13
0
        protected override void  Created(CreateContentContext context)
        {
            var socket = context.ContentItem.As <SocketsPart>();

            if (socket != null)
            {
                // TODO: But we perhaps don't need to do this since ConnectorCollection tracks removed and added objects,
                // ideally we can drop this and let everything happen at the end of transaction scope.
                // If updating, perform connector persistence
                socket.Sockets.AllSockets.Invoke(c => { c.Connectors.Flush(_mechanics.Value); }, Logger);
            }
            base.Created(context);
        }
        public override Task CreatedAsync(CreateContentContext context)
        {
            if (_hca.HttpContext.Items.ContainsKey("OrchardCore.AuditTrail.Restored"))
            {
                return(RecordAuditTrailEventAsync(ContentAuditTrailEventProvider.Restored, context.ContentItem));
            }
            else if (!context.ContentItem.Published)
            {
                return(RecordAuditTrailEventAsync(ContentAuditTrailEventProvider.Created, context.ContentItem));
            }

            return(Task.CompletedTask);
        }
Beispiel #15
0
        public virtual void Create(ContentItem contentItem, VersionOptions options)
        {
            if (contentItem.VersionRecord == null)
            {
                // produce root record to determine the model id
                contentItem.VersionRecord = new ContentItemVersionRecord {
                    ContentItemRecord = new ContentItemRecord(),
                    Number            = 1,
                    Latest            = true,
                    Published         = true
                };
            }

            // add to the collection manually for the created case
            contentItem.VersionRecord.ContentItemRecord.Versions.Add(contentItem.VersionRecord);
            contentItem.VersionRecord.ContentItemRecord.ContentType = AcquireContentTypeRecord(contentItem.ContentType);

            // version may be specified
            if (options.VersionNumber != 0)
            {
                contentItem.VersionRecord.Number = options.VersionNumber;
            }

            // draft flag on create is required for explicitly-published content items
            if (options.IsDraft)
            {
                contentItem.VersionRecord.Published = false;
            }

            _contentItemStore.Store(contentItem);

            // build a context with the initialized instance to create
            var context = new CreateContentContext(contentItem);

            // invoke handlers to add information to persistent stores
            Handlers.Invoke(handler => handler.Creating(context), _logger);

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

            if (options.IsPublished)
            {
                var publishContext = new PublishContentContext(contentItem, null);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Publishing(publishContext), _logger);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Published(publishContext), _logger);
            }
        }
Beispiel #16
0
        public override Task CreatedAsync(CreateContentContext context, PartyPart part)
        {
            if (part.PartyType == PartyType.Person)
            {
                part.FullName = part.Content.FirstName.ToString() + " " + part.Content.LastName.ToString();
            }
            else if (part.PartyType == PartyType.Organization)
            {
                part.FirstName = string.Empty;
                part.LastName  = string.Empty;
            }

            part.ContentItem.DisplayText = part.FullName;
            //part.Apply();
            return(Task.CompletedTask);
        }
Beispiel #17
0
        protected void AssociateLoyalzooAccount(CreateContentContext context)
        {
            //Non eseguo la creazione di un nuovo utente Loyalzoo se chiamo dal pannello di amministrazione di Orchard
            if (_controllerContextAccessor.Context.Controller.GetType().FullName != "Orchard.Users.Controllers.AdminController")
            {
                APIResult accountCreationResult = _fidelityService.CreateLoyalzooAccountFromContext(context);

                if (accountCreationResult.success == true)
                {
                    _controllerContextAccessor.Context.Controller.TempData.Add("LoyalzooRegistrationSuccess", true);
                }
                else
                {
                    _controllerContextAccessor.Context.Controller.TempData.Add("LoyalzooRegistrationSuccess", false);
                }
            }
        }
        /// <summary>
        /// Need to override CreatingAsync to set the right parent on Creation.
        /// This will attach the item to the right list when the item is created from a list of another culture
        /// </summary>
        public override async Task CreatingAsync(CreateContentContext context, LocalizationPart instance)
        {
            var containedPart = context.ContentItem.As <ContainedPart>();

            if (containedPart != null)
            {
                var list = await _session.QueryIndex <LocalizedContentItemIndex>(i => (i.Published || i.Latest) && i.ContentItemId == containedPart.ListContentItemId).FirstOrDefaultAsync();

                var localizedList = await _session.QueryIndex <LocalizedContentItemIndex>(i => (i.Published || i.Latest) && i.LocalizationSet == list.LocalizationSet && i.Culture == instance.Culture).FirstOrDefaultAsync();

                if (localizedList != null)
                {
                    containedPart.ListContentItemId = localizedList.ContentItemId;
                    containedPart.Apply();
                }
            }
        }
Beispiel #19
0
        public virtual void Create(ContentItem contentItem, VersionOptions options)
        {
            if (contentItem.Number == 0)
            {
                contentItem.Number    = 1;
                contentItem.Latest    = true;
                contentItem.Published = true;
            }

            // Version may be specified
            if (options.VersionNumber != 0)
            {
                contentItem.Number = options.VersionNumber;
            }

            // Draft flag on create is required for explicitly-published content items
            if (options.IsDraft)
            {
                contentItem.Published = false;
            }

            // Build a context with the initialized instance to create
            var context = new CreateContentContext(contentItem);

            // invoke handlers to add information to persistent stores
            Handlers.Invoke(handler => handler.Creating(context), _logger);

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

            if (options.IsPublished)
            {
                var publishContext = new PublishContentContext(contentItem, null);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Publishing(publishContext), _logger);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Published(publishContext), _logger);
            }

            _session.Save(contentItem);
            _contentManagerSession.Store(contentItem);
        }
        public void Create(ContentItem contentItem, VersionOptions options)
        {
            if (contentItem.Number == 0)
            {
                contentItem.Number    = 1;
                contentItem.Latest    = true;
                contentItem.Published = true;
            }

            if (String.IsNullOrEmpty(contentItem.ContentItemVersionId))
            {
                contentItem.ContentItemVersionId = _idGenerator.GenerateUniqueId(contentItem);
            }

            // Draft flag on create is required for explicitly-published content items
            if (options.IsDraft)
            {
                contentItem.Published = false;
            }

            // Build a context with the initialized instance to create
            var context = new CreateContentContext(contentItem);

            // invoke handlers to add information to persistent stores
            Handlers.Invoke(handler => handler.Creating(context), _logger);

            Handlers.Reverse().Invoke(handler => handler.Created(context), _logger);

            _session.Save(contentItem);
            _contentManagerSession.Store(contentItem);

            if (options.IsPublished)
            {
                var publishContext = new PublishContentContext(contentItem, null);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Publishing(publishContext), _logger);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Reverse().Invoke(handler => handler.Published(publishContext), _logger);
            }
        }
        public override void Creating(CreateContentContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);

            if (contentTypeDefinition == null)
            {
                return;
            }

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                var partName = typePartDefinition.PartDefinition.Name;
                var partType = _contentPartFactory.GetContentPartType(partName) ?? typeof(ContentPart);

                var part = context.ContentItem.Get(partType, partName) as ContentPart;

                if (part != null)
                {
                    _partHandlers.Invoke(handler => handler.Creating(context, part), Logger);
                }
            }
        }
Beispiel #22
0
        public override async Task CreatingAsync(CreateContentContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);

            if (contentTypeDefinition == null)
            {
                return;
            }

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                var partName  = typePartDefinition.PartDefinition.Name;
                var activator = _contentPartFactory.GetTypeActivator(partName);

                var part = context.ContentItem.Get(activator.Type, typePartDefinition.Name) as ContentPart;

                if (part != null)
                {
                    await _partHandlers.InvokeAsync(async handler => await handler.CreatingAsync(context, part), Logger);
                }
            }
        }
        public APIResult CreateLoyalzooAccountFromContext(CreateContentContext context)
        {
            try
            {
                IUser            userPart     = context.ContentItem.As <IUser>();
                LoyalzooUserPart loyalzooPart = context.ContentItem.As <LoyalzooUserPart>();

                if (userPart != null && loyalzooPart != null)
                {
                    return(CreateLoyalzooAccount(loyalzooPart, userPart.UserName, userPart.Email));

                    //string userName = "";
                    //if (userPart.UserName == "testale2")
                    //    userName = Guid.NewGuid().ToString();
                    //else
                    //    userName = userPart.UserName;

                    //return CreateLoyalzooAccount(loyalzooPart, userName, userPart.Email);
                }
                else
                {
                    return new APIResult {
                               success = false, data = null, message = "The user is not configured to use Loyalzoo."
                    }
                };
            }
            catch (Exception e)
            {
                APIResult exceptionData = new APIResult();

                exceptionData.success = false;
                exceptionData.message = e.Message;
                exceptionData.data    = null;

                return(exceptionData);
            }
        }
Beispiel #24
0
        //todo: add log scopes for these operations

        public override async Task CreatingAsync(CreateContentContext context)
        {
            // the presence of this key indicates that a content item is being restored by the audit trail module
            if (!_httpContextAccessor.HttpContext.Items.ContainsKey("OrchardCore.AuditTrail.Restored"))
            {
                return;
            }

            try
            {
                if (!await _syncOrchestrator.Restore(context.ContentItem))
                {
                    // sad paths have already been notified to the user and logged
                    Cancel(context);
                }
            }
            catch (Exception ex)
            {
                // we log the exception, even though some exceptions will have already been logged,
                // as there might have been an 'unexpected' exception thrown
                _logger.LogError(ex, "Exception saving draft.");
                Cancel(context);
            }
        }
Beispiel #25
0
 public override Task CreatedAsync(CreateContentContext context) => AddContextAsync(context);
 protected override void Creating(CreateContentContext context, TestModelPart instance)
 {
     instance.CreatingCalled = true;
 }
Beispiel #27
0
        private async Task <ContentValidateResult> CreateContentItemVersionAsync(ContentItem contentItem, IEnumerable <ContentItem> evictionVersions = null)
        {
            if (String.IsNullOrEmpty(contentItem.ContentItemId))
            {
                // NewAsync should be used to create new content items.
                throw new ArgumentNullException(nameof(ContentItem.ContentItemId));
            }

            // Initializes the Id as it could be interpreted as an updated object when added back to YesSql
            contentItem.Id = 0;

            // Maintain modified and published dates as these will be reset by the Create Handlers
            var modifiedUtc  = contentItem.ModifiedUtc;
            var publishedUtc = contentItem.PublishedUtc;
            var owner        = contentItem.Owner;
            var author       = contentItem.Author;

            if (String.IsNullOrEmpty(contentItem.ContentItemVersionId))
            {
                contentItem.ContentItemVersionId = _idGenerator.GenerateUniqueId(contentItem);
            }

            // Remove previous latest item or they will continue to be listed as latest.
            // When importing a new draft the existing latest must be set to false. The creating version wins.
            if (contentItem.Latest && !contentItem.Published)
            {
                await RemoveLatestVersionAsync(contentItem, evictionVersions);
            }
            else if (contentItem.Published)
            {
                // When importing a published item existing drafts and existing published must be removed.
                // Otherwise an existing draft would become an orphan and if published would overwrite
                // the imported (which we assume is the version that wins) content.
                await RemoveVersionsAsync(contentItem, evictionVersions);
            }
            // When neither published or latest the operation will create a database record
            // which will be part of the content item archive.

            // Invoked create handlers.
            var context = new CreateContentContext(contentItem);
            await Handlers.InvokeAsync((handler, context) => handler.CreatingAsync(context), context, _logger);

            // The content item should be placed in the session store so that further calls
            // to ContentManager.Get by a scoped index provider will resolve the imported item correctly.
            _session.Save(contentItem);
            _contentManagerSession.Store(contentItem);

            await ReversedHandlers.InvokeAsync((handler, context) => handler.CreatedAsync(context), context, _logger);

            await UpdateAsync(contentItem);

            var result = await ValidateAsync(contentItem);

            if (!result.Succeeded)
            {
                return(result);
            }

            if (contentItem.Published)
            {
                // Invoke published handlers to add information to persistent stores
                var publishContext = new PublishContentContext(contentItem, null);

                await Handlers.InvokeAsync((handler, context) => handler.PublishingAsync(context), publishContext, _logger);

                await ReversedHandlers.InvokeAsync((handler, context) => handler.PublishedAsync(context), publishContext, _logger);
            }
            else
            {
                await SaveDraftAsync(contentItem);
            }

            // Restore values that may have been altered by handlers.
            if (modifiedUtc.HasValue)
            {
                contentItem.ModifiedUtc = modifiedUtc;
            }
            if (publishedUtc.HasValue)
            {
                contentItem.PublishedUtc = publishedUtc;
            }

            // There is a risk here that the owner or author does not exist in the importing system.
            // We check that at least a value has been supplied, if not the owner property and author
            // property would be left as the user who has run this import.
            if (!String.IsNullOrEmpty(owner))
            {
                contentItem.Owner = owner;
            }
            if (!String.IsNullOrEmpty(author))
            {
                contentItem.Author = author;
            }

            return(result);
        }
Beispiel #28
0
 protected override void Creating(CreateContentContext context)
 {
     base.Creating(context);
 }
 public virtual void Created(CreateContentContext context, TPart instance)
 {
 }
 public virtual void Created(CreateContentContext context) {}
 protected virtual void Created(CreateContentContext context, TPart instance)
 {
 }