Skip to content

Commit 1f56607

Browse files
committed
Adds a VirtualPath property to IFile which is the relative path of the file to the root of the website.
1 parent 2ad1327 commit 1f56607

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

src/Umbraco.Core/Models/File.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public virtual string Alias
5555
}
5656

5757
/// <summary>
58-
/// Gets or sets the Path to the File from the root of the site
58+
/// Gets or sets the Path to the File from the root of the file's associated IFileSystem
5959
/// </summary>
6060
[DataMember]
6161
public virtual string Path
@@ -92,6 +92,11 @@ public virtual string Content
9292
}
9393
}
9494

95+
/// <summary>
96+
/// Gets or sets the file's virtual path (i.e. the file path relative to the root of the website)
97+
/// </summary>
98+
public string VirtualPath { get; set; }
99+
95100
/// <summary>
96101
/// Boolean indicating whether the file could be validated
97102
/// </summary>

src/Umbraco.Core/Models/IFile.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface IFile : IAggregateRoot
1919
string Alias { get; }
2020

2121
/// <summary>
22-
/// Gets or sets the Path to the File from the root of the site
22+
/// Gets or sets the Path to the File from the root of the file's associated IFileSystem
2323
/// </summary>
2424
string Path { get; set; }
2525

@@ -28,6 +28,11 @@ public interface IFile : IAggregateRoot
2828
/// </summary>
2929
string Content { get; set; }
3030

31+
/// <summary>
32+
/// Gets or sets the file's virtual path (i.e. the file path relative to the root of the website)
33+
/// </summary>
34+
string VirtualPath { get; set; }
35+
3136
/// <summary>
3237
/// Boolean indicating whether the file could be validated
3338
/// </summary>

src/Umbraco.Core/Persistence/Repositories/FileRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ protected virtual void PersistNewItem(TEntity entity)
140140
//the id can be the hash
141141
entity.Id = entity.Path.GetHashCode();
142142
entity.Key = entity.Path.EncodeAsGuid();
143+
entity.VirtualPath = FileSystem.GetUrl(entity.Path);
143144
}
144145
}
145146

@@ -153,6 +154,7 @@ protected virtual void PersistUpdatedItem(TEntity entity)
153154
//the id can be the hash
154155
entity.Id = entity.Path.GetHashCode();
155156
entity.Key = entity.Path.EncodeAsGuid();
157+
entity.VirtualPath = FileSystem.GetUrl(entity.Path);
156158
}
157159
}
158160

src/Umbraco.Core/Persistence/Repositories/PartialViewRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ public override PartialView Get(string id)
3939
var created = FileSystem.GetCreated(path).UtcDateTime;
4040
var updated = FileSystem.GetLastModified(path).UtcDateTime;
4141

42+
4243
var script = new PartialView(path)
4344
{
4445
//id can be the hash
4546
Id = path.GetHashCode(),
4647
Content = content,
4748
Key = path.EncodeAsGuid(),
4849
CreateDate = created,
49-
UpdateDate = updated
50+
UpdateDate = updated,
51+
VirtualPath = FileSystem.GetUrl(id)
5052
};
5153

5254
//on initial construction we don't want to have dirty properties tracked

src/Umbraco.Core/Persistence/Repositories/ScriptRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public override Script Get(string id)
5252
Content = content,
5353
Key = path.EncodeAsGuid(),
5454
CreateDate = created,
55-
UpdateDate = updated
55+
UpdateDate = updated,
56+
VirtualPath = FileSystem.GetUrl(id)
5657
};
5758

5859
//on initial construction we don't want to have dirty properties tracked

src/Umbraco.Core/Persistence/Repositories/StylesheetRepository.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ internal class StylesheetRepository : FileRepository<string, Stylesheet>, IStyle
1818
private readonly IDatabaseUnitOfWork _dbwork;
1919

2020
internal StylesheetRepository(IUnitOfWork work, IDatabaseUnitOfWork db, IFileSystem fileSystem)
21-
: base(work, fileSystem)
22-
{
21+
: base(work, fileSystem)
22+
{
2323
_dbwork = db;
24-
}
24+
}
2525

2626
public StylesheetRepository(IUnitOfWork work, IDatabaseUnitOfWork db)
2727
: this(work, db, new PhysicalFileSystem(SystemDirectories.Css))
@@ -43,7 +43,7 @@ public override Stylesheet Get(string id)
4343
{
4444
byte[] bytes = new byte[stream.Length];
4545
stream.Position = 0;
46-
stream.Read(bytes, 0, (int) stream.Length);
46+
stream.Read(bytes, 0, (int)stream.Length);
4747
content = Encoding.UTF8.GetString(bytes);
4848
}
4949

@@ -52,20 +52,21 @@ public override Stylesheet Get(string id)
5252
var updated = FileSystem.GetLastModified(path).UtcDateTime;
5353

5454
var stylesheet = new Stylesheet(path)
55-
{
56-
Content = content,
57-
Key = path.EncodeAsGuid(),
58-
CreateDate = created,
59-
UpdateDate = updated,
60-
Id = GetStylesheetId(path)
61-
};
55+
{
56+
Content = content,
57+
Key = path.EncodeAsGuid(),
58+
CreateDate = created,
59+
UpdateDate = updated,
60+
Id = GetStylesheetId(path),
61+
VirtualPath = FileSystem.GetUrl(id)
62+
};
6263

6364
//on initial construction we don't want to have dirty properties tracked
6465
// http://issues.umbraco.org/issue/U4-1946
6566
stylesheet.ResetDirtyProperties(false);
6667

6768
return stylesheet;
68-
69+
6970
}
7071

7172
// Fix for missing Id's on FileService.GetStylesheets() call. This is needed as sytlesheets can only bo loaded in the editor via
@@ -77,8 +78,11 @@ private int GetStylesheetId(string path)
7778
.Select("*")
7879
.From<NodeDto>()
7980
.Where("nodeObjectType = @NodeObjectType AND umbracoNode.text = @Alias",
80-
new { NodeObjectType = UmbracoObjectTypes.Stylesheet.GetGuid(),
81-
Alias = path.TrimEnd(".css").Replace("\\", "/") });
81+
new
82+
{
83+
NodeObjectType = UmbracoObjectTypes.Stylesheet.GetGuid(),
84+
Alias = path.TrimEnd(".css").Replace("\\", "/")
85+
});
8286
var nodeDto = _dbwork.Database.FirstOrDefault<NodeDto>(sql);
8387
return nodeDto == null ? 0 : nodeDto.NodeId;
8488
}
@@ -90,7 +94,7 @@ private IEnumerable<Tuple<int, string>> GetStylesheetIds(string[] paths)
9094
.Select("*")
9195
.From<NodeDto>()
9296
.Where("nodeObjectType = @NodeObjectType AND umbracoNode.text in (@aliases)",
93-
new
97+
new
9498
{
9599
NodeObjectType = UmbracoObjectTypes.Stylesheet.GetGuid(),
96100
aliases = paths.Select(x => x.TrimEnd(".css").Replace("\\", "/")).ToArray()

0 commit comments

Comments
 (0)