/// <summary> /// After a content has been copied, also copy uploaded files. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="args">The event arguments.</param> static void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> args) { // get the image cropper field properties with a value var properties = args.Original.Properties.Where(x => IsCropperField(x, true)); // copy files var isUpdated = false; foreach (var property in properties) { var jo = GetJObject((string)property.Value, true); if (jo == null || jo["src"] == null) { continue; } var src = jo["src"].Value <string>(); if (string.IsNullOrWhiteSpace(src)) { continue; } var sourcePath = MediaFileSystem.GetRelativePath(src); var copyPath = MediaFileSystem.CopyFile(args.Copy, property.PropertyType, sourcePath); jo["src"] = MediaFileSystem.GetUrl(copyPath); args.Copy.SetValue(property.Alias, jo.ToString()); isUpdated = true; } // if updated, re-save the copy with the updated value if (isUpdated) { sender.Save(args.Copy); } }
/// <summary> /// After a content has been copied, also copy uploaded files. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="args">The event arguments.</param> public void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> args) { // get the image cropper field properties var properties = args.Original.Properties.Where(IsCropperField); // copy files var isUpdated = false; foreach (var property in properties) { //copy each of the property values (variants, segments) to the destination by using the edited value foreach (var propertyValue in property.Values) { var propVal = property.GetValue(propertyValue.Culture, propertyValue.Segment); var src = GetFileSrcFromPropertyValue(propVal, out var jo); if (src == null) { continue; } var sourcePath = _mediaFileSystem.GetRelativePath(src); var copyPath = _mediaFileSystem.CopyFile(args.Copy, property.PropertyType, sourcePath); jo["src"] = _mediaFileSystem.GetUrl(copyPath); args.Copy.SetValue(property.Alias, jo.ToString(), propertyValue.Culture, propertyValue.Segment); isUpdated = true; } } // if updated, re-save the copy with the updated value if (isUpdated) { sender.Save(args.Copy); } }
private void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> e) { if (e.RelateToOriginal) { var relationService = ApplicationContext.Current.Services.RelationService; var relationType = relationService.GetRelationTypeByAlias(Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias); if (relationType == null) { relationType = new RelationType(new Guid(Constants.ObjectTypes.Document), new Guid(Constants.ObjectTypes.Document), Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias, Constants.Conventions.RelationTypes.RelateDocumentOnCopyName) { IsBidirectional = true }; relationService.Save(relationType); } var relation = new Relation(e.Original.Id, e.Copy.Id, relationType); relationService.Save(relation); ApplicationContext.Current.Services.AuditService.Add( AuditType.Copy, string.Format("Copied content with Id: '{0}' related to original content with Id: '{1}'", e.Copy.Id, e.Original.Id), e.Copy.WriterId, e.Copy.Id); } }
/// <summary> /// After a content has been copied, also copy uploaded files. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="args">The event arguments.</param> internal void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> args) { // get the upload field properties with a value var properties = args.Original.Properties.Where(IsUploadField); // copy files var isUpdated = false; foreach (var property in properties) { //copy each of the property values (variants, segments) to the destination foreach (var propertyValue in property.Values) { var propVal = property.GetValue(propertyValue.Culture, propertyValue.Segment); if (propVal == null || !(propVal is string str) || str.IsNullOrWhiteSpace()) { continue; } var sourcePath = _mediaFileSystem.GetRelativePath(str); var copyPath = _mediaFileSystem.CopyFile(args.Copy, property.PropertyType, sourcePath); args.Copy.SetValue(property.Alias, _mediaFileSystem.GetUrl(copyPath), propertyValue.Culture, propertyValue.Segment); isUpdated = true; } } // if updated, re-save the copy with the updated value if (isUpdated) { sender.Save(args.Copy); } }
/// <summary> /// When an entity is copied new permissions may be assigned to it based on it's parent, if that is the /// case then we need to clear all user permissions cache. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> e) { //check if permissions have changed var permissionsChanged = ((Content)e.Copy).WasPropertyDirty("PermissionsChanged"); if (permissionsChanged) { DistributedCache.Instance.RefreshAllUserPermissionsCache(); } }
/// <summary> /// After the content is copied we need to check if there are files that also need to be copied /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> e) { if (e.Original.Properties.Any(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.ImageCropperAlias)) { bool isUpdated = false; var fs = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>(); //Loop through properties to check if the content contains media that should be deleted foreach (var property in e.Original.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.ImageCropperAlias && x.Value != null && string.IsNullOrEmpty(x.Value.ToString()) == false)) { JObject json; try { json = JsonConvert.DeserializeObject <JObject>(property.Value.ToString()); } catch (Exception ex) { LogHelper.Error <ImageCropperPropertyEditor>("An error occurred parsing the value stored in the image cropper value: " + property.Value.ToString(), ex); continue; } if (json["src"] != null && json["src"].ToString().IsNullOrWhiteSpace() == false) { if (fs.FileExists(fs.GetRelativePath(json["src"].ToString()))) { var currentPath = fs.GetRelativePath(json["src"].ToString()); var propertyId = e.Copy.Properties.First(x => x.Alias == property.Alias).Id; var newPath = fs.GetRelativePath(propertyId, System.IO.Path.GetFileName(currentPath)); fs.CopyFile(currentPath, newPath); json["src"] = fs.GetUrl(newPath); e.Copy.SetValue(property.Alias, json.ToString()); //Copy thumbnails foreach (var thumbPath in fs.GetThumbnails(currentPath)) { var newThumbPath = fs.GetRelativePath(propertyId, System.IO.Path.GetFileName(thumbPath)); fs.CopyFile(thumbPath, newThumbPath); } isUpdated = true; } } } if (isUpdated) { //need to re-save the copy with the updated path value sender.Save(e.Copy); } } }
/// <summary> /// After a content has been copied, also copy uploaded files. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="args">The event arguments.</param> static void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> args) { // get the upload field properties with a value var properties = args.Original.Properties.Where(x => IsUploadField(x, true)); // copy files var isUpdated = false; foreach (var property in properties) { var sourcePath = MediaFileSystem.GetRelativePath((string)property.Value); var copyPath = MediaFileSystem.CopyFile(args.Copy, property.PropertyType, sourcePath); args.Copy.SetValue(property.Alias, MediaFileSystem.GetUrl(copyPath)); isUpdated = true; } // if updated, re-save the copy with the updated value if (isUpdated) { sender.Save(args.Copy); } }
/// <summary> /// After the content is copied we need to check if there are files that also need to be copied /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void ContentServiceCopied(IContentService sender, Core.Events.CopyEventArgs <IContent> e) { if (e.Original.Properties.Any(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias)) { bool isUpdated = false; var fs = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>(); //Loop through properties to check if the content contains media that should be deleted foreach (var property in e.Original.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias && x.Value != null && string.IsNullOrEmpty(x.Value.ToString()) == false)) { if (fs.FileExists(fs.GetRelativePath(property.Value.ToString()))) { var currentPath = fs.GetRelativePath(property.Value.ToString()); var propertyId = e.Copy.Properties.First(x => x.Alias == property.Alias).Id; var newPath = fs.GetRelativePath(propertyId, System.IO.Path.GetFileName(currentPath)); fs.CopyFile(currentPath, newPath); e.Copy.SetValue(property.Alias, fs.GetUrl(newPath)); //Copy thumbnails foreach (var thumbPath in fs.GetThumbnails(currentPath)) { var newThumbPath = fs.GetRelativePath(propertyId, System.IO.Path.GetFileName(thumbPath)); fs.CopyFile(thumbPath, newThumbPath); } isUpdated = true; } } if (isUpdated) { //need to re-save the copy with the updated path value sender.Save(e.Copy); } } }
private void ContentService_Copied(IContentService sender, Core.Events.CopyEventArgs <IContent> args) => _notifier.Notify(_actions.GetAction <ActionCopy>(), args.Original);