-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBulkRemovePersonalizationRules.aspx
More file actions
170 lines (148 loc) · 6.88 KB
/
Copy pathBulkRemovePersonalizationRules.aspx
File metadata and controls
170 lines (148 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<%@ Page Language="C#" AutoEventWireup="true" Debug="true" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.Globalization" %>
<%@ Import Namespace="Sitecore.Layouts" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="Sitecore.Collections" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="Sitecore.Data.Managers" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Sitecore.SharedSource" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Bulk - Remove Sub-Layout Personalization Rules and Update Data-Source</title>
<style>
body {
font-family: verdana, arial, sans-serif;
}
table.table-style-three {
font-family: verdana, arial, sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #3A3A3A;
border-collapse: collapse;
}
table.table-style-three th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #FFA6A6;
background-color: #D56A6A;
color: #ffffff;
}
table.table-style-three tr:hover td {
cursor: pointer;
}
table.table-style-three tr:nth-child(even) td {
background-color: #F7CFCF;
}
table.table-style-three td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #FFA6A6;
background-color: #ffffff;
}
.positionAbsolute {
position: absolute;
}
</style>
<script language="CS" runat="server">
StringBuilder sb;
DataTable tb;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Sitecore.Context.User.IsAuthenticated == false)
{
Response.Redirect("login.aspx?returnUrl=BulkRemovePersonalizationRules.aspx");
}
}
protected void btnGetReport_Click(object sender, EventArgs e)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("Summary:").Append("<br/>");
string path = txtPath.Text;
Database db = Database.GetDatabase("master");
Item parent = db.GetItem(path);
if (parent != null)
{
// Default device from Sitecore
var deviceItem = db.GetItem("{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}");
DeviceItem device = new DeviceItem(deviceItem);
foreach (Item childItem in parent.Axes.GetDescendants())
{
if (childItem.Fields != null && childItem.Fields["__Renderings"] != null && childItem.Fields["__Renderings"].ToString() != string.Empty)
{
var renderings = childItem.Visualization.GetRenderings(device, true).Where(r => r.RenderingID == Sitecore.Data.ID.Parse(txtRenderingID.Text)).ToArray();
if (renderings.Count() == 0)
{
string logThis = "Item not updated: " + childItem.Paths.Path + ", Error: Rendering with ID " + txtRenderingID.Text + " not found in the item presentation!";
Sitecore.Diagnostics.Log.Info(logThis, this);
sb.Append(logThis);
continue;
}
// Get the layout definitions and the device
Sitecore.Data.Fields.LayoutField layoutField = new Sitecore.Data.Fields.LayoutField(childItem.Fields[Sitecore.FieldIDs.LayoutField]);
if (!string.IsNullOrEmpty(layoutField.Value))
{
Sitecore.Layouts.LayoutDefinition layoutDefinition = Sitecore.Layouts.LayoutDefinition.Parse(layoutField.Value);
Sitecore.Layouts.DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(device.ID.ToString());
var renderingID = txtRenderingID.Text;
var renderingItem = deviceDefinition.GetRendering(renderingID);
if (renderingItem != null)
{
// Remove all the personalization rules
renderingItem.Rules.RemoveAll();
// Update the renderings datasource value accordingly
renderingItem.Datasource = txtNewDataSourceID.Text;
// Save the layout changes
childItem.Editing.BeginEdit();
layoutField.Value = layoutDefinition.ToXml();
childItem.Editing.EndEdit();
sb.Append("Item updated: " + childItem.Paths.Path).Append(", Rendering updated.").Append("<br />");
}
}
}
}
lblSummary.Text = sb.ToString();
}
}
catch (Exception ex)
{
lblSummary.Text = ex.ToString();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>Remove Sub-layout Presentation Rules and Update Datasource in Bulk - Visit Dubai</h2>
<h4>Use this tool to remove all the presentation rules from the sub-layout and also update the data-source</h4>
<table>
<tr>
<td>Provide Parent Item Path:<asp:TextBox ID="txtPath" Width="700px" runat="server"></asp:TextBox></td>
<td>Rendering ID:<asp:TextBox ID="txtRenderingID" Width="700px" runat="server"></asp:TextBox></td>
<td>New DataSource ID:<asp:TextBox ID="txtNewDataSourceID" Width="700px" runat="server"></asp:TextBox></td>
<td>
<asp:Button ID="btnGetReport" runat="server" Text="Execute" OnClick="btnGetReport_Click" /></td>
</tr>
<tr>
<td>
<asp:Label ID="lblSummary" CssClass="positionAbsolute" runat="server"></asp:Label></td>
</tr>
</table>
</form>
</body>
</html>