Skip to content

Commit

Permalink
Emptying Combinator cache on shell activation if marker file exists; …
Browse files Browse the repository at this point in the history
…Adding validate-pull-request.yml to csproj
  • Loading branch information
Dragonnhun committed Oct 4, 2023
1 parent b0d6c52 commit 37e25f3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Constants/FileNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Piedone.Combinator.Constants
{
public static class FileNames
{
public const string ClearCache = "_" + nameof(ClearCache);
}
}
9 changes: 9 additions & 0 deletions Constants/FolderNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Piedone.Combinator.Constants
{
public static class FolderNames
{
public const string PiedoneModules = "_" + nameof(PiedoneModules);
public const string Combinator = nameof(Combinator);
public const string Sites = nameof(Sites);
}
}
51 changes: 51 additions & 0 deletions EventHandlers/CacheFileEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Orchard.Environment;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.FileSystems.AppData;
using Piedone.Combinator.Constants;
using Piedone.Combinator.Services;

namespace Piedone.Combinator.EventHandlers
{
[OrchardFeature("Piedone.Combinator")]
public class CacheFileEventHandler : IOrchardShellEvents
{
private const string ClearCacheFileName = FileNames.ClearCache + ".txt";

private readonly ICacheFileService _cacheFileService;
private readonly IAppDataFolder _appDataFolder;

private readonly string _basePath;

/// <summary>
/// Gets or sets a value indicating whether emptying Combinator cache is disabled, primarily through HostComponents.config.
/// </summary>
public bool IsEmptyingCacheDisabled { get; set; }

public CacheFileEventHandler(ICacheFileService cacheFileService, IAppDataFolder appDataFolder, ShellSettings shellSettings)
{
_cacheFileService = cacheFileService;
_appDataFolder = appDataFolder;

_basePath = _appDataFolder.Combine(FolderNames.Sites, shellSettings.Name, FolderNames.PiedoneModules, FolderNames.Combinator);
}

public void Activated()
{
if (IsEmptyingCacheDisabled) return;

var pathToClearCacheFile = _appDataFolder.Combine(_basePath, ClearCacheFileName);

if (!_appDataFolder.FileExists(pathToClearCacheFile)) return;

_cacheFileService.Empty();

_appDataFolder.DeleteFile(pathToClearCacheFile);
}

public void Terminating()
{
// Terminating event does not need to be implemented.
}
}
}
6 changes: 6 additions & 0 deletions Piedone.Combinator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
<Content Include="Module.txt" />
</ItemGroup>
<ItemGroup>
<Compile Include="Constants\FolderNames.cs" />
<Compile Include="Constants\FileNames.cs" />
<Compile Include="Commands\CombinatorCommands.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Drivers\CombinatorSettingsPartDriver.cs" />
Expand All @@ -170,6 +172,7 @@
<Compile Include="EventHandlers\ICombinatorEventMonitor.cs" />
<Compile Include="EventHandlers\ICombinatorResourceEventHandler.cs" />
<Compile Include="EventHandlers\LessPreprocessor.cs" />
<Compile Include="EventHandlers\CacheFileEventHandler.cs" />
<Compile Include="EventHandlers\SassPreprocessor.cs" />
<Compile Include="Extensions\CombinedFileRecordExtensions.cs" />
<Compile Include="Extensions\RequireSettingsExtensions.cs" />
Expand Down Expand Up @@ -290,4 +293,7 @@
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include=".github\workflows\validate-pull-request.yml" />
</ItemGroup>
</Project>

0 comments on commit 37e25f3

Please sign in to comment.