/// <summary>
        /// Override the delete method so that we can ensure that all related content type's are updated as part of the overall transaction
        /// </summary>
        /// <param name="entity"></param>
        public override void Delete(IDataTypeDefinition entity)
        {
            //Find ContentTypes using this IDataTypeDefinition on a PropertyType
            var query = Query <PropertyType> .Builder.Where(x => x.DataTypeDefinitionId == entity.Id);

            //TODO: Don't we need to be concerned about media and member types here too ?
            var contentTypes = _contentTypeRepository.GetByQuery(query);

            //Loop through the list of results and remove the PropertyTypes that references the DataTypeDefinition that is being deleted
            foreach (var contentType in contentTypes)
            {
                if (contentType == null)
                {
                    continue;
                }

                foreach (var group in contentType.PropertyGroups)
                {
                    var types = @group.PropertyTypes.Where(x => x.DataTypeDefinitionId == entity.Id).ToList();
                    foreach (var propertyType in types)
                    {
                        @group.PropertyTypes.Remove(propertyType);
                    }
                }

                _contentTypeRepository.AddOrUpdate(contentType);
            }

            //call the base method to queue the deletion of this data type
            base.Delete(entity);
        }
Exemple #2
0
        /// <summary>
        /// Deletes an <see cref="IDataType"/>
        /// </summary>
        /// <remarks>
        /// Please note that deleting a <see cref="IDataType"/> will remove
        /// all the <see cref="IPropertyType"/> data that references this <see cref="IDataType"/>.
        /// </remarks>
        /// <param name="dataType"><see cref="IDataType"/> to delete</param>
        /// <param name="userId">Optional Id of the user issuing the deletion</param>
        public void Delete(IDataType dataType, int userId = Cms.Core.Constants.Security.SuperUserId)
        {
            var evtMsgs = EventMessagesFactory.Get();

            using (var scope = ScopeProvider.CreateCoreScope())
            {
                var deletingDataTypeNotification = new DataTypeDeletingNotification(dataType, evtMsgs);
                if (scope.Notifications.PublishCancelable(deletingDataTypeNotification))
                {
                    scope.Complete();
                    return;
                }

                // find ContentTypes using this IDataTypeDefinition on a PropertyType, and delete
                // TODO: media and members?!
                // TODO: non-group properties?!
                var query        = Query <PropertyType>().Where(x => x.DataTypeId == dataType.Id);
                var contentTypes = _contentTypeRepository.GetByQuery(query);
                foreach (var contentType in contentTypes)
                {
                    foreach (var propertyGroup in contentType.PropertyGroups)
                    {
                        var types = propertyGroup.PropertyTypes?.Where(x => x.DataTypeId == dataType.Id).ToList();
                        if (types is not null)
                        {
                            foreach (var propertyType in types)
                            {
                                propertyGroup.PropertyTypes?.Remove(propertyType);
                            }
                        }
                    }

                    // so... we are modifying content types here. the service will trigger Deleted event,
                    // which will propagate to DataTypeCacheRefresher which will clear almost every cache
                    // there is to clear... and in addition published snapshot caches will clear themselves too, so
                    // this is probably safe although it looks... weird.
                    //
                    // what IS weird is that a content type is losing a property and we do NOT raise any
                    // content type event... so ppl better listen on the data type events too.

                    _contentTypeRepository.Save(contentType);
                }

                _dataTypeRepository.Delete(dataType);

                scope.Notifications.Publish(new DataTypeDeletedNotification(dataType, evtMsgs).WithStateFrom(deletingDataTypeNotification));

                Audit(AuditType.Delete, userId, dataType.Id);

                scope.Complete();
            }
        }
Exemple #3
0
        /// <summary>
        /// Deletes an <see cref="IDataType"/>
        /// </summary>
        /// <remarks>
        /// Please note that deleting a <see cref="IDataType"/> will remove
        /// all the <see cref="PropertyType"/> data that references this <see cref="IDataType"/>.
        /// </remarks>
        /// <param name="dataType"><see cref="IDataType"/> to delete</param>
        /// <param name="userId">Optional Id of the user issueing the deletion</param>
        public void Delete(IDataType dataType, int userId = 0)
        {
            using (var scope = ScopeProvider.CreateScope())
            {
                var deleteEventArgs = new DeleteEventArgs <IDataType>(dataType);
                if (scope.Events.DispatchCancelable(Deleting, this, deleteEventArgs))
                {
                    scope.Complete();
                    return;
                }


                // find ContentTypes using this IDataTypeDefinition on a PropertyType, and delete
                // fixme - media and members?!
                // fixme - non-group properties?!
                var query        = Query <PropertyType>().Where(x => x.DataTypeId == dataType.Id);
                var contentTypes = _contentTypeRepository.GetByQuery(query);
                foreach (var contentType in contentTypes)
                {
                    foreach (var propertyGroup in contentType.PropertyGroups)
                    {
                        var types = propertyGroup.PropertyTypes.Where(x => x.DataTypeId == dataType.Id).ToList();
                        foreach (var propertyType in types)
                        {
                            propertyGroup.PropertyTypes.Remove(propertyType);
                        }
                    }

                    // so... we are modifying content types here. the service will trigger Deleted event,
                    // which will propagate to DataTypeCacheRefresher which will clear almost every cache
                    // there is to clear... and in addition published snapshot caches will clear themselves too, so
                    // this is probably safe alghough it looks... weird.
                    //
                    // what IS weird is that a content type is losing a property and we do NOT raise any
                    // content type event... so ppl better listen on the data type events too.

                    _contentTypeRepository.Save(contentType);
                }

                _dataTypeRepository.Delete(dataType);

                deleteEventArgs.CanCancel = false;
                scope.Events.Dispatch(Deleted, this, deleteEventArgs);
                Audit(AuditType.Delete, userId, dataType.Id);

                scope.Complete();
            }
        }