fixup! New: Parse language tags from existing subtitles files
Closes #5890
This commit is contained in:
parent
dbeaceea5c
commit
ceebc71fe9
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Data;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Dapper;
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
@ -19,7 +20,7 @@ namespace NzbDrone.Core.Datastore.Migration
|
|||
|
||||
private void UpdateLanguageTags(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
var updatedLanguageTags = new Dictionary<int, List<string>>();
|
||||
var updatedLanguageTags = new List<object>();
|
||||
var now = DateTime.Now;
|
||||
|
||||
using (var cmd = conn.CreateCommand())
|
||||
|
@ -34,7 +35,11 @@ namespace NzbDrone.Core.Datastore.Migration
|
|||
var relativePath = reader.GetString(1);
|
||||
var languageTags = LanguageParser.ParseLanguageTags(relativePath);
|
||||
|
||||
updatedLanguageTags.Add(id, languageTags);
|
||||
updatedLanguageTags.Add(new
|
||||
{
|
||||
Id = id,
|
||||
LanguageTags = languageTags
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,28 +53,8 @@ namespace NzbDrone.Core.Datastore.Migration
|
|||
WriteIndented = true
|
||||
};
|
||||
|
||||
foreach (var pair in updatedLanguageTags)
|
||||
{
|
||||
using (var updateCmd = conn.CreateCommand())
|
||||
{
|
||||
updateCmd.Transaction = tran;
|
||||
|
||||
if (conn.GetType().FullName == "Npgsql.NpgsqlConnection")
|
||||
{
|
||||
updateCmd.CommandText = "UPDATE \"SubtitleFiles\" SET \"LanguageTags\" = $1, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = $2";
|
||||
}
|
||||
else
|
||||
{
|
||||
updateCmd.CommandText = "UPDATE \"SubtitleFiles\" SET \"LanguageTags\" = ?, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = ?";
|
||||
}
|
||||
|
||||
updateCmd.AddParameter(JsonSerializer.Serialize(pair.Value, serializerSettings));
|
||||
|
||||
updateCmd.AddParameter(pair.Key);
|
||||
|
||||
updateCmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
var updateSubtitleFilesSql = "UPDATE \"SubtitleFiles\" SET \"LanguageTags\" = @LanguageTags, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = @Id";
|
||||
conn.Execute(updateSubtitleFilesSql, updatedLanguageTags, transaction: tran);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue