Removed dependence in Stylesheet repository on Entity Service.
This commit is contained in:
@@ -14,14 +14,16 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// </summary>
|
||||
internal class StylesheetRepository : FileRepository<string, Stylesheet>, IStylesheetRepository
|
||||
{
|
||||
internal StylesheetRepository(IUnitOfWork work, IFileSystem fileSystem)
|
||||
private readonly IDatabaseUnitOfWork _dbwork;
|
||||
|
||||
internal StylesheetRepository(IUnitOfWork work, IDatabaseUnitOfWork db, IFileSystem fileSystem)
|
||||
: base(work, fileSystem)
|
||||
{
|
||||
|
||||
_dbwork = db;
|
||||
}
|
||||
|
||||
public StylesheetRepository(IUnitOfWork work)
|
||||
: this(work, new PhysicalFileSystem(SystemDirectories.Css))
|
||||
public StylesheetRepository(IUnitOfWork work, IDatabaseUnitOfWork db)
|
||||
: this(work, db, new PhysicalFileSystem(SystemDirectories.Css))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -63,16 +65,23 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
return stylesheet;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Fix for missing Id's on FileService.GetStylesheets() call. This is needed as sytlesheets can only bo loaded in the editor via
|
||||
// their Id so listing stylesheets needs to list there Id as well for custom plugins to render the build in editor.
|
||||
// http://issues.umbraco.org/issue/U4-3258
|
||||
private static int GetStylesheetId(string path)
|
||||
private int GetStylesheetId(string path)
|
||||
{
|
||||
var ss = ApplicationContext.Current.Services.EntityService.GetRootEntities(UmbracoObjectTypes.Stylesheet).SingleOrDefault(s => s.Name == path.TrimEnd(".css").Replace("\\", "/"));
|
||||
return ss == null ? 0 : ss.Id;
|
||||
var sql = new Sql()
|
||||
.Select("nodeId")
|
||||
.From("umbracoNode")
|
||||
.Where("umbracoNode.nodeObjectType = @NodeObjectType && umbracoNode.text = @Alias",
|
||||
new { NodeObjectType = UmbracoObjectTypes.Stylesheet, Alias = path.TrimEnd(".css").Replace("\\", "/") });
|
||||
var nodeDto = _dbwork.Database.FirstOrDefault<Umbraco.Core.Models.Rdbms.NodeDto>(sql);
|
||||
return nodeDto == null ? 0 : nodeDto.NodeId;
|
||||
|
||||
//var ss = ApplicationContext.Current.Services.EntityService.GetRootEntities(UmbracoObjectTypes.Stylesheet).SingleOrDefault(s => s.Name == path.TrimEnd(".css").Replace("\\", "/"));
|
||||
//return ss == null ? 0 : ss.Id;
|
||||
}
|
||||
|
||||
public override IEnumerable<Stylesheet> GetAll(params string[] ids)
|
||||
|
||||
@@ -97,9 +97,9 @@ namespace Umbraco.Core.Persistence
|
||||
return new ScriptRepository(uow);
|
||||
}
|
||||
|
||||
public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow)
|
||||
public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow, IDatabaseUnitOfWork db)
|
||||
{
|
||||
return new StylesheetRepository(uow);
|
||||
return new StylesheetRepository(uow, db);
|
||||
}
|
||||
|
||||
public virtual ITemplateRepository CreateTemplateRepository(IDatabaseUnitOfWork uow)
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="Stylesheet"/> objects</returns>
|
||||
public IEnumerable<Stylesheet> GetStylesheets(params string[] names)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), _dataUowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetAll(names);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>A <see cref="Stylesheet"/> object</returns>
|
||||
public Stylesheet GetStylesheetByName(string name)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork()))
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(_fileUowProvider.GetUnitOfWork(), _dataUowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.Get(name);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Umbraco.Core.Services
|
||||
return;
|
||||
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow))
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow, _dataUowProvider.GetUnitOfWork()))
|
||||
{
|
||||
repository.AddOrUpdate(stylesheet);
|
||||
uow.Commit();
|
||||
@@ -88,7 +88,7 @@ namespace Umbraco.Core.Services
|
||||
public void DeleteStylesheet(string name, int userId = 0)
|
||||
{
|
||||
var uow = _fileUowProvider.GetUnitOfWork();
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow))
|
||||
using (var repository = _repositoryFactory.CreateStylesheetRepository(uow, _dataUowProvider.GetUnitOfWork()))
|
||||
{
|
||||
var stylesheet = repository.Get(name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user