public static async Task UpdateSitesSplitTableNameAsync(TreeInfo newTreeInfo, Dictionary <int, TableInfo> splitSiteTableDict) { var siteMetadataFilePath = newTreeInfo.GetTableMetadataFilePath(DataProvider.SiteDao.TableName); if (FileUtils.IsFileExists(siteMetadataFilePath)) { var siteTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(FileUtils.ReadText(siteMetadataFilePath, Encoding.UTF8)); foreach (var fileName in siteTableInfo.RowFiles) { var filePath = newTreeInfo.GetTableContentFilePath(DataProvider.SiteDao.TableName, fileName); var oldRows = TranslateUtils.JsonDeserialize <List <JObject> >(FileUtils.ReadText(filePath, Encoding.UTF8)); var newRows = new List <Dictionary <string, object> >(); foreach (var row in oldRows) { var dict = TranslateUtils.JsonGetDictionaryIgnorecase(row); if (dict.ContainsKey(nameof(SiteInfo.Id))) { var siteId = Convert.ToInt32(dict[nameof(SiteInfo.Id)]); dict[nameof(SiteInfo.TableName)] = ContentDao.GetContentTableName(siteId); } newRows.Add(dict); } await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newRows)); } } //foreach (var siteId in splitSiteTableDict.Keys) //{ // var siteTableInfo = splitSiteTableDict[siteId]; // var siteTableName = UpdateUtils.GetSplitContentTableName(siteId); // siteTableInfo.Columns //} //var tableFilePath = newTreeInfo.GetTableMetadataFilePath(DataProvider.TableDao.TableName); //if (FileUtils.IsFileExists(tableFilePath)) //{ // var siteTableInfo = TranslateUtils.JsonDeserialize<TableInfo>(FileUtils.ReadText(tableFilePath, Encoding.UTF8)); // var filePath = newTreeInfo.GetTableContentFilePath(DataProvider.SiteDao.TableName, siteTableInfo.RowFiles[siteTableInfo.RowFiles.Count]); // var tableInfoList = TranslateUtils.JsonDeserialize<List<CMS.Model.TableInfo>>(FileUtils.ReadText(filePath, Encoding.UTF8)); // await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(tableInfoList)); //} }
public IHttpActionResult Submit() { try { var request = new AuthenticatedRequest(); if (!request.IsAdminLoggin || !request.AdminPermissionsImpl.HasSystemPermissions(ConfigManager.SettingsPermissions.SiteAdd)) { return(Unauthorized()); } var createType = request.GetPostString("createType"); var createTemplateId = request.GetPostString("createTemplateId"); var siteName = request.GetPostString("siteName"); var isRoot = request.GetPostBool("isRoot"); var parentId = request.GetPostInt("parentId"); var siteDir = request.GetPostString("siteDir"); var domainName = request.GetPostString("domainName"); var tableRule = ETableRuleUtils.GetEnumType(request.GetPostString("tableRule")); var tableChoose = request.GetPostString("tableChoose"); var tableHandWrite = request.GetPostString("tableHandWrite"); var isImportContents = request.GetPostBool("isImportContents"); var isImportTableStyles = request.GetPostBool("isImportTableStyles"); if (!isRoot) { if (DirectoryUtils.IsSystemDirectory(siteDir)) { return(BadRequest("文件夹名称不能为系统文件夹名称,请更改文件夹名称!")); } if (!DirectoryUtils.IsDirectoryNameCompliant(siteDir)) { return(BadRequest("文件夹名称不符合系统要求,请更改文件夹名称!")); } var list = DataProvider.SiteDao.GetLowerSiteDirList(parentId); if (list.IndexOf(siteDir.ToLower()) != -1) { return(BadRequest("已存在相同的发布路径,请更改文件夹名称!")); } } var channelInfo = new ChannelInfo(); channelInfo.ChannelName = channelInfo.IndexName = "首页"; channelInfo.ParentId = 0; channelInfo.ContentModelPluginId = string.Empty; var tableName = string.Empty; if (tableRule == ETableRule.Choose) { tableName = tableChoose; } else if (tableRule == ETableRule.HandWrite) { tableName = tableHandWrite; if (!DataProvider.DatabaseDao.IsTableExists(tableName)) { DataProvider.ContentDao.CreateContentTable(tableName, DataProvider.ContentDao.TableColumnsDefault); } else { DataProvider.DatabaseDao.AlterSystemTable(tableName, DataProvider.ContentDao.TableColumnsDefault); } } var siteInfo = new SiteInfo { SiteName = AttackUtils.FilterXss(siteName), SiteDir = siteDir, DomainName = domainName, TableName = tableName, ParentId = parentId, IsRoot = isRoot }; siteInfo.Additional.IsCheckContentLevel = false; siteInfo.Additional.Charset = ECharsetUtils.GetValue(ECharset.utf_8); var siteId = DataProvider.ChannelDao.InsertSiteInfo(channelInfo, siteInfo, request.AdminName); if (string.IsNullOrEmpty(tableName)) { tableName = ContentDao.GetContentTableName(siteId); DataProvider.ContentDao.CreateContentTable(tableName, DataProvider.ContentDao.TableColumnsDefault); DataProvider.SiteDao.UpdateTableName(siteId, tableName); } if (request.AdminPermissionsImpl.IsSystemAdministrator && !request.AdminPermissionsImpl.IsConsoleAdministrator) { var siteIdList = request.AdminPermissionsImpl.GetSiteIdList() ?? new List <int>(); siteIdList.Add(siteId); var adminInfo = AdminManager.GetAdminInfoByUserId(request.AdminId); DataProvider.AdministratorDao.UpdateSiteIdCollection(adminInfo, TranslateUtils.ObjectCollectionToString(siteIdList)); } var siteTemplateDir = string.Empty; var onlineTemplateName = string.Empty; if (StringUtils.EqualsIgnoreCase(createType, "local")) { siteTemplateDir = createTemplateId; } else if (StringUtils.EqualsIgnoreCase(createType, "cloud")) { onlineTemplateName = createTemplateId; } var redirectUrl = PageProgressBar.GetCreateSiteUrl(siteId, isImportContents, isImportTableStyles, siteTemplateDir, onlineTemplateName, StringUtils.Guid()); SystemManager.UpdateSites(); return(Ok(new { Value = redirectUrl })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task UpdateSplitContentsTableInfoAsync(Dictionary <int, TableInfo> splitSiteTableDict, List <int> siteIdList, string oldTableName, TableInfo oldTableInfo, ConvertInfo converter) { if (converter == null) { converter = new ConvertInfo(); } if (converter.IsAbandon) { await CliUtils.PrintRowAsync(oldTableName, "Abandon", "--"); return; } if (converter.NewColumns == null || converter.NewColumns.Count == 0) { converter.NewColumns = oldTableInfo.Columns; } await CliUtils.PrintRowAsync(oldTableName, "#split-content#", oldTableInfo.TotalCount.ToString("#,0")); if (oldTableInfo.RowFiles.Count > 0) { var i = 0; using (var progress = new ProgressBar()) { foreach (var fileName in oldTableInfo.RowFiles) { progress.Report((double)i++ / oldTableInfo.RowFiles.Count); var newRows = new List <Dictionary <string, object> >(); var oldFilePath = OldTreeInfo.GetTableContentFilePath(oldTableName, fileName); var oldRows = TranslateUtils.JsonDeserialize <List <JObject> >(await FileUtils.ReadTextAsync(oldFilePath, Encoding.UTF8)); newRows.AddRange(UpdateUtils.UpdateRows(oldRows, converter.ConvertKeyDict, converter.ConvertValueDict)); var siteIdWithRows = new Dictionary <int, List <Dictionary <string, object> > >(); foreach (var siteId in siteIdList) { siteIdWithRows.Add(siteId, new List <Dictionary <string, object> >()); } foreach (var newRow in newRows) { if (newRow.ContainsKey(nameof(CMS.Model.ContentInfo.SiteId))) { var siteId = Convert.ToInt32(newRow[nameof(CMS.Model.ContentInfo.SiteId)]); if (siteIdList.Contains(siteId)) { var rows = siteIdWithRows[siteId]; rows.Add(newRow); } } } foreach (var siteId in siteIdList) { var siteRows = siteIdWithRows[siteId]; var siteTableName = ContentDao.GetContentTableName(siteId); var siteTableInfo = splitSiteTableDict[siteId]; siteTableInfo.TotalCount += siteRows.Count; foreach (var tableColumn in converter.NewColumns) { if (!siteTableInfo.Columns.Any(t => StringUtils.EqualsIgnoreCase(t.AttributeName, tableColumn.AttributeName))) { siteTableInfo.Columns.Add(tableColumn); } } if (siteRows.Count > 0) { var siteTableFileName = $"{siteTableInfo.RowFiles.Count + 1}.json"; siteTableInfo.RowFiles.Add(siteTableFileName); var filePath = NewTreeInfo.GetTableContentFilePath(siteTableName, siteTableFileName); await FileUtils.WriteTextAsync(filePath, Encoding.UTF8, TranslateUtils.JsonSerialize(siteRows)); } } } } } }
private int Validate_SiteInfo(out string errorMessage) { try { var isRoot = TranslateUtils.ToBool(RblIsRoot.SelectedValue); // 是否主站 var parentSiteId = 0; var siteDir = string.Empty; var domainName = string.Empty; if (DirectoryUtils.IsSystemDirectory(TbSiteDir.Text) || DirectoryUtils.IsWebSiteDirectory(TbSiteDir.Text)) { errorMessage = "文件夹名称不能为系统文件夹名称!"; return(0); } parentSiteId = TranslateUtils.ToInt(DdlParentId.SelectedValue); siteDir = TbSiteDir.Text; var list = DataProvider.SiteDao.GetLowerSiteDirList(parentSiteId); if (list.IndexOf(siteDir.ToLower()) != -1) { errorMessage = "已存在相同的发布路径!"; return(0); } if (!DirectoryUtils.IsDirectoryNameCompliant(siteDir)) { errorMessage = "文件夹名称不符合系统要求!"; return(0); } if (isRoot == false)//如果不是主站 { if (String.IsNullOrWhiteSpace(TbDomainName.Text)) { errorMessage = "网站域名不能为空!"; return(0); } else { String[] domainNames = TbDomainName.Text.Split(';'); foreach (String domain in domainNames) { if (SystemManager.SiteList.ContainsKey(domain)) { errorMessage = "域名“" + domain + "”已被其他网站占用,请选择其他域名!"; return(0); } else if (domainName.Length > 0) { domainName += ";" + domain; } else { domainName += ";" + domain; } } } if (domainName.Split(';').Length > 3) { errorMessage = "一个网站最多只能绑定3个域名,而您绑定了" + domainName.Split(';').Length + "个,请删除多余的域名!"; return(0); } } var nodeInfo = new ChannelInfo(); nodeInfo.ChannelName = nodeInfo.IndexName = "首页"; nodeInfo.ParentId = 0; nodeInfo.ContentModelPluginId = string.Empty; var tableName = string.Empty; var tableRule = ETableRuleUtils.GetEnumType(RblTableRule.SelectedValue); if (tableRule == ETableRule.Choose) { tableName = DdlTableChoose.SelectedValue; } else if (tableRule == ETableRule.HandWrite) { tableName = TbTableHandWrite.Text; if (!DataProvider.DatabaseDao.IsTableExists(tableName)) { DataProvider.ContentDao.CreateContentTable(tableName, DataProvider.ContentDao.TableColumnsDefault); } else { DataProvider.DatabaseDao.AlterSystemTable(tableName, DataProvider.ContentDao.TableColumnsDefault); } } var siteInfo = new SiteInfo { SiteName = AttackUtils.FilterXss(TbSiteName.Text), DomainName = domainName, SiteDir = siteDir, TableName = tableName, ParentId = parentSiteId, IsRoot = isRoot }; siteInfo.Additional.IsCheckContentLevel = TranslateUtils.ToBool(RblIsCheckContentUseLevel.SelectedValue); if (siteInfo.Additional.IsCheckContentLevel) { siteInfo.Additional.CheckContentLevel = TranslateUtils.ToInt(DdlCheckContentLevel.SelectedValue); } siteInfo.Additional.Charset = DdlCharset.SelectedValue; var siteId = DataProvider.ChannelDao.InsertSiteInfo(nodeInfo, siteInfo, AuthRequest.AdminName); if (string.IsNullOrEmpty(tableName)) { tableName = ContentDao.GetContentTableName(siteId); DataProvider.ContentDao.CreateContentTable(tableName, DataProvider.ContentDao.TableColumnsDefault); DataProvider.SiteDao.UpdateTableName(siteId, tableName); } if (AuthRequest.AdminPermissionsImpl.IsSystemAdministrator && !AuthRequest.AdminPermissionsImpl.IsConsoleAdministrator) { var siteIdList = AuthRequest.AdminPermissionsImpl.GetSiteIdList() ?? new List <int>(); siteIdList.Add(siteId); var adminInfo = AdminManager.GetAdminInfoByUserId(AuthRequest.AdminId); DataProvider.AdministratorDao.UpdateSiteIdCollection(adminInfo, TranslateUtils.ObjectCollectionToString(siteIdList)); } AuthRequest.AddAdminLog("创建新站点", $"站点名称:{AttackUtils.FilterXss(TbSiteName.Text)}"); errorMessage = string.Empty; return(siteId); } catch (Exception e) { errorMessage = e.Message; return(0); } }
public static async Task Execute(IJobContext context) { if (!CliUtils.ParseArgs(Options, context.Args)) { return; } if (_isHelp) { PrintUsage(); return; } if (string.IsNullOrEmpty(_directory)) { await CliUtils.PrintErrorAsync("未指定需要转换至最新版本的备份数据文件夹:directory"); return; } var oldTreeInfo = new TreeInfo(_directory); var newTreeInfo = new TreeInfo(Folder); if (!DirectoryUtils.IsDirectoryExists(oldTreeInfo.DirectoryPath)) { await CliUtils.PrintErrorAsync($"备份数据的文件夹 {oldTreeInfo.DirectoryPath} 不存在"); return; } DirectoryUtils.CreateDirectoryIfNotExists(newTreeInfo.DirectoryPath); var updater = new UpdaterManager(oldTreeInfo, newTreeInfo); var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); await Console.Out.WriteLineAsync($"备份数据文件夹: {oldTreeInfo.DirectoryPath},升级数据文件夹: {newTreeInfo.DirectoryPath},升级版本: {version.Substring(0, version.Length - 2)}"); var oldTableNames = TranslateUtils.JsonDeserialize <List <string> >(await FileUtils.ReadTextAsync(oldTreeInfo.TablesFilePath, Encoding.UTF8)); var newTableNames = new List <string>(); await CliUtils.PrintRowLineAsync(); await CliUtils.PrintRowAsync("备份表名称", "升级表名称", "总条数"); await CliUtils.PrintRowLineAsync(); var siteIdList = new List <int>(); var tableNameListForContent = new List <string>(); var tableNameListForGovPublic = new List <string>(); var tableNameListForGovInteract = new List <string>(); var tableNameListForJob = new List <string>(); UpdateUtils.LoadSites(oldTreeInfo, siteIdList, tableNameListForContent, tableNameListForGovPublic, tableNameListForGovInteract, tableNameListForJob); var splitSiteTableDict = new Dictionary <int, TableInfo>(); if (_contentSplit) { var converter = ContentConverter.GetSplitConverter(); foreach (var siteId in siteIdList) { splitSiteTableDict.Add(siteId, new TableInfo { Columns = converter.NewColumns, TotalCount = 0, RowFiles = new List <string>() }); } } foreach (var oldTableName in oldTableNames) { var oldMetadataFilePath = oldTreeInfo.GetTableMetadataFilePath(oldTableName); if (!FileUtils.IsFileExists(oldMetadataFilePath)) { continue; } var oldTableInfo = TranslateUtils.JsonDeserialize <TableInfo>(await FileUtils.ReadTextAsync(oldMetadataFilePath, Encoding.UTF8)); if (StringUtils.ContainsIgnoreCase(tableNameListForContent, oldTableName)) { if (_contentSplit) { var converter = ContentConverter.GetConverter(oldTableName, oldTableInfo.Columns); await updater.UpdateSplitContentsTableInfoAsync(splitSiteTableDict, siteIdList, oldTableName, oldTableInfo, converter); } else { var converter = ContentConverter.GetConverter(oldTableName, oldTableInfo.Columns); var tuple = await updater.GetNewTableInfoAsync(oldTableName, oldTableInfo, converter); if (tuple != null) { newTableNames.Add(tuple.Item1); await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item1), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item2)); } } } else { var tuple = await updater.UpdateTableInfoAsync(oldTableName, oldTableInfo, tableNameListForGovPublic, tableNameListForGovInteract, tableNameListForJob); if (tuple != null) { newTableNames.Add(tuple.Item1); await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(tuple.Item1), Encoding.UTF8, TranslateUtils.JsonSerialize(tuple.Item2)); } } } if (_contentSplit) { foreach (var siteId in siteIdList) { var siteTableInfo = splitSiteTableDict[siteId]; var siteTableName = ContentDao.GetContentTableName(siteId); newTableNames.Add(siteTableName); await FileUtils.WriteTextAsync(newTreeInfo.GetTableMetadataFilePath(siteTableName), Encoding.UTF8, TranslateUtils.JsonSerialize(siteTableInfo)); } await UpdateUtils.UpdateSitesSplitTableNameAsync(newTreeInfo, splitSiteTableDict); } await FileUtils.WriteTextAsync(newTreeInfo.TablesFilePath, Encoding.UTF8, TranslateUtils.JsonSerialize(newTableNames)); await CliUtils.PrintRowLineAsync(); await Console.Out.WriteLineAsync($"恭喜,成功从备份文件夹:{oldTreeInfo.DirectoryPath} 升级至新版本:{newTreeInfo.DirectoryPath} !"); }