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(); } }
public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus) { var alreadyUpdated = new HashSet <string>(); int updatedItems = 0; using (var transaction = repository.BeginTransaction()) { var detailsWithImages = repository.Find( Parameter.Equal("ValueTypeKey", "String"), Parameter.Like("StringValue", "%<img%") ); foreach (var detail in detailsWithImages) { if (alreadyUpdated.Contains(detail.EnclosingItem.Name)) { continue; } alreadyUpdated.Add(detail.EnclosingItem.Name); linkTracker.UpdateLinks(detail.EnclosingItem); itemRepository.SaveOrUpdate(detail.EnclosingItem); updatedItems++; } repository.Flush(); transaction.Commit(); } return(new MigrationResult(this) { UpdatedItems = updatedItems }); }
public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus) { var alreadyUpdated = new HashSet <int>(); int updatedItems = 0; using (var transaction = repository.BeginTransaction()) { foreach (var detail in repository.Find("Name", Tracker.LinkDetailName)) { if (alreadyUpdated.Contains(detail.EnclosingItem.ID)) { continue; } alreadyUpdated.Add(detail.EnclosingItem.ID); linkTracker.UpdateLinks(detail.EnclosingItem); itemRepository.SaveOrUpdate(detail.EnclosingItem); updatedItems++; } repository.Flush(); transaction.Commit(); } return(new MigrationResult(this) { UpdatedItems = updatedItems }); }
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" }); }
private void EnsureName(ContentItem item) { if (string.IsNullOrEmpty(item.Name)) { item.Name = item.ID.ToString(); repository.SaveOrUpdate(item); } }
private int AdvancePubDateForSite(ContentItem startPage) { var childs = CmsFinder.FindAllDescendentsOf <ContentItem>(startPage); childs.Add(startPage); var childCount = 0; foreach (var child in childs.Where(child => child.IsPublished())) { child.Published = child.Published.HasValue ? child.Published.Value.AddSeconds(1.0) : DateTime.Now; _contentItemRepository.SaveOrUpdate(child); ++childCount; } return(childCount); }
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 }); }
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 }); }
/// <summary>Creates a version of the item. This must be called before the item item is modified to save a version before modifications.</summary> /// <param name="item">The item to create a old version of.</param> /// <returns>The old version.</returns> public virtual ContentItem AddVersion(ContentItem item, bool asPreviousVersion = true) { if (item == null) { throw new ArgumentNullException("item"); } CancellableItemEventArgs args = new CancellableItemEventArgs(item); if (ItemSavingVersion != null) { ItemSavingVersion.Invoke(this, args); } if (args.Cancel) { return(null); } item = args.AffectedItem; if (!item.IsPage) { var page = Find.ClosestPage(item); if (page == null) { throw new InvalidOperationException("Cannot create version of part which isn't on a page: " + item); } var pageVersion = AddVersion(page, asPreviousVersion: asPreviousVersion); var partVersion = pageVersion.FindPartVersion(item); return(partVersion); } ContentItem version = item.CloneForVersioningRecursive(stateChanger, asPreviousVersion); if (item.Parent != null) { version["ParentID"] = item.Parent.ID; } //ContentVersion savedVersion; if (asPreviousVersion) { /*savedVersion = */ Repository.Save(version, asPreviousVersion); item.VersionIndex = Repository.GetGreatestVersionIndex(item) + 1; itemRepository.SaveOrUpdate(item); } else { version.VersionIndex = Repository.GetGreatestVersionIndex(item) + 1; /*savedVersion = */ Repository.Save(version, asPreviousVersion); } if (ItemSavedVersion != null) { ItemSavedVersion.Invoke(this, new ItemEventArgs(version)); } TrimVersionCountTo(item, maximumVersionsPerItem); return(version); // Repository.DeserializeVersion(savedVersion); }
public override void Save(ContentItem item) { repository.SaveOrUpdate(item); }