Ejemplo n.º 1
0
        public void MoveItem(ItemDefinition itemDefinition, ItemDefinition destination, CallContext context)
        {
            if (DisableSerialization)
            {
                return;
            }

            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

            var sourceItem      = GetSourceFromDefinition(itemDefinition, true);        // we use cache here because we want the old path present before the move
            var destinationItem = GetSourceFromDefinition(destination);

            if (!_predicate.Includes(destinationItem).IsIncluded)             // if the destination we are moving to is NOT included for serialization, we delete the existing item
            {
                var existingItem = GetExistingSerializedItem(sourceItem.Id);

                if (existingItem != null)
                {
                    existingItem.Delete();
                    _logger.MovedItemToNonIncludedLocation(_serializationProvider.LogName, existingItem);
                }

                return;
            }

            _serializationProvider.MoveSerializedItem(sourceItem, destinationItem);
            _logger.MovedItem(_serializationProvider.LogName, sourceItem, destinationItem);
        }
Ejemplo n.º 2
0
        public void MoveItem(ItemDefinition itemDefinition, ItemDefinition destination, CallContext context)
        {
            if (DisableSerialization)
            {
                return;
            }

            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

            var oldSourceItem = GetSourceFromId(itemDefinition.ID, true); // we use cache here because we want the old path

            var oldPath = oldSourceItem.Path;                             // NOTE: we cap the path here, because once we enter the cache-disabled section - to get the new paths for parent and children - the path cache updates and the old path is lost in oldSourceItem because it is reevaluated each time.

            var destinationItem = GetSourceFromId(destination.ID);

            if (!_predicate.Includes(destinationItem).IsIncluded)             // if the destination we are moving to is NOT included for serialization, we delete the existing item
            {
                var existingItem = _targetDataStore.GetByPathAndId(oldSourceItem.Path, oldSourceItem.Id, oldSourceItem.DatabaseName);

                if (existingItem != null)
                {
                    _targetDataStore.Remove(existingItem);
                    _logger.MovedItemToNonIncludedLocation(_targetDataStore.FriendlyName, existingItem);
                }

                return;
            }

            using (new DatabaseCacheDisabler())
            {
                // disabling the DB caches while running this ensures that any children of the moved item are retrieved with their proper post-rename paths and thus are not saved at their old location

                var sourceItem = GetSourceFromId(itemDefinition.ID);                 // re-get the item with cache disabled



                // this allows us to filter out any excluded children by predicate when the data store moves children
                var predicatedItem = new PredicateFilteredItemData(sourceItem, _predicate);

                _targetDataStore.MoveOrRenameItem(predicatedItem, oldPath);
                _logger.MovedItem(_targetDataStore.FriendlyName, sourceItem, destinationItem);
            }
        }
Ejemplo n.º 3
0
        public virtual void MoveItem(ItemDefinition itemDefinition, ItemDefinition destination, CallContext context)
        {
            if (DisableSerialization)
            {
                return;
            }

            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");

            var sourceItem = GetSourceFromId(itemDefinition.ID, true); // we use cache here because we want the old path (no cache would have the new path); TpSync always has old path

            var oldPath = sourceItem.Path;                             // NOTE: we cap the path here, because Sitecore can change the item's path value as we're updating stuff.

            var destinationItem = GetSourceFromId(destination.ID);

            if (destinationItem == null)
            {
                return;                                           // can occur with TpSync on, when this isn't the configuration we're moving for the data store will return null
            }
            if (!_predicate.Includes(destinationItem).IsIncluded) // if the destination we are moving to is NOT included for serialization, we delete the existing item
            {
                var existingItem = _targetDataStore.GetByPathAndId(sourceItem.Path, sourceItem.Id, sourceItem.DatabaseName);

                if (existingItem != null)
                {
                    _targetDataStore.Remove(existingItem);
                    _logger.MovedItemToNonIncludedLocation(_targetDataStore.FriendlyName, existingItem);
                }

                return;
            }

            // rebase the path to the new destination path (this handles children too)
            var rebasedSourceItem = new PathRebasingProxyItem(sourceItem, destinationItem.Path, destinationItem.Id);

            // this allows us to filter out any excluded children by predicate when the data store moves children
            var predicatedItem = new PredicateFilteredItemData(rebasedSourceItem, _predicate);

            _targetDataStore.MoveOrRenameItem(predicatedItem, oldPath);
            _logger.MovedItem(_targetDataStore.FriendlyName, predicatedItem, destinationItem);
        }