我滴个乖乖
This commit is contained in:
528
ZelWiki.Repository/ConfigurationRepository.cs
Normal file
528
ZelWiki.Repository/ConfigurationRepository.cs
Normal file
@@ -0,0 +1,528 @@
|
||||
using NTDLS.Helpers;
|
||||
using SixLabors.ImageSharp;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Caching;
|
||||
using ZelWiki.Caching;
|
||||
using ZelWiki.Library;
|
||||
using ZelWiki.Models;
|
||||
using ZelWiki.Models.DataModels;
|
||||
|
||||
namespace ZelWiki.Repository
|
||||
{
|
||||
public static class ConfigurationRepository
|
||||
{
|
||||
#region Upgrade Database.
|
||||
|
||||
public static string GetVersionStateVersion()
|
||||
{
|
||||
var entries = ManagedDataStorage.Config.ExecuteScalar<string>(@"Scripts\Initialization\GetVersionStateVersion.sql");
|
||||
return entries ?? "0.0.0";
|
||||
}
|
||||
|
||||
public static void SetVersionStateVersion()
|
||||
{
|
||||
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 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See @Initialization.Versions.md
|
||||
/// </summary>
|
||||
public static void UpgradeDatabase()
|
||||
{
|
||||
try
|
||||
{
|
||||
var versionString = GetVersionStateVersion();
|
||||
int storedPaddedVersion = Utility.PadVersionString(versionString);
|
||||
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
int currentPaddedVersion = Utility.PadVersionString(
|
||||
string.Join('.', (assembly.GetName().Version?.ToString() ?? "0.0.0.0").Split('.').Take(3)));
|
||||
|
||||
if (currentPaddedVersion == storedPaddedVersion)
|
||||
{
|
||||
return; //The database version is already at the latest version.
|
||||
}
|
||||
|
||||
var updateScriptNames = Assembly.GetExecutingAssembly().GetManifestResourceNames()
|
||||
.Where(o => o.Contains("Repository.Scripts.Initialization.Versions", StringComparison.InvariantCultureIgnoreCase)).OrderBy(o => o);
|
||||
|
||||
string startVersionTag = ".Initialization.Versions.";
|
||||
string endVersionTag = ".^";
|
||||
|
||||
foreach (var updateScriptName in updateScriptNames)
|
||||
{
|
||||
int startIndex = updateScriptName.IndexOf(startVersionTag, StringComparison.InvariantCultureIgnoreCase);
|
||||
if (startIndex >= 0)
|
||||
{
|
||||
startIndex += startVersionTag.Length;
|
||||
|
||||
int 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("_", "");
|
||||
|
||||
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 databaseFactory = ManagedDataStorage.Collection.Single(o => o.Name == databaseName).Factory;
|
||||
|
||||
databaseFactory.Execute(scriptText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine(updateScriptName);
|
||||
}
|
||||
|
||||
SetVersionStateVersion();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExceptionRepository.InsertException(ex, "Database upgrade failed.");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static ConfigurationEntries GetConfigurationEntryValuesByGroupName(string groupName, bool allowCache = true)
|
||||
{
|
||||
if (allowCache)
|
||||
{
|
||||
var cacheKey = WikiCacheKeyFunction.Build(WikiCache.Category.Configuration, [groupName]);
|
||||
if (!WikiCache.TryGet<ConfigurationEntries>(cacheKey, out var result))
|
||||
{
|
||||
result = GetConfigurationEntryValuesByGroupName(groupName, false);
|
||||
WikiCache.Put(cacheKey, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var entries = ManagedDataStorage.Config.Query<ConfigurationEntry>
|
||||
("GetConfigurationEntryValuesByGroupName.sql", new { GroupName = groupName }).ToList();
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
if (entry.IsEncrypted)
|
||||
{
|
||||
try
|
||||
{
|
||||
entry.Value = Security.Helpers.DecryptString(Security.Helpers.MachineKey, entry.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
entry.Value = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ConfigurationEntries(entries);
|
||||
}
|
||||
|
||||
public static List<Theme> GetAllThemes()
|
||||
{
|
||||
var collection = ManagedDataStorage.Config.Query<Theme>("GetAllThemes.sql").ToList();
|
||||
|
||||
foreach (var theme in collection)
|
||||
{
|
||||
theme.Files = theme.DelimitedFiles.Split(';', StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static WikiDatabaseStatistics GetWikiDatabaseMetrics()
|
||||
{
|
||||
return ManagedDataStorage.Config.Ephemeral(o =>
|
||||
{
|
||||
using var users_db = o.Attach("users.db", "users_db");
|
||||
using var pages_db = o.Attach("pages.db", "pages_db");
|
||||
|
||||
var result = o.QuerySingle<WikiDatabaseStatistics>("GetWikiDatabaseStatistics.sql");
|
||||
result.Exceptions = ExceptionRepository.GetExceptionCount();
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
/// <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();
|
||||
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>
|
||||
public static bool GetCryptoCheck()
|
||||
{
|
||||
var value = ManagedDataStorage.Config.QueryFirstOrDefault<string>("GetCryptoCheck.sql") ?? string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
value = Security.Helpers.DecryptString(Security.Helpers.MachineKey, value);
|
||||
if (value == Constants.CRYPTOCHECK)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
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>
|
||||
public static void SetCryptoCheck()
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Content = Security.Helpers.EncryptString(Security.Helpers.MachineKey, Constants.CRYPTOCHECK)
|
||||
};
|
||||
|
||||
ManagedDataStorage.Config.QueryFirstOrDefault<string>("SetCryptoCheck.sql", param);
|
||||
}
|
||||
|
||||
public static void SaveConfigurationEntryValueByGroupAndEntry(string groupName, string entryName, string value)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
GroupName = groupName,
|
||||
EntryName = entryName,
|
||||
Value = value
|
||||
};
|
||||
|
||||
ManagedDataStorage.Config.Execute("SaveConfigurationEntryValueByGroupAndEntry.sql", param);
|
||||
|
||||
ConfigurationRepository.ReloadEverything();
|
||||
}
|
||||
|
||||
public static List<ConfigurationNest> GetConfigurationNest()
|
||||
{
|
||||
var result = new List<ConfigurationNest>();
|
||||
var flatConfig = GetFlatConfiguration();
|
||||
|
||||
var groups = flatConfig.GroupBy(o => o.GroupId).ToList();
|
||||
foreach (var group in groups)
|
||||
{
|
||||
var nest = new ConfigurationNest
|
||||
{
|
||||
Id = group.Key,
|
||||
Name = group.Select(o => o.GroupName).First(),
|
||||
Description = group.Select(o => o.GroupDescription).First()
|
||||
};
|
||||
|
||||
foreach (var value in group.OrderBy(o => o.EntryName))
|
||||
{
|
||||
string entryValue;
|
||||
if (value.IsEncrypted)
|
||||
{
|
||||
try
|
||||
{
|
||||
entryValue = Security.Helpers.DecryptString(Security.Helpers.MachineKey, value.EntryValue);
|
||||
}
|
||||
catch
|
||||
{
|
||||
entryValue = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entryValue = value.EntryValue;
|
||||
}
|
||||
|
||||
nest.Entries.Add(new ConfigurationEntry()
|
||||
{
|
||||
Id = value.EntryId,
|
||||
Value = entryValue,
|
||||
Description = value.EntryDescription,
|
||||
Name = value.EntryName,
|
||||
DataType = value.DataType.ToLower(),
|
||||
IsEncrypted = value.IsEncrypted,
|
||||
ConfigurationGroupId = group.Key,
|
||||
});
|
||||
}
|
||||
result.Add(nest);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<ConfigurationFlat> GetFlatConfiguration()
|
||||
=> ManagedDataStorage.Config.Query<ConfigurationFlat>("GetFlatConfiguration.sql").ToList();
|
||||
|
||||
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)
|
||||
{
|
||||
WikiCache.Put(cacheKey, result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var param = new
|
||||
{
|
||||
GroupName = groupName,
|
||||
EntryName = entryName
|
||||
};
|
||||
|
||||
var configEntry = ManagedDataStorage.Config.QuerySingle<ConfigurationEntry>("GetConfigurationEntryValuesByGroupNameAndEntryName.sql", param);
|
||||
if (configEntry?.IsEncrypted == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
configEntry.Value = Security.Helpers.DecryptString(Security.Helpers.MachineKey, configEntry.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
configEntry.Value = "";
|
||||
}
|
||||
}
|
||||
|
||||
return configEntry?.Value?.ToString();
|
||||
}
|
||||
|
||||
public static T? Get<T>(string groupName, string entryName)
|
||||
{
|
||||
var value = GetConfigurationEntryValuesByGroupNameAndEntryName(groupName, entryName);
|
||||
return Converters.ConvertTo<T>(value.EnsureNotNull());
|
||||
}
|
||||
|
||||
public static T? Get<T>(string groupName, string entryName, T defaultValue)
|
||||
{
|
||||
var value = GetConfigurationEntryValuesByGroupNameAndEntryName(groupName, entryName);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return Converters.ConvertTo<T>(value);
|
||||
}
|
||||
|
||||
#region Menu Items.
|
||||
|
||||
public static List<MenuItem> GetAllMenuItems(string? orderBy = null, string? orderByDirection = null)
|
||||
{
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllMenuItems.sql", orderBy, orderByDirection);
|
||||
return ManagedDataStorage.Config.Query<MenuItem>(query).ToList();
|
||||
}
|
||||
|
||||
public static MenuItem GetMenuItemById(int id)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Id = id
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Config.QuerySingle<MenuItem>("GetMenuItemById.sql", param);
|
||||
}
|
||||
|
||||
public static void DeleteMenuItemById(int id)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Id = id
|
||||
};
|
||||
|
||||
ManagedDataStorage.Config.Execute("DeleteMenuItemById.sql", param);
|
||||
|
||||
WikiCache.ClearCategory(WikiCache.Category.Configuration);
|
||||
GlobalConfiguration.MenuItems = GetAllMenuItems();
|
||||
}
|
||||
|
||||
public static int UpdateMenuItemById(MenuItem menuItem)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
menuItem.Id,
|
||||
menuItem.Name,
|
||||
menuItem.Link,
|
||||
menuItem.Ordinal
|
||||
};
|
||||
|
||||
var menuItemId = ManagedDataStorage.Config.ExecuteScalar<int>("UpdateMenuItemById.sql", param);
|
||||
|
||||
WikiCache.ClearCategory(WikiCache.Category.Configuration);
|
||||
GlobalConfiguration.MenuItems = GetAllMenuItems();
|
||||
|
||||
return menuItemId;
|
||||
}
|
||||
|
||||
public static int InsertMenuItem(MenuItem menuItem)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
menuItem.Name,
|
||||
menuItem.Link,
|
||||
menuItem.Ordinal
|
||||
};
|
||||
|
||||
var menuItemId = ManagedDataStorage.Config.ExecuteScalar<int>("InsertMenuItem.sql", param);
|
||||
|
||||
WikiCache.ClearCategory(WikiCache.Category.Configuration);
|
||||
GlobalConfiguration.MenuItems = GetAllMenuItems();
|
||||
|
||||
return menuItemId;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static void ReloadEmojis()
|
||||
{
|
||||
WikiCache.ClearCategory(WikiCache.Category.Emoji);
|
||||
GlobalConfiguration.Emojis = EmojiRepository.GetAllEmojis();
|
||||
|
||||
if (GlobalConfiguration.PreLoadAnimatedEmojis)
|
||||
{
|
||||
new Thread(() =>
|
||||
{
|
||||
var parallelOptions = new ParallelOptions
|
||||
{
|
||||
MaxDegreeOfParallelism = Environment.ProcessorCount / 2 < 2 ? 2 : Environment.ProcessorCount / 2
|
||||
};
|
||||
|
||||
Parallel.ForEach(GlobalConfiguration.Emojis, parallelOptions, emoji =>
|
||||
{
|
||||
if (emoji.MimeType.Equals("image/gif", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var imageCacheKey = WikiCacheKey.Build(WikiCache.Category.Emoji, [emoji.Shortcut]);
|
||||
emoji.ImageData = EmojiRepository.GetEmojiByName(emoji.Name)?.ImageData;
|
||||
|
||||
if (emoji.ImageData != null)
|
||||
{
|
||||
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 (Width, Height) = Utility.ScaleToMaxOf(img.Width, img.Height, GlobalConfiguration.DefaultEmojiHeight);
|
||||
|
||||
//Adjust to any specified scaling.
|
||||
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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReloadEverything()
|
||||
{
|
||||
WikiCache.Clear();
|
||||
|
||||
GlobalConfiguration.IsDebug = Debugger.IsAttached;
|
||||
|
||||
var performanceConfig = GetConfigurationEntryValuesByGroupName("Performance", false);
|
||||
GlobalConfiguration.PageCacheSeconds = performanceConfig.Value<int>("Page Cache Time (Seconds)");
|
||||
GlobalConfiguration.RecordCompilationMetrics = performanceConfig.Value<bool>("Record Compilation Metrics");
|
||||
GlobalConfiguration.CacheMemoryLimitMB = performanceConfig.Value<int>("Cache Memory Limit MB");
|
||||
|
||||
WikiCache.Initialize(GlobalConfiguration.CacheMemoryLimitMB, GlobalConfiguration.PageCacheSeconds);
|
||||
|
||||
var basicConfig = GetConfigurationEntryValuesByGroupName("Basic");
|
||||
var customizationConfig = GetConfigurationEntryValuesByGroupName("Customization");
|
||||
var htmlConfig = GetConfigurationEntryValuesByGroupName("HTML Layout");
|
||||
var functionalityConfig = GetConfigurationEntryValuesByGroupName("Functionality");
|
||||
var membershipConfig = GetConfigurationEntryValuesByGroupName("Membership");
|
||||
var searchConfig = GetConfigurationEntryValuesByGroupName("Search");
|
||||
var filesAndAttachmentsConfig = GetConfigurationEntryValuesByGroupName("Files and Attachments");
|
||||
|
||||
GlobalConfiguration.Address = basicConfig?.Value<string>("Address") ?? string.Empty;
|
||||
GlobalConfiguration.Name = basicConfig?.Value<string>("Name") ?? string.Empty;
|
||||
GlobalConfiguration.Copyright = basicConfig?.Value<string>("Copyright") ?? string.Empty;
|
||||
|
||||
var themeName = customizationConfig.Value("Theme", "Light");
|
||||
|
||||
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.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.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.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.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.MaxEmojiFileSize = filesAndAttachmentsConfig.Value<int>("Max Emoji File Size");
|
||||
|
||||
GlobalConfiguration.MenuItems = GetAllMenuItems();
|
||||
|
||||
ReloadEmojis();
|
||||
}
|
||||
}
|
||||
}
|
||||
160
ZelWiki.Repository/EmojiRepository.cs
Normal file
160
ZelWiki.Repository/EmojiRepository.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using ZelWiki.Library;
|
||||
using ZelWiki.Models.DataModels;
|
||||
|
||||
namespace ZelWiki.Repository
|
||||
{
|
||||
public static partial class EmojiRepository
|
||||
{
|
||||
public static List<Emoji> GetAllEmojis()
|
||||
=> ManagedDataStorage.Emoji.Query<Emoji>("GetAllEmojis.sql").ToList();
|
||||
|
||||
public static IEnumerable<Emoji> GetEmojisByCategory(string category)
|
||||
=> ManagedDataStorage.Emoji.Query<Emoji>("GetEmojisByCategory.sql", new { Category = category });
|
||||
|
||||
public static IEnumerable<EmojiCategory> GetEmojiCategoriesGrouped()
|
||||
=> ManagedDataStorage.Emoji.Query<EmojiCategory>("GetEmojiCategoriesGrouped.sql");
|
||||
|
||||
public static IEnumerable<int> SearchEmojiCategoryIds(List<string> categories)
|
||||
{
|
||||
return ManagedDataStorage.Emoji.Ephemeral(o =>
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
SearchTokenCount = categories.Count
|
||||
};
|
||||
|
||||
using var tempTable = o.CreateTempTableFrom("TempCategories", categories);
|
||||
return o.Query<int>("SearchEmojiCategoryIds.sql", param);
|
||||
});
|
||||
}
|
||||
|
||||
public static List<EmojiCategory> GetEmojiCategoriesByName(string name)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Name = name
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Emoji.Query<EmojiCategory>("GetEmojiCategoriesByName.sql", param).ToList();
|
||||
}
|
||||
|
||||
public static void DeleteById(int id)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Id = id
|
||||
};
|
||||
|
||||
ManagedDataStorage.Emoji.Execute("DeleteEmojiById.sql", param);
|
||||
|
||||
ConfigurationRepository.ReloadEmojis();
|
||||
}
|
||||
|
||||
public static Emoji? GetEmojiByName(string name)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Name = name
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Emoji.QuerySingleOrDefault<Emoji>("GetEmojiByName.sql", param);
|
||||
}
|
||||
|
||||
public static int UpsertEmoji(UpsertEmoji emoji)
|
||||
{
|
||||
int emojiId = ManagedDataStorage.Emoji.Ephemeral(o =>
|
||||
{
|
||||
var transaction = o.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
if (emoji.Id == null || emoji.Id == 0)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Name = emoji.Name,
|
||||
ImageData = emoji.ImageData == null ? null : Utility.Compress(emoji.ImageData),
|
||||
MimeType = emoji.MimeType
|
||||
};
|
||||
emoji.Id = o.ExecuteScalar<int>("InsertEmoji.sql", param);
|
||||
}
|
||||
else
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
EmojiId = emoji.Id,
|
||||
Name = emoji.Name,
|
||||
ImageData = emoji.ImageData == null ? null : Utility.Compress(emoji.ImageData),
|
||||
MimeType = emoji.MimeType
|
||||
};
|
||||
o.ExecuteScalar<int>("UpdateEmoji.sql", param);
|
||||
}
|
||||
|
||||
var upsertEmojiCategoriesParam = new
|
||||
{
|
||||
EmojiId = emoji.Id
|
||||
};
|
||||
|
||||
using var tempTable = o.CreateTempTableFrom("TempEmojiCategories", emoji.Categories, transaction);
|
||||
o.Execute("UpsertEmojiCategories.sql", upsertEmojiCategoriesParam);
|
||||
|
||||
transaction.Commit();
|
||||
|
||||
return (int)emoji.Id;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
});
|
||||
|
||||
ConfigurationRepository.ReloadEmojis();
|
||||
|
||||
return emojiId;
|
||||
}
|
||||
|
||||
public static List<Emoji> GetAllEmojisPaged(int pageNumber,
|
||||
string? orderBy = null, string? orderByDirection = null, List<string>? categories = null)
|
||||
{
|
||||
int pageSize = ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
if (categories == null || categories.Count == 0)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize
|
||||
};
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllEmojisPaged.sql", orderBy, orderByDirection);
|
||||
return ManagedDataStorage.Emoji.Query<Emoji>(query, param).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
var emojiCategoryIds = SearchEmojiCategoryIds(categories);
|
||||
|
||||
var param = new
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Emoji.Ephemeral(o =>
|
||||
{
|
||||
var getAllEmojisPagedByCategoriesParam = new
|
||||
{
|
||||
SearchTokenCount = emojiCategoryIds.Count(),
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize
|
||||
};
|
||||
|
||||
using var tempTable = o.CreateTempTableFrom("TempEmojiCategoryIds", emojiCategoryIds);
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllEmojisPagedByCategories.sql", orderBy, orderByDirection);
|
||||
return o.Query<Emoji>(query, getAllEmojisPagedByCategoriesParam).ToList();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
81
ZelWiki.Repository/ExceptionRepository.cs
Normal file
81
ZelWiki.Repository/ExceptionRepository.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using ZelWiki.Models.DataModels;
|
||||
|
||||
namespace ZelWiki.Repository
|
||||
{
|
||||
public static class ExceptionRepository
|
||||
{
|
||||
public static void PurgeExceptions()
|
||||
{
|
||||
ManagedDataStorage.Exceptions.Execute("PurgeExceptions.sql");
|
||||
}
|
||||
|
||||
public static void InsertException(string? text = null, string? exceptionText = null, string? stackTrace = null)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Text = text,
|
||||
ExceptionText = exceptionText,
|
||||
StackTrace = stackTrace,
|
||||
CreatedDate = DateTime.UtcNow,
|
||||
};
|
||||
|
||||
ManagedDataStorage.Exceptions.Execute("InsertException.sql", param);
|
||||
}
|
||||
|
||||
public static void InsertException(Exception ex)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Text = string.Empty,
|
||||
ExceptionText = ex.Message,
|
||||
StackTrace = ex.StackTrace,
|
||||
CreatedDate = DateTime.UtcNow,
|
||||
};
|
||||
|
||||
ManagedDataStorage.Exceptions.Execute("InsertException.sql", param);
|
||||
}
|
||||
|
||||
public static void InsertException(Exception ex, string? text = null)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Text = text,
|
||||
ExceptionText = ex.Message,
|
||||
StackTrace = ex.StackTrace,
|
||||
CreatedDate = DateTime.UtcNow
|
||||
};
|
||||
|
||||
ManagedDataStorage.Exceptions.Execute("InsertException.sql", param);
|
||||
}
|
||||
|
||||
public static int GetExceptionCount()
|
||||
{
|
||||
return ManagedDataStorage.Exceptions.ExecuteScalar<int>("GetExceptionCount.sql");
|
||||
}
|
||||
|
||||
public static List<WikiException> GetAllExceptionsPaged(int pageNumber,
|
||||
string? orderBy = null, string? orderByDirection = null)
|
||||
{
|
||||
int pageSize = ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
var param = new
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
};
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetAllExceptionsPaged.sql", orderBy, orderByDirection);
|
||||
return ManagedDataStorage.Exceptions.Query<WikiException>(query, param).ToList();
|
||||
}
|
||||
|
||||
public static WikiException GetExceptionById(int id)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Id = id
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Exceptions.QuerySingle<WikiException>("GetExceptionById.sql", param);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
ZelWiki.Repository/ManagedDataStorage.cs
Normal file
40
ZelWiki.Repository/ManagedDataStorage.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using NTDLS.SqliteDapperWrapper;
|
||||
|
||||
namespace ZelWiki.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores instances of ManagedDataStorageFactories that are used to store various parts of the data for the site.
|
||||
/// </summary>
|
||||
public static class ManagedDataStorage
|
||||
{
|
||||
private static (string Name, ManagedDataStorageFactory Factory)[]? _collection = null;
|
||||
|
||||
public static (string Name, ManagedDataStorageFactory Factory)[] Collection
|
||||
{
|
||||
get
|
||||
{
|
||||
_collection ??=
|
||||
[
|
||||
("DeletedPageRevisions", DeletedPageRevisions),
|
||||
("DeletedPages", DeletedPages),
|
||||
("Pages", Pages),
|
||||
("Statistics", Statistics),
|
||||
("Emoji", Emoji),
|
||||
("Exceptions", Exceptions),
|
||||
("Users", Users),
|
||||
("Config", Config)
|
||||
];
|
||||
return _collection;
|
||||
}
|
||||
}
|
||||
|
||||
public static ManagedDataStorageFactory DeletedPageRevisions { get; private set; } = new();
|
||||
public static ManagedDataStorageFactory DeletedPages { get; private set; } = new();
|
||||
public static ManagedDataStorageFactory Pages { get; private set; } = new();
|
||||
public static ManagedDataStorageFactory Statistics { get; private set; } = new();
|
||||
public static ManagedDataStorageFactory Emoji { get; private set; } = new();
|
||||
public static ManagedDataStorageFactory Exceptions { get; private set; } = new();
|
||||
public static ManagedDataStorageFactory Users { get; private set; } = new();
|
||||
public static ManagedDataStorageFactory Config { get; private set; } = new();
|
||||
}
|
||||
}
|
||||
279
ZelWiki.Repository/PageFileRepository.cs
Normal file
279
ZelWiki.Repository/PageFileRepository.cs
Normal file
@@ -0,0 +1,279 @@
|
||||
using NTDLS.SqliteDapperWrapper;
|
||||
using ZelWiki.Caching;
|
||||
using ZelWiki.Models.DataModels;
|
||||
|
||||
namespace ZelWiki.Repository
|
||||
{
|
||||
public static class PageFileRepository
|
||||
{
|
||||
public static void DetachPageRevisionAttachment(string pageNavigation, string fileNavigation, int pageRevision)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageNavigation = pageNavigation,
|
||||
FileNavigation = fileNavigation,
|
||||
PageRevision = pageRevision
|
||||
};
|
||||
|
||||
ManagedDataStorage.Pages.Execute("DetachPageRevisionAttachment.sql", param);
|
||||
}
|
||||
|
||||
public static List<OrphanedPageAttachment> GetOrphanedPageAttachmentsPaged(
|
||||
int pageNumber, string? orderBy = null, string? orderByDirection = null)
|
||||
{
|
||||
int pageSize = ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
var param = new
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize
|
||||
};
|
||||
|
||||
var query = RepositoryHelper.TransposeOrderby("GetOrphanedPageAttachments.sql", orderBy, orderByDirection);
|
||||
return ManagedDataStorage.Pages.Query<OrphanedPageAttachment>(query, param).ToList();
|
||||
}
|
||||
|
||||
public static void PurgeOrphanedPageAttachments()
|
||||
=> ManagedDataStorage.Pages.Execute("PurgeOrphanedPageAttachments.sql");
|
||||
|
||||
public static void PurgeOrphanedPageAttachment(int pageFileId, int revision)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageFileId = pageFileId,
|
||||
Revision = revision
|
||||
};
|
||||
ManagedDataStorage.Pages.Execute("PurgeOrphanedPageAttachment.sql", param);
|
||||
}
|
||||
|
||||
public static List<PageFileAttachmentInfo> GetPageFilesInfoByPageNavigationAndPageRevisionPaged(string pageNavigation, int pageNumber, int? pageSize = null, int? pageRevision = null)
|
||||
{
|
||||
pageSize ??= ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
var param = new
|
||||
{
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize,
|
||||
PageNavigation = pageNavigation,
|
||||
PageRevision = pageRevision
|
||||
};
|
||||
return ManagedDataStorage.Pages.Query<PageFileAttachmentInfo>("GetPageFilesInfoByPageNavigationAndPageRevisionPaged.sql", param).ToList();
|
||||
}
|
||||
|
||||
public static PageFileAttachmentInfo? GetPageFileAttachmentInfoByPageNavigationPageRevisionAndFileNavigation(string pageNavigation, string fileNavigation, int? pageRevision = null)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageNavigation = pageNavigation,
|
||||
FileNavigation = fileNavigation,
|
||||
PageRevision = pageRevision
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Pages.QuerySingleOrDefault<PageFileAttachmentInfo>("GetPageFileAttachmentInfoByPageNavigationPageRevisionAndFileNavigation.sql", param);
|
||||
}
|
||||
|
||||
public static PageFileAttachment? GetPageFileAttachmentByPageNavigationFileRevisionAndFileNavigation(string pageNavigation, string fileNavigation, int? fileRevision = null)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageNavigation = pageNavigation,
|
||||
FileNavigation = fileNavigation,
|
||||
FileRevision = fileRevision
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Pages.QuerySingleOrDefault<PageFileAttachment>("GetPageFileAttachmentByPageNavigationFileRevisionAndFileNavigation.sql", param);
|
||||
}
|
||||
|
||||
public static PageFileAttachment? GetPageFileAttachmentByPageNavigationPageRevisionAndFileNavigation(string pageNavigation, string fileNavigation, int? pageRevision = null, bool allowCache = true)
|
||||
{
|
||||
if (allowCache)
|
||||
{
|
||||
var cacheKey = WikiCacheKeyFunction.Build(WikiCache.Category.Page, [pageNavigation, fileNavigation, pageRevision]);
|
||||
if (!WikiCache.TryGet<PageFileAttachment>(cacheKey, out var result))
|
||||
{
|
||||
if ((result = GetPageFileAttachmentByPageNavigationPageRevisionAndFileNavigation(pageNavigation, fileNavigation, pageRevision, false)) != null)
|
||||
{
|
||||
WikiCache.Put(cacheKey, result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var param = new
|
||||
{
|
||||
PageNavigation = pageNavigation,
|
||||
FileNavigation = fileNavigation,
|
||||
PageRevision = pageRevision
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Pages.QuerySingleOrDefault<PageFileAttachment>(
|
||||
"GetPageFileAttachmentByPageNavigationPageRevisionAndFileNavigation.sql", param);
|
||||
}
|
||||
|
||||
public static List<PageFileAttachmentInfo> GetPageFileAttachmentRevisionsByPageAndFileNavigationPaged(string pageNavigation, string fileNavigation, int pageNumber)
|
||||
{
|
||||
int pageSize = ConfigurationRepository.Get<int>("Customization", "Pagination Size");
|
||||
|
||||
var param = new
|
||||
{
|
||||
PageNavigation = pageNavigation,
|
||||
FileNavigation = fileNavigation,
|
||||
PageNumber = pageNumber,
|
||||
PageSize = pageSize
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Pages.Ephemeral(o =>
|
||||
{
|
||||
using var users_db = o.Attach("users.db", "users_db");
|
||||
|
||||
var result = o.Query<PageFileAttachmentInfo>(
|
||||
"GetPageFileAttachmentRevisionsByPageAndFileNavigationPaged.sql", param).ToList();
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public static List<PageFileAttachmentInfo> GetPageFilesInfoByPageId(int pageId)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageId = pageId
|
||||
};
|
||||
|
||||
return ManagedDataStorage.Pages.Query<PageFileAttachmentInfo>("GetPageFilesInfoByPageId.sql", param).ToList();
|
||||
}
|
||||
|
||||
public static PageFileRevisionAttachmentInfo? GetPageFileInfoByFileNavigation(ManagedDataStorageInstance connection, int pageId, string fileNavigation)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageId = pageId,
|
||||
Navigation = fileNavigation,
|
||||
};
|
||||
|
||||
return connection.QuerySingleOrDefault<PageFileRevisionAttachmentInfo>("GetPageFileInfoByFileNavigation.sql", param);
|
||||
}
|
||||
|
||||
public static PageFileRevisionAttachmentInfo? GetPageCurrentRevisionAttachmentByFileNavigation(ManagedDataStorageInstance connection, int pageId, string fileNavigation)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
PageId = pageId,
|
||||
Navigation = fileNavigation,
|
||||
};
|
||||
|
||||
return connection.QuerySingleOrDefault<PageFileRevisionAttachmentInfo>("GetPageCurrentRevisionAttachmentByFileNavigation.sql", param);
|
||||
}
|
||||
|
||||
public static void UpsertPageFile(PageFileAttachment item, Guid userId)
|
||||
{
|
||||
bool hasFileChanged = false;
|
||||
|
||||
ManagedDataStorage.Pages.Ephemeral(o =>
|
||||
{
|
||||
var transaction = o.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var pageFileInfo = GetPageFileInfoByFileNavigation(o, item.PageId, item.FileNavigation);
|
||||
if (pageFileInfo == null)
|
||||
{
|
||||
//If the page file does not exist, then insert it.
|
||||
|
||||
var InsertPageFileParam = new
|
||||
{
|
||||
PageId = item.PageId,
|
||||
Name = item.Name,
|
||||
FileNavigation = item.FileNavigation,
|
||||
ContentType = item.ContentType,
|
||||
Size = item.Size,
|
||||
CreatedDate = item.CreatedDate,
|
||||
Data = item.Data
|
||||
};
|
||||
|
||||
o.Execute("InsertPageFile.sql", InsertPageFileParam);
|
||||
|
||||
//Get the id of the newly inserted page file.
|
||||
pageFileInfo = GetPageFileInfoByFileNavigation(o, item.PageId, item.FileNavigation)
|
||||
?? throw new Exception("Failed find newly inserted page attachment.");
|
||||
|
||||
hasFileChanged = true;
|
||||
}
|
||||
|
||||
|
||||
int currentFileRevision = 0;
|
||||
var newDataHash = Security.Helpers.Crc32(item.Data);
|
||||
|
||||
var currentlyAttachedFile = GetPageCurrentRevisionAttachmentByFileNavigation(o, item.PageId, item.FileNavigation);
|
||||
if (currentlyAttachedFile != null)
|
||||
{
|
||||
//The PageFile exists and a revision of it is attached to this page revision.
|
||||
//Keep track of the file revision, and determine if the file has changed (via the file hash).
|
||||
|
||||
currentFileRevision = currentlyAttachedFile.Revision;
|
||||
hasFileChanged = currentlyAttachedFile.DataHash != newDataHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
//The file either does not exist or is not attached to the current page revision.
|
||||
hasFileChanged = true;
|
||||
|
||||
//We determined earlier that the PageFile does exist, so keep track of the file revision.
|
||||
currentFileRevision = pageFileInfo.Revision;
|
||||
}
|
||||
|
||||
if (hasFileChanged)
|
||||
{
|
||||
currentFileRevision++;
|
||||
|
||||
//Get the current page revision so that we can associate the page file attachment with the current page revision.
|
||||
int currentPageRevision = PageRepository.GetCurrentPageRevision(o, item.PageId);
|
||||
|
||||
var updatePageFileRevisionParam = new
|
||||
{
|
||||
PageFileId = pageFileInfo.PageFileId,
|
||||
FileRevision = currentFileRevision
|
||||
};
|
||||
//The file has changed (or is newly inserted), bump the file revision.
|
||||
o.Execute("UpdatePageFileRevision.sql", updatePageFileRevisionParam);
|
||||
|
||||
var insertPageFileRevisionParam = new
|
||||
{
|
||||
PageFileId = pageFileInfo.PageFileId,
|
||||
ContentType = item.ContentType,
|
||||
Size = item.Size,
|
||||
CreatedDate = item.CreatedDate,
|
||||
CreatedByUserId = userId,
|
||||
Data = item.Data,
|
||||
FileRevision = currentFileRevision,
|
||||
DataHash = newDataHash,
|
||||
};
|
||||
|
||||
//Insert the actual file data.
|
||||
o.Execute("InsertPageFileRevision.sql", insertPageFileRevisionParam);
|
||||
|
||||
var associatePageFileAttachmentWithPageRevisionParam = new
|
||||
{
|
||||
PageId = item.PageId,
|
||||
PageFileId = pageFileInfo.PageFileId,
|
||||
PageRevision = currentPageRevision,
|
||||
FileRevision = currentFileRevision,
|
||||
PreviousFileRevision = currentlyAttachedFile?.Revision //This is so we can disassociate the previous file revision.
|
||||
};
|
||||
|
||||
//Associate the latest version of the file with the latest version of the page.
|
||||
o.Execute("AssociatePageFileAttachmentWithPageRevision.sql", associatePageFileAttachmentWithPageRevisionParam);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
1175
ZelWiki.Repository/PageRepository.cs
Normal file
1175
ZelWiki.Repository/PageRepository.cs
Normal file
File diff suppressed because it is too large
Load Diff
74
ZelWiki.Repository/RepositoryHelper.cs
Normal file
74
ZelWiki.Repository/RepositoryHelper.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using NTDLS.SqliteDapperWrapper;
|
||||
|
||||
namespace ZelWiki.Repository
|
||||
{
|
||||
internal static class RepositoryHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Fills in a custom orderby on a given sql script.
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="orderBy"></param>
|
||||
/// <returns></returns>
|
||||
public static string TransposeOrderby(string filename, string? orderBy, string? orderByDirection)
|
||||
{
|
||||
var script = ManagedDataStorageInstance.TranslateSqlScript(filename);
|
||||
|
||||
if (string.IsNullOrEmpty(orderBy))
|
||||
{
|
||||
return script;
|
||||
}
|
||||
|
||||
string beginParentTag = "--CUSTOM_ORDER_BEGIN::";
|
||||
string endParentTag = "--::CUSTOM_ORDER_BEGIN";
|
||||
|
||||
string beginConfigTag = "--CONFIG::";
|
||||
string endConfigTag = "--::CONFIG";
|
||||
|
||||
while (true)
|
||||
{
|
||||
int beginParentIndex = script.IndexOf(beginParentTag, StringComparison.OrdinalIgnoreCase);
|
||||
int endParentIndex = script.IndexOf(endParentTag, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (beginParentIndex > 0 && endParentIndex > beginParentIndex)
|
||||
{
|
||||
var sectionText = script.Substring(beginParentIndex + beginParentTag.Length, (endParentIndex - beginParentIndex) - endParentTag.Length).Trim();
|
||||
|
||||
int beginConfigIndex = sectionText.IndexOf(beginConfigTag, StringComparison.OrdinalIgnoreCase);
|
||||
int endConfigIndex = sectionText.IndexOf(endConfigTag, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (beginConfigIndex >= 0 && endConfigIndex > beginConfigIndex)
|
||||
{
|
||||
var configText = sectionText.Substring(beginConfigIndex + beginConfigTag.Length, (endConfigIndex - beginConfigIndex) - endConfigTag.Length).Trim();
|
||||
|
||||
var configs = configText.Split("\n").Select(o => o.Trim())
|
||||
.Where(o => o.Contains('='))
|
||||
.Select(o => (Name: o.Split("=")[0], Field: o.Split("=")[1]));
|
||||
|
||||
var selectedConfig = configs.SingleOrDefault(o => string.Equals(o.Name, orderBy, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (selectedConfig == default)
|
||||
{
|
||||
throw new Exception($"No order by mapping was found in '{filename}' for the field '{orderBy}'.");
|
||||
}
|
||||
|
||||
script = script.Substring(0, beginParentIndex)
|
||||
+ $"ORDER BY\r\n\t{selectedConfig.Field} "
|
||||
+ (string.Equals(orderByDirection, "asc", StringComparison.InvariantCultureIgnoreCase) ? "asc" : "desc")
|
||||
+ script.Substring(endParentIndex + endParentTag.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"No order configuration was found in '{filename}'.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return script;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
ZelWiki.Repository/Scripts/AnonymizeProfile.sql
Normal file
10
ZelWiki.Repository/Scripts/AnonymizeProfile.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
UPDATE
|
||||
Profile
|
||||
SET
|
||||
AccountName = @StandinName,
|
||||
Navigation = @Navigation,
|
||||
Biography = 'Deleted account.',
|
||||
Avatar = null,
|
||||
ModifiedDate = @ModifiedDate
|
||||
WHERE
|
||||
UserId = @UserId
|
||||
@@ -0,0 +1,21 @@
|
||||
--Remove the previous page file revision attachment, if any.
|
||||
DELETE FROM PageRevisionAttachment
|
||||
WHERE
|
||||
PageId = @PageId
|
||||
AND PageFileId = @PageFileId
|
||||
AND FileRevision = @PreviousFileRevision
|
||||
AND PageRevision = @PageRevision;
|
||||
|
||||
--Associate the file revision record with the page revision.
|
||||
INSERT INTO PageRevisionAttachment
|
||||
(
|
||||
PageId,
|
||||
PageFileId,
|
||||
FileRevision,
|
||||
PageRevision
|
||||
)
|
||||
SELECT
|
||||
@PageId,
|
||||
@PageFileId,
|
||||
@FileRevision,
|
||||
@PageRevision;
|
||||
26
ZelWiki.Repository/Scripts/CreatePage.sql
Normal file
26
ZelWiki.Repository/Scripts/CreatePage.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
INSERT INTO Page
|
||||
(
|
||||
Name,
|
||||
Namespace,
|
||||
Description,
|
||||
Navigation,
|
||||
Revision,
|
||||
CreatedByUserId,
|
||||
CreatedDate,
|
||||
ModifiedByUserId,
|
||||
ModifiedDate
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Name,
|
||||
@Namespace,
|
||||
@Description,
|
||||
@Navigation,
|
||||
1,
|
||||
@CreatedByUserId,
|
||||
@CreatedDate,
|
||||
@ModifiedByUserId,
|
||||
@ModifiedDate
|
||||
);
|
||||
|
||||
SELECT last_insert_rowid();
|
||||
15
ZelWiki.Repository/Scripts/CreateProfile.sql
Normal file
15
ZelWiki.Repository/Scripts/CreateProfile.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
INSERT INTO Profile
|
||||
(
|
||||
UserId,
|
||||
AccountName,
|
||||
Navigation,
|
||||
CreatedDate,
|
||||
ModifiedDate
|
||||
)
|
||||
SELECT
|
||||
@UserId,
|
||||
@AccountName,
|
||||
@Navigation,
|
||||
@CreatedDate,
|
||||
@ModifiedDate
|
||||
|
||||
2
ZelWiki.Repository/Scripts/DeleteEmojiById.sql
Normal file
2
ZelWiki.Repository/Scripts/DeleteEmojiById.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
DELETE FROM EmojiCategory WHERE EmojiId = @Id;
|
||||
DELETE FROM Emoji WHERE Id = @Id;
|
||||
4
ZelWiki.Repository/Scripts/DeleteMenuItemById.sql
Normal file
4
ZelWiki.Repository/Scripts/DeleteMenuItemById.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
DELETE FROM
|
||||
MenuItem
|
||||
WHERE
|
||||
Id = @Id
|
||||
6
ZelWiki.Repository/Scripts/DeletePageCommentById.sql
Normal file
6
ZelWiki.Repository/Scripts/DeletePageCommentById.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
DELETE FROM
|
||||
PageComment
|
||||
WHERE
|
||||
PageId = @PageId
|
||||
AND Id = @CommentId
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
DELETE FROM
|
||||
PageComment
|
||||
WHERE
|
||||
PageId = @PageId
|
||||
AND UserId = @UserId
|
||||
AND Id = @CommentId
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
DELETE FROM [CompilationStatistics] WHERE PageId = @PageId;
|
||||
23
ZelWiki.Repository/Scripts/DetachPageRevisionAttachment.sql
Normal file
23
ZelWiki.Repository/Scripts/DetachPageRevisionAttachment.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
DELETE FROM PageRevisionAttachment
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM PageFile AS PF
|
||||
INNER JOIN Page AS P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN PageRevision AS PR
|
||||
ON PR.PageId = P.Id
|
||||
INNER JOIN PageRevisionAttachment AS PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
AND PRA.PageRevision = PR.Revision
|
||||
INNER JOIN PageFileRevision AS PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = PRA.FileRevision
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
AND PR.Revision = @PageRevision
|
||||
AND PageRevisionAttachment.PageId = P.Id
|
||||
AND PageRevisionAttachment.PageFileId = PF.Id
|
||||
AND PageRevisionAttachment.PageRevision = PR.Revision
|
||||
);
|
||||
6
ZelWiki.Repository/Scripts/DoesEmailAddressExist.sql
Normal file
6
ZelWiki.Repository/Scripts/DoesEmailAddressExist.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
AspNetUsers
|
||||
WHERE
|
||||
Email = @EmailAddress
|
||||
7
ZelWiki.Repository/Scripts/DoesProfileAccountExist.sql
Normal file
7
ZelWiki.Repository/Scripts/DoesProfileAccountExist.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
Profile
|
||||
WHERE
|
||||
Navigation = @Navigation
|
||||
LIMIT 1
|
||||
1
ZelWiki.Repository/Scripts/ForeignKeyCheck.sql
Normal file
1
ZelWiki.Repository/Scripts/ForeignKeyCheck.sql
Normal file
@@ -0,0 +1 @@
|
||||
PRAGMA foreign_key_check;
|
||||
28
ZelWiki.Repository/Scripts/GetAccountProfileByNavigation.sql
Normal file
28
ZelWiki.Repository/Scripts/GetAccountProfileByNavigation.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
SELECT
|
||||
U.UserId,
|
||||
U.Avatar,
|
||||
ANU.Email as EmailAddress,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
U.Biography,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'firstname') as FirstName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'lastname') as LastName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'timezone') as TimeZone,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'language') as Language,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType LIKE '%/country') as Country,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'theme') as Theme,
|
||||
U.CreatedDate,
|
||||
U.ModifiedDate,
|
||||
UCR.ClaimValue as Role,
|
||||
ANU.EmailConfirmed
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
WHERE
|
||||
U.Navigation = @Navigation
|
||||
28
ZelWiki.Repository/Scripts/GetAccountProfileByUserId.sql
Normal file
28
ZelWiki.Repository/Scripts/GetAccountProfileByUserId.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
SELECT
|
||||
U.UserId,
|
||||
U.Avatar,
|
||||
ANU.Email as EmailAddress,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
U.Biography,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'firstname') as FirstName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'lastname') as LastName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'timezone') as TimeZone,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'language') as Language,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType LIKE '%/country') as Country,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'theme') as Theme,
|
||||
U.CreatedDate,
|
||||
U.ModifiedDate,
|
||||
UCR.ClaimValue as Role,
|
||||
ANU.EmailConfirmed
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
WHERE
|
||||
U.UserId = @UserId
|
||||
@@ -0,0 +1,46 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
DeletedUser.AccountName as DeletedByUserName,
|
||||
DM.DeletedDate,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Page] as P
|
||||
WHERE
|
||||
P.Id IN (SELECT PID.Value FROM TempPageIds as PID)
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN DeletionMeta as DM
|
||||
ON DM.PageId = P.Id
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = P.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as DeletedUser
|
||||
ON DeletedUser.UserId = DM.DeletedByUserID
|
||||
WHERE
|
||||
P.Id IN (SELECT PID.Value FROM TempPageIds as PID)
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Page=P.[Name]
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
42
ZelWiki.Repository/Scripts/GetAllDeletedPagesPaged.sql
Normal file
42
ZelWiki.Repository/Scripts/GetAllDeletedPagesPaged.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
DeletedUser.AccountName as DeletedByUserName,
|
||||
DM.DeletedDate,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Page] as P
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN DeletionMeta as DM
|
||||
ON DM.PageId = P.Id
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = P.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as DeletedUser
|
||||
ON DeletedUser.UserId = DM.DeletedByUserID
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Page=P.[Name]
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
9
ZelWiki.Repository/Scripts/GetAllEmojis.sql
Normal file
9
ZelWiki.Repository/Scripts/GetAllEmojis.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
[Id],
|
||||
[Name],
|
||||
MimeType,
|
||||
'%%' || lower([Name]) || '%%' as [Shortcut]
|
||||
FROM
|
||||
Emoji
|
||||
ORDER BY
|
||||
[Name]
|
||||
27
ZelWiki.Repository/Scripts/GetAllEmojisPaged.sql
Normal file
27
ZelWiki.Repository/Scripts/GetAllEmojisPaged.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
SELECT
|
||||
E.Id,
|
||||
E.[Name],
|
||||
E.MimeType,
|
||||
'%%' || lower(E.[Name]) || '%%' as Shortcut,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
(Round(Count(0) / (@PageSize + 0.0) + 0.999))
|
||||
FROM
|
||||
Emoji as iE
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
Emoji as E
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=E.[Name]
|
||||
MimeType=E.[MimeType]
|
||||
Shortcut=E.[Name]
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
E.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
35
ZelWiki.Repository/Scripts/GetAllEmojisPagedByCategories.sql
Normal file
35
ZelWiki.Repository/Scripts/GetAllEmojisPagedByCategories.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
SELECT
|
||||
E.Id,
|
||||
E.[Name],
|
||||
E.MimeType,
|
||||
'%%' || lower(E.[Name]) || '%%' as Shortcut,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
(Round(Count(0) / (@PageSize + 0.0) + 0.999))
|
||||
FROM
|
||||
Emoji as iE
|
||||
INNER JOIN EmojiCategory as iEC
|
||||
ON iEC.EmojiId = iE.Id
|
||||
WHERE
|
||||
iEC.Id IN (SELECT Value FROM TempEmojiCategoryIds)
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
Emoji as E
|
||||
INNER JOIN EmojiCategory as EC
|
||||
ON EC.EmojiId = E.Id
|
||||
WHERE
|
||||
EC.Id IN (SELECT Value FROM TempEmojiCategoryIds)
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=E.[Name]
|
||||
MimeType=E.[MimeType]
|
||||
Shortcut=E.[Name]
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
E.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
28
ZelWiki.Repository/Scripts/GetAllExceptionsPaged.sql
Normal file
28
ZelWiki.Repository/Scripts/GetAllExceptionsPaged.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
SELECT
|
||||
Id,
|
||||
[Text],
|
||||
[ExceptionText],
|
||||
[StackTrace],
|
||||
[CreatedDate],
|
||||
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Exception] as P
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Exception]
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Id=Id
|
||||
CreatedDate=[CreatedDate]
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
Id
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
19
ZelWiki.Repository/Scripts/GetAllMenuItems.sql
Normal file
19
ZelWiki.Repository/Scripts/GetAllMenuItems.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
SELECT
|
||||
[Id] as [Id],
|
||||
[Name] as [Name],
|
||||
[Link] as [Link],
|
||||
[Ordinal] as [Ordinal]
|
||||
FROM
|
||||
[MenuItem]
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Id=Id
|
||||
Name=Name
|
||||
Link=Link
|
||||
Ordinal=Ordinal
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
[Ordinal]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
43
ZelWiki.Repository/Scripts/GetAllNamespacePagesPaged.sql
Normal file
43
ZelWiki.Repository/Scripts/GetAllNamespacePagesPaged.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Page] as P
|
||||
WHERE
|
||||
P.[Namespace] = @Namespace
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = P.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
WHERE
|
||||
P.[Namespace] = @Namespace
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=P.[Name]
|
||||
Revision=P.Revision
|
||||
ModifiedBy=ModifiedUser.AccountName
|
||||
ModifiedDate=P.ModifiedDate
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
4
ZelWiki.Repository/Scripts/GetAllNamespaces.sql
Normal file
4
ZelWiki.Repository/Scripts/GetAllNamespaces.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
SELECT DISTINCT
|
||||
[Namespace]
|
||||
FROM
|
||||
[Page]
|
||||
27
ZelWiki.Repository/Scripts/GetAllNamespacesPaged.sql
Normal file
27
ZelWiki.Repository/Scripts/GetAllNamespacesPaged.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
SELECT
|
||||
P.[Namespace],
|
||||
Count(0) as [CountOfPages],
|
||||
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
Count(DISTINCT P.[Namespace]) / (@PageSize + 0.0)
|
||||
FROM
|
||||
[Page] as P
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
GROUP BY
|
||||
[Namespace]
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=P.[Namespace]
|
||||
Pages=Count(0)
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.[Namespace]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
17
ZelWiki.Repository/Scripts/GetAllPages.sql
Normal file
17
ZelWiki.Repository/Scripts/GetAllPages.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Description],
|
||||
PR.Body,
|
||||
PR.Revision,
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
WHERE
|
||||
PR.Revision = P.Revision
|
||||
38
ZelWiki.Repository/Scripts/GetAllPagesByInstructionPaged.sql
Normal file
38
ZelWiki.Repository/Scripts/GetAllPagesByInstructionPaged.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN PageProcessingInstruction as PPI
|
||||
ON PPI.PageId = P.Id
|
||||
WHERE
|
||||
PPI.Instruction = @Instruction
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = P.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
INNER JOIN PageProcessingInstruction as PPI
|
||||
ON PPI.PageId = P.Id
|
||||
WHERE
|
||||
PPI.Instruction = @Instruction
|
||||
ORDER BY
|
||||
P.[Name],
|
||||
P.Id
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
44
ZelWiki.Repository/Scripts/GetAllPagesByPageIdPaged.sql
Normal file
44
ZelWiki.Repository/Scripts/GetAllPagesByPageIdPaged.sql
Normal file
@@ -0,0 +1,44 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
(SELECT COUNT(0) FROM deletedpagerevisions_db.[PageRevision] WHERE PageId = P.Id) as DeletedRevisionCount,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Page] as P
|
||||
WHERE
|
||||
P.Id IN (SELECT PID.Value FROM TempPageIds as PID)
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = P.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
WHERE
|
||||
P.Id IN (SELECT PID.Value FROM TempPageIds as PID)
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=p.Name
|
||||
Revision=P.Revision
|
||||
ModifiedBy=ModifiedUser.AccountName
|
||||
ModifiedDate=P.ModifiedDate
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
40
ZelWiki.Repository/Scripts/GetAllPagesPaged.sql
Normal file
40
ZelWiki.Repository/Scripts/GetAllPagesPaged.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
(SELECT COUNT(0) FROM deletedpagerevisions_db.[PageRevision] WHERE PageId = P.Id) as DeletedRevisionCount,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Page] as P
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = P.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=p.Name
|
||||
Revision=P.Revision
|
||||
ModifiedBy=ModifiedUser.AccountName
|
||||
ModifiedDate=P.ModifiedDate
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
62
ZelWiki.Repository/Scripts/GetAllPublicProfilesPaged.sql
Normal file
62
ZelWiki.Repository/Scripts/GetAllPublicProfilesPaged.sql
Normal file
@@ -0,0 +1,62 @@
|
||||
--This proc is exactly like GetAllUsersPaged except it has no filter on personal infomation so it can be used for public info.
|
||||
|
||||
SELECT
|
||||
U.UserId,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'timezone') as TimeZone,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'language') as Language,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType LIKE '%/country') as Country,
|
||||
U.CreatedDate,
|
||||
U.ModifiedDate,
|
||||
UCR.ClaimValue as Role,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
Profile as P
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCFirstName
|
||||
ON UCFirstName.UserId = U.UserId
|
||||
AND UCFirstName.ClaimType = 'firstname'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCLastName
|
||||
ON UCLastName.UserId = U.UserId
|
||||
AND UCLastName.ClaimType = 'lastname'
|
||||
WHERE
|
||||
@SearchToken IS NULL
|
||||
OR U.AccountName LIKE '%' || @SearchToken || '%'
|
||||
OR ANU.Email LIKE '%' || @SearchToken || '%'
|
||||
OR UCFirstName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
OR UCLastName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCFirstName
|
||||
ON UCFirstName.UserId = U.UserId
|
||||
AND UCFirstName.ClaimType = 'firstname'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCLastName
|
||||
ON UCLastName.UserId = U.UserId
|
||||
AND UCLastName.ClaimType = 'lastname'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
WHERE
|
||||
@SearchToken IS NULL
|
||||
OR U.AccountName LIKE '%' || @SearchToken || '%'
|
||||
OR ANU.Email LIKE '%' || @SearchToken || '%'
|
||||
OR UCFirstName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
OR UCLastName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
ORDER BY
|
||||
U.AccountName,
|
||||
U.UserId
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
17
ZelWiki.Repository/Scripts/GetAllRoles.sql
Normal file
17
ZelWiki.Repository/Scripts/GetAllRoles.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
SELECT
|
||||
Id,
|
||||
[Name],
|
||||
[Description]
|
||||
FROM
|
||||
[Role]
|
||||
[MenuItem]
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=Name
|
||||
Description=Description
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
12
ZelWiki.Repository/Scripts/GetAllThemes.sql
Normal file
12
ZelWiki.Repository/Scripts/GetAllThemes.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
SELECT
|
||||
[Name],
|
||||
ClassNavBar,
|
||||
ClassNavLink,
|
||||
ClassDropdown,
|
||||
ClassBranding,
|
||||
EditorTheme,
|
||||
DelimitedFiles
|
||||
FROM
|
||||
[Theme]
|
||||
ORDER BY
|
||||
[Name]
|
||||
29
ZelWiki.Repository/Scripts/GetAllUsers.sql
Normal file
29
ZelWiki.Repository/Scripts/GetAllUsers.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
SELECT
|
||||
U.UserId,
|
||||
ANU.Email as EmailAddress,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
UCFirstName.ClaimValue as FirstName,
|
||||
UCLastName.ClaimValue as LastName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'timezone') as TimeZone,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'language') as Language,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType LIKE '%/country') as Country,
|
||||
U.CreatedDate,
|
||||
U.ModifiedDate,
|
||||
UCR.ClaimValue as Role,
|
||||
ANU.EmailConfirmed
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCFirstName
|
||||
ON UCFirstName.UserId = U.UserId
|
||||
AND UCFirstName.ClaimType = 'firstname'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCLastName
|
||||
ON UCLastName.UserId = U.UserId
|
||||
AND UCLastName.ClaimType = 'lastname'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
77
ZelWiki.Repository/Scripts/GetAllUsersPaged.sql
Normal file
77
ZelWiki.Repository/Scripts/GetAllUsersPaged.sql
Normal file
@@ -0,0 +1,77 @@
|
||||
SELECT
|
||||
U.UserId,
|
||||
ANU.Email as EmailAddress,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
UCFirstName.ClaimValue as FirstName,
|
||||
UCLastName.ClaimValue as LastName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'timezone') as TimeZone,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'language') as Language,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType LIKE '%/country') as Country,
|
||||
U.CreatedDate,
|
||||
U.ModifiedDate,
|
||||
UCR.ClaimValue as Role,
|
||||
ANU.EmailConfirmed,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCFirstName
|
||||
ON UCFirstName.UserId = U.UserId
|
||||
AND UCFirstName.ClaimType = 'firstname'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCLastName
|
||||
ON UCLastName.UserId = U.UserId
|
||||
AND UCLastName.ClaimType = 'lastname'
|
||||
WHERE
|
||||
@SearchToken IS NULL
|
||||
OR U.AccountName LIKE '%' || @SearchToken || '%'
|
||||
OR ANU.Email LIKE '%' || @SearchToken || '%'
|
||||
OR UCFirstName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
OR UCLastName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCFirstName
|
||||
ON UCFirstName.UserId = U.UserId
|
||||
AND UCFirstName.ClaimType = 'firstname'
|
||||
LEFT OUTER JOIN AspNetUserClaims as UCLastName
|
||||
ON UCLastName.UserId = U.UserId
|
||||
AND UCLastName.ClaimType = 'lastname'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
WHERE
|
||||
@SearchToken IS NULL
|
||||
OR U.AccountName LIKE '%' || @SearchToken || '%'
|
||||
OR ANU.Email LIKE '%' || @SearchToken || '%'
|
||||
OR UCFirstName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
OR UCLastName.ClaimValue LIKE '%' || @SearchToken || '%'
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Account=U.AccountName
|
||||
FirstName=UCFirstName.ClaimValue
|
||||
LastName=UCLastName.ClaimValue
|
||||
Created=U.CreatedDate
|
||||
TimeZone=TimeZone
|
||||
Language=Language
|
||||
Country=Country
|
||||
EmailAddress=ANU.Email
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
U.AccountName
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
15
ZelWiki.Repository/Scripts/GetAssociatedTags.sql
Normal file
15
ZelWiki.Repository/Scripts/GetAssociatedTags.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
SELECT
|
||||
[Extent].[Tag],
|
||||
Count(DISTINCT [Extent].PageId) as [PageCount]
|
||||
FROM
|
||||
PageTag as [Root]
|
||||
INNER JOIN PageTag as [Interm]
|
||||
ON [Interm].[Tag] = [Root].[Tag]
|
||||
AND [Interm].[PageId] = [Root].[PageId]
|
||||
INNER JOIN PageTag as [Extent]
|
||||
ON [Extent].[PageId] = [Interm].[PageId]
|
||||
WHERE
|
||||
[Root].[Tag] = @Tag
|
||||
GROUP BY
|
||||
[Extent].[Tag]
|
||||
LIMIT 100;
|
||||
18
ZelWiki.Repository/Scripts/GetBasicProfileByUserId.sql
Normal file
18
ZelWiki.Repository/Scripts/GetBasicProfileByUserId.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
SELECT
|
||||
U.UserId,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
U.Biography,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'theme') as Theme,
|
||||
UCR.ClaimValue as Role
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
WHERE
|
||||
U.UserId = @UserId
|
||||
50
ZelWiki.Repository/Scripts/GetCompilationStatisticsPaged.sql
Normal file
50
ZelWiki.Repository/Scripts/GetCompilationStatisticsPaged.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
SELECT
|
||||
MAX(P.Name) as Name,
|
||||
MAX(P.Namespace) as Namespace,
|
||||
MAX(P.Navigation) as Navigation,
|
||||
MAX(Stats.CreatedDate) as LatestBuild,
|
||||
COUNT(0) as Compilations,
|
||||
AVG(Stats.WikifyTimeMs) as AvgBuildTimeMs,
|
||||
AVG(Stats.MatchCount) as AvgWikiMatches,
|
||||
SUM(Stats.ErrorCount) as TotalErrorCount,
|
||||
AVG(Stats.OutgoingLinkCount) as AvgOutgoingLinkCount,
|
||||
AVG(Stats.TagCount) as AvgTagCount,
|
||||
AVG(Stats.BodySize) as AvgRawBodySize,
|
||||
AVG(Stats.ProcessedBodySize) as AvgWikifiedBodySize,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(DISTINCT P.Id) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
CompilationStatistics as Stats
|
||||
INNER JOIN pages_db.[Page] as P
|
||||
ON P.Id = Stats.PageId
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
CompilationStatistics as Stats
|
||||
INNER JOIN pages_db.[Page] as P
|
||||
ON P.Id = Stats.PageId
|
||||
GROUP BY
|
||||
Stats.PageId
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Name=MAX(P.Name)
|
||||
Namespace=MAX(P.Namespace)
|
||||
Navigation=MAX(P.Navigation)
|
||||
CreatedDate=MAX(P.CreatedDate)
|
||||
Compilations=COUNT(0)
|
||||
AvgBuildTimeMs=AVG(Stats.WikifyTimeMs)
|
||||
AvgWikiMatches=AVG(Stats.MatchCount)
|
||||
TotalErrorCount=SUM(Stats.ErrorCount)
|
||||
AvgOutgoingLinkCount=AVG(Stats.OutgoingLinkCount)
|
||||
AvgTagCount=AVG(Stats.TagCount)
|
||||
AvgRawBodySize=AVG(Stats.BodySize)
|
||||
AvgWikifiedBodySize=AVG(Stats.ProcessedBodySize)
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
MAX(P.Name) DESC
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize;
|
||||
@@ -0,0 +1,13 @@
|
||||
SELECT
|
||||
CE.[Id] as [Id],
|
||||
CE.[ConfigurationGroupId] as [ConfigurationGroupId],
|
||||
CE.[Name] as [Name],
|
||||
CE.[Value] as [Value],
|
||||
CE.[IsEncrypted] as [IsEncrypted],
|
||||
CE.[Description] as [Description]
|
||||
FROM
|
||||
[ConfigurationEntry] as CE
|
||||
INNER JOIN [ConfigurationGroup] as CG
|
||||
ON CG.Id = CE.ConfigurationGroupId
|
||||
WHERE
|
||||
CG.[Name] = @GroupName
|
||||
@@ -0,0 +1,13 @@
|
||||
SELECT
|
||||
CE.[Id] as [Id],
|
||||
CE.[ConfigurationGroupId] as [ConfigurationGroupId],
|
||||
CE.[Name] as [Name],
|
||||
CE.[Value] as [Value],
|
||||
CE.[Description] as [Description]
|
||||
FROM
|
||||
[ConfigurationEntry] as CE
|
||||
INNER JOIN [ConfigurationGroup] as CG
|
||||
ON CG.Id = CE.ConfigurationGroupId
|
||||
WHERE
|
||||
CG.[Name] = @GroupName
|
||||
AND CE.[Name] = @EntryName
|
||||
@@ -0,0 +1,6 @@
|
||||
SELECT
|
||||
Count(0) as Attachments
|
||||
FROM
|
||||
PageFile
|
||||
WHERE
|
||||
PageId = @PageId
|
||||
1
ZelWiki.Repository/Scripts/GetCryptoCheck.sql
Normal file
1
ZelWiki.Repository/Scripts/GetCryptoCheck.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT Content FROM CryptoCheck
|
||||
6
ZelWiki.Repository/Scripts/GetCurrentPageRevision.sql
Normal file
6
ZelWiki.Repository/Scripts/GetCurrentPageRevision.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
SELECT
|
||||
Revision
|
||||
FROM
|
||||
[Page]
|
||||
WHERE
|
||||
Id = @PageId
|
||||
1
ZelWiki.Repository/Scripts/GetDatabasePageCount.sql
Normal file
1
ZelWiki.Repository/Scripts/GetDatabasePageCount.sql
Normal file
@@ -0,0 +1 @@
|
||||
PRAGMA page_count;
|
||||
1
ZelWiki.Repository/Scripts/GetDatabasePageSize.sql
Normal file
1
ZelWiki.Repository/Scripts/GetDatabasePageSize.sql
Normal file
@@ -0,0 +1 @@
|
||||
PRAGMA page_size;
|
||||
1
ZelWiki.Repository/Scripts/GetDatabaseVersion.sql
Normal file
1
ZelWiki.Repository/Scripts/GetDatabaseVersion.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT SQLITE_VERSION();
|
||||
31
ZelWiki.Repository/Scripts/GetDeletedPageById.sql
Normal file
31
ZelWiki.Repository/Scripts/GetDeletedPageById.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
PR.[Description],
|
||||
PR.Body,
|
||||
PR.Revision,
|
||||
P.Revision as MostCurrentRevision,
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
PR.ModifiedByUserId,
|
||||
PR.ModifiedDate,
|
||||
DM.DeletedDate,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
DeletedUser.AccountName as DeletedByUserName
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
AND PR.Revision = P.Revision
|
||||
INNER JOIN DeletionMeta as DM
|
||||
ON DM.PageId = P.Id
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = P.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as DeletedUser
|
||||
ON DeletedUser.UserId = DM.DeletedByUserID
|
||||
WHERE
|
||||
P.Id = @PageId
|
||||
12
ZelWiki.Repository/Scripts/GetDeletedPageIdsByTokens.sql
Normal file
12
ZelWiki.Repository/Scripts/GetDeletedPageIdsByTokens.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
SELECT
|
||||
T.PageId
|
||||
FROM
|
||||
PageToken as T
|
||||
INNER JOIN TempTokens as TT
|
||||
ON TT.[value] = T.Token
|
||||
WHERE
|
||||
Coalesce(TT.[value], '') <> ''
|
||||
GROUP BY
|
||||
T.PageId
|
||||
HAVING
|
||||
Count(0) = @TokenCount
|
||||
18
ZelWiki.Repository/Scripts/GetDeletedPageRevisionById.sql
Normal file
18
ZelWiki.Repository/Scripts/GetDeletedPageRevisionById.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
SELECT
|
||||
PR.PageId as Id,
|
||||
PR.Name,
|
||||
PR.[Description],
|
||||
PR.Revision as Revision,
|
||||
PR.Body,
|
||||
DM.DeletedDate,
|
||||
DeletedUser.AccountName as DeletedByUserName
|
||||
FROM
|
||||
[PageRevision] as PR
|
||||
INNER JOIN DeletionMeta as DM
|
||||
ON DM.PageId = PR.PageId
|
||||
AND DM.Revision = PR.Revision
|
||||
LEFT OUTER JOIN users_db.Profile as DeletedUser
|
||||
ON DeletedUser.UserId = DM.DeletedByUserID
|
||||
WHERE
|
||||
PR.PageId = @PageId
|
||||
AND PR.Revision = @Revision
|
||||
@@ -0,0 +1,39 @@
|
||||
SELECT
|
||||
PR.PageId as Id,
|
||||
PR.Name,
|
||||
PR.[Description],
|
||||
PR.Revision as Revision,
|
||||
DM.DeletedDate,
|
||||
DeletedUser.AccountName as DeletedByUserName,
|
||||
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
Count(0) / (@PageSize + 0.0)
|
||||
FROM
|
||||
[PageRevision] as PR
|
||||
WHERE
|
||||
PR.PageId = @PageId
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[PageRevision] as PR
|
||||
INNER JOIN DeletionMeta as DM
|
||||
ON DM.PageId = PR.PageId
|
||||
AND DM.Revision = PR.Revision
|
||||
LEFT OUTER JOIN users_db.Profile as DeletedUser
|
||||
ON DeletedUser.UserId = DM.DeletedByUserID
|
||||
WHERE
|
||||
PR.PageId = @PageId
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Revision=PR.Revision
|
||||
DeletedDate=DM.DeletedDate
|
||||
DeletedBy=DeletedUser.AccountName
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
PR.Revision
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
10
ZelWiki.Repository/Scripts/GetEmojiByName.sql
Normal file
10
ZelWiki.Repository/Scripts/GetEmojiByName.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
E.Id,
|
||||
E.[Name],
|
||||
E.MimeType,
|
||||
'%%' || lower(E.[Name]) || '%%' as Shortcut,
|
||||
ImageData
|
||||
FROM
|
||||
Emoji as E
|
||||
WHERE
|
||||
E.[Name] = @Name
|
||||
10
ZelWiki.Repository/Scripts/GetEmojiCategoriesByName.sql
Normal file
10
ZelWiki.Repository/Scripts/GetEmojiCategoriesByName.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
Ec.Id,
|
||||
EC.EmojiId,
|
||||
EC.Category
|
||||
FROM
|
||||
Emoji as E
|
||||
INNER JOIN EmojiCategory as EC
|
||||
ON EC.EmojiId = E.Id
|
||||
WHERE
|
||||
E.[Name] = @Name
|
||||
22
ZelWiki.Repository/Scripts/GetEmojiCategoriesGrouped.sql
Normal file
22
ZelWiki.Repository/Scripts/GetEmojiCategoriesGrouped.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
SELECT
|
||||
Category,
|
||||
(
|
||||
SELECT
|
||||
Count(0)
|
||||
FROM
|
||||
EmojiCategory as iEC
|
||||
INNER JOIN Emoji as iE
|
||||
ON iE.Id = iEC.EmojiId
|
||||
WHERE
|
||||
iEC.Category = EC.Category
|
||||
) as EmojiCount
|
||||
FROM
|
||||
EmojiCategory as EC
|
||||
INNER JOIN Emoji as E
|
||||
ON E.Id = EC.EmojiId
|
||||
WHERE
|
||||
E.[Name] NOT LIKE '%' || EC.Category || '%'
|
||||
GROUP BY
|
||||
Category
|
||||
ORDER BY
|
||||
Category
|
||||
13
ZelWiki.Repository/Scripts/GetEmojisByCategory.sql
Normal file
13
ZelWiki.Repository/Scripts/GetEmojisByCategory.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
SELECT DISTINCT
|
||||
E.[Id],
|
||||
E.[Name],
|
||||
E.MimeType,
|
||||
'%%' || lower([Name]) || '%%' as [Shortcut]
|
||||
FROM
|
||||
Emoji as E
|
||||
INNER JOIN EmojiCategory as EC
|
||||
ON EC.EmojiId = E.Id
|
||||
WHERE
|
||||
EC.Category = @Category
|
||||
ORDER BY
|
||||
E.[Name]
|
||||
27
ZelWiki.Repository/Scripts/GetExactPageSearchTokens.sql
Normal file
27
ZelWiki.Repository/Scripts/GetExactPageSearchTokens.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
SELECT
|
||||
PageId,
|
||||
SUM([Match]) as [Match],
|
||||
SUM([Weight]) as [Weight],
|
||||
SUM([Score]) as [Score]
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
T.PageId,
|
||||
COUNT(DISTINCT T.Token) / (@TokenCount + 0.0) as [Match],
|
||||
SUM(T.[Weight] * 1.5) as [Weight],
|
||||
--Extra weight on score for exact matches:
|
||||
SUM(T.[Weight] * 1.5) * (COUNT(DISTINCT T.Token) / (@TokenCount + 0.0)) as [Score]
|
||||
FROM
|
||||
PageToken as T
|
||||
INNER JOIN TempSearchTerms as ST
|
||||
ON ST.Token = T.Token
|
||||
GROUP BY
|
||||
T.PageId
|
||||
) as T
|
||||
GROUP BY
|
||||
T.PageId
|
||||
HAVING
|
||||
SUM(Score) >= @MinimumMatchScore
|
||||
ORDER BY
|
||||
SUM([Score]) DESC
|
||||
LIMIT 250;
|
||||
10
ZelWiki.Repository/Scripts/GetExceptionById.sql
Normal file
10
ZelWiki.Repository/Scripts/GetExceptionById.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
Id,
|
||||
[Text],
|
||||
[ExceptionText],
|
||||
[StackTrace],
|
||||
[CreatedDate]
|
||||
FROM
|
||||
[Exception]
|
||||
WHERE
|
||||
Id = @Id
|
||||
1
ZelWiki.Repository/Scripts/GetExceptionCount.sql
Normal file
1
ZelWiki.Repository/Scripts/GetExceptionCount.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT COUNT(0) FROM Exception
|
||||
22
ZelWiki.Repository/Scripts/GetFlatConfiguration.sql
Normal file
22
ZelWiki.Repository/Scripts/GetFlatConfiguration.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
SELECT
|
||||
CG.Id as [GroupId],
|
||||
CG.[Name] as [GroupName],
|
||||
CG.[Description] as [GroupDescription],
|
||||
|
||||
CE.[Id] as [EntryId],
|
||||
CE.[Name] as [EntryName],
|
||||
CE.[Value] as [EntryValue],
|
||||
CE.[Description] as [EntryDescription],
|
||||
CE.IsEncrypted,
|
||||
CE.IsRequired,
|
||||
|
||||
DT.[Name] as DataType
|
||||
FROM
|
||||
[ConfigurationEntry] as CE
|
||||
INNER JOIN [ConfigurationGroup] as CG
|
||||
ON CG.Id = CE.ConfigurationGroupId
|
||||
INNER JOIN DataType as DT
|
||||
ON DT.Id = CE.DataTypeId
|
||||
ORDER BY
|
||||
CG.[Name],
|
||||
CE.[Name]
|
||||
28
ZelWiki.Repository/Scripts/GetFuzzyPageSearchTokens.sql
Normal file
28
ZelWiki.Repository/Scripts/GetFuzzyPageSearchTokens.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
SELECT
|
||||
PageId,
|
||||
SUM([Match]) as [Match],
|
||||
SUM([Weight]) as [Weight],
|
||||
SUM([Score]) as [Score]
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
T.PageId,
|
||||
COUNT(DISTINCT T.DoubleMetaphone) / (@TokenCount + 0.0) as [Match],
|
||||
SUM(T.[Weight] * 1.0) as [Weight],
|
||||
--No weight benefits on score for fuzzy matching weight for exact matches:
|
||||
(COUNT(DISTINCT T.DoubleMetaphone) / (@TokenCount + 0.0)) as [Score]
|
||||
FROM
|
||||
PageToken as T
|
||||
INNER JOIN TempSearchTerms as ST
|
||||
ON ST.Token != T.Token
|
||||
AND ST.DoubleMetaphone = T.DoubleMetaphone
|
||||
GROUP BY
|
||||
T.PageId
|
||||
) as T
|
||||
GROUP BY
|
||||
T.PageId
|
||||
HAVING
|
||||
SUM(Score) >= @MinimumMatchScore
|
||||
ORDER BY
|
||||
SUM([Score]) DESC
|
||||
LIMIT 250;
|
||||
22
ZelWiki.Repository/Scripts/GetLatestPageRevisionById.sql
Normal file
22
ZelWiki.Repository/Scripts/GetLatestPageRevisionById.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
PR.[Description],
|
||||
PR.Body,
|
||||
PR.Revision,
|
||||
P.Revision as MostCurrentRevision,
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
PR.ModifiedByUserId,
|
||||
PR.ModifiedDate,
|
||||
MBU.AccountName as ModifiedByUserName
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
AND PR.Revision = P.Revision
|
||||
LEFT OUTER JOIN users_db.Profile as MBU
|
||||
ON MBU.UserId = P.ModifiedByUserId
|
||||
WHERE
|
||||
P.Id = @PageId
|
||||
@@ -0,0 +1,20 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Namespace],
|
||||
P.[Description],
|
||||
P.Navigation,
|
||||
PR.Revision,
|
||||
PR.DataHash,
|
||||
P.Revision as MostCurrentRevision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
WHERE
|
||||
P.Id = @PageId
|
||||
AND PR.Revision = COALESCE(@Revision, P.Revision)
|
||||
11
ZelWiki.Repository/Scripts/GetMenuItemById.sql
Normal file
11
ZelWiki.Repository/Scripts/GetMenuItemById.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
SELECT
|
||||
[Id] as [Id],
|
||||
[Name] as [Name],
|
||||
[Link] as [Link],
|
||||
[Ordinal] as [Ordinal]
|
||||
FROM
|
||||
[MenuItem]
|
||||
WHERE
|
||||
Id = @Id
|
||||
ORDER BY
|
||||
[Ordinal]
|
||||
35
ZelWiki.Repository/Scripts/GetMissingPagesPaged.sql
Normal file
35
ZelWiki.Repository/Scripts/GetMissingPagesPaged.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
SELECT
|
||||
P.Id as SourcePageId,
|
||||
P.[Name] as SourcePageName,
|
||||
P.[Navigation] as SourcePageNavigation,
|
||||
PR.ReferencesPageName as TargetPageName,
|
||||
PR.ReferencesPageNavigation as TargetPageNavigation,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
PageReference as PR
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PR.PageId
|
||||
WHERE
|
||||
PR.ReferencesPageId IS NULL
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
PageReference as PR
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PR.PageId
|
||||
WHERE
|
||||
PR.ReferencesPageId IS NULL
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
SourcePage=P.[Name]
|
||||
TargetPage=PR.ReferencesPageName
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.[Name]
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
50
ZelWiki.Repository/Scripts/GetOrphanedPageAttachments.sql
Normal file
50
ZelWiki.Repository/Scripts/GetOrphanedPageAttachments.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
SELECT
|
||||
PFR.PageFileId,
|
||||
P.Name as PageName,
|
||||
P.Namespace,
|
||||
P.Navigation as PageNavigation,
|
||||
PF.Name as FileName,
|
||||
PF.Navigation as FileNavigation,
|
||||
PFR.Size,
|
||||
PFR.Revision as FileRevision,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
(Round(Count(0) / (@PageSize + 0.0) + 0.999))
|
||||
FROM
|
||||
PageFileRevision as PFR
|
||||
INNER JOIN PageFile as PF
|
||||
ON PF.Id = PFR.PageFileId
|
||||
INNER JOIN Page as P
|
||||
ON P.Id = PF.PageId
|
||||
LEFT OUTER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageFileId = PFR.PageFileId
|
||||
AND PRA.FileRevision = PFR.Revision
|
||||
WHERE
|
||||
PRA.PageFileId IS NULL
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
PageFileRevision as PFR
|
||||
INNER JOIN PageFile as PF
|
||||
ON PF.Id = PFR.PageFileId
|
||||
INNER JOIN Page as P
|
||||
ON P.Id = PF.PageId
|
||||
LEFT OUTER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageFileId = PFR.PageFileId
|
||||
AND PRA.FileRevision = PFR.Revision
|
||||
WHERE
|
||||
PRA.PageFileId IS NULL
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Page=P.Name
|
||||
File=PF.Name
|
||||
Size=PFR.Size
|
||||
Revision=PFR.Revision
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
P.Name
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
32
ZelWiki.Repository/Scripts/GetPageCommentsPaged.sql
Normal file
32
ZelWiki.Repository/Scripts/GetPageCommentsPaged.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
SELECT
|
||||
PC.Id,
|
||||
PC.PageId,
|
||||
PC.CreatedDate,
|
||||
PC.UserId,
|
||||
PC.Body,
|
||||
U.AccountName as UserName,
|
||||
U.AccountName as UserNavigation,
|
||||
P.[Name] as PageName,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
(Round(Count(0) / (@PageSize + 0.0) + 0.999))
|
||||
FROM
|
||||
[Page] as iP
|
||||
INNER JOIN PageComment as iPC
|
||||
ON iPC.PageId = iP.Id
|
||||
WHERE
|
||||
iP.Navigation = @Navigation
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN PageComment as PC
|
||||
ON PC.PageId = P.Id
|
||||
LEFT OUTER JOIN users_db.Profile as U
|
||||
ON U.UserId = PC.UserId
|
||||
WHERE
|
||||
P.Navigation = @Navigation
|
||||
ORDER BY
|
||||
PC.CreatedDate DESC
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
@@ -0,0 +1,20 @@
|
||||
SELECT
|
||||
PF.PageId,
|
||||
PFA.PageFileId,
|
||||
PFR.Revision,
|
||||
PFR.ContentType,
|
||||
PFR.Size,
|
||||
PFR.DataHash
|
||||
FROM
|
||||
PageFile as PF
|
||||
INNER JOIN Page as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN PageRevisionAttachment as PFA
|
||||
ON PFA.PageFileId = PF.Id
|
||||
AND PFA.PageRevision = P.Revision
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = PFA.FileRevision
|
||||
WHERE
|
||||
PF.PageId = @PageId
|
||||
AND PF.Navigation = @Navigation
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
SELECT
|
||||
PFR.Revision,
|
||||
PF.[Id] as [Id],
|
||||
PF.[PageId] as [PageId],
|
||||
PF.[Name] as [Name],
|
||||
PFR.[ContentType] as [ContentType],
|
||||
PFR.[Size] as [Size],
|
||||
PF.[CreatedDate] as [CreatedDate],
|
||||
PFR.[Data] as [Data]
|
||||
FROM
|
||||
PageFile as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
AND PFR.Revision = Coalesce(@FileRevision, PF.Revision)
|
||||
@@ -0,0 +1,46 @@
|
||||
SELECT
|
||||
PF.[Id] as [Id],
|
||||
PF.[PageId] as [PageId],
|
||||
PF.[Name] as [Name],
|
||||
PFR.[ContentType] as [ContentType],
|
||||
PFR.[Size] as [Size],
|
||||
PF.[CreatedDate] as [CreatedDate],
|
||||
PFR.[Data]
|
||||
FROM
|
||||
[PageFile] as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
PF.Id as PageFileId,
|
||||
PR.Revision as PageRevision,
|
||||
MAX(PRA.FileRevision) as LatestAttachedFileRevision
|
||||
FROM
|
||||
Page as P
|
||||
INNER JOIN PageFile as PF
|
||||
ON PF.PageId = P.Id
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
AND PRA.PageRevision = PR.Revision
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
AND PR.Revision = Coalesce(@PageRevision, P.Revision)
|
||||
GROUP BY
|
||||
PF.Id
|
||||
) as Latest
|
||||
ON Latest.PageFileId = PF.Id
|
||||
AND Latest.LatestAttachedFileRevision = PRA.FileRevision
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = Latest.LatestAttachedFileRevision
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
AND PRA.PageRevision = Latest.PageRevision
|
||||
@@ -0,0 +1,45 @@
|
||||
SELECT
|
||||
PF.[Id] as [Id],
|
||||
PF.[PageId] as [PageId],
|
||||
PF.[Name] as [Name],
|
||||
PFR.[ContentType] as [ContentType],
|
||||
PFR.[Size] as [Size],
|
||||
PF.[CreatedDate] as [CreatedDate]
|
||||
FROM
|
||||
[PageFile] as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
PF.Id as PageFileId,
|
||||
PR.Revision as PageRevision,
|
||||
MAX(PRA.FileRevision) as LatestAttachedFileRevision
|
||||
FROM
|
||||
Page as P
|
||||
INNER JOIN PageFile as PF
|
||||
ON PF.PageId = P.Id
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
AND PRA.PageRevision = PR.Revision
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
AND PR.Revision = Coalesce(@PageRevision, P.Revision)
|
||||
GROUP BY
|
||||
PF.Id
|
||||
) as Latest
|
||||
ON Latest.PageFileId = PF.Id
|
||||
AND Latest.LatestAttachedFileRevision = PRA.FileRevision
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = Latest.LatestAttachedFileRevision
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
AND PRA.PageRevision = Latest.PageRevision
|
||||
@@ -0,0 +1,41 @@
|
||||
SELECT
|
||||
PFR.Revision,
|
||||
PF.[Id] as [Id],
|
||||
PF.[PageId] as [PageId],
|
||||
PF.[Name] as [Name],
|
||||
PFR.[ContentType] as [ContentType],
|
||||
PFR.[Size] as [Size],
|
||||
PFR.[CreatedDate] as [CreatedDate],
|
||||
PFR.Revision as FileRevision,
|
||||
UP.UserID as CreatedByUserId,
|
||||
UP.AccountName as CreatedByUserName,
|
||||
UP.Navigation as CreatedByNavigation,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
PageFile as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
LEFT OUTER JOIN users_db.Profile UP
|
||||
ON UP.UserId = PFR.CreatedByUserId
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
PageFile as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
LEFT OUTER JOIN users_db.Profile UP
|
||||
ON UP.UserId = PFR.CreatedByUserId
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PF.Navigation = @FileNavigation
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize;
|
||||
@@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
PF.Id as PageFileId,
|
||||
PF.PageId,
|
||||
PF.Revision
|
||||
FROM
|
||||
PageFile as PF
|
||||
WHERE
|
||||
PF.PageId = @PageId
|
||||
AND PF.Navigation = @Navigation
|
||||
@@ -0,0 +1,24 @@
|
||||
SELECT
|
||||
PF.[Id] as [Id],
|
||||
PF.[PageId] as [PageId],
|
||||
PF.[Name] as [Name],
|
||||
PFR.[ContentType] as [ContentType],
|
||||
PFR.[Size] as [Size],
|
||||
PF.[CreatedDate] as [CreatedDate]
|
||||
FROM
|
||||
[PageFile] as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
AND PRA.PageRevision = PR.Revision
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = PRA.FileRevision
|
||||
WHERE
|
||||
P.Id = @PageId
|
||||
AND PF.[Name] = @FileName
|
||||
AND PR.Revision = Coalesce(@PageRevision, P.Revision)
|
||||
28
ZelWiki.Repository/Scripts/GetPageFilesInfoByPageId.sql
Normal file
28
ZelWiki.Repository/Scripts/GetPageFilesInfoByPageId.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
SELECT
|
||||
PF.[Id] as [Id],
|
||||
PF.[PageId] as [PageId],
|
||||
PF.[Name] as [Name],
|
||||
PFR.[ContentType] as [ContentType],
|
||||
PFR.[Size] as [Size],
|
||||
PF.[CreatedDate] as [CreatedDate],
|
||||
PR.Revision as PageRevision,
|
||||
PFR.Revision as FileRevision,
|
||||
PF.Navigation as FileNavigation,
|
||||
P.Navigation as PageNavigation
|
||||
FROM
|
||||
[PageFile] as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
AND PRA.PageRevision = PR.Revision
|
||||
AND PRA.FileRevision = PF.Revision --Latest file revision.
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = PRA.FileRevision
|
||||
WHERE
|
||||
P.Id = @PageId
|
||||
AND PR.Revision = P.Revision
|
||||
@@ -0,0 +1,55 @@
|
||||
SELECT
|
||||
PF.[Id] as [Id],
|
||||
PF.[PageId] as [PageId],
|
||||
PF.[Name] as [Name],
|
||||
PFR.[ContentType] as [ContentType],
|
||||
PFR.[Size] as [Size],
|
||||
PF.[CreatedDate] as [CreatedDate],
|
||||
PR.Revision as PageRevision,
|
||||
PFR.Revision as FileRevision,
|
||||
PF.Navigation as FileNavigation,
|
||||
P.Navigation as PageNavigation,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[PageFile] as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
AND PRA.PageRevision = PR.Revision
|
||||
AND PRA.FileRevision = PF.Revision --Latest file revision.
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = PRA.FileRevision
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PR.Revision = Coalesce(@PageRevision, P.Revision)
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[PageFile] as PF
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PF.PageId
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
INNER JOIN PageRevisionAttachment as PRA
|
||||
ON PRA.PageId = P.Id
|
||||
AND PRA.PageFileId = PF.Id
|
||||
AND PRA.PageRevision = PR.Revision
|
||||
AND PRA.FileRevision = PF.Revision --Latest file revision.
|
||||
INNER JOIN PageFileRevision as PFR
|
||||
ON PFR.PageFileId = PF.Id
|
||||
AND PFR.Revision = PRA.FileRevision
|
||||
WHERE
|
||||
P.Navigation = @PageNavigation
|
||||
AND PR.Revision = Coalesce(@PageRevision, P.Revision)
|
||||
ORDER BY
|
||||
PF.[Name],
|
||||
PF.Id
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
12
ZelWiki.Repository/Scripts/GetPageIdsByTokens.sql
Normal file
12
ZelWiki.Repository/Scripts/GetPageIdsByTokens.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
SELECT
|
||||
T.PageId
|
||||
FROM
|
||||
PageToken as T
|
||||
INNER JOIN TempTokens as TT
|
||||
ON TT.[value] = T.Token
|
||||
WHERE
|
||||
Coalesce(TT.[value], '') <> ''
|
||||
GROUP BY
|
||||
T.PageId
|
||||
HAVING
|
||||
Count(0) = @TokenCount
|
||||
13
ZelWiki.Repository/Scripts/GetPageInfoByNamespaces.sql
Normal file
13
ZelWiki.Repository/Scripts/GetPageInfoByNamespaces.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
SELECT DISTINCT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Description],
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN TempNamespaces as TN
|
||||
ON TN.[value] = P.[Namespace]
|
||||
14
ZelWiki.Repository/Scripts/GetPageInfoByNavigation.sql
Normal file
14
ZelWiki.Repository/Scripts/GetPageInfoByNavigation.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Description],
|
||||
P.Navigation,
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate
|
||||
FROM
|
||||
[Page] as P
|
||||
WHERE
|
||||
P.Navigation = @Navigation
|
||||
15
ZelWiki.Repository/Scripts/GetPageInfoByTags.sql
Normal file
15
ZelWiki.Repository/Scripts/GetPageInfoByTags.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
SELECT DISTINCT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Description],
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate
|
||||
FROM
|
||||
PageTag as PT
|
||||
INNER JOIN TempTags AS T
|
||||
ON T.Value = PT.Tag
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PT.PageId
|
||||
6
ZelWiki.Repository/Scripts/GetPageNavigationByPageId.sql
Normal file
6
ZelWiki.Repository/Scripts/GetPageNavigationByPageId.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
SELECT
|
||||
Navigation
|
||||
FROM
|
||||
Page
|
||||
WHERE
|
||||
Id = @PageId
|
||||
10
ZelWiki.Repository/Scripts/GetPageNextRevision.sql
Normal file
10
ZelWiki.Repository/Scripts/GetPageNextRevision.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
PR.Revision
|
||||
FROM
|
||||
[PageRevision] as PR
|
||||
WHERE
|
||||
PR.PageId = @PageId
|
||||
AND PR.Revision > @Revision
|
||||
ORDER BY
|
||||
PR.Revision ASC
|
||||
LIMIT 1;
|
||||
10
ZelWiki.Repository/Scripts/GetPagePreviousRevision.sql
Normal file
10
ZelWiki.Repository/Scripts/GetPagePreviousRevision.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
SELECT
|
||||
PR.Revision
|
||||
FROM
|
||||
[PageRevision] as PR
|
||||
WHERE
|
||||
PR.PageId = @PageId
|
||||
AND PR.Revision < @Revision
|
||||
ORDER BY
|
||||
PR.Revision DESC
|
||||
LIMIT 1;
|
||||
@@ -0,0 +1,7 @@
|
||||
SELECT
|
||||
PageId,
|
||||
Instruction
|
||||
FROM
|
||||
PageProcessingInstruction
|
||||
WHERE
|
||||
PageId = @PageId
|
||||
18
ZelWiki.Repository/Scripts/GetPageRevisionById.sql
Normal file
18
ZelWiki.Repository/Scripts/GetPageRevisionById.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Description],
|
||||
PR.Body,
|
||||
PR.Revision,
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
WHERE
|
||||
P.Id = @PageId
|
||||
AND PR.Revision = Coalesce(@Revision, P.Revision)
|
||||
24
ZelWiki.Repository/Scripts/GetPageRevisionByNavigation.sql
Normal file
24
ZelWiki.Repository/Scripts/GetPageRevisionByNavigation.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
PR.[Description],
|
||||
PR.Body,
|
||||
PR.Revision,
|
||||
P.Revision as MostCurrentRevision,
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
PR.ModifiedByUserId,
|
||||
PR.ModifiedDate,
|
||||
MBU.AccountName as ModifiedByUserName,
|
||||
(SELECT COUNT(0) FROM PageRevision AS iPR
|
||||
WHERE iPR.PageId = P.Id AND iPR.Revision > PR.Revision) as HigherRevisionCount
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
LEFT OUTER JOIN users_db.Profile as MBU
|
||||
ON MBU.UserId = P.ModifiedByUserId
|
||||
WHERE
|
||||
P.Navigation = @Navigation
|
||||
AND PR.Revision = COALESCE(@Revision, P.Revision)
|
||||
@@ -0,0 +1,6 @@
|
||||
SELECT
|
||||
Count(0)
|
||||
FROM
|
||||
[PageRevision] as PR
|
||||
WHERE
|
||||
PR.PageId = @PageId
|
||||
23
ZelWiki.Repository/Scripts/GetPageRevisionInfoById.sql
Normal file
23
ZelWiki.Repository/Scripts/GetPageRevisionInfoById.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Description],
|
||||
PR.Revision,
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
--Createduser.AccountName as CreatedByUserName,
|
||||
P.CreatedDate,
|
||||
PR.ModifiedByUserId,
|
||||
--ModifiedUser.AccountName as ModifiedByUserName,
|
||||
PR.ModifiedDate
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
--INNER JOIN [User] as ModifiedUser
|
||||
-- ON ModifiedUser.Id = PR.ModifiedByUserId
|
||||
--INNER JOIN [User] as Createduser
|
||||
-- ON Createduser.Id = P.CreatedByUserId
|
||||
WHERE
|
||||
P.Id = @PageId
|
||||
AND PR.Revision = COALESCE(@Revision, P.Revision)
|
||||
@@ -0,0 +1,49 @@
|
||||
SELECT
|
||||
P.Id as PageId,
|
||||
PR.[Name],
|
||||
PR.[Description],
|
||||
PR.Revision,
|
||||
P.Revision as HighestRevision,
|
||||
P.Navigation,
|
||||
P.CreatedByUserId,
|
||||
Createduser.AccountName as CreatedByUserName,
|
||||
P.CreatedDate,
|
||||
PR.ModifiedByUserId,
|
||||
ModifiedUser.AccountName as ModifiedByUserName,
|
||||
PR.ModifiedDate,
|
||||
(SELECT COUNT(0) FROM PageRevision AS iPR WHERE iPR.PageId = P.Id AND iPR.Revision > PR.Revision) as HigherRevisionCount,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
WHERE
|
||||
P.Navigation = @Navigation
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
[Page] as P
|
||||
INNER JOIN [PageRevision] as PR
|
||||
ON PR.PageId = P.Id
|
||||
LEFT OUTER JOIN users_db.Profile as ModifiedUser
|
||||
ON ModifiedUser.UserId = PR.ModifiedByUserId
|
||||
LEFT OUTER JOIN users_db.Profile as Createduser
|
||||
ON Createduser.UserId = P.CreatedByUserId
|
||||
WHERE
|
||||
P.Navigation = @Navigation
|
||||
--CUSTOM_ORDER_BEGIN::
|
||||
--CONFIG::
|
||||
/*
|
||||
Revision=PR.Revision
|
||||
ModifiedBy=ModifiedUser.AccountName
|
||||
ModifiedDate=PR.ModifiedDate
|
||||
Page=PR.[Name]
|
||||
*/
|
||||
--::CONFIG
|
||||
ORDER BY
|
||||
PR.Revision DESC
|
||||
--::CUSTOM_ORDER_BEGIN
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
6
ZelWiki.Repository/Scripts/GetPageTagsById.sql
Normal file
6
ZelWiki.Repository/Scripts/GetPageTagsById.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
SELECT
|
||||
PT.Tag
|
||||
FROM
|
||||
[PageTag] as PT
|
||||
WHERE
|
||||
PT.PageId = @PageId
|
||||
@@ -0,0 +1,7 @@
|
||||
SELECT
|
||||
[Avatar] as Bytes,
|
||||
AvatarContentType as ContentType
|
||||
FROM
|
||||
Profile
|
||||
WHERE
|
||||
Navigation = @Navigation
|
||||
@@ -0,0 +1,24 @@
|
||||
SELECT
|
||||
U.UserId,
|
||||
U.EmailAddress,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
U.PasswordHash,
|
||||
U.FirstName,
|
||||
U.LastName,
|
||||
U.TimeZone,
|
||||
U.Country,
|
||||
U.[Language],
|
||||
U.Biography,
|
||||
U.CreatedDate,
|
||||
U.ModifiedDate,
|
||||
U.VerificationCode,
|
||||
R.[Name] as [Role],
|
||||
U.EmailConfirmed
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN Role as R
|
||||
ON R.Id = U.RoleId
|
||||
WHERE
|
||||
(U.EmailAddress = @AccountNameOrEmail OR U.AccountName = @AccountNameOrEmail)
|
||||
AND U.PasswordHash = @PasswordHash
|
||||
44
ZelWiki.Repository/Scripts/GetProfilesByRoleIdPaged.sql
Normal file
44
ZelWiki.Repository/Scripts/GetProfilesByRoleIdPaged.sql
Normal file
@@ -0,0 +1,44 @@
|
||||
SELECT
|
||||
U.UserId,
|
||||
ANU.Email as EmailAddress,
|
||||
U.AccountName,
|
||||
U.Navigation,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'firstname') as FirstName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'lastname') as LastName,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'timezone') as TimeZone,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType = 'language') as Language,
|
||||
(select UC.ClaimValue from AspNetUserClaims as UC WHERE UC.UserId = U.UserId AND UC.ClaimType LIKE '%/country') as Country,
|
||||
U.CreatedDate,
|
||||
U.ModifiedDate,
|
||||
UCR.ClaimValue as Role,
|
||||
ANU.EmailConfirmed,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
Profile as P
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
WHERE
|
||||
R.Id = @RoleId
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
Profile as U
|
||||
INNER JOIN AspNetUsers as ANU
|
||||
ON ANU.Id = U.UserId
|
||||
INNER JOIN AspNetUserClaims as UCR
|
||||
ON UCR.UserId = U.UserId
|
||||
AND UCR.ClaimType LIKE '%/role'
|
||||
INNER JOIN Role as R
|
||||
ON R.Name = UCR.ClaimValue
|
||||
WHERE
|
||||
R.Id = @RoleId
|
||||
ORDER BY
|
||||
U.AccountName,
|
||||
U.UserId
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
29
ZelWiki.Repository/Scripts/GetRelatedPagesPaged.sql
Normal file
29
ZelWiki.Repository/Scripts/GetRelatedPagesPaged.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.[Revision],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
Round(Count(0) / (@PageSize + 0.0) + 0.999)
|
||||
FROM
|
||||
PageReference as PR
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PR.PageId
|
||||
WHERE
|
||||
PR.ReferencesPageId = @PageId
|
||||
AND PR.PageId <> PR.ReferencesPageId
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
PageReference as PR
|
||||
INNER JOIN [Page] as P
|
||||
ON P.Id = PR.PageId
|
||||
WHERE
|
||||
PR.ReferencesPageId = @PageId
|
||||
AND PR.PageId <> PR.ReferencesPageId
|
||||
ORDER BY
|
||||
P.[Name]
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
8
ZelWiki.Repository/Scripts/GetRoleByName.sql
Normal file
8
ZelWiki.Repository/Scripts/GetRoleByName.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
SELECT
|
||||
Id,
|
||||
[Name],
|
||||
[Description]
|
||||
FROM
|
||||
[Role]
|
||||
WHERE
|
||||
[Name] = @Name
|
||||
53
ZelWiki.Repository/Scripts/GetSimilarPagesPaged.sql
Normal file
53
ZelWiki.Repository/Scripts/GetSimilarPagesPaged.sql
Normal file
@@ -0,0 +1,53 @@
|
||||
SELECT
|
||||
P.Id,
|
||||
P.[Name],
|
||||
P.Navigation,
|
||||
P.[Description],
|
||||
P.Revision,
|
||||
P.CreatedByUserId,
|
||||
P.CreatedDate,
|
||||
P.ModifiedByUserId,
|
||||
P.ModifiedDate,
|
||||
@PageSize as PaginationPageSize,
|
||||
(
|
||||
SELECT
|
||||
CAST((Count(0) + (@PageSize - 1.0)) / @PageSize AS INTEGER)
|
||||
FROM
|
||||
Page as P
|
||||
WHERE
|
||||
P.Id IN
|
||||
(
|
||||
SELECT
|
||||
PT.PageId
|
||||
FROM
|
||||
PageTag as RootTags
|
||||
LEFT OUTER JOIN PageTag as PT
|
||||
ON PT.Tag = RootTags.Tag
|
||||
WHERE
|
||||
RootTags.PageId = @PageId
|
||||
GROUP BY
|
||||
PT.PageId
|
||||
HAVING
|
||||
((Count(0) / (SELECT COUNT(0) FROM PageTag as iP WHERE iP.PageId = @PageId)) * 100.0) >= @Similarity
|
||||
)
|
||||
) as PaginationPageCount
|
||||
FROM
|
||||
Page as P
|
||||
WHERE
|
||||
P.Id IN
|
||||
(
|
||||
SELECT
|
||||
PT.PageId
|
||||
FROM
|
||||
PageTag as RootTags
|
||||
LEFT OUTER JOIN PageTag as PT
|
||||
ON PT.Tag = RootTags.Tag
|
||||
WHERE
|
||||
RootTags.PageId = @PageId
|
||||
GROUP BY
|
||||
PT.PageId
|
||||
HAVING
|
||||
((Count(0) / (SELECT COUNT(0) FROM PageTag as iP WHERE iP.PageId = @PageId)) * 100.0) >= @Similarity
|
||||
)
|
||||
LIMIT @PageSize
|
||||
OFFSET (@PageNumber - 1) * @PageSize
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user