Ejemplo n.º 1
0
        /// <summary>Update a page version with another, i.e. save a version of the current item and replace it with the replacement item. Returns a version of the previously published item.</summary>
        /// <param name="currentItem">The item that will be stored as a previous version.</param>
        /// <param name="replacementItem">The item that will take the place of the current item using it's ID. Any saved version of this item will not be modified.</param>
        /// <returns>A version of the previously published item.</returns>
        public virtual ContentItem ReplaceVersion(ContentItem currentItem, ContentItem replacementItem)
        {
            CancelDestinationEventArgs args = new CancelDestinationEventArgs(currentItem, replacementItem);
            if (ItemReplacingVersion != null)
                ItemReplacingVersion.Invoke(this, args);
            if (!args.Cancel)
            {
                currentItem = args.AffectedItem;
                replacementItem = args.Destination;

                using (ITransaction transaction = _itemRepository.BeginTransaction())
                {
                    ContentItem versionOfCurrentItem = SaveVersion(currentItem);
                    ClearAllDetails(currentItem);

                    UpdateCurrentItemData(currentItem, replacementItem);

                    currentItem.Updated = Utility.CurrentTime();
                    _itemRepository.Update(currentItem);

                    if (ItemReplacedVersion != null)
                        ItemReplacedVersion.Invoke(this, new ItemEventArgs(replacementItem));
                    if (replacementItem.VersionOf == currentItem)
                        _itemRepository.Delete(replacementItem);

                    _itemRepository.Flush();
                    transaction.Commit();

                    return versionOfCurrentItem;
                }
            }
            return currentItem;
        }
Ejemplo n.º 2
0
 private void OnItemMoved(object sender, CancelDestinationEventArgs e)
 {
     if (LeavingTrash(e))
         _recycleBinHandler.RestoreValues(e.AffectedItem);
     else if (_recycleBinHandler.IsInTrash(e.Destination))
         _recycleBinHandler.ExpireTrashedItem(e.AffectedItem);
 }
Ejemplo n.º 3
0
 private void ItemMovingEvenHandler(object sender, CancelDestinationEventArgs e)
 {
     OnItemMoving(e.AffectedItem, e.Destination);
 }