Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update styledoutput ids when merge is completed in branch service #217

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,20 @@ DELETE FROM `{tableName}`

await UpdateProgressInQueue(databaseConnection, queueId, totalItemsInHistory, true);

// Check if any ids need to be updated for styledoutput entries.
foreach (var oldId in idMapping[WiserTableNames.WiserStyledOutput])
{
var newId = GetMappedId(WiserTableNames.WiserStyledOutput, idMapping, oldId.Key);
if (newId != oldId.Key)
{
// An Id is different and needs to be updated inside the styledoutputs.
foreach (var processingId in idMapping[WiserTableNames.WiserStyledOutput])
{
await ReplaceStyledOutputIdInsideStyledOutputAsync(databaseConnection, processingId.Key, oldId.Key, newId.Value);
}
}
}

try
{
// Clear wiser_history in the selected environment, so that next time we can just sync all changes again.
Expand Down Expand Up @@ -2533,6 +2547,54 @@ private static async Task UpdateProgressInQueue(IDatabaseConnection databaseConn
await databaseConnection.ExecuteAsync($"UPDATE {WiserTableNames.WiserBranchesQueue} SET items_processed = ?itemsProcessed WHERE id = ?queueId");
}

private static async Task ReplaceStyledOutputIdInsideStyledOutputAsync(IDatabaseConnection databaseConnection,
ulong targetStyledOutput, ulong oldId, ulong newId)
{
var originalDatabase = databaseConnection.ConnectedDatabase;

// Get current Content
var items = await databaseConnection.GetAsync($"""
SELECT
`format_begin`, `format_item`, `format_end`, `format_empty`
FROM `{originalDatabase}`.`{WiserTableNames.WiserStyledOutput}` AS prod
WHERE prod.id = {targetStyledOutput}
ORDER BY file.id ASC
LIMIT 1
""");
if (items.Rows.Count == 0)
{
// The Target styledOutput does not exist, no need to update this one.
return;
}

var formatBegin = items.Rows[0].Field<string>("format_begin");
var formatItem = items.Rows[0].Field<string>("format_item");
var formatEnd = items.Rows[0].Field<string>("format_end");
var formatEmpty = items.Rows[0].Field<string>("format_empty");

// Note: Curly Brace needs to be included in search/replace
var searchString = $"{{StyledOutput~{oldId}";
var replaceString = $"{{StyledOutput~{newId}";

formatBegin = formatBegin.Replace(searchString, replaceString);
formatItem = formatItem.Replace(searchString, replaceString);
formatEnd = formatEnd.Replace(searchString, replaceString);
formatEmpty = formatEmpty.Replace(searchString, replaceString);

await databaseConnection.ExecuteAsync($"""
UPDATE {WiserTableNames.WiserStyledOutput}
SET
format_begin = {formatBegin},
format_item = {formatItem},
format_end = {formatEnd},
format_empty = {formatEmpty}
WHERE id = {targetStyledOutput}
ORDER BY file.id ASC
LIMIT 1
""");

HansHappyHorizon marked this conversation as resolved.
Show resolved Hide resolved
}

private static async Task<BranchMergeLinkCacheModel> GetLinkDataAsync(ulong? linkId, Dictionary<string, object> sqlParameters, string tableName, MySqlConnection branchConnection, List<BranchMergeLinkCacheModel> linksCache)
{
var result = new BranchMergeLinkCacheModel { Id = linkId ?? 0 };
Expand Down