Files
Orchard/src/Orchard.Web/Modules/Upgrade/Controllers/TaxonomyController.cs
Sebastien Ros 66b297c4db Adding upgrade steps for Content Picker
--HG--
branch : 1.x
extra : rebase_source : c58efb226ce34208a2b73341d5ef3a0cb5afcafa
2013-06-21 16:05:35 -07:00

66 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Orchard;
using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData;
using Orchard.Environment.Features;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Security;
using Orchard.UI.Admin;
using Orchard.UI.Notify;
using Upgrade.Services;
using Upgrade.ViewModels;
namespace Upgrade.Controllers {
[Admin]
public class TaxonomyController : Controller {
private readonly IUpgradeService _upgradeService;
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly IOrchardServices _orchardServices;
private readonly IFeatureManager _featureManager;
public TaxonomyController(
IUpgradeService upgradeService,
IContentDefinitionManager contentDefinitionManager,
IOrchardServices orchardServices,
IFeatureManager featureManager) {
_upgradeService = upgradeService;
_contentDefinitionManager = contentDefinitionManager;
_orchardServices = orchardServices;
_featureManager = featureManager;
}
public Localizer T { get; set; }
public ILogger Logger { get; set; }
public ActionResult Index() {
if(_featureManager.GetEnabledFeatures().All(x => x.Id != "Orchard.Taxonomies")) {
_orchardServices.Notifier.Warning(T("You need to enable Orchard.Taxonomies in order to migrate Contrib.Taxonomies to Orchard.Taxonomies."));
}
return View();
}
[HttpPost, ActionName("Index")]
public ActionResult IndexPOST() {
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to migrate Contrib.Taxonomies.")))
return new HttpUnauthorizedResult();
try {
_upgradeService.CopyTable("Contrib_Taxonomies_TermPartRecord", "Orchard_Taxonomies_TermPartRecord");
_orchardServices.Notifier.Information(T("Taxonomies were migrated successfully."));
}
catch(Exception e) {
Logger.Error(e, "Unexpected error while migrating to Orchard.Taxonomies. Please check the log.");
_orchardServices.Notifier.Error(T("Unexpected error while migrating to Orchard.Taxonomies. Please check the log."));
}
return RedirectToAction("Index");
}
}
}