2017-01-17 14:02:48 +00:00
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2019-12-22 22:08:53 +00:00
|
|
|
|
using FluentMigrator;
|
|
|
|
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
2017-01-17 14:02:48 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore.Migration
|
|
|
|
|
{
|
|
|
|
|
[Migration(121)]
|
|
|
|
|
public class update_filedate_config : NzbDroneMigrationBase
|
|
|
|
|
{
|
|
|
|
|
protected override void MainDbUpgrade()
|
|
|
|
|
{
|
|
|
|
|
Execute.WithConnection(SetTitleSlug);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetTitleSlug(IDbConnection conn, IDbTransaction tran)
|
|
|
|
|
{
|
|
|
|
|
using (IDbCommand getSeriesCmd = conn.CreateCommand())
|
|
|
|
|
{
|
|
|
|
|
getSeriesCmd.Transaction = tran;
|
2022-03-28 20:45:52 +00:00
|
|
|
|
getSeriesCmd.CommandText = @"SELECT ""Id"", ""Value"" FROM ""Config"" WHERE ""Key"" = 'filedate'";
|
2017-01-17 14:02:48 +00:00
|
|
|
|
using (IDataReader seriesReader = getSeriesCmd.ExecuteReader())
|
|
|
|
|
{
|
|
|
|
|
while (seriesReader.Read())
|
|
|
|
|
{
|
|
|
|
|
var id = seriesReader.GetInt32(0);
|
|
|
|
|
var value = seriesReader.GetString(1);
|
|
|
|
|
|
|
|
|
|
using (IDbCommand updateCmd = conn.CreateCommand())
|
|
|
|
|
{
|
|
|
|
|
updateCmd.Transaction = tran;
|
2022-03-28 20:45:52 +00:00
|
|
|
|
updateCmd.CommandText = "UPDATE \"Config\" SET \"Value\" = 'Release' WHERE \"Id\" = ?";
|
2017-01-17 14:02:48 +00:00
|
|
|
|
updateCmd.AddParameter(id);
|
|
|
|
|
|
|
|
|
|
updateCmd.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ToUrlSlug(string value)
|
|
|
|
|
{
|
|
|
|
|
//First to lower case
|
|
|
|
|
value = value.ToLowerInvariant();
|
|
|
|
|
|
|
|
|
|
//Remove all accents
|
|
|
|
|
var bytes = Encoding.GetEncoding("Cyrillic").GetBytes(value);
|
|
|
|
|
value = Encoding.ASCII.GetString(bytes);
|
|
|
|
|
|
|
|
|
|
//Replace spaces
|
|
|
|
|
value = Regex.Replace(value, @"\s", "-", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
//Remove invalid chars
|
|
|
|
|
value = Regex.Replace(value, @"[^a-z0-9\s-_]", "", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
//Trim dashes from end
|
|
|
|
|
value = value.Trim('-', '_');
|
|
|
|
|
|
|
|
|
|
//Replace double occurences of - or _
|
|
|
|
|
value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-22 21:24:10 +00:00
|
|
|
|
}
|