/// <summary> /// The default serialization event handler does not catch duplications (bug 384823) /// </summary> public void OnItemCopied(object sender, EventArgs e) { if (DisabledLocally) { return; } // param 0 = source item, param 1 = destination item var item = Event.ExtractParameter <Item>(e, 1); if (item == null) { return; } if (!Presets.Includes(item)) { return; } ShadowWriter.PutItem(Operation.Updated, item, item.Parent); // putting the root isn't enough; if it has children those also need to get serialized var descendants = item.Axes.GetDescendants(); foreach (var descendant in descendants) { ShadowWriter.PutItem(Operation.Updated, descendant, descendant.Parent); } }
/// <summary> /// The default serialization event handler actually deletes serialized subitems if the parent item is renamed. This patches that behavior to preserve subitem files. (bug 384931) /// </summary> public void OnItemRenamed(object sender, EventArgs e) { if (DisabledLocally) { return; } // param 0 = renamed item, param 1 = old item name var item = Event.ExtractParameter <Item>(e, 0); var oldName = Event.ExtractParameter <string>(e, 1); if (item == null || oldName == null) { return; } // the name wasn't actually changed, you sneaky template builder you. Don't write. if (oldName.Equals(item.Name, StringComparison.Ordinal)) { return; } if (!Presets.Includes(item)) { return; } // we push this to get updated. Because saving now ignores "inconsquential" changes like a rename that do not change data fields, // this keeps renames occurring even if the field changes are inconsequential ShadowWriter.PutItem(Operation.Updated, item, item.Parent); var reference = new ItemReference(item).ToString(); var oldReference = reference.Substring(0, reference.LastIndexOf('/') + 1) + oldName; var oldSerializationPath = PathUtils.GetDirectoryPath(oldReference); var newSerializationPath = PathUtils.GetDirectoryPath(reference); if (Directory.Exists(oldSerializationPath) && !Directory.Exists(newSerializationPath)) { Directory.Move(oldSerializationPath, newSerializationPath); } }