Merge branch '7.2.0' of https://github.com/umbraco/Umbraco-CMS into 7.2.0
This commit is contained in:
@@ -375,16 +375,15 @@ AND umbracoNode.id <> @id",
|
||||
var existing = existingByIds.FirstOrDefault(valueDto => valueDto.Id == pre.Value.Id);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.Value = pre.Value.Value;
|
||||
existing.SortOrder = sortOrder;
|
||||
_preValRepository.AddOrUpdate(new PreValueEntity
|
||||
{
|
||||
//setting an id will update it
|
||||
Id = existing.Id,
|
||||
Alias = existing.Alias,
|
||||
SortOrder = existing.SortOrder,
|
||||
Value = existing.Value,
|
||||
DataType = dataType,
|
||||
//These are the new values to update
|
||||
Alias = pre.Key,
|
||||
SortOrder = sortOrder,
|
||||
Value = pre.Value.Value
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
@@ -229,30 +229,27 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
//TODO: Should we raise an event here since we are really saving values for the data type?
|
||||
|
||||
using (new WriteLock(Locker))
|
||||
using (var uow = _uowProvider.GetUnitOfWork())
|
||||
{
|
||||
using (var uow = _uowProvider.GetUnitOfWork())
|
||||
using (var transaction = uow.Database.GetTransaction())
|
||||
{
|
||||
using (var transaction = uow.Database.GetTransaction())
|
||||
var sortOrderObj =
|
||||
uow.Database.ExecuteScalar<object>(
|
||||
"SELECT max(sortorder) FROM cmsDataTypePreValues WHERE datatypeNodeId = @DataTypeId", new { DataTypeId = dataTypeId });
|
||||
int sortOrder;
|
||||
if (sortOrderObj == null || int.TryParse(sortOrderObj.ToString(), out sortOrder) == false)
|
||||
{
|
||||
var sortOrderObj =
|
||||
uow.Database.ExecuteScalar<object>(
|
||||
"SELECT max(sortorder) FROM cmsDataTypePreValues WHERE datatypeNodeId = @DataTypeId", new { DataTypeId = dataTypeId });
|
||||
int sortOrder;
|
||||
if (sortOrderObj == null || int.TryParse(sortOrderObj.ToString(), out sortOrder) == false)
|
||||
{
|
||||
sortOrder = 1;
|
||||
}
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
var dto = new DataTypePreValueDto { DataTypeNodeId = dataTypeId, Value = value, SortOrder = sortOrder };
|
||||
uow.Database.Insert(dto);
|
||||
sortOrder++;
|
||||
}
|
||||
|
||||
transaction.Complete();
|
||||
sortOrder = 1;
|
||||
}
|
||||
|
||||
foreach (var value in values)
|
||||
{
|
||||
var dto = new DataTypePreValueDto { DataTypeNodeId = dataTypeId, Value = value, SortOrder = sortOrder };
|
||||
uow.Database.Insert(dto);
|
||||
sortOrder++;
|
||||
}
|
||||
|
||||
transaction.Complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,10 +391,17 @@ namespace Umbraco.Core.Services
|
||||
internal IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames)
|
||||
{
|
||||
var snippetPath = IOHelper.MapPath(string.Format("{0}/PartialViewMacros/Templates/", SystemDirectories.Umbraco));
|
||||
return Directory.GetFiles(snippetPath, "*.cshtml")
|
||||
var files = Directory.GetFiles(snippetPath, "*.cshtml")
|
||||
.Select(Path.GetFileNameWithoutExtension)
|
||||
.Except(filterNames, StringComparer.InvariantCultureIgnoreCase)
|
||||
.ToArray();
|
||||
|
||||
//Ensure the ones that are called 'Empty' are at the top
|
||||
var empty = files.Where(x => Path.GetFileName(x).InvariantStartsWith("Empty"))
|
||||
.OrderBy(x => x.Length)
|
||||
.ToArray();
|
||||
|
||||
return empty.Union(files.Except(empty));
|
||||
}
|
||||
|
||||
internal void DeletePartialViewFolder(string folderPath)
|
||||
@@ -515,7 +522,10 @@ namespace Umbraco.Core.Services
|
||||
.ToFirstUpperInvariant()
|
||||
.ToSafeAlias(false);
|
||||
|
||||
repository.AddOrUpdate(new Macro(name, name) { ScriptPath = partialView.Path });
|
||||
//The partial view path to be saved with the macro must be a fully qualified virtual path
|
||||
var virtualPath = string.Format("{0}/{1}/{2}", SystemDirectories.MvcViews, "MacroPartials", partialView.Path);
|
||||
|
||||
repository.AddOrUpdate(new Macro(name, name) { ScriptPath = virtualPath });
|
||||
}
|
||||
|
||||
//commit both - ensure that the macro is created if one was added
|
||||
|
||||
@@ -408,7 +408,7 @@ namespace Umbraco.Tests.Mvc
|
||||
var ctx = new UmbracoContext(
|
||||
GetHttpContextFactory(url, routeData).HttpContext,
|
||||
appCtx,
|
||||
new PublishedCaches(cache, new PublishedMediaCache()),
|
||||
new PublishedCaches(cache, new PublishedMediaCache(appCtx)),
|
||||
new WebSecurity(http, appCtx));
|
||||
|
||||
//if (setSingleton)
|
||||
|
||||
@@ -281,7 +281,7 @@ namespace Umbraco.Tests.Plugins
|
||||
public void Resolves_Attributed_Trees()
|
||||
{
|
||||
var trees = PluginManager.Current.ResolveAttributedTrees();
|
||||
Assert.AreEqual(18, trees.Count());
|
||||
Assert.AreEqual(19, trees.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -92,9 +92,9 @@ namespace Umbraco.Tests.PublishedCache
|
||||
|
||||
_umbracoContext = new UmbracoContext(
|
||||
_httpContextFactory.HttpContext,
|
||||
ApplicationContext.Current,
|
||||
new PublishedCaches(cache, new PublishedMediaCache()),
|
||||
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext.Current));
|
||||
ApplicationContext,
|
||||
new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
|
||||
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext));
|
||||
|
||||
_cache = _umbracoContext.ContentCache;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Tests.PublishedCache
|
||||
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot2.Id);
|
||||
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application), ctx);
|
||||
var roots = cache.GetAtRoot();
|
||||
Assert.AreEqual(2, roots.Count());
|
||||
Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));
|
||||
@@ -126,6 +126,8 @@ namespace Umbraco.Tests.PublishedCache
|
||||
[Test]
|
||||
public void Convert_From_Search_Result()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var result = new SearchResult()
|
||||
{
|
||||
Id = 1234,
|
||||
@@ -144,7 +146,7 @@ namespace Umbraco.Tests.PublishedCache
|
||||
result.Fields.Add("updateDate", "2012-07-16T10:34:09");
|
||||
result.Fields.Add("writerName", "Shannon");
|
||||
|
||||
var store = new PublishedMediaCache();
|
||||
var store = new PublishedMediaCache(ctx.Application);
|
||||
var doc = store.ConvertFromSearchResult(result);
|
||||
|
||||
DoAssert(doc, 1234, 0, 0, "", "Image", 0, "Shannon", "", 0, 0, "-1,1234", default(DateTime), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
@@ -154,9 +156,11 @@ namespace Umbraco.Tests.PublishedCache
|
||||
[Test]
|
||||
public void Convert_From_XPath_Navigator()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var xmlDoc = GetMediaXml();
|
||||
var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator();
|
||||
var cache = new PublishedMediaCache();
|
||||
var cache = new PublishedMediaCache(ctx.Application);
|
||||
var doc = cache.ConvertFromXPathNavigator(navigator);
|
||||
|
||||
DoAssert(doc, 2000, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon2", 22, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
});
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(new PublishedCaches(
|
||||
new PublishedContentCache(), new PublishedMediaCache()));
|
||||
new PublishedContentCache(), new PublishedMediaCache(ApplicationContext)));
|
||||
|
||||
if (PublishedContentModelFactoryResolver.HasCurrent == false)
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
|
||||
@@ -11,6 +11,7 @@ using Examine.LuceneEngine;
|
||||
using Examine.LuceneEngine.Providers;
|
||||
using Lucene.Net.Analysis.Standard;
|
||||
using Lucene.Net.Store;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
@@ -60,7 +61,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
internal static IPublishedContent GetNode(int id, UmbracoContext umbracoContext)
|
||||
{
|
||||
var ctx = umbracoContext;
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application), ctx);
|
||||
var doc = cache.GetById(id);
|
||||
Assert.IsNotNull(doc);
|
||||
return doc;
|
||||
@@ -112,7 +113,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -141,7 +142,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//ensure it is found
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
@@ -181,7 +182,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -203,7 +204,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -225,7 +226,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(1111);
|
||||
@@ -247,7 +248,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
@@ -266,7 +267,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
indexer.RebuildIndex();
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);
|
||||
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);
|
||||
|
||||
//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
|
||||
var publishedMedia = cache.GetById(3113);
|
||||
@@ -374,7 +375,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Assert.AreEqual(mChild1.Id, publishedSubChild1.Parent.Id);
|
||||
}
|
||||
|
||||
[Test, Ignore]//TODO Shannon look at this test
|
||||
[Test]
|
||||
public void Ancestors_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
@@ -393,7 +394,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Assert.IsTrue(publishedSubChild1.Ancestors().Select(x => x.Id).ContainsAll(new[] { mChild1.Id, mRoot.Id }));
|
||||
}
|
||||
|
||||
[Test, Ignore]//TODO Shannon look at this test
|
||||
[Test]
|
||||
public void AncestorsOrSelf_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
@@ -412,6 +413,100 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Assert.IsTrue(publishedSubChild1.AncestorsOrSelf().Select(x => x.Id).ContainsAll(
|
||||
new[] { mSubChild1.Id, mChild1.Id, mRoot.Id }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_From_Legacy_Xml()
|
||||
{
|
||||
var config = SettingsForTests.GenerateMockSettings();
|
||||
|
||||
var contentMock = Mock.Get(config.Content);
|
||||
contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(true);
|
||||
|
||||
SettingsForTests.ConfigureSettings(config);
|
||||
|
||||
var nodeId = 2112;
|
||||
|
||||
var xml = XElement.Parse(@"<node id=""2112"" version=""5b3e46ab-3e37-4cfa-ab70-014234b5bd39"" parentID=""2222"" level=""3"" writerID=""0"" nodeType=""1032"" template=""0"" sortOrder=""1"" createDate=""2010-05-19T17:32:46"" updateDate=""2010-05-19T17:32:46"" nodeName=""Sam's Umbraco Image"" urlName=""acnestressscrub"" writerName=""Administrator"" nodeTypeAlias=""Image"" path=""-1,1111,2222,2112"">
|
||||
<data alias=""umbracoFile""><![CDATA[/media/1234/blah.pdf]]></data>
|
||||
<data alias=""umbracoWidth"">115</data>
|
||||
<data alias=""umbracoHeight"">268</data>
|
||||
<data alias=""umbracoBytes"">10726</data>
|
||||
<data alias=""umbracoExtension"">jpg</data>
|
||||
<node id=""3113"" version=""5b3e46ab-3e37-4cfa-ab70-014234b5bd33"" parentID=""2112"" level=""4"" writerID=""0"" nodeType=""1032"" template=""0"" sortOrder=""2"" createDate=""2010-05-19T17:32:46"" updateDate=""2010-05-19T17:32:46"" nodeName=""Another Umbraco Image"" urlName=""acnestressscrub"" writerName=""Administrator"" nodeTypeAlias=""Image"" path=""-1,1111,2222,2112,3113"">
|
||||
<data alias=""umbracoFile""><![CDATA[/media/1234/blah.pdf]]></data>
|
||||
<data alias=""umbracoWidth"">115</data>
|
||||
<data alias=""umbracoHeight"">268</data>
|
||||
<data alias=""umbracoBytes"">10726</data>
|
||||
<data alias=""umbracoExtension"">jpg</data>
|
||||
</node>
|
||||
</node>");
|
||||
var node = xml.DescendantsAndSelf("node").Single(x => (int) x.Attribute("id") == nodeId);
|
||||
|
||||
var publishedMedia = new PublishedMediaCache(ApplicationContext);
|
||||
|
||||
var nav = node.CreateNavigator();
|
||||
|
||||
var converted = publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/node"), nodeId);
|
||||
|
||||
Assert.AreEqual(nodeId, converted.Id);
|
||||
Assert.AreEqual(3, converted.Level);
|
||||
Assert.AreEqual(1, converted.SortOrder);
|
||||
Assert.AreEqual("Sam's Umbraco Image", converted.Name);
|
||||
Assert.AreEqual("-1,1111,2222,2112", converted.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_From_Standard_Xml()
|
||||
{
|
||||
var config = SettingsForTests.GenerateMockSettings();
|
||||
|
||||
var contentMock = Mock.Get(config.Content);
|
||||
contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(true);
|
||||
|
||||
SettingsForTests.ConfigureSettings(config);
|
||||
|
||||
var nodeId = 2112;
|
||||
|
||||
var xml = XElement.Parse(@"<Image id=""2112"" version=""5b3e46ab-3e37-4cfa-ab70-014234b5bd39"" parentID=""2222"" level=""3"" writerID=""0"" nodeType=""1032"" template=""0"" sortOrder=""1"" createDate=""2010-05-19T17:32:46"" updateDate=""2010-05-19T17:32:46"" nodeName=""Sam's Umbraco Image"" urlName=""acnestressscrub"" writerName=""Administrator"" nodeTypeAlias=""Image"" path=""-1,1111,2222,2112"" isDoc="""">
|
||||
<umbracoFile><![CDATA[/media/1234/blah.pdf]]></umbracoFile>
|
||||
<umbracoWidth>115</umbracoWidth>
|
||||
<umbracoHeight>268</umbracoHeight>
|
||||
<umbracoBytes>10726</umbracoBytes>
|
||||
<umbracoExtension>jpg</umbracoExtension>
|
||||
<Image id=""3113"" version=""5b3e46ab-3e37-4cfa-ab70-014234b5bd33"" parentID=""2112"" level=""4"" writerID=""0"" nodeType=""1032"" template=""0"" sortOrder=""2"" createDate=""2010-05-19T17:32:46"" updateDate=""2010-05-19T17:32:46"" nodeName=""Another Umbraco Image"" urlName=""acnestressscrub"" writerName=""Administrator"" nodeTypeAlias=""Image"" path=""-1,1111,2222,2112,3113"" isDoc="""">
|
||||
<umbracoFile><![CDATA[/media/1234/blah.pdf]]></umbracoFile>
|
||||
<umbracoWidth>115</umbracoWidth>
|
||||
<umbracoHeight>268</umbracoHeight>
|
||||
<umbracoBytes>10726</umbracoBytes>
|
||||
<umbracoExtension>jpg</umbracoExtension>
|
||||
</Image>
|
||||
</Image>");
|
||||
var node = xml.DescendantsAndSelf("Image").Single(x => (int)x.Attribute("id") == nodeId);
|
||||
|
||||
var publishedMedia = new PublishedMediaCache(ApplicationContext);
|
||||
|
||||
var nav = node.CreateNavigator();
|
||||
|
||||
var converted = publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/Image"), nodeId);
|
||||
|
||||
Assert.AreEqual(nodeId, converted.Id);
|
||||
Assert.AreEqual(3, converted.Level);
|
||||
Assert.AreEqual(1, converted.SortOrder);
|
||||
Assert.AreEqual("Sam's Umbraco Image", converted.Name);
|
||||
Assert.AreEqual("-1,1111,2222,2112", converted.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Detects_Error_In_Xml()
|
||||
{
|
||||
var errorXml = new XElement("error", string.Format("No media is maching '{0}'", 1234));
|
||||
var nav = errorXml.CreateNavigator();
|
||||
|
||||
var publishedMedia = new PublishedMediaCache(ApplicationContext);
|
||||
var converted = publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/"), 1234);
|
||||
|
||||
Assert.IsNull(converted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -356,7 +356,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
var ctx = new UmbracoContext(
|
||||
httpContext,
|
||||
ApplicationContext,
|
||||
new PublishedCaches(cache, new PublishedMediaCache()),
|
||||
new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
|
||||
new WebSecurity(httpContext, ApplicationContext));
|
||||
|
||||
if (setSingleton)
|
||||
|
||||
@@ -19,10 +19,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
[SetUp]
|
||||
public virtual void Initialize()
|
||||
{
|
||||
using (DisposableTimer.TraceDuration<BaseUmbracoConfigurationTest>("init"))
|
||||
{
|
||||
SettingsForTests.Reset();
|
||||
}
|
||||
SettingsForTests.Reset();
|
||||
|
||||
}
|
||||
|
||||
@@ -30,10 +27,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
public virtual void TearDown()
|
||||
{
|
||||
//reset settings
|
||||
using (DisposableTimer.TraceDuration<BaseUmbracoConfigurationTest>("teardown"))
|
||||
{
|
||||
SettingsForTests.Reset();
|
||||
}
|
||||
SettingsForTests.Reset();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ using Umbraco.Core.Xml;
|
||||
using Umbraco.Web.Models;
|
||||
using UmbracoExamine;
|
||||
using umbraco;
|
||||
using umbraco.cms.businesslogic;
|
||||
using ContentType = umbraco.cms.businesslogic.ContentType;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
@@ -31,21 +29,30 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// </remarks>
|
||||
internal class PublishedMediaCache : IPublishedMediaCache
|
||||
{
|
||||
public PublishedMediaCache()
|
||||
{
|
||||
}
|
||||
public PublishedMediaCache(ApplicationContext applicationContext)
|
||||
{
|
||||
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
|
||||
_applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generally used for unit testing to use an explicit examine searcher
|
||||
/// </summary>
|
||||
/// <param name="applicationContext"></param>
|
||||
/// <param name="searchProvider"></param>
|
||||
/// <param name="indexProvider"></param>
|
||||
internal PublishedMediaCache(BaseSearchProvider searchProvider, BaseIndexProvider indexProvider)
|
||||
internal PublishedMediaCache(ApplicationContext applicationContext, BaseSearchProvider searchProvider, BaseIndexProvider indexProvider)
|
||||
{
|
||||
_searchProvider = searchProvider;
|
||||
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
|
||||
if (searchProvider == null) throw new ArgumentNullException("searchProvider");
|
||||
if (indexProvider == null) throw new ArgumentNullException("indexProvider");
|
||||
|
||||
_applicationContext = applicationContext;
|
||||
_searchProvider = searchProvider;
|
||||
_indexProvider = indexProvider;
|
||||
}
|
||||
|
||||
private readonly ApplicationContext _applicationContext;
|
||||
private readonly BaseSearchProvider _searchProvider;
|
||||
private readonly BaseIndexProvider _indexProvider;
|
||||
|
||||
@@ -56,17 +63,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
public virtual IEnumerable<IPublishedContent> GetAtRoot(UmbracoContext umbracoContext, bool preview)
|
||||
{
|
||||
var rootMedia = global::umbraco.cms.businesslogic.media.Media.GetRootMedias();
|
||||
var result = new List<IPublishedContent>();
|
||||
//TODO: need to get a ConvertFromMedia method but we'll just use this for now.
|
||||
foreach (var media in rootMedia
|
||||
.Select(m => global::umbraco.library.GetMedia(m.Id, true))
|
||||
.Where(media => media != null && media.Current != null))
|
||||
{
|
||||
media.MoveNext();
|
||||
result.Add(ConvertFromXPathNavigator(media.Current));
|
||||
}
|
||||
return result;
|
||||
//TODO: We should be able to look these ids first in Examine!
|
||||
|
||||
var rootMedia = _applicationContext.Services.MediaService.GetRootMedia();
|
||||
return rootMedia.Select(m => GetUmbracoMedia(m.Id));
|
||||
}
|
||||
|
||||
public virtual IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, XPathVariable[] vars)
|
||||
@@ -96,7 +96,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
public bool XPathNavigatorIsNavigable { get { return false; } }
|
||||
|
||||
public virtual bool HasContent(UmbracoContext context, bool preview) { throw new NotImplementedException(); }
|
||||
public virtual bool HasContent(UmbracoContext context, bool preview) { throw new NotImplementedException(); }
|
||||
|
||||
private ExamineManager GetExamineManagerSafe()
|
||||
{
|
||||
@@ -197,32 +197,25 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
() => id);
|
||||
|
||||
var media = global::umbraco.library.GetMedia(id, true);
|
||||
if (media != null && media.Current != null)
|
||||
{
|
||||
media.MoveNext();
|
||||
var moved = media.Current.MoveToFirstChild();
|
||||
//first check if we have an error
|
||||
if (moved)
|
||||
{
|
||||
if (media.Current.Name.InvariantEquals("error"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (moved)
|
||||
{
|
||||
//move back to the parent and return
|
||||
media.Current.MoveToParent();
|
||||
}
|
||||
return ConvertFromXPathNavigator(media.Current);
|
||||
}
|
||||
|
||||
return ConvertFromXPathNodeIterator(media, id);
|
||||
}
|
||||
|
||||
internal IPublishedContent ConvertFromXPathNodeIterator(XPathNodeIterator media, int id)
|
||||
{
|
||||
if (media != null && media.Current != null)
|
||||
{
|
||||
return media.Current.Name.InvariantEquals("error")
|
||||
? null
|
||||
: ConvertFromXPathNavigator(media.Current);
|
||||
}
|
||||
|
||||
LogHelper.Debug<PublishedMediaCache>(
|
||||
"Could not retrieve media {0} from Examine index or from legacy library.GetMedia method",
|
||||
() => id);
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
internal IPublishedContent ConvertFromSearchResult(SearchResult searchResult)
|
||||
{
|
||||
@@ -425,7 +418,6 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
var media = library.GetMedia(parentId, true);
|
||||
if (media != null && media.Current != null)
|
||||
{
|
||||
media.MoveNext();
|
||||
xpath = media.Current;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Web.Standalone
|
||||
|
||||
var caches = new PublishedCaches(
|
||||
new PublishedCache.XmlPublishedCache.PublishedContentCache(),
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache());
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache(ApplicationContext.Current));
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(caches);
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ namespace Umbraco.Web
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(new PublishedCaches(
|
||||
new PublishedCache.XmlPublishedCache.PublishedContentCache(),
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache()));
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache(ApplicationContext)));
|
||||
|
||||
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector),
|
||||
new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
|
||||
|
||||
@@ -518,9 +518,8 @@ namespace umbraco
|
||||
|
||||
LogHelper.Debug<library>("No media result for id {0}", () => MediaId);
|
||||
|
||||
var xd = new XmlDocument();
|
||||
xd.LoadXml(string.Format("<error>No media is maching '{0}'</error>", MediaId));
|
||||
return xd.CreateNavigator().Select("/");
|
||||
var errorXml = new XElement("error", string.Format("No media is maching '{0}'", MediaId));
|
||||
return errorXml.CreateNavigator().Select("/");
|
||||
}
|
||||
|
||||
private static XElement GetMediaDo(int mediaId, bool deep)
|
||||
@@ -529,8 +528,11 @@ namespace umbraco
|
||||
if (media == null) return null;
|
||||
var serializer = new EntityXmlSerializer();
|
||||
var serialized = serializer.Serialize(
|
||||
ApplicationContext.Current.Services.MediaService, ApplicationContext.Current.Services.DataTypeService,
|
||||
ApplicationContext.Current.Services.UserService, media, deep);
|
||||
ApplicationContext.Current.Services.MediaService,
|
||||
ApplicationContext.Current.Services.DataTypeService,
|
||||
ApplicationContext.Current.Services.UserService,
|
||||
media,
|
||||
deep);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user