Skip to content

Commit

Permalink
Optimize the query that runs to get placeholders with allowed control…
Browse files Browse the repository at this point in the history
…s in WFFM
  • Loading branch information
DmitryKolinchuk committed Nov 8, 2016
1 parent 41c2f22 commit e951a58
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Sitecore.Support.67820.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{D43A7792-343B-40A8-A83B-5DA809C6A7C5}") = "Sitecore.Support.67820", "Sitecore.Support.67820\Sitecore.Support.67820.csproj", "{822D616A-C68C-4CA8-B2DC-D362425A26BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{822D616A-C68C-4CA8-B2DC-D362425A26BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{822D616A-C68C-4CA8-B2DC-D362425A26BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{822D616A-C68C-4CA8-B2DC-D362425A26BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{822D616A-C68C-4CA8-B2DC-D362425A26BA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<commands>
<command name="forms:selectplaceholders" type="Sitecore.Support.Forms.Core.Commands.RestrinctingPlaceholders,Sitecore.Support.67820" patch:instead="*[@type='Sitecore.Forms.Core.Commands.RestrinctingPlaceholders,Sitecore.Forms.Core']"/>
</commands>
</sitecore>
</configuration>
6 changes: 6 additions & 0 deletions src/Sitecore.Support.67820/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Sitecore.Support.67820")]
[assembly: AssemblyProduct("Sitecore.Support.67820")]
[assembly: ComVisible(false)]
133 changes: 133 additions & 0 deletions src/Sitecore.Support.67820/RestrinctingPlaceholders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Form.Core.Configuration;
using Sitecore.Form.Core.Utility;
using Sitecore.Forms.Core.Data;
using Sitecore.Shell.Framework.Commands;
using Sitecore.Text;
using Sitecore.Web;
using Sitecore.Web.UI.Sheer;
using Sitecore.WFFM.Abstractions;
using Sitecore.WFFM.Abstractions.Constants.Core;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Sitecore.Support.Forms.Core.Commands
{
[Serializable]
public class RestrinctingPlaceholders : Sitecore.Shell.Framework.Commands.Command
{
public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
{
Sitecore.Context.ClientPage.Start(this, "Run");
}

protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
{
Sitecore.Data.Items.Item item = StaticSettings.ContextDatabase.GetItem(IDs.SettingsRoot);
Sitecore.Diagnostics.Assert.ArgumentNotNull(item, "item");
if (args.IsPostBack)
{
if (args.HasResult)
{
string value = RestrinctingPlaceholders.GetValue();
item.Editing.BeginEdit();
item.Fields[FormIDs.ModuleSettingsID].Value = args.Result;
item.Editing.EndEdit();
this.UpdateAllowedRenderings(value, args.Result);
Sitecore.Diagnostics.Log.Audit(this, "Set the following restricting placeholders: {0}", new string[]
{
Sitecore.Diagnostics.AuditFormatter.FormatItem(item)
});
return;
}
}
else
{
Sitecore.Text.UrlString urlString = new Sitecore.Text.UrlString(Sitecore.UIUtil.GetUri("control:Forms.CustomizeTreeListDialog"));
Sitecore.Web.UrlHandle urlHandle = new Sitecore.Web.UrlHandle();
urlHandle["value"] = RestrinctingPlaceholders.GetValue();
urlHandle["source"] = Sitecore.WFFM.Abstractions.Constants.Core.Constants.RestrinctingPlaceholders;
urlHandle["language"] = item.Language.Name;
urlHandle["includetemplatesforselection"] = "Placeholder";
urlHandle["includetemplatesfordisplay"] = "Placeholder Settings Folder,Placeholder";
urlHandle["includeitemsfordisplay"] = string.Empty;
urlHandle["excludetemplatesforselection"] = "Placeholder Settings Folder";
urlHandle["icon"] = "Business/32x32/table_selection_block.png";
urlHandle["title"] = DependenciesManager.ResourceManager.Localize("RESTRINCTING_PLACEHOLDERS");
urlHandle["text"] = DependenciesManager.ResourceManager.Localize("RESTRINCTING_PLACEHOLDERS_TEXT");
urlHandle.Add(urlString);
Sitecore.Web.UI.Sheer.SheerResponse.ShowModalDialog(urlString.ToString(), "800px", "500px", string.Empty, true);
args.WaitForPostBack();
}
}

protected void UpdateAllowedRenderings(string oldValue, string newValue)
{
List<string> list = new List<string>(oldValue.Split(new char[]
{
'|'
}));
List<string> list2 = new List<string>(newValue.Split(new char[]
{
'|'
}));
foreach (string current in list)
{
if (!list2.Contains(current))
{
Sitecore.Data.Items.Item item = StaticSettings.ContextDatabase.GetItem(current);
if (item != null)
{
PlaceholderSettingsDefinition placeholderSettingsDefinition = new PlaceholderSettingsDefinition(item);
placeholderSettingsDefinition.RemoveControl(IDs.FormInterpreterID.ToString());
placeholderSettingsDefinition.RemoveControl(IDs.FormMvcInterpreterID.ToString());
}
}
}
foreach (string current2 in list2)
{
if (!list.Contains(current2))
{
Sitecore.Data.Items.Item item2 = StaticSettings.ContextDatabase.GetItem(current2);
if (item2 != null)
{
PlaceholderSettingsDefinition placeholderSettingsDefinition2 = new PlaceholderSettingsDefinition(item2);
placeholderSettingsDefinition2.AddControl(IDs.FormInterpreterID.ToString());
placeholderSettingsDefinition2.AddControl(IDs.FormMvcInterpreterID.ToString());
}
}
}
}
// Sitecore.Support.67820
public static Item[] GetPlaceholdersWithAllowedControl(Sitecore.Data.ID controlID)
{
Item item = StaticSettings.ContextDatabase.GetItem(ItemIDs.PlaceholderSettingsRoot);
Assert.IsNotNull(item, "placeholders root");
string query = string.Format(".//*[contains(@Allowed Controls, '{0}')]", controlID);
return item.Axes.SelectItems(query);
}

private static string GetValue()
{
List<Sitecore.Data.Items.Item> list = new List<Sitecore.Data.Items.Item>();
Sitecore.Data.Items.Item[] placeholdersWithAllowedControl = RestrinctingPlaceholders.GetPlaceholdersWithAllowedControl(IDs.FormInterpreterID);
Sitecore.Data.Items.Item[] placeholdersWithAllowedControl2 = RestrinctingPlaceholders.GetPlaceholdersWithAllowedControl(IDs.FormMvcInterpreterID);
if (placeholdersWithAllowedControl != null)
{
list = placeholdersWithAllowedControl.ToList<Sitecore.Data.Items.Item>();
}
if (placeholdersWithAllowedControl2 != null)
{
foreach (Sitecore.Data.Items.Item current in from item in placeholdersWithAllowedControl2
where list.All((Sitecore.Data.Items.Item x) => x.ID != item.ID)
select item)
{
list.Add(current);
}
}
return string.Join("|", Sitecore.Form.Core.Utility.Utils.ToStringArray(list.ToArray()));
}
}
}
96 changes: 96 additions & 0 deletions src/Sitecore.Support.67820/Sitecore.Support.67820.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{822D616A-C68C-4CA8-B2DC-D362425A26BA}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sitecore.Support</RootNamespace>
<AssemblyName>Sitecore.Support.67820</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Sitecore.Forms.Core, Version=8.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WFFM.Sitecore.Forms.Core.8.1.0\lib\Sitecore.Forms.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.Kernel">
<HintPath>..\packages\SC.Sitecore.Kernel.8.1.0\lib\Sitecore.Kernel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Sitecore.WFFM.Abstractions, Version=8.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WFFM.Sitecore.WFFM.Abstractions.8.1.0\lib\Sitecore.WFFM.Abstractions.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Include="RestrinctingPlaceholders.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Config\Include\zzz\Sitecore.Support.67820.config" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:58827/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
6 changes: 6 additions & 0 deletions src/Sitecore.Support.67820/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SC.Sitecore.Kernel" version="8.1.0" targetFramework="net45" />
<package id="WFFM.Sitecore.Forms.Core" version="8.1.0" targetFramework="net45" />
<package id="WFFM.Sitecore.WFFM.Abstractions" version="8.1.0" targetFramework="net45" />
</packages>

0 comments on commit e951a58

Please sign in to comment.