Skip to content

Commit 9fe0c21

Browse files
CopilotKevinJump
andauthored
Add IgnoreStopIfOnceExists setting for write-only deployments (#879)
* Initial plan * Add IgnoreStopIfOnceExists setting to support write-only deployments Co-authored-by: KevinJump <[email protected]> * Refactor: improve readability of import decision logic Co-authored-by: KevinJump <[email protected]> * Add XML documentation for method parameters Co-authored-by: KevinJump <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: KevinJump <[email protected]>
1 parent cba1094 commit 9fe0c21

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

uSync.BackOffice.Targets/appsettings-schema.usync.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
"description": "location of the once file (relative to the uSync folder)\n ",
8585
"default": "usync.once"
8686
},
87+
"IgnoreStopIfOnceExists": {
88+
"type": "boolean",
89+
"description": "When enabled, the presence of a once file will override the stop file, allowing import to proceed\n ",
90+
"default": false
91+
},
8792
"LockRootTypes": {
8893
"type": "array",
8994
"description": "lock specific types at root so they can't be changed in child sites. \n ",

uSync.BackOffice/Configuration/uSyncSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public class uSyncSettings
5050
[DefaultValue("usync.once")]
5151
public string OnceFile { get; set; } = "usync.once";
5252

53+
/// <summary>
54+
/// When enabled, the presence of a once file will override the stop file, allowing import to proceed
55+
/// </summary>
56+
[DefaultValue(false)]
57+
public bool IgnoreStopIfOnceExists { get; set; } = false;
58+
5359
/// <summary>
5460
/// lock specific types at root so they can't be changed in child sites.
5561
/// </summary>

uSync.BackOffice/Notifications/uSyncApplicationStartingHandler.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,18 @@ private async Task InituSyncAsync()
129129
{
130130
_logger.LogInformation("uSync: Running Import at startup {group}", _uSyncConfig.Settings.ImportAtStartup);
131131

132-
if (!HasStopFile(_uSyncConfig.GetWorkingFolder()))
132+
var workingFolder = _uSyncConfig.GetWorkingFolder();
133+
var hasStopFile = HasStopFile(workingFolder);
134+
var hasOnceFile = HasOnceFile(workingFolder);
135+
136+
if (ShouldProceedWithImport(hasStopFile, hasOnceFile))
133137
{
134138
await _uSyncService.StartupImportAsync(_uSyncConfig.GetFolders(), false, new SyncHandlerOptions
135139
{
136140
Group = _uSyncConfig.Settings.ImportAtStartup
137141
});
138142

139-
await ProcessOnceFileAsync(_uSyncConfig.GetWorkingFolder());
143+
await ProcessOnceFileAsync(workingFolder);
140144
}
141145
else
142146
{
@@ -178,6 +182,30 @@ private bool HasSyncFolders()
178182
private bool HasStopFile(string folder)
179183
=> _syncFileService.FileExists($"{folder}/{_uSyncConfig.Settings.StopFile}");
180184

185+
/// <summary>
186+
/// Does the uSync folder contain a uSync.once file?
187+
/// </summary>
188+
private bool HasOnceFile(string folder)
189+
=> _syncFileService.FileExists($"{folder}/{_uSyncConfig.Settings.OnceFile}");
190+
191+
/// <summary>
192+
/// Determines if the import should proceed based on the presence of stop and once files.
193+
/// </summary>
194+
/// <param name="hasStopFile">Whether a stop file exists in the working folder</param>
195+
/// <param name="hasOnceFile">Whether a once file exists in the working folder</param>
196+
/// <returns>True if import should proceed, false otherwise</returns>
197+
private bool ShouldProceedWithImport(bool hasStopFile, bool hasOnceFile)
198+
{
199+
// If there's no stop file, proceed with import
200+
if (!hasStopFile) return true;
201+
202+
// If stop file exists and IgnoreStopIfOnceExists is enabled, check for once file
203+
if (_uSyncConfig.Settings.IgnoreStopIfOnceExists && hasOnceFile) return true;
204+
205+
// Otherwise, stop file blocks the import
206+
return false;
207+
}
208+
181209
/// <summary>
182210
/// Process the once file (if it exists we rename it to usync.stop).
183211
/// </summary>

0 commit comments

Comments
 (0)