forked from DNNCommunity/DNN.Repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Upgrade.cs
188 lines (140 loc) · 7.65 KB
/
Upgrade.cs
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//-------------------------------------------------------------------------
using System.IO;
using System.Web;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Definitions;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Common.Utilities;
namespace DotNetNuke.Modules.Repository
{
public class Upgrade
{
#region "Public Functions and Subs"
// this upgrade is for anything prior to 03.01.02 which is the re-branding release
// that removes all references to Gooddogs Repository Module.
public static string CustomUpgradeGRM3toDRM3()
{
string m_message = "";
try {
PortalSettings _portalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
DesktopModuleController _desktopModuleController = new DesktopModuleController();
if ((DesktopModuleController.GetDesktopModuleByModuleName("Gooddogs Repository", Null.NullInteger) == null)) {
return "Gooddogs Repository Not installed - no upgrade required";
}
ModuleDefinitionController _moduleDefinitionControler = new ModuleDefinitionController();
int OldRepositoryDefId = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Gooddogs Repository", DesktopModuleController.GetDesktopModuleByModuleName("Gooddogs Repository", Null.NullInteger).DesktopModuleID).ModuleDefID;
int OldDashboardDefId = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Gooddogs Dashboard", DesktopModuleController.GetDesktopModuleByModuleName("Gooddogs Dashboard", Null.NullInteger).DesktopModuleID).ModuleDefID;
int NewRepositoryDefId = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Repository", DesktopModuleController.GetDesktopModuleByModuleName("Repository", Null.NullInteger).DesktopModuleID).ModuleDefID;
int NewDashboardDefId = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Repository Dashboard", DesktopModuleController.GetDesktopModuleByModuleName("Repository Dashboard", Null.NullInteger).DesktopModuleID).ModuleDefID;
RepositoryController m_repositoryController = new RepositoryController();
ModuleInfo _moduleInfo = null;
ModuleController _moduleController = new ModuleController();
// replace all Gooddogs Repository controls with the new Repository controls
ArrayList _allModules = _moduleController.GetAllModules();
foreach (ModuleInfo mi in _allModules) {
if (mi.ModuleDefID == OldRepositoryDefId) {
m_repositoryController.ChangeRepositoryModuleDefId(mi.ModuleID, mi.ModuleDefID, NewRepositoryDefId);
}
if (mi.ModuleDefID == OldDashboardDefId) {
m_repositoryController.ChangeRepositoryModuleDefId(mi.ModuleID, mi.ModuleDefID, NewDashboardDefId);
}
}
// we're all done .. so now we can remove the old Gooddogs Repository and Gooddogs Dashboard modules
m_repositoryController.DeleteRepositoryModuleDefId(OldRepositoryDefId);
m_repositoryController.DeleteRepositoryModuleDefId(OldDashboardDefId);
} catch (Exception ex) {
m_message += "EXCEPTION: " + ex.Message + " - " + ex.StackTrace.ToString();
}
m_message += "All Modules upgraded from GRM3 to DRM3";
return m_message;
}
// ///
// /// CusomtUpgrade315:
// /// This upgrade deals with changing the author info as stored from username to userid
// /// because of this user folders where files are stored will change from the user's username to the
// /// user's id. The sql script will handle updating the tables, but we need this upgrade function
// /// to change the name of the folder where each users files have been stored.
// ///
// /// cycle through all the repository modules. if they are using user folders, get the root location, then
// /// rename all the user folders
// ///
public static string CustomUpgrade315()
{
string m_message = "";
Hashtable settings = null;
string m_foldername = null;
string[] m_Folders = null;
string m_Folder = null;
string m_userFolder = null;
string m_newFolder = null;
DotNetNuke.Entities.Users.UserController m_userController = new DotNetNuke.Entities.Users.UserController();
DotNetNuke.Entities.Users.UserInfo m_userInfo = null;
try {
PortalSettings _portalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
DesktopModuleController _desktopModuleController = new DesktopModuleController();
if ((DesktopModuleController.GetDesktopModuleByModuleName("Repository", Null.NullInteger) == null)) {
return "No existing Repository modules found - no upgrade required";
}
RepositoryController repositories = new RepositoryController();
ArrayList arrModules = new ArrayList();
ModuleInfo objModule = null;
arrModules = repositories.GetRepositoryModules(_portalSettings.PortalId);
foreach (ModuleInfo objModule_loopVariable in arrModules) {
objModule = objModule_loopVariable;
// get the module settings
settings = objModule.ModuleSettings;
// if this module is using UserFolders...
if (!string.IsNullOrEmpty(Convert.ToString(settings["userfolders"]))) {
// then get the base folder name
if (!string.IsNullOrEmpty(Convert.ToString(settings["folderlocation"]))) {
m_foldername = HttpContext.Current.Server.MapPath(_portalSettings.HomeDirectory) + "Repository";
// look in the base folder for any user folders
m_Folders = Directory.GetDirectories(m_foldername);
foreach (string m_Folder_loopVariable in m_Folders) {
m_Folder = m_Folder_loopVariable;
m_userFolder = m_Folder.Substring(m_Folder.LastIndexOf("\\") + 1);
m_userInfo = DotNetNuke.Entities.Users.UserController.GetUserByName(objModule.PortalID, m_userFolder);
if ((m_userInfo != null)) {
// we have a user folder, change the folder name to be the userid
m_newFolder = m_Folder.Substring(0, m_Folder.LastIndexOf("\\") + 1) + m_userInfo.UserID.ToString();
Directory.Move(m_Folder, m_newFolder);
}
}
}
}
}
} catch (Exception ex) {
m_message += "EXCEPTION: " + ex.Message + " - " + ex.StackTrace.ToString();
}
m_message += "All DRM3 Modules upgraded to 3.1.5";
return m_message;
}
#endregion
}
}