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