FIX: Database fix for empty category name - move childs and rebuild paths#216
FIX: Database fix for empty category name - move childs and rebuild paths#216Root-Core wants to merge 1 commit intonzbdav-dev:mainfrom
Conversation
|
I tested it, and setting the 'cat' query parameter to an empty string does indeed cause #191, which is fixed by this PR. |
|
This db migration should fix the database entries. I hope I haven't missed anything. |
| public static string? GetQueryParam(this HttpContext httpContext, string name) | ||
| { | ||
| return httpContext.Request.Query[name].FirstOrDefault(); | ||
| return httpContext.Request.Query[name].FirstOrDefault().OrNull(); |
There was a problem hiding this comment.
This change is really the only change needed to fix #191. All the other refactors in ConfigManager, HealthCheckService, DavDatabaseContext, EnvironmentUtil, StringUtil, are unecessary, imo.
return StringUtil.EmptyToNull(httpContext.Request.Query[name].FirstOrDefault());
(And I'm a fan of the db-migration to cleanup any unhealthy cases, we can keep that too)
| SELECT d.Name | ||
| FROM ConfigItems c | ||
| JOIN DavItems d | ||
| ON d.Name = c.ConfigValue | ||
| WHERE c.ConfigName = 'api.manual-category' |
There was a problem hiding this comment.
Why not
SELECT c.ConfigValue
WHERE c.ConfigName = 'api.manual-category'
| migrationBuilder.Sql(@" | ||
| UPDATE OR IGNORE DavItems | ||
| SET ParentId = COALESCE( | ||
| ( | ||
| SELECT Id | ||
| FROM DavItems | ||
| WHERE Name = COALESCE( | ||
| (SELECT ConfigValue FROM ConfigItems WHERE ConfigName = 'api.manual-category'), | ||
| 'uncategorized' | ||
| ) | ||
| ), | ||
| '00000000-0000-0000-0000-000000000002' | ||
| ) | ||
| WHERE ParentId = (SELECT Id FROM DavItems WHERE Name = ''); | ||
| "); | ||
|
|
||
| // Remove empty parent | ||
| // Previous duplicates will be removed due to 'ON DELETE CASCADE' | ||
| migrationBuilder.Sql(@" | ||
| DELETE FROM DavItems WHERE Name = '' | ||
| "); |
There was a problem hiding this comment.
I think we want,
migrationBuilder.Sql(@"
UPDATE DavItems
SET Name = COALESCE(
(SELECT ConfigValue FROM ConfigItems WHERE ConfigName = 'api.manual-category'),
'uncategorized'
)
WHERE Name = ''
AND ParentId = '00000000-0000-0000-0000-000000000002'
");
This will rename the empty-name category folder to whatever is configured in the api.manual-category setting.
Then BuildFullPath should rebuild all the paths.
|
|
||
| #nullable disable | ||
|
|
||
| namespace NzbWebDAV.Database.Migrations |
There was a problem hiding this comment.
I wonder if this migration is worth the complexity.
I'm worried about edge cases that could end up making things worse for someone's db.
Would replacing the entire Up()` method in this migration with something like this be a safer bet?
delete from QueueItems where Category = '';
delete from HistoryItems where Category ='';
delete from DavItems where Name = '' and ParentId = '00000000-0000-0000-0000-000000000002';
This has very predictable results, and would "fix" the problem well-enough for those that encountered the #191 bug.
But if you think it's worth trying to recover those cases where prowlarr imported with empty category (instead of simply deleting them), I added some additional comments below.
3145f83 to
7897608
Compare
7897608 to
83dd8ba
Compare
|
@nzbdav-dev Should I rebase on the I see, that you also addressed |
83dd8ba to
bb49f52
Compare
|
Rebased and dropped commit 83dd8ba I think this is the best of both worlds! |
bb49f52 to
788218c
Compare
|
Thanks for rebasing @Root-Core!
At this stage of the project, I'm inclined to keep pr acceptance to those that are minimal and single-purpose |
788218c to
c7c9742
Compare
One last try. :)
You are right, I missed that.. I moved the extension into the existing
I understand your point and normally I would try keeping it lean, but the PR changed a bit in it's goals. |
c7c9742 to
3289e97
Compare
3289e97 to
20d91a4
Compare
I have split the refactoring out into #272, which should make things easier. |
Fixes #191
The current code base now handles empty categories, but it does not fix existing issues.
This PR fixes the DB and makes content accessible again.
Disclaimer: No AI was used in this pull request.