示例#1
0
        /// <summary>
        /// Queues ContentChannelItems of this ContentChannel to have their indexes deleted
        /// </summary>
        /// <param name="contentChannelId">The content channel identifier.</param>
        public void DeleteIndexedDocumentsByContentChannel(int contentChannelId)
        {
            var contentChannelItemIds = new ContentChannelItemService(new RockContext()).Queryable()
                                        .Where(i => i.ContentChannelId == contentChannelId).Select(a => a.Id).ToList();

            int contentChannelItemEntityTypeId = EntityTypeCache.GetId <Rock.Model.ContentChannelItem>().Value;

            foreach (var contentChannelItemId in contentChannelItemIds)
            {
                var transaction = new DeleteIndexEntityTransaction {
                    EntityId = contentChannelItemId, EntityTypeId = contentChannelItemEntityTypeId
                };
                transaction.Enqueue();
            }
        }
示例#2
0
        /// <summary>
        /// Creates audit logs and/or triggers workflows for items that were changed
        /// </summary>
        /// <param name="updatedItems">The updated items.</param>
        /// <param name="personAlias">The person alias.</param>
        /// <param name="enableAuditing">if set to <c>true</c> [enable auditing].</param>
        protected virtual void RockPostSave(List <ContextItem> updatedItems, PersonAlias personAlias, bool enableAuditing = false)
        {
            if (enableAuditing)
            {
                try
                {
                    var audits = updatedItems.Select(i => i.Audit).ToList();
                    if (audits.Any(a => a.Details.Any()))
                    {
                        var transaction = new Rock.Transactions.AuditTransaction();
                        transaction.Audits = audits;
                        Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                    }
                }
                catch (SystemException ex)
                {
                    ExceptionLogService.LogException(ex, null);
                }
            }

            List <ITransaction> indexTransactions = new List <ITransaction>();

            foreach (var item in updatedItems)
            {
                if (item.State == EntityState.Detached || item.State == EntityState.Deleted)
                {
                    TriggerWorkflows(item, WorkflowTriggerType.PostDelete, personAlias);
                }
                else
                {
                    if (item.PreSaveState == EntityState.Added)
                    {
                        TriggerWorkflows(item, WorkflowTriggerType.PostAdd, personAlias);
                    }

                    TriggerWorkflows(item, WorkflowTriggerType.ImmediatePostSave, personAlias);
                    TriggerWorkflows(item, WorkflowTriggerType.PostSave, personAlias);
                }

                if (item.Entity is IModel)
                {
                    var model = item.Entity as IModel;
                    model.PostSaveChanges(this);
                }

                // check if this entity should be passed on for indexing
                if (item.Entity is IRockIndexable)
                {
                    if (item.State == EntityState.Detached || item.State == EntityState.Deleted)
                    {
                        DeleteIndexEntityTransaction transaction = new DeleteIndexEntityTransaction();
                        transaction.EntityTypeId = item.Entity.TypeId;
                        transaction.EntityId     = item.Entity.Id;

                        indexTransactions.Add(transaction);
                    }
                    else
                    {
                        IndexEntityTransaction transaction = new IndexEntityTransaction();
                        transaction.EntityTypeId = item.Entity.TypeId;
                        transaction.EntityId     = item.Entity.Id;

                        indexTransactions.Add(transaction);
                    }
                }

                if (item.Entity is ICacheable)
                {
                    (item.Entity as ICacheable).UpdateCache(item.PreSaveState, this);
                }
            }

            // check if Indexing is enabled in another thread to avoid deadlock when Snapshot Isolation is turned off when the Index components upload/load attributes
            if (indexTransactions.Any())
            {
                System.Threading.Tasks.Task.Run(() =>
                {
                    var indexingEnabled = IndexContainer.GetActiveComponent() == null ? false : true;
                    if (indexingEnabled)
                    {
                        indexTransactions.ForEach(t => RockQueue.TransactionQueue.Enqueue(t));
                    }
                });
            }
        }