mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing upgrading issues
--HG-- branch : 1.x
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Transactions;
|
||||
using System.Web.Mvc;
|
||||
using Orchard;
|
||||
using Orchard.Environment.Features;
|
||||
@@ -30,7 +31,7 @@ namespace Upgrade.Controllers {
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
if(_featureManager.GetEnabledFeatures().All(x => x.Id != "Orchard.ContentPicker")) {
|
||||
if (_featureManager.GetEnabledFeatures().All(x => x.Id != "Orchard.ContentPicker")) {
|
||||
_orchardServices.Notifier.Warning(T("You need to enable Orchard.ContentPicker in order to migrate Content Picker items to Orchard.ContentPicker."));
|
||||
}
|
||||
|
||||
@@ -41,9 +42,11 @@ namespace Upgrade.Controllers {
|
||||
public ActionResult IndexPOST() {
|
||||
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to migrate Orchard.ContentPicker.")))
|
||||
return new HttpUnauthorizedResult();
|
||||
try {
|
||||
_upgradeService.CopyTable("Navigation_ContentMenuItemPartRecord", "Orchard_ContentPicker_ContentMenuItemPartRecord", new string[0]);
|
||||
|
||||
try {
|
||||
_upgradeService.ExecuteReader("DELETE FROM " + _upgradeService.GetPrefixedTableName("Orchard_ContentPicker_ContentMenuItemPartRecord"), null);
|
||||
_upgradeService.CopyTable("Navigation_ContentMenuItemPartRecord", "Orchard_ContentPicker_ContentMenuItemPartRecord", new string[0]);
|
||||
|
||||
_orchardServices.Notifier.Information(T("Content Picker menu items were migrated successfully."));
|
||||
}
|
||||
catch(Exception e) {
|
||||
|
@@ -2,10 +2,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web.Mvc;
|
||||
using Orchard;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Media.Models;
|
||||
@@ -16,7 +16,6 @@ using Orchard.Security;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Notify;
|
||||
using MediaFolder = Orchard.Media.Models.MediaFolder;
|
||||
using Orchard.Mvc.Extensions;
|
||||
|
||||
namespace Upgrade.Controllers {
|
||||
[Admin]
|
||||
@@ -25,16 +24,19 @@ namespace Upgrade.Controllers {
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly IMediaService _mediaService;
|
||||
private readonly IMediaLibraryService _mediaLibraryService;
|
||||
private readonly IStorageProvider _storageProvider;
|
||||
|
||||
public MediaController(
|
||||
IOrchardServices orchardServices,
|
||||
IFeatureManager featureManager,
|
||||
IMediaService mediaService,
|
||||
IMediaLibraryService mediaLibraryService) {
|
||||
IMediaLibraryService mediaLibraryService,
|
||||
IStorageProvider storageProvider) {
|
||||
_orchardServices = orchardServices;
|
||||
_featureManager = featureManager;
|
||||
_mediaService = mediaService;
|
||||
_mediaLibraryService = mediaLibraryService;
|
||||
_storageProvider = storageProvider;
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
@@ -60,7 +62,7 @@ namespace Upgrade.Controllers {
|
||||
foreach (var mediaFolder in mediaFolders) {
|
||||
ImportMediaFolder(mediaFolder, null);
|
||||
}
|
||||
|
||||
|
||||
_orchardServices.Notifier.Information(T("Media files were migrated successfully."));
|
||||
|
||||
return RedirectToAction("Index");
|
||||
@@ -95,13 +97,14 @@ namespace Upgrade.Controllers {
|
||||
}
|
||||
|
||||
try {
|
||||
_orchardServices.Notifier.Information(T("Importing {0}.", mediaFile.MediaPath));
|
||||
var url = _mediaService.GetPublicUrl(mediaFile.MediaPath);
|
||||
url = Url.MakeAbsolute(url);
|
||||
var prefix = _mediaService.GetPublicUrl("foo.$$$");
|
||||
var trim = prefix.IndexOf("foo.$$$");
|
||||
|
||||
var buffer = new WebClient().DownloadData(url);
|
||||
var stream = new MemoryStream(buffer);
|
||||
var mediaPart = _mediaLibraryService.ImportStream(mediaLibraryFolder.TermId, stream, Path.GetFileName(url));
|
||||
_orchardServices.Notifier.Information(T("Importing {0}.", mediaFile.MediaPath));
|
||||
var storageFile = _storageProvider.GetFile(mediaFile.MediaPath.Substring(trim));
|
||||
using (var stream = storageFile.OpenRead()) {
|
||||
_mediaLibraryService.ImportStream(mediaLibraryFolder.TermId, stream, Path.GetFileName(mediaFile.MediaPath));
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
_orchardServices.Notifier.Error(T("Error while importing {0}. Please check the logs", mediaFile.MediaPath));
|
||||
|
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Transactions;
|
||||
using System.Web.Mvc;
|
||||
using Orchard;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
@@ -12,23 +10,19 @@ 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;
|
||||
}
|
||||
@@ -40,6 +34,16 @@ namespace Upgrade.Controllers {
|
||||
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."));
|
||||
}
|
||||
else {
|
||||
var flag = false;
|
||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Taxonomies_TermContentItem"), (reader, conn) => {
|
||||
flag = true;
|
||||
});
|
||||
|
||||
if (flag) {
|
||||
_orchardServices.Notifier.Warning(T("This migration step might have been done already."));
|
||||
}
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
@@ -50,7 +54,7 @@ namespace Upgrade.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
try {
|
||||
_upgradeService.CopyTable("Contrib_Taxonomies_TaxonomyPartRecord", "Orchard_Taxonomies_TaxonomyPartRecord", new string[0]);
|
||||
_upgradeService.CopyTable("Contrib_Taxonomies_TermContentItem", "Orchard_Taxonomies_TermContentItem", new [] { "Id" });
|
||||
_upgradeService.CopyTable("Contrib_Taxonomies_TermContentItem", "Orchard_Taxonomies_TermContentItem", new[] {"Id"});
|
||||
_upgradeService.CopyTable("Contrib_Taxonomies_TermPartRecord", "Orchard_Taxonomies_TermPartRecord", new string[0]);
|
||||
_upgradeService.CopyTable("Contrib_Taxonomies_TermsPartRecord", "Orchard_Taxonomies_TermsPartRecord", new string[0]);
|
||||
_upgradeService.CopyTable("Contrib_Taxonomies_TermWidgetPartRecord", "Orchard_Taxonomies_TermWidgetPartRecord", new string[0]);
|
||||
|
@@ -94,7 +94,9 @@ namespace Upgrade.Services {
|
||||
|
||||
while (reader != null && reader.Read()) {
|
||||
try {
|
||||
action(reader, session.Connection);
|
||||
if (action != null) {
|
||||
action(reader, session.Connection);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Logger.Error(e, "Error while executing custom SQL Statement in Upgrade.");
|
||||
|
Reference in New Issue
Block a user