123123
This commit is contained in:
@@ -13,11 +13,12 @@ namespace ZelWiki.Repository
|
||||
{
|
||||
public static class ConfigurationRepository
|
||||
{
|
||||
#region Upgrade Database.
|
||||
#region
|
||||
|
||||
public static string GetVersionStateVersion()
|
||||
{
|
||||
var entries = ManagedDataStorage.Config.ExecuteScalar<string>(@"Scripts\Initialization\GetVersionStateVersion.sql");
|
||||
var entries =
|
||||
ManagedDataStorage.Config.ExecuteScalar<string>(@"Scripts\Initialization\GetVersionStateVersion.sql");
|
||||
return entries ?? "0.0.0";
|
||||
}
|
||||
|
||||
@@ -25,11 +26,12 @@ namespace ZelWiki.Repository
|
||||
{
|
||||
var version = string.Join('.',
|
||||
(Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "0.0.0.0").Split('.').Take(3));
|
||||
ManagedDataStorage.Config.Execute(@"Scripts\Initialization\SetVersionStateVersion.sql", new { Version = version });
|
||||
ManagedDataStorage.Config.Execute(@"Scripts\Initialization\SetVersionStateVersion.sql",
|
||||
new { Version = version });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See @Initialization.Versions.md
|
||||
///
|
||||
/// </summary>
|
||||
public static void UpgradeDatabase()
|
||||
{
|
||||
@@ -45,43 +47,44 @@ namespace ZelWiki.Repository
|
||||
|
||||
if (currentPaddedVersion == storedPaddedVersion)
|
||||
{
|
||||
return; //The database version is already at the latest version.
|
||||
return;
|
||||
}
|
||||
|
||||
var updateScriptNames = Assembly.GetExecutingAssembly().GetManifestResourceNames()
|
||||
.Where(o => o.Contains("Repository.Scripts.Initialization.Versions", StringComparison.InvariantCultureIgnoreCase)).OrderBy(o => o);
|
||||
.Where(o => o.Contains("Repository.Scripts.Initialization.Versions",
|
||||
StringComparison.InvariantCultureIgnoreCase)).OrderBy(o => o);
|
||||
|
||||
string startVersionTag = ".Initialization.Versions.";
|
||||
string endVersionTag = ".^";
|
||||
var startVersionTag = ".Initialization.Versions.";
|
||||
var endVersionTag = ".^";
|
||||
|
||||
foreach (var updateScriptName in updateScriptNames)
|
||||
{
|
||||
int startIndex = updateScriptName.IndexOf(startVersionTag, StringComparison.InvariantCultureIgnoreCase);
|
||||
int startIndex =
|
||||
updateScriptName.IndexOf(startVersionTag, StringComparison.InvariantCultureIgnoreCase);
|
||||
if (startIndex >= 0)
|
||||
{
|
||||
startIndex += startVersionTag.Length;
|
||||
|
||||
int endIndex = updateScriptName.IndexOf(endVersionTag, startIndex, StringComparison.InvariantCultureIgnoreCase);
|
||||
var endIndex = updateScriptName.IndexOf(endVersionTag, startIndex,
|
||||
StringComparison.InvariantCultureIgnoreCase);
|
||||
if (endIndex > startIndex)
|
||||
{
|
||||
//The name of the script file without the namespaces, version numbers etc.
|
||||
var fullScriptName = updateScriptName.Substring(endIndex + endVersionTag.Length).Trim().Replace("_", "");
|
||||
var fullScriptName = updateScriptName.Substring(endIndex + endVersionTag.Length).Trim()
|
||||
.Replace("_", "");
|
||||
|
||||
int filesFolderVersion = Utility.PadVersionString(updateScriptName.Substring(startIndex, endIndex - startIndex).Trim().Replace("_", ""));
|
||||
int filesFolderVersion = Utility.PadVersionString(updateScriptName
|
||||
.Substring(startIndex, endIndex - startIndex).Trim().Replace("_", ""));
|
||||
if (filesFolderVersion > storedPaddedVersion)
|
||||
{
|
||||
//Get the script text.
|
||||
using var stream = assembly.GetManifestResourceStream(updateScriptName);
|
||||
using var reader = new StreamReader(stream.EnsureNotNull());
|
||||
var scriptText = reader.ReadToEnd();
|
||||
|
||||
//Get the script "metadata" from the file name.
|
||||
|
||||
var scriptNameParts = fullScriptName.Split('^');
|
||||
//string executionOrder = scriptNameParts[0];
|
||||
string databaseName = scriptNameParts[1];
|
||||
//string scriptName = scriptNameParts[2];
|
||||
var databaseName = scriptNameParts[1];
|
||||
|
||||
var databaseFactory = ManagedDataStorage.Collection.Single(o => o.Name == databaseName).Factory;
|
||||
var databaseFactory = ManagedDataStorage.Collection.Single(o => o.Name == databaseName)
|
||||
.Factory;
|
||||
|
||||
databaseFactory.Execute(scriptText);
|
||||
}
|
||||
@@ -95,13 +98,14 @@ namespace ZelWiki.Repository
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionRepository.InsertException(ex, "Database upgrade failed.");
|
||||
ExceptionRepository.InsertException(ex, "数据库升级失败");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static ConfigurationEntries GetConfigurationEntryValuesByGroupName(string groupName, bool allowCache = true)
|
||||
public static ConfigurationEntries GetConfigurationEntryValuesByGroupName(string groupName,
|
||||
bool allowCache = true)
|
||||
{
|
||||
if (allowCache)
|
||||
{
|
||||
@@ -163,27 +167,25 @@ namespace ZelWiki.Repository
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if this is the first time the wiki has run. Returns true if it is the first time.
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool IsFirstRun()
|
||||
{
|
||||
bool isEncryptionValid = GetCryptoCheck();
|
||||
var isEncryptionValid = GetCryptoCheck();
|
||||
if (isEncryptionValid == false)
|
||||
{
|
||||
SetCryptoCheck();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an encrypted value from the database so we can determine if encryption is setup.
|
||||
/// If the value is missing then we are NOT setup.
|
||||
/// If the value is present but we cant decrypt it, then we are NOT setup.
|
||||
/// /// If the value is present and we can decrypt it, then we are setup and good to go!
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool GetCryptoCheck()
|
||||
{
|
||||
var value = ManagedDataStorage.Config.QueryFirstOrDefault<string>("GetCryptoCheck.sql") ?? string.Empty;
|
||||
@@ -203,9 +205,9 @@ namespace ZelWiki.Repository
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an encrypted value to the database so we can test at a later time to ensure that encryption is setup.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static void SetCryptoCheck()
|
||||
{
|
||||
var param = new
|
||||
@@ -275,6 +277,7 @@ namespace ZelWiki.Repository
|
||||
ConfigurationGroupId = group.Key,
|
||||
});
|
||||
}
|
||||
|
||||
result.Add(nest);
|
||||
}
|
||||
|
||||
@@ -284,14 +287,16 @@ namespace ZelWiki.Repository
|
||||
public static List<ConfigurationFlat> GetFlatConfiguration()
|
||||
=> ManagedDataStorage.Config.Query<ConfigurationFlat>("GetFlatConfiguration.sql").ToList();
|
||||
|
||||
public static string? GetConfigurationEntryValuesByGroupNameAndEntryName(string groupName, string entryName, bool allowCache = true)
|
||||
public static string? GetConfigurationEntryValuesByGroupNameAndEntryName(string groupName, string entryName,
|
||||
bool allowCache = true)
|
||||
{
|
||||
if (allowCache)
|
||||
{
|
||||
var cacheKey = WikiCacheKeyFunction.Build(WikiCache.Category.Configuration, [groupName, entryName]);
|
||||
if (!WikiCache.TryGet<string>(cacheKey, out var result))
|
||||
{
|
||||
if ((result = GetConfigurationEntryValuesByGroupNameAndEntryName(groupName, entryName, false)) != null)
|
||||
if ((result = GetConfigurationEntryValuesByGroupNameAndEntryName(groupName, entryName, false)) !=
|
||||
null)
|
||||
{
|
||||
WikiCache.Put(cacheKey, result);
|
||||
}
|
||||
@@ -306,7 +311,9 @@ namespace ZelWiki.Repository
|
||||
EntryName = entryName
|
||||
};
|
||||
|
||||
var configEntry = ManagedDataStorage.Config.QuerySingle<ConfigurationEntry>("GetConfigurationEntryValuesByGroupNameAndEntryName.sql", param);
|
||||
var configEntry =
|
||||
ManagedDataStorage.Config.QuerySingle<ConfigurationEntry>(
|
||||
"GetConfigurationEntryValuesByGroupNameAndEntryName.sql", param);
|
||||
if (configEntry?.IsEncrypted == true)
|
||||
{
|
||||
try
|
||||
@@ -431,33 +438,31 @@ namespace ZelWiki.Repository
|
||||
|
||||
if (emoji.ImageData != null)
|
||||
{
|
||||
var scaledImageCacheKey = WikiCacheKey.Build(WikiCache.Category.Emoji, [emoji.Shortcut, "100"]);
|
||||
var scaledImageCacheKey =
|
||||
WikiCacheKey.Build(WikiCache.Category.Emoji, [emoji.Shortcut, "100"]);
|
||||
var decompressedImageBytes = Utility.Decompress(emoji.ImageData);
|
||||
var img = Image.Load(new MemoryStream(decompressedImageBytes));
|
||||
|
||||
int customScalePercent = 100;
|
||||
var customScalePercent = 100;
|
||||
|
||||
var (Width, Height) = Utility.ScaleToMaxOf(img.Width, img.Height, GlobalConfiguration.DefaultEmojiHeight);
|
||||
|
||||
//Adjust to any specified scaling.
|
||||
var (Width, Height) = Utility.ScaleToMaxOf(img.Width, img.Height,
|
||||
GlobalConfiguration.DefaultEmojiHeight);
|
||||
|
||||
Height = (int)(Height * (customScalePercent / 100.0));
|
||||
Width = (int)(Width * (customScalePercent / 100.0));
|
||||
|
||||
//Adjusting by a ratio (and especially after applying additional scaling) may have caused one
|
||||
// dimension to become very small (or even negative). So here we will check the height and width
|
||||
// to ensure they are both at least n pixels and adjust both dimensions.
|
||||
|
||||
if (Height < 16)
|
||||
{
|
||||
Height += 16 - Height;
|
||||
Width += 16 - Height;
|
||||
}
|
||||
|
||||
if (Width < 16)
|
||||
{
|
||||
Height += 16 - Width;
|
||||
Width += 16 - Width;
|
||||
}
|
||||
|
||||
//These are hard to generate, so just keep it forever.
|
||||
|
||||
var resized = Images.ResizeGifImage(decompressedImageBytes, Width, Height);
|
||||
var itemCache = new ImageCacheItem(resized, "image/gif");
|
||||
WikiCache.Put(scaledImageCacheKey, itemCache, new CacheItemPolicy());
|
||||
@@ -497,27 +502,34 @@ namespace ZelWiki.Repository
|
||||
|
||||
GlobalConfiguration.FixedMenuPosition = customizationConfig.Value("Fixed Header Menu Position", false);
|
||||
GlobalConfiguration.AllowSignup = membershipConfig.Value("Allow Signup", false);
|
||||
GlobalConfiguration.DefaultProfileRecentlyModifiedCount = performanceConfig.Value<int>("Default Profile Recently Modified Count");
|
||||
GlobalConfiguration.DefaultProfileRecentlyModifiedCount =
|
||||
performanceConfig.Value<int>("Default Profile Recently Modified Count");
|
||||
GlobalConfiguration.PreLoadAnimatedEmojis = performanceConfig.Value<bool>("Pre-Load Animated Emojis");
|
||||
GlobalConfiguration.SystemTheme = GetAllThemes().Single(o => o.Name == themeName);
|
||||
GlobalConfiguration.DefaultEmojiHeight = customizationConfig.Value<int>("Default Emoji Height");
|
||||
GlobalConfiguration.AllowGoogleAuthentication = membershipConfig.Value<bool>("Allow Google Authentication");
|
||||
GlobalConfiguration.DefaultTimeZone = customizationConfig?.Value<string>("Default TimeZone") ?? string.Empty;
|
||||
GlobalConfiguration.IncludeWikiDescriptionInMeta = functionalityConfig.Value<bool>("Include wiki Description in Meta");
|
||||
GlobalConfiguration.DefaultTimeZone =
|
||||
customizationConfig?.Value<string>("Default TimeZone") ?? string.Empty;
|
||||
GlobalConfiguration.IncludeWikiDescriptionInMeta =
|
||||
functionalityConfig.Value<bool>("Include wiki Description in Meta");
|
||||
GlobalConfiguration.IncludeWikiTagsInMeta = functionalityConfig.Value<bool>("Include wiki Tags in Meta");
|
||||
GlobalConfiguration.EnablePageComments = functionalityConfig.Value<bool>("Enable Page Comments");
|
||||
GlobalConfiguration.EnablePublicProfiles = functionalityConfig.Value<bool>("Enable Public Profiles");
|
||||
GlobalConfiguration.ShowCommentsOnPageFooter = functionalityConfig.Value<bool>("Show Comments on Page Footer");
|
||||
GlobalConfiguration.ShowLastModifiedOnPageFooter = functionalityConfig.Value<bool>("Show Last Modified on Page Footer");
|
||||
GlobalConfiguration.ShowCommentsOnPageFooter =
|
||||
functionalityConfig.Value<bool>("Show Comments on Page Footer");
|
||||
GlobalConfiguration.ShowLastModifiedOnPageFooter =
|
||||
functionalityConfig.Value<bool>("Show Last Modified on Page Footer");
|
||||
GlobalConfiguration.IncludeSearchOnNavbar = searchConfig.Value<bool>("Include Search on Navbar");
|
||||
GlobalConfiguration.HTMLHeader = htmlConfig?.Value<string>("Header") ?? string.Empty;
|
||||
GlobalConfiguration.HTMLFooter = htmlConfig?.Value<string>("Footer") ?? string.Empty;
|
||||
GlobalConfiguration.HTMLPreBody = htmlConfig?.Value<string>("Pre-Body") ?? string.Empty;
|
||||
GlobalConfiguration.HTMLPostBody = htmlConfig?.Value<string>("Post-Body") ?? string.Empty;
|
||||
GlobalConfiguration.BrandImageSmall = customizationConfig?.Value<string>("Brand Image (Small)") ?? string.Empty;
|
||||
GlobalConfiguration.BrandImageSmall =
|
||||
customizationConfig?.Value<string>("Brand Image (Small)") ?? string.Empty;
|
||||
GlobalConfiguration.FooterBlurb = customizationConfig?.Value<string>("FooterBlurb") ?? string.Empty;
|
||||
GlobalConfiguration.MaxAvatarFileSize = filesAndAttachmentsConfig.Value<int>("Max Avatar File Size");
|
||||
GlobalConfiguration.MaxAttachmentFileSize = filesAndAttachmentsConfig.Value<int>("Max Attachment File Size");
|
||||
GlobalConfiguration.MaxAttachmentFileSize =
|
||||
filesAndAttachmentsConfig.Value<int>("Max Attachment File Size");
|
||||
GlobalConfiguration.MaxEmojiFileSize = filesAndAttachmentsConfig.Value<int>("Max Emoji File Size");
|
||||
|
||||
GlobalConfiguration.MenuItems = GetAllMenuItems();
|
||||
@@ -525,4 +537,4 @@ namespace ZelWiki.Repository
|
||||
ReloadEmojis();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user