Enable deployments to export as drafts (next: do the same for import subscriptions, and for the regular import/export)

This commit is contained in:
Bertrand Le Roy
2015-04-13 14:38:17 -07:00
parent 18582128a4
commit 7e5c3980c2
10 changed files with 41 additions and 27 deletions

View File

@@ -74,6 +74,7 @@ namespace Orchard.ImportExport.Drivers {
Metadata = part.IncludeMetadata,
Data = part.IncludeData,
Files = part.IncludeFiles,
DeployAsDraft = part.DeployAsDrafts,
ContentTypes = contentTypes,
SelectedContentTypes = part.ContentTypes,
CustomSteps = new List<CustomStepEntry>(),
@@ -118,17 +119,10 @@ namespace Orchard.ImportExport.Drivers {
if (!updater.TryUpdateModel(viewModel, Prefix, null, null)) return Editor(part, shapeHelper);
//TODO:For now cannot edit target. to be added back in.
//var source = part.ContentItem.ContentManager.Get(viewModel.DeploymentConfigurationId);
//if (source != null) {
// part.DeploymentConfiguration = source;
//}
//else {
// updater.AddModelError("DeploymentConfigurationId", T("Subscription could not be saved as no target was provided."));
//}
part.IncludeMetadata = viewModel.Metadata;
part.IncludeData = viewModel.Data;
part.IncludeFiles = viewModel.Files;
part.DeployAsDrafts = viewModel.DeployAsDraft;
part.Filter = (FilterOptions) Enum.Parse(typeof (FilterOptions), viewModel.FilterChoice);
part.VersionHistoryOption = (VersionHistoryOptions) Enum.Parse(typeof (VersionHistoryOptions), viewModel.DataImportChoice);
part.ContentTypes = viewModel.SelectedContentTypes.ToList();

View File

@@ -15,6 +15,8 @@ namespace Orchard.ImportExport.Migrations {
.ContentPartRecord()
.Column<bool>("IncludeMetadata")
.Column<bool>("IncludeData")
.Column<bool>("IncludeFiles")
.Column<bool>("DeployAsDrafts")
.Column<string>("VersionHistoryOption")
.Column<string>("ContentTypes", col => col.Unlimited())
.Column<string>("QueryIdentity")
@@ -80,7 +82,7 @@ namespace Orchard.ImportExport.Migrations {
SchemaBuilder.AlterTable("RemoteOrchardDeploymentPartRecord", table => table
.AddColumn<string>("PrivateApiKey", c => c.Unlimited()));
return 1;
return 3;
}
public int UpdateFrom1() {
@@ -88,5 +90,11 @@ namespace Orchard.ImportExport.Migrations {
.AddColumn<bool>("IncludeFiles"));
return 2;
}
public int UpdateFrom2() {
SchemaBuilder.AlterTable("DeploymentSubscriptionPartRecord", table => table
.AddColumn<bool>("DeployAsDrafts"));
return 3;
}
}
}

View File

@@ -14,6 +14,7 @@ namespace Orchard.ImportExport.Models {
public virtual bool IncludeMetadata { get; set; }
public virtual bool IncludeData { get; set; }
public virtual bool IncludeFiles { get; set; }
public virtual bool DeployAsDrafts { get; set; }
public virtual VersionHistoryOptions VersionHistoryOption { get; set; }
public virtual FilterOptions Filter { get; set; }
public virtual string DeploymentType { get; set; }
@@ -62,6 +63,11 @@ namespace Orchard.ImportExport.Models {
set { Record.IncludeFiles = value; }
}
public bool DeployAsDrafts {
get { return Record.DeployAsDrafts; }
set { Record.DeployAsDrafts = value; }
}
public VersionHistoryOptions VersionHistoryOption {
get { return Record.VersionHistoryOption; }
set { Record.VersionHistoryOption = value; }

View File

@@ -5,6 +5,7 @@ namespace Orchard.ImportExport.Models {
public bool ExportMetadata { get; set; }
public bool ExportData { get; set; }
public bool ExportFiles { get; set; }
public bool ExportAsDraft { get; set; }
public int? ImportBatchSize { get; set; }
public VersionHistoryOptions VersionHistoryOptions { get; set; }
public bool ExportSiteSettings { get; set; }

View File

@@ -6,6 +6,7 @@ namespace Orchard.ImportExport.Models {
public bool IncludeMetadata { get; set; }
public bool IncludeData { get; set; }
public bool IncludeFiles { get; set; }
public bool DeployAsDrafts { get; set; }
public string QueryIdentity { get; set; }
public VersionHistoryOptions VersionHistoryOption { get; set; }
public DateTime? DeployChangesAfterUtc { get; set; }

View File

@@ -11,6 +11,7 @@ using NuGet;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Settings;
using Orchard.Environment.Descriptor;
using Orchard.FileSystems.AppData;
using Orchard.ImportExport.Models;
@@ -285,13 +286,19 @@ namespace Orchard.ImportExport.Services {
var itemList = contentItems.ToList();
foreach (var contentItemElement in contentTypes
.Select(type => itemList
.Where(i => i.ContentType == type))
.SelectMany(items => items
foreach (var typeName in contentTypes) {
var isTypeDraftable = _contentDefinitionManager.GetTypeDefinition(typeName)
.Settings.GetModel<ContentTypeSettings>().Draftable;
foreach (var contentItemElement in itemList
.Where(i => i.ContentType == typeName)
.Select(contentItemElement => ExportContentItem(contentItemElement, context).Data)
.Where(contentItemElement => contentItemElement != null))) {
data.Add(contentItemElement);
.Where(contentItemElement => contentItemElement != null)
) {
if (context.ExportOptions.ExportAsDraft && isTypeDraftable) {
contentItemElement.Attr("Status", "Draft");
}
data.Add(contentItemElement);
}
}
return data;

View File

@@ -6,7 +6,6 @@ using System.Linq;
using Orchard.ContentManagement;
using Orchard.Environment.Extensions;
using Orchard.FileSystems.AppData;
using Orchard.ImportExport.Handlers;
using Orchard.ImportExport.Models;
using Orchard.Localization;
using Orchard.Logging;
@@ -154,6 +153,7 @@ namespace Orchard.ImportExport.Services {
IncludeMetadata = subscription.IncludeMetadata,
IncludeData = subscription.IncludeData,
IncludeFiles = subscription.IncludeFiles,
DeployAsDrafts = subscription.DeployAsDrafts,
DeployChangesAfterUtc =
(subscription.Filter == FilterOptions.ChangesSinceLastImport)
? subscription.DeployedChangesToUtc : null,
@@ -197,6 +197,7 @@ namespace Orchard.ImportExport.Services {
ExportData = exportingItems.Any(),
ExportMetadata = request.IncludeMetadata,
ExportFiles = request.IncludeFiles,
ExportAsDraft = request.DeployAsDrafts,
VersionHistoryOptions = request.VersionHistoryOption,
CustomSteps = exportSteps
});
@@ -245,16 +246,6 @@ namespace Orchard.ImportExport.Services {
return GetSubscriptionFilePath(executionId, type);
}
private string WriteSubscriptionFile(string executionId, string type, Stream deploymentFile) {
var path = PrepareSubscriptionFilePath(executionId, type);
if (path != null) {
using (var file = _appDataFolder.CreateFile(path)) {
deploymentFile.CopyTo(file);
}
}
return path;
}
private string GetSubscriptionFilePath(string executionId, string type) {
var format = type == "text/xml" ? "{0}.xml" : "{0}.nupkg";
var exportFile = string.Format(format, executionId);

View File

@@ -11,6 +11,7 @@ namespace Orchard.ImportExport.ViewModels {
public bool Metadata { get; set; }
public bool Data { get; set; }
public bool Files { get; set; }
public bool DeployAsDraft { get; set; }
public bool UsePredefinedQuery { get; set; }
public string DataImportChoice { get; set; }
public string FilterChoice { get; set; }

View File

@@ -79,6 +79,10 @@
@Html.RadioButtonFor(m => m.DataImportChoice, "Draft", new { id = "Draft" })
<label for="Draft" class="forcheckbox">@T("Only Drafts")</label>
</div>
<div>
@Html.EditorFor(m => m.DeployAsDraft)
<label for="@Html.FieldIdFor(m => m.DeployAsDraft)" class="forcheckbox">@T("Deploy all draftable items as drafts")</label>
</div>
</fieldset>
@if (Model.CustomSteps.Any())
{

View File

@@ -707,7 +707,8 @@ namespace Orchard.ContentManagement {
var status = element.Attribute("Status");
var item = context.Session.Get(identity, VersionOptions.Latest, XmlConvert.DecodeName(element.Name.LocalName));
var versionRequired = (status != null && status.Value == "Draft") ? VersionOptions.DraftRequired : VersionOptions.Latest;
var item = context.Session.Get(identity, versionRequired, XmlConvert.DecodeName(element.Name.LocalName));
if (item == null) {
item = New(XmlConvert.DecodeName(element.Name.LocalName));
if (status != null && status.Value == "Draft") {