mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
commit
94a7311c4b
194
src/Orchard.Tests/DataMigration/SchemaCommandGeneratorTests.cs
Normal file
194
src/Orchard.Tests/DataMigration/SchemaCommandGeneratorTests.cs
Normal file
@ -0,0 +1,194 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
using Autofac.Features.Metadata;
|
||||
using NHibernate;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data;
|
||||
using Orchard.Data.Conventions;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Data.Migration.Generator;
|
||||
using Orchard.Data.Migration.Interpreters;
|
||||
using Orchard.Data.Migration.Records;
|
||||
using Orchard.Data.Migration.Schema;
|
||||
using Orchard.DevTools.Services;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Folders;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.ShellBuilders.Models;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.Tests.ContentManagement;
|
||||
using Orchard.Data.Providers;
|
||||
using Orchard.Tests.FileSystems.AppData;
|
||||
|
||||
namespace Orchard.Tests.DataMigration {
|
||||
[TestFixture]
|
||||
public class SchemaCommandGeneratorTests {
|
||||
private IContainer _container;
|
||||
private StubFolders _folders;
|
||||
private ISchemaCommandGenerator _generator;
|
||||
|
||||
private ISessionFactory _sessionFactory;
|
||||
private ISession _session;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void CreateDb() {
|
||||
var types = new[] {
|
||||
typeof(BlogRecord),
|
||||
typeof(BodyRecord),
|
||||
typeof(BlogArchiveRecord),
|
||||
typeof(ContentItemVersionRecord),
|
||||
typeof(ContentItemRecord),
|
||||
typeof(ContentTypeRecord)};
|
||||
|
||||
var databaseFileName = System.IO.Path.GetTempFileName();
|
||||
_sessionFactory = DataUtility.CreateSessionFactory(
|
||||
databaseFileName, types );
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
_folders = new StubFolders();
|
||||
|
||||
var manager = (IDataServicesProviderFactory)new DataServicesProviderFactory(new[] {
|
||||
new Meta<CreateDataServicesProvider>(
|
||||
(dataFolder, connectionString) => new SqlCeDataServicesProvider(dataFolder, connectionString),
|
||||
new Dictionary<string, object> {{"ProviderName", "SqlCe"}})
|
||||
});
|
||||
|
||||
builder.RegisterInstance(new ShellSettings { Name = "Default", DataTablePrefix = "TEST_", DataProvider = "SqlCe"});
|
||||
builder.RegisterInstance(AppDataFolderTests.CreateAppDataFolder(Path.GetDirectoryName(databaseFileName))).As<IAppDataFolder>();
|
||||
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
|
||||
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
|
||||
builder.RegisterInstance(manager).As<IDataServicesProviderFactory>();
|
||||
builder.RegisterType<NullInterpreter>().As<IDataMigrationInterpreter>();
|
||||
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
|
||||
builder.RegisterInstance(_folders).As<IExtensionFolders>();
|
||||
builder.RegisterType<SchemaCommandGenerator>().As<ISchemaCommandGenerator>();
|
||||
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
|
||||
_session = _sessionFactory.OpenSession();
|
||||
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();
|
||||
|
||||
builder.RegisterInstance(new ShellBlueprint() { Records = types.Select(t => new RecordBlueprint { Feature = new Feature() { Descriptor = new FeatureDescriptor() { Name = "Feature1" } }, TableName = "TEST_" + t.Name, Type = t })});
|
||||
|
||||
_container = builder.Build();
|
||||
_generator = _container.Resolve<ISchemaCommandGenerator>();
|
||||
|
||||
_folders.Manifests.Add("Module1", @"
|
||||
name: Module1
|
||||
version: 0.1
|
||||
orchardversion: 1
|
||||
features:
|
||||
Feature1:
|
||||
Description: Feature
|
||||
");
|
||||
}
|
||||
|
||||
public class StubFolders : IExtensionFolders {
|
||||
public StubFolders() {
|
||||
Manifests = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public IDictionary<string, string> Manifests { get; set; }
|
||||
|
||||
public IEnumerable<ExtensionDescriptor> AvailableExtensions() {
|
||||
foreach (var e in Manifests) {
|
||||
string name = e.Key;
|
||||
var parseResult = ExtensionFolders.ParseManifest(Manifests[name]);
|
||||
yield return ExtensionFolders.GetDescriptorForExtension("~/", name, "Module", parseResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ShouldCreateCreateTableCommands() {
|
||||
var commands = _generator.GetCreateFeatureCommands("Feature1", false).ToList();
|
||||
Assert.That(commands, Is.Not.Null);
|
||||
Assert.That(commands.Count(), Is.EqualTo(6));
|
||||
|
||||
var blogRecord = commands.Where(c => c.Name == "TEST_BlogRecord").First();
|
||||
|
||||
Assert.That(blogRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Id" && !c.IsIdentity && c.IsPrimaryKey && c.DbType == DbType.Int32));
|
||||
Assert.That(blogRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Description" && c.DbType == DbType.String));
|
||||
Assert.That(blogRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "PostCount" && c.DbType == DbType.Int32));
|
||||
|
||||
var blogArchiveRecord = commands.Where(c => c.Name == "TEST_BlogArchiveRecord").First();
|
||||
Assert.That(blogArchiveRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Id" && c.IsPrimaryKey && c.DbType == DbType.Int32));
|
||||
Assert.That(blogArchiveRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Year" && c.DbType == DbType.Int32));
|
||||
Assert.That(blogArchiveRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Month" && c.DbType == DbType.Int32));
|
||||
Assert.That(blogArchiveRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "PostCount" && c.DbType == DbType.Int32));
|
||||
Assert.That(blogArchiveRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Blog_id" && c.DbType == DbType.Int32));
|
||||
|
||||
var bodyRecord = commands.Where(c => c.Name == "TEST_BodyRecord").First();
|
||||
Assert.That(bodyRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Id" && c.IsPrimaryKey && c.DbType == DbType.Int32));
|
||||
Assert.That(bodyRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Text" && c.DbType == DbType.String && c.Length == 10000));
|
||||
Assert.That(bodyRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "Format" && c.DbType == DbType.String && c.Length == 42));
|
||||
Assert.That(bodyRecord.TableCommands.OfType<CreateColumnCommand>().Any(c => c.ColumnName == "ContentItemRecord_id" && c.DbType == DbType.Int32));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ScaffoldingCommandInterpreterShouldDetectContentParts() {
|
||||
|
||||
var commands = _generator.GetCreateFeatureCommands("Feature1", false).ToList();
|
||||
Assert.That(commands, Is.Not.Null);
|
||||
Assert.That(commands.Count(), Is.EqualTo(6));
|
||||
|
||||
var sw = new StringWriter();
|
||||
var interpreter = new ScaffoldingCommandInterpreter(sw);
|
||||
|
||||
var blogRecord = commands.Where(c => c.Name == "TEST_BlogRecord").First();
|
||||
var blogArchiveRecord = commands.Where(c => c.Name == "TEST_BlogArchiveRecord").First();
|
||||
var bodyRecord = commands.Where(c => c.Name == "TEST_BodyRecord").First();
|
||||
|
||||
sw.GetStringBuilder().Clear();
|
||||
interpreter.Visit(blogRecord);
|
||||
Assert.That(sw.ToString().Contains("SchemaBuilder.CreateTable(\"TEST_BlogRecord"));
|
||||
Assert.That(sw.ToString().Contains(".ContentPartRecord()"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"Description\", DbType.String)"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"PostCount\", DbType.Int32)"));
|
||||
|
||||
sw.GetStringBuilder().Clear();
|
||||
interpreter.Visit(blogArchiveRecord);
|
||||
Assert.That(sw.ToString().Contains("SchemaBuilder.CreateTable(\"TEST_BlogArchiveRecord"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"Id\", DbType.Int32, column => column.PrimaryKey().Identity())"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"Year\", DbType.Int32)"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"Month\", DbType.Int32)"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"PostCount\", DbType.Int32)"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"Blog_id\", DbType.Int32)"));
|
||||
|
||||
sw.GetStringBuilder().Clear();
|
||||
interpreter.Visit(bodyRecord);
|
||||
Assert.That(sw.ToString().Contains("SchemaBuilder.CreateTable(\"TEST_BodyRecord"));
|
||||
Assert.That(sw.ToString().Contains(".ContentPartVersionRecord()"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"Text\", DbType.String, column => column.WithLength(10000))"));
|
||||
Assert.That(sw.ToString().Contains(".Column(\"Format\", DbType.String, column => column.WithLength(42))"));
|
||||
Assert.That(!sw.ToString().Contains("ContentItemRecord_id"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class BlogRecord : ContentPartRecord {
|
||||
public virtual string Description { get; set; }
|
||||
public virtual int PostCount { get; set; }
|
||||
}
|
||||
|
||||
public class BodyRecord : ContentPartVersionRecord {
|
||||
[StringLengthMax]
|
||||
public virtual string Text { get; set; }
|
||||
[StringLength(42)]
|
||||
public virtual string Format { get; set; }
|
||||
}
|
||||
|
||||
public class BlogArchiveRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual BlogRecord Blog { get; set; }
|
||||
public virtual int Year { get; set; }
|
||||
public virtual int Month { get; set; }
|
||||
public virtual int PostCount { get; set; }
|
||||
}
|
||||
}
|
@ -181,6 +181,7 @@
|
||||
<Compile Include="ContentManagement\Records\GammaRecord.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DataMigration\SchemaCommandGeneratorTests.cs" />
|
||||
<Compile Include="DataMigration\SchemaBuilderTests.cs" />
|
||||
<Compile Include="DataMigration\DataMigrationTests.cs" />
|
||||
<Compile Include="DataMigration\Utilities\NullInterpreter.cs" />
|
||||
@ -254,6 +255,10 @@
|
||||
<Compile Include="Utility\ReflectTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.DevTools\Orchard.DevTools.csproj">
|
||||
<Project>{67C1D3AF-A0EC-46B2-BAE1-DF1DA8E0B890}</Project>
|
||||
<Name>Orchard.DevTools</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Web\Modules\Orchard.Users\Orchard.Users.csproj">
|
||||
<Project>{79AED36E-ABD0-4747-93D3-8722B042454B}</Project>
|
||||
<Name>Orchard.Users</Name>
|
||||
|
@ -0,0 +1,24 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
|
||||
namespace Orchard.Core.Common.Extensions {
|
||||
public static class HtmlHelperExtensions {
|
||||
public static LocalizedString PublishedStateForModel(this HtmlHelper<CommonMetadataViewModel> htmlHelper, Localizer T) {
|
||||
return htmlHelper.PublishedState(htmlHelper.ViewData.Model, T);
|
||||
}
|
||||
|
||||
public static LocalizedString PublishedState(this HtmlHelper htmlHelper, CommonMetadataViewModel metadata, Localizer T) {
|
||||
return htmlHelper.DateTime(metadata.VersionPublishedUtc, T("Draft"));
|
||||
}
|
||||
|
||||
public static LocalizedString PublishedWhenForModel(this HtmlHelper<CommonMetadataViewModel> htmlHelper, Localizer T) {
|
||||
return htmlHelper.PublishedWhen(htmlHelper.ViewData.Model, T);
|
||||
}
|
||||
|
||||
public static LocalizedString PublishedWhen(this HtmlHelper htmlHelper, CommonMetadataViewModel metadata, Localizer T) {
|
||||
return htmlHelper.DateTimeRelative(metadata.VersionPublishedUtc, T("as a Draft"), T);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.ViewModels.CommonMetadataViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %><%
|
||||
if (Model.Creator != null) { %>
|
||||
<div class="metadata">
|
||||
<div class="posted"><%: T("Published by {0}", Model.Creator != null ? Model.Creator.UserName : T("nobody(?)").ToString())%></div>
|
||||
</div>
|
||||
<div class="posted"><%: T("Published by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T))%></div>
|
||||
</div><%
|
||||
} %>
|
@ -27,6 +27,13 @@ namespace Orchard.Core.Contents.Handlers {
|
||||
{"Id", context.ContentItem.Id}
|
||||
};
|
||||
}
|
||||
if (context.Metadata.RemoveRouteValues == null) {
|
||||
context.Metadata.RemoveRouteValues = new RouteValueDictionary {
|
||||
{"Area", "Contents"},
|
||||
{"Controller", "Item"},
|
||||
{"Action", "Remove"}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Contents.ViewModels.ListContentsViewModel>" %>
|
||||
<h1><%:Html.TitleForPage(T("Manage {0} Content", !string.IsNullOrEmpty(Model.TypeDisplayName) ? Model.TypeDisplayName : T("").Text).ToString())%></h1>
|
||||
<h1><%:Html.TitleForPage((string.IsNullOrEmpty(Model.TypeDisplayName) ? T("Manage Content") : T("Manage {0} Content", Model.TypeDisplayName)).ToString())%></h1>
|
||||
<div class="manage">
|
||||
<%:Html.ActionLink(!string.IsNullOrEmpty(Model.TypeDisplayName) ? T("Add new {0} content", Model.TypeDisplayName).Text : T("Add new content").Text, "Create", new { }, new { @class = "button primaryAction" })%>
|
||||
</div>
|
||||
|
@ -12,7 +12,8 @@
|
||||
<%:Html.Hidden("id", Model.Item.Id, new { id = "" })%>
|
||||
<button type="submit"><%:T("Remove") %></button><%
|
||||
} %>
|
||||
<br /><% Html.Zone("meta"); %>
|
||||
</div>
|
||||
<div style="clear:both;"></div>
|
||||
<% Html.Zone("primary"); %>
|
||||
<% Html.ZonesAny(); %>
|
||||
</div>
|
@ -1,11 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement.Aspects" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement" %>
|
||||
<%var routable = Model.Item.As<IRoutableAspect>();
|
||||
if (routable != null && !string.IsNullOrEmpty(routable.Title)) {%>
|
||||
<h1>
|
||||
<%:routable.Title%></h1>
|
||||
<%} %>
|
||||
<% Html.Zone("primary", ":manage :metadata");
|
||||
<h1><%:Html.ItemDisplayText(Model.Item)%></h1>
|
||||
<% Html.Zone("metadata");
|
||||
Html.Zone("primary", ":manage :metadata");
|
||||
Html.ZonesAny(); %>
|
||||
|
@ -65,6 +65,7 @@
|
||||
<Compile Include="Common\Drivers\BodyDriver.cs" />
|
||||
<Compile Include="Common\Drivers\CommonDriver.cs" />
|
||||
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
|
||||
<Compile Include="Common\Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Common\Fields\TextField.cs" />
|
||||
<Compile Include="Common\Services\ICommonService.cs" />
|
||||
<Compile Include="Common\Services\CommonService.cs" />
|
||||
|
@ -111,7 +111,7 @@ namespace Orchard.Blogs.Controllers {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Delete(string blogSlug) {
|
||||
public ActionResult Remove(string blogSlug) {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Couldn't delete blog")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
|
@ -77,12 +77,6 @@ namespace Orchard.Blogs.Drivers {
|
||||
};
|
||||
}
|
||||
|
||||
protected override DriverResult Display(BlogPost post, string displayType) {
|
||||
return Combined(
|
||||
ContentItemTemplate("Items/Blogs.BlogPost").LongestMatch(displayType, "Summary", "SummaryAdmin"),
|
||||
ContentPartTemplate(post, "Parts/Blogs.BlogPost.Metadata").LongestMatch(displayType, "Summary", "SummaryAdmin").Location("meta", "1"));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(BlogPost post) {
|
||||
return ContentItemTemplate("Items/Blogs.BlogPost");
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
|
||||
namespace Orchard.Blogs.Extensions {
|
||||
public static class HtmlHelperExtensions {
|
||||
public static LocalizedString PublishedState(this HtmlHelper<BlogPost> htmlHelper, Localizer T) {
|
||||
return htmlHelper.PublishedState(htmlHelper.ViewData.Model, T);
|
||||
}
|
||||
|
||||
public static LocalizedString PublishedState(this HtmlHelper htmlHelper, BlogPost blogPost, Localizer T) {
|
||||
return htmlHelper.DateTime(blogPost.As<ICommonAspect>().VersionPublishedUtc, T("Draft"));
|
||||
}
|
||||
|
||||
public static LocalizedString PublishedWhen(this HtmlHelper<BlogPost> htmlHelper, Localizer T) {
|
||||
return htmlHelper.PublishedWhen(htmlHelper.ViewData.Model, T);
|
||||
}
|
||||
|
||||
public static LocalizedString PublishedWhen(this HtmlHelper htmlHelper, BlogPost blogPost, Localizer T) {
|
||||
return htmlHelper.DateTimeRelative(blogPost.As<ICommonAspect>().VersionPublishedUtc, T("as a Draft"), T);
|
||||
}
|
||||
}
|
||||
}
|
@ -46,7 +46,9 @@ namespace Orchard.Blogs.Handlers {
|
||||
return;
|
||||
}
|
||||
|
||||
var containerId = requestContext.HttpContext.Request.Form["containerId"];
|
||||
//todo: don't get at the container form data directly. right now the container is set in the common driver editor (updater)
|
||||
//todo: which is too late for what's needed (currently) in this handler
|
||||
var containerId = requestContext.HttpContext.Request.Form["CommonAspect.containerId"];
|
||||
if (!string.IsNullOrEmpty(containerId)) {
|
||||
int cId;
|
||||
if (int.TryParse(containerId, out cId)) {
|
||||
|
@ -74,7 +74,6 @@
|
||||
<Compile Include="Controllers\BlogPostController.cs" />
|
||||
<Compile Include="Drivers\BlogPostDriver.cs" />
|
||||
<Compile Include="Extensions\FeedManagerExtensions.cs" />
|
||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Extensions\UrlHelperExtensions.cs" />
|
||||
<Compile Include="Filters\ArchivesFilter.cs" />
|
||||
<Compile Include="Models\ArchiveData.cs" />
|
||||
@ -136,16 +135,12 @@
|
||||
<Content Include="Views\DisplayTemplates\Parts\Blogs.Blog.Manage.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Parts\Blogs.BlogPost.List.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Items\Blogs.Blog.Summary.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Parts\Blogs.BlogPost.Metadata.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Parts\Blogs.Blog.Description.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Parts\Blogs.Blog.Metadata.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Parts\Blogs.BlogPost.Metadata.SummaryAdmin.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Parts\Blogs.BlogPost.Metadata.Summary.ascx" />
|
||||
<Content Include="Views\BlogPost\Item.ascx" />
|
||||
<Content Include="Views\BlogAdmin\Create.ascx" />
|
||||
<Content Include="Views\BlogAdmin\Edit.ascx" />
|
||||
<Content Include="Views\Blog\Item.ascx" />
|
||||
<Content Include="Views\DisplayTemplates\Items\Blogs.BlogPost.SummaryAdmin.ascx" />
|
||||
<Content Include="Views\EditorTemplates\Parts\Blogs.Blog.Fields.ascx" />
|
||||
<Content Include="Views\EditorTemplates\Items\Blogs.Blog.ascx" />
|
||||
<Content Include="Views\EditorTemplates\Items\Blogs.BlogPost.ascx" />
|
||||
|
@ -51,11 +51,11 @@ namespace Orchard.Blogs {
|
||||
},
|
||||
new RouteDescriptor {
|
||||
Route = new Route(
|
||||
"Admin/Blogs/{blogSlug}/Delete",
|
||||
"Admin/Blogs/{blogSlug}/Remove",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "BlogAdmin"},
|
||||
{"action", "Delete"}
|
||||
{"action", "Remove"}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"blogSlug", _blogSlugConstraint}
|
||||
|
@ -2,6 +2,10 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels" %>
|
||||
<h2><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h2>
|
||||
<div class="meta"><%: Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
|
||||
<div class="meta"><%: Html.PublishedState(new CommonMetadataViewModel(Model.Item.As<CommonAspect>()), T) %> | <%Html.Zone("meta");%></div>
|
||||
<div class="content"><% Html.Zone("primary", ":manage :metadata");%></div>
|
||||
|
@ -1,58 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
|
||||
<%@ Import Namespace="Orchard.ContentManagement.Aspects"%>
|
||||
<%@ Import Namespace="Orchard.ContentManagement"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<div class="summary">
|
||||
<div class="properties">
|
||||
<h3><%: Html.Link(Model.Item.Title, Url.BlogPostEdit(Model.Item))%></h3>
|
||||
<ul>
|
||||
<li><%
|
||||
if (Model.Item.HasPublished) { %>
|
||||
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/online.gif") %>" alt="<%: T("Online") %>" title="<%: T("The page is currently online") %>" /> <%: T("Published")%><%
|
||||
}
|
||||
else { %>
|
||||
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/offline.gif") %>" alt="<%: T("Offline") %>" title="<%: T("The page is currently offline") %>" /> <%: T("Not Published")%><%
|
||||
} %> |
|
||||
</li>
|
||||
<li><%
|
||||
if (Model.Item.HasDraft) { %>
|
||||
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/draft.gif") %>" alt="<%: T("Draft") %>" title="<%: T("The post has a draft") %>" /><%: Html.PublishedState(Model.Item, T) %><%
|
||||
}
|
||||
else { %>
|
||||
<%: T("No draft")%><%
|
||||
} %> |
|
||||
</li>
|
||||
<li><%
|
||||
if (Model.Item.ScheduledPublishUtc.HasValue && Model.Item.ScheduledPublishUtc.Value > DateTime.UtcNow) { %>
|
||||
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/scheduled.gif") %>" alt="<%: T("Scheduled") %>" title="<%: T("The post is scheduled for publishing") %>" /><%: T("Scheduled")%>
|
||||
<%: Html.DateTime(Model.Item.ScheduledPublishUtc.Value, T("M/d/yyyy h:mm tt"))%><%
|
||||
}
|
||||
else if (Model.Item.IsPublished) { %>
|
||||
<%: T("Published: {0}", Html.DateTimeRelative(Model.Item.As<ICommonAspect>().VersionPublishedUtc.Value, T)) %><%
|
||||
}
|
||||
else { %>
|
||||
<%: T("Last modified: {0}", Html.DateTimeRelative(Model.Item.As<ICommonAspect>().ModifiedUtc.Value, T)) %><%
|
||||
} %> |
|
||||
</li>
|
||||
<li><%: T("By {0}", Model.Item.Creator.UserName)%></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="related"><%
|
||||
if (Model.Item.HasPublished){ %>
|
||||
<a href="<%: Url.BlogPost(Model.Item) %>" title="<%: T("View Post")%>"><%: T("View")%></a><%: T(" | ")%><%
|
||||
if (Model.Item.HasDraft) { %>
|
||||
<a href="<%: Html.AntiForgeryTokenGetUrl(Url.BlogPostPublish(Model.Item)) %>" title="<%: T("Publish Draft")%>"><%: T("Publish Draft")%></a><%: T(" | ")%><%
|
||||
} %>
|
||||
<a href="<%: Html.AntiForgeryTokenGetUrl(Url.BlogPostUnpublish(Model.Item)) %>" title="<%: T("Unpublish Post")%>"><%: T("Unpublish")%></a><%: T(" | ")%><%
|
||||
}
|
||||
else { %>
|
||||
<a href="<%: Html.AntiForgeryTokenGetUrl(Url.BlogPostPublish(Model.Item)) %>" title="<%: T("Publish Post")%>"><%: T("Publish")%></a><%: T(" | ")%><%
|
||||
} %>
|
||||
<a href="<%: Url.BlogPostEdit(Model.Item) %>" title="<%: T("Edit Post")%>"><%: T("Edit")%></a><%: T(" | ")%>
|
||||
<a href="<%: Html.AntiForgeryTokenGetUrl(Url.BlogPostDelete(Model.Item)) %>" title="<%: T("Remove Post")%>"><%: T("Remove")%></a>
|
||||
<br /><%Html.Zone("meta");%>
|
||||
</div>
|
||||
<div style="clear:both;"></div>
|
||||
</div>
|
@ -1,6 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%><%
|
||||
if (Model.Creator != null) {
|
||||
%><span class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %> | </span><%
|
||||
} %>
|
@ -1,2 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
@ -1,8 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<div class="metadata"><%
|
||||
if (Model.Creator != null) {
|
||||
%><div class="posted"><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %></div><%
|
||||
} %>
|
||||
</div>
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Orchard.Data.Migration.Interpreters;
|
||||
@ -16,7 +17,35 @@ namespace Orchard.DevTools.Services {
|
||||
_output.WriteLine("\t\t\t// Creating table {0}", command.Name);
|
||||
_output.WriteLine("\t\t\tSchemaBuilder.CreateTable(\"{0}\", table => table", command.Name);
|
||||
|
||||
|
||||
var matchContentPartRecord = command.TableCommands.OfType<CreateColumnCommand>().Any(
|
||||
c =>
|
||||
c.IsPrimaryKey
|
||||
&& c.ColumnName == "Id"
|
||||
&& !c.IsIdentity
|
||||
&& c.DbType == DbType.Int32);
|
||||
|
||||
var matchContentPartVersionRecord = matchContentPartRecord && command.TableCommands.OfType<CreateColumnCommand>().Any(
|
||||
c =>
|
||||
c.ColumnName == "ContentItemRecord_id"
|
||||
&& c.DbType == DbType.Int32);
|
||||
|
||||
if ( matchContentPartVersionRecord ) {
|
||||
_output.WriteLine("\t\t\t\t.ContentPartVersionRecord()");
|
||||
}
|
||||
else if ( matchContentPartRecord ) {
|
||||
_output.WriteLine("\t\t\t\t.ContentPartRecord()");
|
||||
}
|
||||
|
||||
foreach ( var createColumn in command.TableCommands.OfType<CreateColumnCommand>() ) {
|
||||
if(createColumn.ColumnName == "Id" && matchContentPartRecord) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(createColumn.ColumnName == "ContentItemRecord_id" && matchContentPartVersionRecord) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var type = createColumn.DbType.ToString();
|
||||
var field = createColumn.ColumnName;
|
||||
var options = new List<string>();
|
||||
@ -25,6 +54,10 @@ namespace Orchard.DevTools.Services {
|
||||
options.Add("PrimaryKey()");
|
||||
}
|
||||
|
||||
if ( createColumn.IsIdentity ) {
|
||||
options.Add("Identity()");
|
||||
}
|
||||
|
||||
if ( createColumn.IsUnique ) {
|
||||
options.Add("Unique()");
|
||||
}
|
||||
|
@ -82,6 +82,7 @@
|
||||
<Content Include="Content\Admin\images\disabled.gif" />
|
||||
<Content Include="Content\Admin\images\enabled.gif" />
|
||||
<Content Include="Module.txt" />
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Views\Admin\Add.ascx" />
|
||||
<Content Include="Views\Admin\Edit.ascx" />
|
||||
<Content Include="Views\Admin\DisplayTemplates\ActionsForUninitialized.ascx" />
|
||||
|
@ -24,7 +24,6 @@ using Orchard.Reports.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Environment.State;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
@ -39,7 +38,6 @@ namespace Orchard.Setup.Services {
|
||||
|
||||
public SetupService(
|
||||
ShellSettings shellSettings,
|
||||
INotifier notifier,
|
||||
IOrchardHost orchardHost,
|
||||
IShellSettingsManager shellSettingsManager,
|
||||
IShellContainerFactory shellContainerFactory,
|
||||
|
@ -2,6 +2,7 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %>
|
||||
<%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %>
|
||||
<h2><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h2>
|
||||
<div class="meta"><%: Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%><%
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %><%
|
||||
if (Model.Creator != null) {
|
||||
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
|
||||
} %>
|
@ -2,6 +2,7 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %>
|
||||
<%Model.Zones.AddRenderPartial("zonetest", "ZoneTest", Model); %>
|
||||
<h2><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h2>
|
||||
<div class="meta"><%: Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%><%
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %><%
|
||||
if (Model.Creator != null) {
|
||||
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
|
||||
} %>
|
@ -2,6 +2,7 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %>
|
||||
<h3><%: Html.Link(Model.Item.Title, Url.BlogPost(Model.Item)) %></h3>
|
||||
<div class="meta"><%: Html.PublishedState(Model.Item, T) %> | <%Html.Zone("meta");%></div>
|
||||
<div class="postsummary">
|
||||
|
@ -1,6 +1,7 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BlogPost>" %>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%><%
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Extensions" %><%
|
||||
if (Model.Creator != null) {
|
||||
%><%: T("Posted by {0} {1}", Model.Creator.UserName, Html.PublishedWhen(Model, T)) %><%
|
||||
} %>
|
@ -13,6 +13,7 @@ namespace Orchard.ContentManagement {
|
||||
public RouteValueDictionary DisplayRouteValues { get; set; }
|
||||
public RouteValueDictionary EditorRouteValues { get; set; }
|
||||
public RouteValueDictionary CreateRouteValues { get; set; }
|
||||
public RouteValueDictionary RemoveRouteValues { get; set; }
|
||||
|
||||
public IEnumerable<string> DisplayGroups { get; set; }
|
||||
public IEnumerable<string> EditorGroups { get; set; }
|
||||
@ -43,5 +44,13 @@ namespace Orchard.ContentManagement {
|
||||
{"id", item.ContentItem.ContentType}
|
||||
};
|
||||
}
|
||||
|
||||
private static RouteValueDictionary GetRemoveRouteValues(IContent item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Contents"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "Remove"}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NHibernate.Cfg;
|
||||
using NHibernate.Mapping;
|
||||
using NHibernate.Tool.hbm2ddl;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data.Migration.Schema;
|
||||
using Orchard.Data.Providers;
|
||||
using NHibernate.Dialect;
|
||||
|
||||
namespace Orchard.Data.Migration.Generator {
|
||||
public class SchemaCommandGenerator : ISchemaCommandGenerator {
|
||||
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
|
||||
private readonly ISessionFactoryHolder _sessionFactoryHolder;
|
||||
|
||||
public SchemaCommandGenerator(
|
||||
IDataServicesProviderFactory dataServicesProviderFactory,
|
||||
ISessionFactoryHolder sessionFactoryHolder) {
|
||||
_dataServicesProviderFactory = dataServicesProviderFactory;
|
||||
_sessionFactoryHolder = sessionFactoryHolder;
|
||||
}
|
||||
|
||||
@ -30,7 +29,7 @@ namespace Orchard.Data.Migration.Generator {
|
||||
yield break;
|
||||
}
|
||||
|
||||
var configuration = _dataServicesProviderFactory.CreateProvider(parameters).BuildConfiguration(parameters);
|
||||
var configuration = _sessionFactoryHolder.GetConfiguration();
|
||||
Dialect.GetDialect(configuration.Properties);
|
||||
var mapping = configuration.BuildMapping();
|
||||
|
||||
@ -42,7 +41,10 @@ namespace Orchard.Data.Migration.Generator {
|
||||
|
||||
foreach(var table in tables.Where(t => parameters.RecordDescriptors.Any(rd => rd.Feature.Descriptor.Name == feature && rd.TableName == t.Name))) {
|
||||
string tableName = table.Name;
|
||||
if(tableName.StartsWith(prefix)) {
|
||||
var recordType = parameters.RecordDescriptors.Where(rd => rd.Feature.Descriptor.Name == feature && rd.TableName == tableName).First().Type;
|
||||
var isContentPart = typeof(ContentPartRecord).IsAssignableFrom(recordType);
|
||||
|
||||
if ( tableName.StartsWith(prefix) ) {
|
||||
tableName = tableName.Substring(prefix.Length);
|
||||
}
|
||||
|
||||
@ -59,10 +61,17 @@ namespace Orchard.Data.Migration.Generator {
|
||||
command.Column(column.Name, sqlType.DbType,
|
||||
action => {
|
||||
if (table1.PrimaryKey.Columns.Any(c => c.Name == column1.Name)) {
|
||||
action.PrimaryKey().Identity();
|
||||
action.PrimaryKey();
|
||||
|
||||
if ( !isContentPart ) {
|
||||
action.Identity();
|
||||
}
|
||||
}
|
||||
|
||||
if (column1.IsLengthDefined()) {
|
||||
|
||||
if ( column1.IsLengthDefined()
|
||||
&& new DbType[] { DbType.StringFixedLength, DbType.String, DbType.AnsiString, DbType.AnsiStringFixedLength }.Contains(sqlType.DbType)
|
||||
&& column1.Length != 255 ) {
|
||||
action.WithLength(column1.Length);
|
||||
}
|
||||
|
||||
@ -92,8 +101,7 @@ namespace Orchard.Data.Migration.Generator {
|
||||
/// Automatically updates a db to a functionning schema
|
||||
/// </summary>
|
||||
public void UpdateDatabase() {
|
||||
var parameters = _sessionFactoryHolder.GetSessionFactoryParameters();
|
||||
var configuration = _dataServicesProviderFactory.CreateProvider(parameters).BuildConfiguration(parameters);
|
||||
var configuration = _sessionFactoryHolder.GetConfiguration();
|
||||
new SchemaUpdate(configuration).Execute(false, true);
|
||||
}
|
||||
|
||||
@ -101,8 +109,7 @@ namespace Orchard.Data.Migration.Generator {
|
||||
/// Automatically creates a db with a functionning schema
|
||||
/// </summary>
|
||||
public void CreateDatabase() {
|
||||
var parameters = _sessionFactoryHolder.GetSessionFactoryParameters();
|
||||
var configuration = _dataServicesProviderFactory.CreateProvider(parameters).BuildConfiguration(parameters);
|
||||
var configuration = _sessionFactoryHolder.GetConfiguration();
|
||||
new SchemaExport(configuration).Execute(false, true, false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user