Ejemplo n.º 1
0
        public override void Save(ContentItem item)
        {
            using (var tx = repository.BeginTransaction())
            {
                // update updated date unless it's a version being saved
                if (!item.VersionOf.HasValue)
                {
                    item.Updated = Utility.CurrentTime();
                }
                // empty string names not allowed, null is replaced with item id
                if (string.IsNullOrEmpty(item.Name))
                {
                    item.Name = null;
                }

                item.AddTo(item.Parent);

                // make sure the ordering is the same next time these siblings are loaded
                var unsavedItems = item.Parent.EnsureChildrenSortOrder();
                foreach (var itemToSave in unsavedItems.Union(new [] { item }))
                {
                    repository.SaveOrUpdate(itemToSave);
                }

                // ensure a name, fallback to id
                if (string.IsNullOrEmpty(item.Name))
                {
                    item.Name = item.ID.ToString();
                    repository.SaveOrUpdate(item);
                }

                tx.Commit();
            }
        }
Ejemplo n.º 2
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>
        /// <param name="storeCurrentVersion">Create a copy of the currently published version before overwriting it.</param>
        /// <returns>A version of the previously published item or the current item when storeCurrentVersion is false.</returns>
        public virtual ContentItem ReplaceVersion(ContentItem currentItem, ContentItem replacementItem, bool storeCurrentVersion = true)
        {
            if (currentItem == null)
            {
                throw new ArgumentNullException("currentItem");
            }
            if (replacementItem == null)
            {
                throw new ArgumentNullException("replacementItem");
            }

            CancellableDestinationEventArgs args = new CancellableDestinationEventArgs(currentItem, replacementItem);

            if (ItemReplacingVersion != null)
            {
                ItemReplacingVersion.Invoke(this, args);
            }
            if (!args.Cancel)
            {
                currentItem     = args.AffectedItem;
                replacementItem = args.Destination;

                using (ITransaction transaction = itemRepository.BeginTransaction())
                {
                    if (storeCurrentVersion)
                    {
                        ContentItem versionOfCurrentItem = AddVersion(currentItem);

                        Replace(currentItem, replacementItem);

                        if ((replacementItem.State == ContentState.Draft || replacementItem.State == ContentState.Waiting) && replacementItem.VersionOf.Value == currentItem)
                        {
                            // drafts can be removed once they have been published
                            currentItem.VersionIndex = replacementItem.VersionIndex;
                            itemRepository.SaveOrUpdate(currentItem);

                            Repository.Delete(replacementItem);
                        }

                        transaction.Commit();
                        return(versionOfCurrentItem);
                    }
                    else
                    {
                        Replace(currentItem, replacementItem);

                        if (replacementItem.State == ContentState.Draft && replacementItem.VersionOf.Value == currentItem)
                        {
                            // drafts can be removed once they have been published
                            //itemRepository.Delete(replacementItem);
                            Repository.Delete(replacementItem);
                        }

                        transaction.Commit();
                        return(currentItem);
                    }
                }
            }
            return(currentItem);
        }
Ejemplo n.º 3
0
        public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
        {
            int updatedItems = 0;

            using (var tx = repository.BeginTransaction())
            {
                var itemsWithUntrackedLinks = repository.Find(Parameter.Like(null, "%/upload/%").Detail() & Parameter.IsNull("TrackedLinks").Detail());
                foreach (var item in itemsWithUntrackedLinks)
                {
                    tracker.UpdateLinks(item);
                    repository.SaveOrUpdate(item);
                    updatedItems++;
                }
                tx.Commit();
            }

            var path = config.UploadFolders.AllElements.Where(uf => !string.IsNullOrEmpty(uf.UrlPrefix)).Select(uf => uf.Path).FirstOrDefault();

            path = Url.ToAbsolute(path);

            return(new MigrationResult(this)
            {
                UpdatedItems = updatedItems,
                RedirectTo = "{ManagementUrl}/Content/LinkTracker/UpdateReferences.aspx"
                             + "?selectedUrl=" + path
                             + "&previousUrl=" + path
                             + "&location=upgrade"
            });
        }
Ejemplo n.º 4
0
 /// <summary>Saves or updates an item storing it in database</summary>
 /// <param name="unsavedItem">Item to save</param>
 public virtual void Save(ContentItem unsavedItem)
 {
     using (var tx = repository.BeginTransaction())
     {
         tx.Committed += (s, a) => Invoke(ItemSaved, new ItemEventArgs(unsavedItem));
         Utility.InvokeEvent(ItemSaving, unsavedItem, this, source.Save, null);
         tx.Commit();
     }
 }
Ejemplo n.º 5
0
        public ContentVersion UpgradeVersion(ContentItem version)
        {
            using (var tx = itemRepository.BeginTransaction())
            {
                var clone = version.CloneForVersioningRecursive();
                clone.VersionOf = version.VersionOf.Value;

                foreach (var child in version.VersionOf.Children.FindParts())
                {
                    child.CloneForVersioningRecursive().AddTo(clone);
                }

                var newVersion = versionRepository.Save(clone);
                itemRepository.Delete(version);

                tx.Commit();

                return(newVersion);
            }
        }
Ejemplo n.º 6
0
        public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
        {
            int updatedItems = 0;

            using (var transaction = repository.BeginTransaction())
            {
                foreach (var item in repository.Find("ChildState", Collections.CollectionState.Unknown))
                {
                    item.ChildState = item.Children.CalculateState();
                    repository.SaveOrUpdate(item);
                    updatedItems++;
                }

                transaction.Commit();
            }

            return(new MigrationResult(this)
            {
                UpdatedItems = updatedItems
            });
        }
Ejemplo n.º 7
0
        public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
        {
            int updatedItems = 0;

            using (var transaction = repository.BeginTransaction())
            {
                var nonNullZoneNameParts = repository.Find(Parameter.IsNull("ZoneName") & Parameter.TypeIn(definitions.GetDefinitions().Where(d => !d.IsPage).Select(d => d.Discriminator).ToArray()));
                foreach (var item in nonNullZoneNameParts)
                {
                    item.ZoneName = "";
                    repository.SaveOrUpdate(item);
                    updatedItems++;
                }

                transaction.Commit();
            }

            return(new MigrationResult(this)
            {
                UpdatedItems = updatedItems
            });
        }