public ActionResult UnsetPublishedVersion(int id) { var contentItem = Services.ContentManager.Get(-1, VersionOptions.VersionRecord(id)); if (contentItem == null) { return(HttpNotFound()); } Services.ContentManager.Unpublish(contentItem); Services.Notifier.Add(NotifyType.Information, T("Version {0} of content item un-published.", contentItem.Version)); return(RedirectToAction("List", new { contentItem.Id })); }
public ActionResult Delete(int id) { var contentItem = Services.ContentManager.Get(-1, VersionOptions.VersionRecord(id)); if (contentItem == null) { return(HttpNotFound()); } Services.ContentManager.Remove(contentItem); Services.Notifier.Add(NotifyType.Information, T("Content item {0} has been deleted.", contentItem.Id)); return(RedirectToAction("ListDeleted")); }
public ActionResult Undelete(int id) { var contentItem = Services.ContentManager.Get(-1, VersionOptions.VersionRecord(id)); if (contentItem == null) { return(HttpNotFound()); } // Undelete and publish contentItem.VersionRecord.Latest = true; Services.ContentManager.Publish(contentItem); Services.Notifier.Add(NotifyType.Information, T("Content item {0} has been un-deleted and re-published.", contentItem.Id)); return(RedirectToAction("List", new { contentItem.Id })); }
public bool UnsetPublishedVersion(int id, int versionId) { ContentItem contentItem = _contentManager.Get(id, VersionOptions.VersionRecord(versionId)); if (contentItem == null) { _notifier.Error(T("Could not find version id {0} of content with id {0}", versionId, id)); return(false); } _contentManager.Unpublish(contentItem); _notifier.Add(NotifyType.Information, T("Version {0} of content item un-published.", contentItem.Version)); return(true); }
public bool Promote(int id, int versionId) { //Get the last version number to create a new version int lastversionNumber = _contentManager.GetAllVersions(id).Max(r => r.VersionRecord.Number); //Retrieve the content item to clone ContentItem contentItem = _contentManager.Get(id, VersionOptions.VersionRecord(versionId)); if (contentItem == null) { _notifier.Error(T("Could not find content with id {0}", id)); return(false); } int versionOfContentItemToClone = contentItem.VersionRecord.Number; //Unfortunately it creates not a new record but updates the old record _contentManager.Create(contentItem, VersionOptions.Number(lastversionNumber + 1)); //var newContent = BuildNewVersion(contentItem); //Update the table that a new version is added ContentItemVersionRecord previousLastRecord = _versionManagerDataService.ContentItemVersionRecords.FirstOrDefault( r => r.ContentItemRecord.Id == id && r.Latest); ContentItemVersionRecord newLastRecord = _versionManagerDataService.ContentItemVersionRecords.Where(r => r.ContentItemRecord.Id == contentItem.Id) .OrderByDescending(r => r.Number) .FirstOrDefault(); if (previousLastRecord != null && newLastRecord != null) { previousLastRecord.Latest = false; newLastRecord.Latest = true; _versionManagerDataService.SetContentItemVersionRecord(previousLastRecord); _versionManagerDataService.SetContentItemVersionRecord(newLastRecord); } _notifier.Information(T("Successfully promoted version {0} to {1}.", versionOfContentItemToClone, lastversionNumber + 1)); return(true); }
public ActionResult Actuate(string name, int?contentId = null, int?contentVersionId = null, string returnUrl = null) { IContent content = null; if (contentId.HasValue) { if (contentVersionId.HasValue) { content = _contentManager.Get(contentId.Value, VersionOptions.VersionRecord(contentVersionId.Value)); } else { content = _contentManager.Get(contentId.Value, VersionOptions.Latest); } } var impulse = _impulseService.CheckForImpulse(name, content); // TODO: Extract data from query string if (impulse == null) { return(HttpNotFound("Could not actuate impulse")); } var context = new ImpulseContext() { Impulse = impulse, ReturnUrl = returnUrl }; var result = _impulseService.ActuateImpulse(context); if (result == ImpulseActuationResult.NotAuthorized) { return(new HttpUnauthorizedResult()); } // Back to origin page (or other as defined in context) if (returnUrl != null) { return(Redirect(context.ReturnUrl)); } return(Json(true)); }
public bool Undelete(int id) { ContentItem contentItem = _contentManager.Get(-1, VersionOptions.VersionRecord(id)); if (contentItem == null) { return(false); } string title = contentItem.Id.ToString(CultureInfo.InvariantCulture); if (contentItem.Has <TitlePart>()) { title = contentItem.As <TitlePart>().Title; } // Undelete and publish contentItem.VersionRecord.Latest = true; _contentManager.Publish(contentItem); _notifier.Information(T("Content item '{0}' has been un-deleted and re-published.", title)); return(true); }
/// <summary> /// Indexes a batch of content items /// </summary> /// <returns> /// <c>true</c> if there are more items to process; otherwise, <c>false</c>. /// </returns> private bool BatchIndex(string indexName, string settingsFilename, IndexSettings indexSettings) { var addToIndex = new List <IDocumentIndex>(); var deleteFromIndex = new List <int>(); bool loop = false; // Rebuilding the index ? if (indexSettings.Mode == IndexingMode.Rebuild) { Logger.Information("Rebuilding index"); _indexingStatus = IndexingStatus.Rebuilding; do { loop = true; // load all content items var contentItems = _contentRepository .Table.Where(versionRecord => versionRecord.Latest && versionRecord.Id > indexSettings.LastContentId) .OrderBy(versionRecord => versionRecord.Id) .Take(ContentItemsPerLoop) .ToList() .Select(versionRecord => _contentManager.Get(versionRecord.ContentItemRecord.Id, VersionOptions.VersionRecord(versionRecord.Id))) .Distinct() .ToList(); // if no more elements to index, switch to update mode if (contentItems.Count == 0) { indexSettings.Mode = IndexingMode.Update; } foreach (var item in contentItems) { try { var settings = GetTypeIndexingSettings(item); // skip items from types which are not indexed if (settings.List.Contains(indexName)) { if (item.HasPublished()) { var published = _contentManager.Get(item.Id, VersionOptions.Published); IDocumentIndex documentIndex = ExtractDocumentIndex(published); if (documentIndex != null && documentIndex.IsDirty) { addToIndex.Add(documentIndex); } } } else if (settings.List.Contains(indexName + ":latest")) { IDocumentIndex documentIndex = ExtractDocumentIndex(item); if (documentIndex != null && documentIndex.IsDirty) { addToIndex.Add(documentIndex); } } indexSettings.LastContentId = item.VersionRecord.Id; } catch (Exception ex) { Logger.Warning(ex, "Unable to index content item #{0} during rebuild", item.Id); } } if (contentItems.Count < ContentItemsPerLoop) { loop = false; } else { _transactionManager.RequireNew(); } } while (loop); } if (indexSettings.Mode == IndexingMode.Update) { Logger.Information("Updating index"); _indexingStatus = IndexingStatus.Updating; do { var indexingTasks = _taskRepository .Table.Where(x => x.Id > indexSettings.LastIndexedId) .OrderBy(x => x.Id) .Take(ContentItemsPerLoop) .ToList() .GroupBy(x => x.ContentItemRecord.Id) .Select(group => new { TaskId = group.Max(task => task.Id), Delete = group.Last().Action == IndexingTaskRecord.Delete, Id = group.Key, ContentItem = _contentManager.Get(group.Key, VersionOptions.Latest) }) .OrderBy(x => x.TaskId) .ToArray(); foreach (var item in indexingTasks) { try { IDocumentIndex documentIndex = null; // item.ContentItem can be null if the content item has been deleted if (item.ContentItem != null) { // skip items from types which are not indexed var settings = GetTypeIndexingSettings(item.ContentItem); if (settings.List.Contains(indexName)) { if (item.ContentItem.HasPublished()) { var published = _contentManager.Get(item.Id, VersionOptions.Published); documentIndex = ExtractDocumentIndex(published); } } else if (settings.List.Contains(indexName + ":latest")) { var latest = _contentManager.Get(item.Id, VersionOptions.Latest); documentIndex = ExtractDocumentIndex(latest); } } if (documentIndex == null || item.Delete) { deleteFromIndex.Add(item.Id); } else if (documentIndex.IsDirty) { addToIndex.Add(documentIndex); } indexSettings.LastIndexedId = item.TaskId; } catch (Exception ex) { Logger.Warning(ex, "Unable to index content item #{0} during update", item.Id); } } if (indexingTasks.Length < ContentItemsPerLoop) { loop = false; } else { _transactionManager.RequireNew(); } } while (loop); } // save current state of the index indexSettings.LastIndexedUtc = _clock.UtcNow; _appDataFolder.CreateFile(settingsFilename, indexSettings.ToXml()); if (deleteFromIndex.Count == 0 && addToIndex.Count == 0) { // nothing more to do _indexingStatus = IndexingStatus.Idle; return(false); } // save new and updated documents to the index try { if (addToIndex.Count > 0) { _indexProvider.Store(indexName, addToIndex); Logger.Information("Added content items to index: {0}", addToIndex.Count); } } catch (Exception ex) { Logger.Warning(ex, "An error occured while adding a document to the index"); } // removing documents from the index try { if (deleteFromIndex.Count > 0) { _indexProvider.Delete(indexName, deleteFromIndex); Logger.Information("Added content items to index: {0}", addToIndex.Count); } } catch (Exception ex) { Logger.Warning(ex, "An error occured while removing a document from the index"); } return(true); }
public void Discover(ShapeTableBuilder builder) { builder.Describe("AuditTrailEvent").OnDisplaying(context => { var record = (AuditTrailEventRecord)context.Shape.Record; if (record.Category != "Content") { return; } var eventData = (IDictionary <string, object>)context.Shape.EventData; var contentItemId = eventData.Get <int>("ContentId"); var previousContentItemVersionId = eventData.Get <int>("PreviousVersionId"); var previousVersionXml = eventData.GetXml("PreviousVersionXml"); var diffGram = eventData.GetXml("DiffGram"); var contentItem = _contentManager.Value.Get(contentItemId, VersionOptions.AllVersions); var previousVersion = previousContentItemVersionId > 0 ? _contentManager.Value.Get(contentItemId, VersionOptions.VersionRecord(previousContentItemVersionId)) : default(ContentItem); if (diffGram != null) { var diffNodes = _analyzer.Analyze(previousVersionXml, diffGram).ToArray(); context.Shape.DiffNodes = diffNodes; } context.Shape.ContentItemId = contentItemId; context.Shape.ContentItem = contentItem; context.Shape.PreviousVersion = previousVersion; }); builder.Describe("AuditTrailEventActions").OnDisplaying(context => { var record = (AuditTrailEventRecord)context.Shape.Record; if (record.Category != "Content") { return; } var eventData = (IDictionary <string, object>)context.Shape.EventData; var contentItemId = eventData.Get <int>("ContentId"); var previousContentItemVersionId = eventData.Get <int>("PreviousVersionId"); var contentItem = _contentManager.Value.Get(contentItemId, VersionOptions.AllVersions); var previousVersion = previousContentItemVersionId > 0 ? _contentManager.Value.Get(contentItemId, VersionOptions.VersionRecord(previousContentItemVersionId)) : default(ContentItem); context.Shape.ContentItemId = contentItemId; context.Shape.ContentItem = contentItem; context.Shape.PreviousVersion = previousVersion; }); }
public ShippingProviderPart GetProvider(int ProviderId, int?VersionRecordId = null) { return(_contentManager.Get <ShippingProviderPart>(ProviderId, VersionRecordId.HasValue ? VersionOptions.VersionRecord(VersionRecordId.Value) : VersionOptions.Published)); }