public AppExportInfoDto GetAppInfo(int appId, int zoneId) { Log.Add($"get app info for app:{appId} and zone:{zoneId}"); var contextZoneId = _zoneMapper.GetZoneId(_tenantId); var currentApp = ImpExpHelpers.GetAppAndCheckZoneSwitchPermissions(zoneId, appId, _user, contextZoneId, Log); var zipExport = Factory.Resolve <ZipExport>().Init(zoneId, appId, currentApp.Folder, currentApp.PhysicalPath, Log); var cultCount = _zoneMapper .CulturesWithState(currentApp.Tenant.Id, currentApp.ZoneId) .Count(c => c.Active); var cms = new CmsRuntime(currentApp, Log, true, false); return(new AppExportInfoDto { Name = currentApp.Name, Guid = currentApp.AppGuid, Version = currentApp.VersionSafe(), EntitiesCount = cms.Entities.All.Count(), LanguagesCount = cultCount, TemplatesCount = cms.Views.GetAll().Count(), HasRazorTemplates = cms.Views.GetRazor().Any(), HasTokenTemplates = cms.Views.GetToken().Any(), FilesCount = zipExport.FileManager.AllFiles.Count(), TransferableFilesCount = zipExport.FileManager.AllTransferableFiles.Count() }); }
public void SetAppId(IModule instance, int?appId) { Log.Add($"SetAppIdForInstance({instance.Id}, -, appid: {appId})"); // Reset temporary template ClearPreview(instance.Id); // ToDo: Should throw exception if a real BlockConfiguration exists var module = (instance as Module <ModuleInfo>).UnwrappedContents; var zoneId = _zoneMapper.GetZoneId(module.OwnerPortalID); if (appId == Eav.Constants.AppIdEmpty || !appId.HasValue) { UpdateInstanceSettingForAllLanguages(instance.Id, Settings.ModuleSettingApp, null, Log); } else { var appName = State.Zones[zoneId].Apps[appId.Value]; UpdateInstanceSettingForAllLanguages(instance.Id, Settings.ModuleSettingApp, appName, Log); } // Change to 1. available template if app has been set if (appId.HasValue) { var appIdentity = new AppIdentity(zoneId, appId.Value); var cms = _cmsRuntimeLazy.Value.Init(appIdentity, true, Log); var templateGuid = cms.Views.GetAll().FirstOrDefault(t => !t.IsHidden)?.Guid; if (templateGuid.HasValue) { SetPreview(instance.Id, templateGuid.Value); } } }
internal static void RemoveAppInTenantAndEav(IZoneMapper zoneMapper, int zoneId, int appId, ITenant tenant, int userId, Log parentLog) { // check portal assignment and that it's not the default app if (zoneId != zoneMapper.GetZoneId(tenant.Id)) { throw new Exception("This app does not belong to portal " + tenant.Id); } if (appId == new ZoneRuntime(zoneId, parentLog).DefaultAppId) { throw new Exception("The default app of a zone cannot be removed."); } // Prepare to Delete folder in dnn - this must be done, before deleting the app in the DB var sexyApp = App.LightWithoutData(tenant, zoneId, appId, null); var folder = sexyApp.Folder; var physPath = sexyApp.PhysicalPath; // now remove from DB. This sometimes fails, so we do this before trying to clean the files // as the db part should be in a transaction, and if it fails, everything should stay as is new ZoneManager(zoneId, parentLog).DeleteApp(appId); // now really delete the files - if the DB didn't end up throwing an error if (!IsNullOrEmpty(folder) && Directory.Exists(physPath)) { Directory.Delete(physPath, true); } }
/// <summary> /// find the AppIdentity of an app which is referenced by a path /// </summary> /// <param name="appPath"></param> /// <returns></returns> internal IAppIdentity GetAppIdFromPath(string appPath) { var wrapLog = Log.Call(appPath); var zid = _zoneMapper.GetZoneId(_tenantId); // get app from AppName var aid = new ZoneRuntime(zid, Log).FindAppId(appPath, true); wrapLog($"found app:{aid}"); return(new AppIdentity(zid, aid)); }
public ExportPartsOverviewDto PreExportSummary(int appId, int zoneId, string scope) { Log.Add($"get content info for z#{zoneId}, a#{appId}, scope:{scope} super?:{_user.IsSuperUser}"); var contextZoneId = _zoneMapper.GetZoneId(_siteId); var currentApp = CmsRuntime.ServiceProvider.Build <ImpExpHelpers>().Init(Log).GetAppAndCheckZoneSwitchPermissions(zoneId, appId, _user, contextZoneId); var cms = CmsRuntime.Init(currentApp, true, Log); var contentTypes = cms.ContentTypes.All.OfScope(scope); var entities = cms.Entities.All; var templates = cms.Views.GetAll(); return(new ExportPartsOverviewDto { ContentTypes = contentTypes.Select(c => new ExportPartsContentTypesDto { Id = c.ContentTypeId, Name = c.Name, StaticName = c.StaticName, Templates = templates.Where(t => t.ContentType == c.StaticName) .Select(t => new IdNameDto { Id = t.Id, Name = t.Name }), Entities = entities .Where(e => e.Type.ContentTypeId == c.ContentTypeId) .Select(e => new ExportPartsEntitiesDto { Title = e.GetBestTitle(), Id = e.EntityId }) }), TemplatesWithoutContentTypes = templates .Where(t => !string.IsNullOrEmpty(t.ContentType)) .Select(t => new IdNameDto { Id = t.Id, Name = t.Name }) }); }
public IList <SiteLanguageDto> GetLanguages(int tenantId) { var callLog = Log.Call(); var zoneId = _zoneMapper.GetZoneId(tenantId); // ReSharper disable once PossibleInvalidOperationException var cultures = _zoneMapper.CulturesWithState(tenantId, zoneId) .Select(c => new SiteLanguageDto { Code = c.Key, Culture = c.Text, IsEnabled = c.Active }) .ToList(); callLog("found:" + cultures.Count); return(cultures); }
public ImportResultDto Reset(int zoneId, int appId, string defaultLanguage) { Log.Add($"Reset App {zoneId}/{appId}"); var result = new ImportResultDto(); SecurityHelpers.ThrowIfNotAdmin(_user); var contextZoneId = _zoneMapper.GetZoneId(_siteId); var currentApp = _impExpHelpers.Init(Log).GetAppAndCheckZoneSwitchPermissions(zoneId, appId, _user, contextZoneId); // 1. Verify the file exists before we flush var path = currentApp.PhysicalPath + "\\" + Eav.Constants.FolderData; if (!Directory.Exists(path)) { result.Success = false; result.Messages.Add(new Message("Error: Path to app.xml not found on hard disk", Message.MessageTypes.Error)); return(result); } var filePath = Path.Combine(path, Eav.Constants.AppDataFile); if (!File.Exists(filePath)) { result.Success = false; result.Messages.Add(new Message($"Can't find the {Eav.Constants.AppDataFile} in the folder", Message.MessageTypes.Error)); return(result); } // 2. Now we can delete the app before we prepare the import _cmsZones.Init(zoneId, Log).AppsMan.RemoveAppInSiteAndEav(appId, false); // 3. Now import the App.xml var allowSystemChanges = _user.IsSuperUser; var xmlImport = _xmlImportWithFilesLazy.Value.Init(defaultLanguage, allowSystemChanges, Log); var imp = new ImportXmlReader(filePath, xmlImport, Log); result.Success = xmlImport.ImportXml(zoneId, appId, imp.XmlDoc); result.Messages.AddRange(xmlImport.Messages); return(result); }