Exemplo n.º 1
0
        /// <inheritdoc/>
        public override bool ApplyDatabaseChanges(StructuredContentHelper helper, StructuredContentChanges changes, RockContext rockContext)
        {
            var imageChanges = changes.GetData <ImageChangeData>();

            if (imageChanges == null)
            {
                return(false);
            }

            var addedBinaryFileIds   = imageChanges?.NewFileIds?.Except(imageChanges.OldFileIds)?.ToList();
            var removedBinaryFileIds = imageChanges?.OldFileIds?.Except(imageChanges.NewFileIds)?.ToList();

            bool needSave          = false;
            var  binaryFileService = new BinaryFileService(rockContext);

            // If there are any newly added binary files then mark them as
            // permanent so they will persist in the database.
            if (addedBinaryFileIds != null && addedBinaryFileIds.Count > 0)
            {
                var filesToAdd = binaryFileService.Queryable()
                                 .Where(b => addedBinaryFileIds.Contains(b.Id))
                                 .ToList();

                filesToAdd.ForEach(b => b.IsTemporary = false);
                needSave = true;
            }

            // If there are any removed binary files then mark them as temporary
            // so they will be later removed by the cleanup job.
            if (removedBinaryFileIds != null && removedBinaryFileIds.Count > 0)
            {
                var filesToRemove = binaryFileService.Queryable()
                                    .Where(b => removedBinaryFileIds.Contains(b.Id))
                                    .ToList();

                filesToRemove.ForEach(b => b.IsTemporary = true);
                needSave = true;
            }

            return(needSave);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        protected override void DetectBlockChanges(ImageData newData, ImageData oldData, StructuredContentChanges changes)
        {
            var imageChanges = changes.GetData <ImageChangeData>();

            if (imageChanges == null)
            {
                imageChanges = new ImageChangeData();
                changes.AddOrReplaceData(imageChanges);
            }

            // If the new data has a file identifier then store it for later review.
            if (newData?.File?.FileId != null)
            {
                imageChanges.NewFileIds.Add(newData.File.FileId.Value);
            }

            // If the old data has a file identifier then store it for alter review.
            if (oldData?.File?.FileId != null)
            {
                imageChanges.OldFileIds.Add(oldData.File.FileId.Value);
            }
        }