1+ // <copyright>
2+ // Copyright by the Spark Development Network
3+ //
4+ // Licensed under the Rock Community License (the "License");
5+ // you may not use this file except in compliance with the License.
6+ // You may obtain a copy of the License at
7+ //
8+ // http://www.rockrms.com/license
9+ //
10+ // Unless required by applicable law or agreed to in writing, software
11+ // distributed under the License is distributed on an "AS IS" BASIS,
12+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ // See the License for the specific language governing permissions and
14+ // limitations under the License.
15+ // </copyright>
16+ //
17+ namespace Rock . Migrations
18+ {
19+ /// <summary>
20+ ///
21+ /// </summary>
22+ public partial class UpdatePersonalDeviceTypeIcons : Rock . Migrations . RockMigration
23+ {
24+ private const string IconCssClassAttributeGuid = "DC0E00D2-7694-410E-82C0-E99A097D0A30" ;
25+ private const string PersonalDeviceTypeTvGuid = Rock . SystemGuid . DefinedValue . PERSONAL_DEVICE_TYPE_TV ;
26+ private const string PersonalDeviceTypeMobileGuid = Rock . SystemGuid . DefinedValue . PERSONAL_DEVICE_TYPE_MOBILE ;
27+ private const string PersonalDeviceTypeComputerGuid = Rock . SystemGuid . DefinedValue . PERSONAL_DEVICE_TYPE_COMPUTER ;
28+
29+ private const string IconCssClassTvValue = "ti ti-device-tv" ;
30+ private const string IconCssClassMobileValue = "ti ti-device-mobile" ;
31+ private const string IconCssClassDesktopValue = "ti ti-device-desktop" ;
32+
33+ /// <summary>
34+ /// Operations to be performed during the upgrade process.
35+ /// </summary>
36+ public override void Up ( )
37+ {
38+ CreateIndex ( "dbo.PersonalDevice" , "PlatformValueId" ) ;
39+ AddForeignKey ( "dbo.PersonalDevice" , "PlatformValueId" , "dbo.DefinedValue" , "Id" ) ;
40+
41+ AddTVIconClass ( ) ;
42+ UpdateMobileIconClass ( ) ;
43+ UpdateComputerIconClass ( ) ;
44+ }
45+
46+ /// <summary>
47+ /// Operations to be performed during the downgrade process.
48+ /// </summary>
49+ public override void Down ( )
50+ {
51+ DropForeignKey ( "dbo.PersonalDevice" , "PlatformValueId" , "dbo.DefinedValue" ) ;
52+ DropIndex ( "dbo.PersonalDevice" , new [ ] { "PlatformValueId" } ) ;
53+ }
54+
55+ #region MSE: Up Methods for Data Migration
56+
57+ private void AddTVIconClass ( )
58+ {
59+ Sql ( $@ "
60+ DECLARE @AttributeId INT = (SELECT [Id] FROM [Attribute] WHERE [Guid] = '{ IconCssClassAttributeGuid } ');
61+ DECLARE @EntityId INT = (SELECT [Id] FROM [DefinedValue] WHERE [Guid] = '{ PersonalDeviceTypeTvGuid } ');
62+
63+ IF @AttributeId IS NOT NULL AND @EntityId IS NOT NULL
64+ BEGIN
65+ IF NOT EXISTS (
66+ SELECT 1
67+ FROM [AttributeValue]
68+ WHERE [AttributeId] = @AttributeId AND [EntityId] = @EntityId
69+ )
70+ BEGIN
71+ INSERT INTO [AttributeValue] ( [IsSystem], [AttributeId], [EntityId], [Value], [Guid] )
72+ VALUES ( 1, @AttributeId, @EntityId, '{ IconCssClassTvValue } ', NEWID() );
73+ END
74+ END
75+ " ) ;
76+ }
77+
78+ private void UpdateMobileIconClass ( )
79+ {
80+ Sql ( $@ "
81+ DECLARE @AttributeId INT = (SELECT [Id] FROM [Attribute] WHERE [Guid] = '{ IconCssClassAttributeGuid } ');
82+ DECLARE @EntityId INT = (SELECT [Id] FROM [DefinedValue] WHERE [Guid] = '{ PersonalDeviceTypeMobileGuid } ');
83+
84+ IF @AttributeId IS NOT NULL AND @EntityId IS NOT NULL
85+ BEGIN
86+ IF EXISTS (
87+ SELECT 1
88+ FROM [AttributeValue]
89+ WHERE [AttributeId] = @AttributeId AND [EntityId] = @EntityId
90+ )
91+ BEGIN
92+ UPDATE [AttributeValue]
93+ SET [Value] = '{ IconCssClassMobileValue } '
94+ WHERE [AttributeId] = @AttributeId AND [EntityId] = @EntityId;
95+ END
96+ ELSE
97+ BEGIN
98+ INSERT INTO [AttributeValue] ( [IsSystem], [AttributeId], [EntityId], [Value], [Guid] )
99+ VALUES ( 1, @AttributeId, @EntityId, '{ IconCssClassMobileValue } ', NEWID() );
100+ END
101+ END
102+ " ) ;
103+ }
104+
105+ private void UpdateComputerIconClass ( )
106+ {
107+ Sql ( $@ "
108+ DECLARE @AttributeId INT = (SELECT [Id] FROM [Attribute] WHERE [Guid] = '{ IconCssClassAttributeGuid } ');
109+ DECLARE @EntityId INT = (SELECT [Id] FROM [DefinedValue] WHERE [Guid] = '{ PersonalDeviceTypeComputerGuid } ');
110+
111+ IF @AttributeId IS NOT NULL AND @EntityId IS NOT NULL
112+ BEGIN
113+ IF EXISTS (
114+ SELECT 1
115+ FROM [AttributeValue]
116+ WHERE [AttributeId] = @AttributeId AND [EntityId] = @EntityId
117+ )
118+ BEGIN
119+ UPDATE [AttributeValue]
120+ SET [Value] = '{ IconCssClassDesktopValue } '
121+ WHERE [AttributeId] = @AttributeId AND [EntityId] = @EntityId;
122+ END
123+ ELSE
124+ BEGIN
125+ INSERT INTO [AttributeValue] ( [IsSystem], [AttributeId], [EntityId], [Value], [Guid] )
126+ VALUES ( 1, @AttributeId, @EntityId, '{ IconCssClassDesktopValue } ', NEWID() );
127+ END
128+ END
129+ " ) ;
130+ }
131+
132+ #endregion
133+ }
134+ }
0 commit comments