Created
April 23, 2013 09:23
-
-
Save adoprog/5442120 to your computer and use it in GitHub Desktop.
Installing Sitecore update package from code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var files = Directory.GetFiles(Server.MapPath("/sitecore/admin/Packages"), "*.update", SearchOption.AllDirectories); | |
Sitecore.Context.SetActiveSite("shell"); | |
using (new SecurityDisabler()) | |
{ | |
using (new ProxyDisabler()) | |
{ | |
using (new SyncOperationContext()) | |
{ | |
foreach (var file in files) | |
{ | |
Install(file); | |
Response.Write("Installed Package: " + file + "<br>"); | |
} | |
} | |
} | |
} | |
protected static string Install(string package) | |
{ | |
var log = LogManager.GetLogger("LogFileAppender"); | |
string result; | |
using (new ShutdownGuard()) | |
{ | |
var installationInfo = new PackageInstallationInfo | |
{ | |
Action = UpgradeAction.Upgrade, | |
Mode = InstallMode.Install, | |
Path = package | |
}; | |
string text = null; | |
List<ContingencyEntry> entries = null; | |
try | |
{ | |
entries = UpdateHelper.Install(installationInfo, log, out text); | |
} | |
catch (PostStepInstallerException ex) | |
{ | |
entries = ex.Entries; | |
text = ex.HistoryPath; | |
throw; | |
} | |
finally | |
{ | |
UpdateHelper.SaveInstallationMessages(entries, text); | |
} | |
result = text; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment