Removing IContentManager.Flush()

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-03-12 11:46:35 -07:00
parent 4cb6c4dd31
commit b39951bad3
20 changed files with 14 additions and 56 deletions

View File

@@ -99,7 +99,6 @@ namespace Orchard.Tests.Modules.Comments.Services {
}
_contentManager.Flush();
Assert.That(_commentService.GetComments().Count(), Is.EqualTo(12));
}
@@ -160,14 +159,12 @@ namespace Orchard.Tests.Modules.Comments.Services {
commentIds[i] = commentedItem.As<CommentPart>().Id;
}
_contentManager.Flush();
Assert.That(_commentService.GetComments().Count(), Is.EqualTo(12));
for (int i = 0; i < 12; i++) {
_commentService.DeleteComment(commentIds[i]);
}
_contentManager.Flush();
Assert.That(_commentService.GetComments().Count(), Is.EqualTo(0));
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -15,6 +16,7 @@ namespace Orchard.Tests.Modules {
public abstract class DatabaseEnabledTestsBase {
protected IContainer _container;
protected ITransaction _transaction;
protected ISession _session;
protected string _databaseFilePath;
@@ -36,6 +38,8 @@ namespace Orchard.Tests.Modules {
_databaseFilePath = Path.GetTempFileName();
_sessionFactory = DataUtility.CreateSessionFactory(_databaseFilePath, DatabaseTypes.ToArray());
_session = _sessionFactory.OpenSession();
_transaction = _session.BeginTransaction(IsolationLevel.ReadCommitted);
_clock = new StubClock();
var builder = new ContainerBuilder();
@@ -45,6 +49,7 @@ namespace Orchard.Tests.Modules {
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
Register(builder);
_container = builder.Build();
}
[TearDown]
@@ -52,6 +57,8 @@ namespace Orchard.Tests.Modules {
if(_container != null)
_container.Dispose();
_transaction.Commit();
if(_session != null)
_session.Close();
}
@@ -66,8 +73,9 @@ namespace Orchard.Tests.Modules {
protected void ClearSession() {
Trace.WriteLine("Flush and clear session");
_session.Flush();
_transaction.Commit();
_session.Clear();
_transaction = _session.BeginTransaction(IsolationLevel.ReadCommitted);
Trace.WriteLine("Flushed and cleared session");
}
}

View File

@@ -211,7 +211,6 @@ namespace Orchard.Tests.Modules.Indexing {
Assert.That(_provider.NumDocs(IndexName), Is.EqualTo(2));
_contentManager.Unpublish(content.ContentItem);
_contentManager.Flush();
while (_indexTaskExecutor.UpdateIndexBatch(IndexName)) {}
Assert.That(_provider.NumDocs(IndexName), Is.EqualTo(1));
@@ -231,7 +230,6 @@ namespace Orchard.Tests.Modules.Indexing {
Assert.That(_provider.NumDocs(IndexName), Is.EqualTo(2));
_contentManager.Remove(content.ContentItem);
_contentManager.Flush();
while (_indexTaskExecutor.UpdateIndexBatch(IndexName)) { }
Assert.That(_provider.NumDocs(IndexName), Is.EqualTo(1));

View File

@@ -104,6 +104,8 @@ namespace Orchard.Tests.Modules.Users.Services {
builder.RegisterInstance(ShellSettingsUtility.CreateEncryptionEnabled());
_session = _sessionFactory.OpenSession();
_session.BeginTransaction();
builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
_container = builder.Build();
_membershipService = _container.Resolve<IMembershipService>();
@@ -134,7 +136,6 @@ namespace Orchard.Tests.Modules.Users.Services {
// Create user lower case
_membershipService.CreateUser(new CreateUserParams("admin", "66554321", "foo@bar.com", "", "", true));
_container.Resolve<IOrchardServices>().ContentManager.Flush();
// Verify unicity with upper case which with turkish coallition would yeld admin with an i without the dot and therefore generate a different user name
Assert.That(_userService.VerifyUserUnicity("ADMIN", "differentfoo@bar.com"), Is.False);

View File

@@ -115,14 +115,12 @@ namespace Orchard.Tests.Modules.Widgets.Services {
Assert.That(layers.Count(), Is.EqualTo(0));
LayerPart layerPartFirst = _widgetService.CreateLayer(LayerName1, LayerDescription1, "");
_contentManager.Flush();
layers = _widgetService.GetLayers();
Assert.That(layers.Count(), Is.EqualTo(1));
Assert.That(layers.First().Id, Is.EqualTo(layerPartFirst.Id));
_widgetService.CreateLayer(LayerName2, LayerDescription2, "");
_contentManager.Flush();
Assert.That(layers.Count(), Is.EqualTo(1));
}
@@ -132,7 +130,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
Assert.That(layers.Count(), Is.EqualTo(0), "No layers yet");
_widgetService.CreateLayer("Test layer 1", "Test layer 1", "");
_contentManager.Flush();
layers = _widgetService.GetLayers();
Assert.That(layers.Count(), Is.EqualTo(1), "One layer was created");
@@ -144,7 +141,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
Assert.That(layers.Count(), Is.EqualTo(0), "No layers yet");
_widgetService.CreateLayer(LayerName1, LayerDescription1, "");
_contentManager.Flush();
layers = _widgetService.GetLayers();
LayerPart layer = layers.First();
@@ -155,7 +151,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
[Test]
public void GetWidgetTest() {
LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, "");
_contentManager.Flush();
WidgetPart widgetResult = _widgetService.GetWidget(0);
Assert.That(widgetResult, Is.Null);
@@ -166,7 +161,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
widgetResult = _widgetService.GetWidget(0);
Assert.That(widgetResult, Is.Null, "Still yields null on an invalid identifier");
_contentManager.Flush();
widgetResult = _widgetService.GetWidget(widgetPart.Id);
Assert.That(widgetResult.Id, Is.EqualTo(widgetPart.Id), "Returns correct widget");
}
@@ -174,21 +168,18 @@ namespace Orchard.Tests.Modules.Widgets.Services {
[Test]
public void GetWidgetsTest() {
LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, "");
_contentManager.Flush();
IEnumerable<WidgetPart> widgetResults = _widgetService.GetWidgets();
Assert.That(widgetResults.Count(), Is.EqualTo(0));
WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", "");
Assert.That(widgetPart, Is.Not.Null);
_contentManager.Flush();
widgetResults = _widgetService.GetWidgets();
Assert.That(widgetResults.Count(), Is.EqualTo(1));
Assert.That(widgetResults.First().Id, Is.EqualTo(widgetPart.Id));
_widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle2, "2", "");
_contentManager.Flush();
widgetResults = _widgetService.GetWidgets();
Assert.That(widgetResults.Count(), Is.EqualTo(2));
@@ -197,7 +188,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
[Test]
public void CreateWidgetTest() {
LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, "");
_contentManager.Flush();
WidgetPart widgetPart = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, "1", "");
Assert.That(widgetPart, Is.Not.Null);
@@ -216,7 +206,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
[Test, Ignore("Fix when possible")]
public void MoveWidgetTest() {
LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, "");
_contentManager.Flush();
// same zone widgets
WidgetPart widgetPart1 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, Position1, Zone1);
@@ -224,7 +213,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
// different zone widget
WidgetPart widgetPart3 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle3, Position3, Zone2);
_contentManager.Flush();
// test 1 - moving first widget up will have no effect
Assert.That(_widgetService.MoveWidgetUp(widgetPart1), Is.False);
@@ -254,7 +242,6 @@ namespace Orchard.Tests.Modules.Widgets.Services {
[Test, Ignore("Fix when possible")]
public void GetLayerWidgetsTest() {
LayerPart layerPart = _widgetService.CreateLayer(LayerName1, LayerDescription1, "");
_contentManager.Flush();
// same zone widgets
WidgetPart widgetPart1 = _widgetService.CreateWidget(layerPart.Id, "HtmlWidget", WidgetTitle1, Position1, Zone1);

View File

@@ -356,7 +356,7 @@ namespace Orchard.Core.Contents.Controllers {
return new HttpUnauthorizedResult();
_contentManager.Publish(contentItem);
Services.ContentManager.Flush();
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName) ? T("That content has been published.") : T("That {0} has been published.", contentItem.TypeDefinition.DisplayName));
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));
@@ -372,7 +372,7 @@ namespace Orchard.Core.Contents.Controllers {
return new HttpUnauthorizedResult();
_contentManager.Unpublish(contentItem);
Services.ContentManager.Flush();
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName) ? T("That content has been unpublished.") : T("That {0} has been unpublished.", contentItem.TypeDefinition.DisplayName));
return this.RedirectLocal(returnUrl, () => RedirectToAction("List"));

View File

@@ -1,9 +1,7 @@
using System.Linq;
using Orchard.Commands;
using Orchard.Commands;
using Orchard.ContentManagement;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Services;
using Orchard.Core.Title.Models;
namespace Orchard.Core.Navigation.Commands {
public class MenuCommands : DefaultOrchardCommandHandler {
@@ -32,7 +30,6 @@ namespace Orchard.Core.Navigation.Commands {
[OrchardSwitches("MenuPosition,MenuText,Url,MenuName")]
public void Create() {
// flushes before doing a query in case a previous command created the menu
_contentManager.Flush();
var menu = _menuService.GetMenu(MenuName);

View File

@@ -130,7 +130,6 @@ namespace Orchard.AntiSpam.Controllers {
break;
}
Services.ContentManager.Flush();
return Index(options, new PagerParameters());
}

View File

@@ -42,7 +42,6 @@ namespace Orchard.Blogs.Handlers {
_blogService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As<BlogPart>();
// Ensure the "right" set of published posts for the blog is obtained
blogPart.ContentItem.ContentManager.Flush();
blogPart.PostCount = _blogPostService.PostCount(blogPart);
}
}

View File

@@ -69,8 +69,6 @@ namespace Orchard.Pages.Commands {
[CommandHelp("page create [/Slug:<slug>] /Title:<title> /Path:<path> [/Text:<text>] [/Owner:<username>] [/MenuName:<name>] [/MenuText:<menu text>] [/Homepage:true|false] [/Publish:true|false] [/UseWelcomeText:true|false]\r\n\t" + "Creates a new page")]
[OrchardSwitches("Slug,Title,Path,Text,Owner,MenuText,Homepage,MenuName,Publish,UseWelcomeText")]
public void Create() {
_contentManager.Flush();
if (String.IsNullOrEmpty(Owner)) {
Owner = _siteService.GetSiteSettings().SuperUser;
}

View File

@@ -117,8 +117,6 @@ namespace Orchard.Projections.Controllers {
layoutRecord.Display = model.Display;
layoutRecord.DisplayType = model.DisplayType;
Services.ContentManager.Flush();
Services.Notifier.Information(T("Layout Created"));
return RedirectToAction("Edit", new { id = layoutRecord.Id });
@@ -213,8 +211,6 @@ namespace Orchard.Projections.Controllers {
layoutRecord.DisplayType = model.DisplayType;
layoutRecord.GroupProperty = layoutRecord.Properties.FirstOrDefault(x => x.Id == model.GroupPropertyId);
Services.ContentManager.Flush();
Services.Notifier.Information(T("Layout Saved"));
return RedirectToAction("Edit", layoutRecord.Id);

View File

@@ -179,7 +179,6 @@ namespace Orchard.Projections.Tests.Services {
Set("double2", (double)-123456.123456);
_contentManager.Publish(_contentItem);
_contentManager.Flush();
Assert.That(Get<string>("string"), Is.EqualTo("one"));
Assert.That(Get<int>("int1"), Is.EqualTo(int.MaxValue));
@@ -201,7 +200,6 @@ namespace Orchard.Projections.Tests.Services {
Set("string", new string('x', 8000));
_contentManager.Publish(_contentItem);
_contentManager.Flush();
Assert.That(Get<string>("string"), Is.EqualTo(new String('x', 4000)));
}

View File

@@ -25,7 +25,6 @@ namespace Orchard.PublishLater.Handlers {
context.Task.ScheduledUtc);
_contentManager.Publish(context.Task.ContentItem);
_orchardServices.ContentManager.Flush();
}
}
}

View File

@@ -45,7 +45,6 @@ namespace Orchard.Widgets.Commands {
}
var owner = _membershipService.GetUser(Owner);
layer.As<ICommonPart>().Owner = owner;
_contentManager.Flush();
Context.Output.WriteLine(T("Layer created successfully.").Text);
}

View File

@@ -104,9 +104,6 @@ namespace Orchard.Widgets.Commands {
widget.RenderTitle = RenderTitle;
if(widget.Has<MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName)) {
// flushes before doing a query in case a previous command created the menu
_contentManager.Flush();
var menu = _menuService.GetMenu(MenuName);
if(menu != null) {

View File

@@ -61,7 +61,6 @@ namespace UpgradeTo16.Controllers {
foreach (var contentType in contentTypesToMigrate) {
_orchardServices.ContentManager.Flush();
_orchardServices.ContentManager.Clear();
var count = 0;
@@ -87,7 +86,6 @@ namespace UpgradeTo16.Controllers {
count++;
}
_orchardServices.ContentManager.Flush();
_orchardServices.ContentManager.Clear();
} while (contents.Any());

View File

@@ -91,7 +91,6 @@ namespace UpgradeTo16.Controllers {
.WithPart("TitlePart"));
// force the first object to be reloaded in order to get a valid AutoroutePart
_orchardServices.ContentManager.Flush();
_orchardServices.ContentManager.Clear();
var count = 0;
@@ -152,7 +151,6 @@ namespace UpgradeTo16.Controllers {
count++;
}
_orchardServices.ContentManager.Flush();
_orchardServices.ContentManager.Clear();
} while (contents.Any());

View File

@@ -660,10 +660,6 @@ namespace Orchard.ContentManagement {
return context.Data;
}
public void Flush() {
_contentItemRepository.Flush();
}
private ContentTypeRecord AcquireContentTypeRecord(string contentType) {
var contentTypeRecord = _contentTypeRepository.Get(x => x.Name == contentType);
if (contentTypeRecord == null) {

View File

@@ -10,7 +10,6 @@ namespace Orchard.ContentManagement {
public interface IContentManager : IDependency {
IEnumerable<ContentTypeDefinition> GetContentTypeDefinitions();
/// <summary>
/// Instantiates a new content item with the specified type
/// </summary>
@@ -73,11 +72,6 @@ namespace Orchard.ContentManagement {
XElement Export(ContentItem contentItem);
void Import(XElement element, ImportContentSession importContentSession);
/// <summary>
/// Flushes all pending content items to the persistance layer
/// </summary>
void Flush();
/// <summary>
/// Clears the current referenced content items
/// </summary>

View File

@@ -74,7 +74,6 @@ namespace Orchard.ContentManagement {
}
}
_contentManager.Flush();
_contentManager.Clear();
}
}