public static bool AfterContentAdded(SiteInfo siteInfo, ChannelInfo channelInfo, int contentId, bool isCrossSiteTrans, bool isAutomatic) { var isTranslated = false; if (isCrossSiteTrans && isAutomatic) { var targetSiteId = 0; if (channelInfo.Additional.TransType == ECrossSiteTransType.SpecifiedSite) { targetSiteId = channelInfo.Additional.TransSiteId; } else if (channelInfo.Additional.TransType == ECrossSiteTransType.SelfSite) { targetSiteId = siteInfo.Id; } else if (channelInfo.Additional.TransType == ECrossSiteTransType.ParentSite) { targetSiteId = SiteManager.GetParentSiteId(siteInfo.Id); } if (targetSiteId > 0) { var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); if (targetSiteInfo != null) { var targetChannelIdArrayList = TranslateUtils.StringCollectionToIntList(channelInfo.Additional.TransChannelIds); if (targetChannelIdArrayList.Count > 0) { foreach (var targetChannelId in targetChannelIdArrayList) { CrossSiteTransUtility.TransContentInfo(siteInfo, channelInfo, contentId, targetSiteInfo, targetChannelId); isTranslated = true; } } } } } foreach (var service in PluginManager.Services) { try { service.OnContentAddCompleted(new ContentEventArgs(siteInfo.Id, channelInfo.Id, contentId)); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(service.OnContentAddCompleted)); } } return(isTranslated); }
public static void Translate(string administratorName, SiteInfo siteInfo, int channelId, int contentId, int targetSiteId, int targetChannelId, ETranslateContentType translateType) { if (siteInfo == null || channelId <= 0 || contentId <= 0 || targetSiteId <= 0 || targetChannelId <= 0) { return; } var targetSiteInfo = SiteManager.GetSiteInfo(targetSiteId); var targetTableName = ChannelManager.GetTableName(targetSiteInfo, targetChannelId); var channelInfo = ChannelManager.GetChannelInfo(siteInfo.Id, channelId); var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var contentInfo = DataProvider.ContentDao.GetContentInfo(tableName, contentId); if (contentInfo == null) { return; } if (translateType == ETranslateContentType.Copy) { FileUtility.MoveFileByContentInfo(siteInfo, targetSiteInfo, contentInfo); contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Copy.ToString()); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Copy.ToString()); var theContentId = DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); foreach (var service in PluginManager.Services) { try { service.OnContentTranslateCompleted(new ContentTranslateEventArgs(siteInfo.Id, channelInfo.Id, contentId, targetSiteId, targetChannelId, theContentId)); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(service.OnContentTranslateCompleted)); } } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(targetSiteInfo.Id, contentInfo.ChannelId, theContentId); } } else if (translateType == ETranslateContentType.Cut) { FileUtility.MoveFileByContentInfo(siteInfo, targetSiteInfo, contentInfo); contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Cut.ToString()); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Cut.ToString()); var newContentId = DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); DataProvider.ContentDao.DeleteContents(siteInfo.Id, tableName, TranslateUtils.ToIntList(contentId), channelId); DataProvider.ChannelDao.UpdateContentNum(siteInfo, channelId, true); DataProvider.ChannelDao.UpdateContentNum(targetSiteInfo, targetChannelId, true); foreach (var service in PluginManager.Services) { try { service.OnContentTranslateCompleted(new ContentTranslateEventArgs(siteInfo.Id, channelInfo.Id, contentId, targetSiteId, targetChannelId, newContentId)); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(service.OnContentTranslateCompleted)); } try { service.OnContentDeleteCompleted(new ContentEventArgs(siteInfo.Id, channelInfo.Id, contentId)); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(service.OnContentDeleteCompleted)); } } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(targetSiteInfo.Id, contentInfo.ChannelId, newContentId); } } else if (translateType == ETranslateContentType.Reference) { if (contentInfo.ReferenceId != 0) { return; } contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.ReferenceId = contentId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.Reference.ToString()); //contentInfo.Attributes.Add(ContentAttribute.TranslateContentType, ETranslateContentType.Reference.ToString()); DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); } else if (translateType == ETranslateContentType.ReferenceContent) { if (contentInfo.ReferenceId != 0) { return; } FileUtility.MoveFileByContentInfo(siteInfo, targetSiteInfo, contentInfo); contentInfo.SiteId = targetSiteId; contentInfo.SourceId = contentInfo.ChannelId; contentInfo.ChannelId = targetChannelId; contentInfo.ReferenceId = contentId; contentInfo.Set(ContentAttribute.TranslateContentType, ETranslateContentType.ReferenceContent.ToString()); var theContentId = DataProvider.ContentDao.Insert(targetTableName, targetSiteInfo, contentInfo); foreach (var service in PluginManager.Services) { try { service.OnContentTranslateCompleted(new ContentTranslateEventArgs(siteInfo.Id, channelInfo.Id, contentId, targetSiteId, targetChannelId, theContentId)); } catch (Exception ex) { LogUtils.AddPluginErrorLog(service.PluginId, ex, nameof(service.OnContentTranslateCompleted)); } } if (contentInfo.IsChecked) { CreateManager.CreateContentAndTrigger(targetSiteInfo.Id, contentInfo.ChannelId, theContentId); } } }