public void SetAppIdForInstance(IInstanceInfo instance, IAppEnvironment env, int?appId, Log parentLog)
        {
            Log.Add($"SetAppIdForInstance({instance.Id}, -, appid: {appId})");
            // Reset temporary template
            ContentGroupManager.ClearPreviewTemplate(instance.Id);

            // ToDo: Should throw exception if a real ContentGroup exists

            var module = (instance as EnvironmentInstance <ModuleInfo>).Original;
            var zoneId = env.ZoneMapper.GetZoneId(module.OwnerPortalID);

            if (appId == 0 || !appId.HasValue)
            {
                DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instance.Id, Settings.AppNameString, null, Log);
            }
            else
            {
                var appName = ((BaseCache)DataSource.GetCache(0, 0)).ZoneApps[zoneId].Apps[appId.Value];
                DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instance.Id, Settings.AppNameString, appName, Log);
            }

            // Change to 1. available template if app has been set
            if (appId.HasValue)
            {
                var app          = App.LightWithoutData(new DnnTenant(null), zoneId, appId.Value, parentLog: Log);
                var templateGuid = app.TemplateManager.GetAllTemplates().FirstOrDefault(t => !t.IsHidden)?.Guid;
                if (templateGuid.HasValue)
                {
                    ContentGroupManager.SetPreviewTemplate(instance.Id, templateGuid.Value);
                }
            }
        }
Beispiel #2
0
 public void SetContentGroupAndBlankTemplate(int instanceId, bool wasCreated, Guid guid)
 {
     // Remove the previewTemplateId (because it's not needed as soon Content is inserted)
     ClearPreviewTemplate(instanceId);
     // Update contentGroup Guid for this module
     if (wasCreated)
     {
         DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instanceId, Settings.ContentGroupGuidString,
                                                                 guid.ToString());
     }
 }
        /// <summary>
        /// Saves a temporary templateId to the module's settings
        /// This templateId will be used until a contentgroup exists
        /// </summary>
        public void SetPreviewTemplate(int instanceId, Guid previewTemplateGuid)
        {
            // todo: 2rm - I believe you are accidentally using uncached module settings access - pls check and probably change
            // todo: note: this is done ca. 3x in this class
            var moduleController = new ModuleController();
            var settings         = moduleController.GetModule(instanceId).ModuleSettings;// older, deprecated api: .GetModuleSettings(instanceId);

            // Do not allow saving the temporary template id if a contentgroup exists for this module
            if (settings[Settings.ContentGroupGuidString] != null)
            {
                throw new Exception("Preview template id cannot be set for a module that already has content.");
            }

            DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instanceId, Settings.PreviewTemplateIdString, previewTemplateGuid.ToString(), Log);
        }
 public void ClearPreviewTemplate(int instanceId)
 {
     Log.Add($"ClearPreviewTemplate(iid: {instanceId})");
     DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instanceId, Settings.PreviewTemplateIdString, null, Log);
 }
Beispiel #5
0
 public void ClearPreviewTemplate(int instanceId)
 {
     DnnStuffToRefactor.UpdateInstanceSettingForAllLanguages(instanceId, Settings.PreviewTemplateIdString, null);
 }