private void PageMoving(object sender, DocumentEventArgs e) { var node = e.Node; var target = e.TargetParentNode; bool isAtSynchronizedSite = _pageSync.IsAtSynchronizedSite(node); bool targetIsAtSynchronizedSite = _pageSync.IsAtSynchronizedSite(target); if (isAtSynchronizedSite != targetIsAtSynchronizedSite) { if (!targetIsAtSynchronizedSite) { // Delete subtree when moving away from synchronized site var subtree = _pageSync.GetSourceDocuments() .OnSite(node.NodeSiteName) .Path(node.NodeAliasPath, PathTypeEnum.Section) .AllCultures() .TypedResult .ToList(); var documentIds = subtree.Select(n => n.DocumentID).ToList(); var attachments = AttachmentInfoProvider.GetAttachments() .WhereIn("AttachmentDocumentID", documentIds) .BinaryData(false) .ExceptVariants() .TypedResult .ToList(); RunSynchronization(async() => { var info = node.NodeAliasPath + "%"; await _pageSync.DeletePages(null, subtree, info); await _assetSync.DeleteAttachments(null, attachments, info); }); } else { // Sync subtree when moving to synchronized site e.CallWhenFinished(() => { var subtree = _pageSync.GetSourceDocuments() .OnSite(node.NodeSiteName) .Path(node.NodeAliasPath, PathTypeEnum.Section) .AllCultures() .WithCoupledColumns() .TypedResult .ToList(); RunSynchronization(async() => { foreach (var page in subtree) { await _pageSync.SyncPageWithAllData(null, page); } }); }); } } }
private void PageUpdating(object sender, DocumentEventArgs e) { var node = e.Node; var oldCanBePublished = false; node.ExecuteWithOriginalData(() => { oldCanBePublished = _pageSync.CanBePublished(node); }); var canBePublished = _pageSync.CanBePublished(node); if (oldCanBePublished && !canBePublished) { // Unpublished e.CallWhenFinished(() => { RunSynchronization(async() => await _pageSync.DeletePage(node)); }); } }