mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Shifting ContentMenuItemPart
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentPicker.Models;
|
using Orchard.ContentPicker.Models;
|
||||||
using Orchard.Core.Navigation.Models;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
|
||||||
@@ -16,8 +15,8 @@ namespace Orchard.ContentPicker.Handlers {
|
|||||||
Filters.Add(StorageFilter.For(repository));
|
Filters.Add(StorageFilter.For(repository));
|
||||||
|
|
||||||
OnLoading<ContentMenuItemPart>((context, part) => part._content.Loader(p => {
|
OnLoading<ContentMenuItemPart>((context, part) => part._content.Loader(p => {
|
||||||
if (part.Record.ContentMenuItemRecord != null) {
|
if (part.ContentItemId != null) {
|
||||||
return contentManager.Get(part.Record.ContentMenuItemRecord.Id);
|
return contentManager.Get(part.ContentItemId.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentPicker.Models;
|
using Orchard.ContentPicker.Models;
|
||||||
using Orchard.Core.Navigation.Models;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
|
||||||
|
@@ -10,8 +10,14 @@ namespace Orchard.ContentPicker.Models {
|
|||||||
get { return _content.Value; }
|
get { return _content.Value; }
|
||||||
set {
|
set {
|
||||||
_content.Value = value;
|
_content.Value = value;
|
||||||
Record.ContentMenuItemRecord = value == null ? null : value.Record;
|
Record.ContentMenuItemRecord = value == null ? null : value.Record;
|
||||||
|
ContentItemId = value == null ? (int?)null : value.Record.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int? ContentItemId {
|
||||||
|
get { return this.Retrieve(x => x.ContentItemId); }
|
||||||
|
set { this.Store(x => x.ContentItemId, value); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,7 +71,7 @@ namespace Upgrade.Controllers {
|
|||||||
|
|
||||||
// ThemeSiteSettingsPartRecord
|
// ThemeSiteSettingsPartRecord
|
||||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Themes_ThemeSiteSettingsPartRecord"),
|
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Themes_ThemeSiteSettingsPartRecord"),
|
||||||
(reader, connection) => site.As<InfosetPart>().Set("ThemeSiteSettingsPart", "CurrentThemeName", (string)reader["CurrentThemeName"]));
|
(reader, connection) => site.As<InfosetPart>().Store("ThemeSiteSettingsPart", "CurrentThemeName", (string)reader["CurrentThemeName"]));
|
||||||
|
|
||||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_Themes_ThemeSiteSettingsPartRecord"), null);
|
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_Themes_ThemeSiteSettingsPartRecord"), null);
|
||||||
|
|
||||||
@@ -79,8 +79,8 @@ namespace Upgrade.Controllers {
|
|||||||
// AkismetSettingsPartRecord
|
// AkismetSettingsPartRecord
|
||||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_AkismetSettingsPartRecord"),
|
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_AkismetSettingsPartRecord"),
|
||||||
(reader, connection) => {
|
(reader, connection) => {
|
||||||
site.As<InfosetPart>().Set("AkismetSettingsPart", "TrustAuthenticatedUsers", reader["TrustAuthenticatedUsers"].ToString());
|
site.As<InfosetPart>().Store("AkismetSettingsPart", "TrustAuthenticatedUsers", (bool)reader["TrustAuthenticatedUsers"]);
|
||||||
site.As<InfosetPart>().Set("AkismetSettingsPart", "ApiKey", reader["ApiKey"].ToString());
|
site.As<InfosetPart>().Store("AkismetSettingsPart", "ApiKey", reader["ApiKey"].ToString());
|
||||||
});
|
});
|
||||||
|
|
||||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_AkismetSettingsPartRecord"), null);
|
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_AkismetSettingsPartRecord"), null);
|
||||||
@@ -88,9 +88,9 @@ namespace Upgrade.Controllers {
|
|||||||
// ReCaptchaSettingsPartRecord
|
// ReCaptchaSettingsPartRecord
|
||||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_ReCaptchaSettingsPartRecord"),
|
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_ReCaptchaSettingsPartRecord"),
|
||||||
(reader, connection) => {
|
(reader, connection) => {
|
||||||
site.As<InfosetPart>().Set("ReCaptchaSettingsPart", "PublicKey", reader["PublicKey"].ToString());
|
site.As<InfosetPart>().Store("ReCaptchaSettingsPart", "PublicKey", reader["PublicKey"].ToString());
|
||||||
site.As<InfosetPart>().Set("ReCaptchaSettingsPart", "PrivateKey", reader["PrivateKey"].ToString());
|
site.As<InfosetPart>().Store("ReCaptchaSettingsPart", "PrivateKey", reader["PrivateKey"].ToString());
|
||||||
site.As<InfosetPart>().Set("ReCaptchaSettingsPart", "TrustAuthenticatedUsers", reader["TrustAuthenticatedUsers"].ToString());
|
site.As<InfosetPart>().Store("ReCaptchaSettingsPart", "TrustAuthenticatedUsers", (bool)reader["TrustAuthenticatedUsers"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_ReCaptchaSettingsPartRecord"), null);
|
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_ReCaptchaSettingsPartRecord"), null);
|
||||||
@@ -98,8 +98,8 @@ namespace Upgrade.Controllers {
|
|||||||
// TypePadSettingsPartRecord
|
// TypePadSettingsPartRecord
|
||||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_TypePadSettingsPartRecord"),
|
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_TypePadSettingsPartRecord"),
|
||||||
(reader, connection) => {
|
(reader, connection) => {
|
||||||
site.As<InfosetPart>().Set("TypePadSettingsPart", "ApiKey", reader["ApiKey"].ToString());
|
site.As<InfosetPart>().Store("TypePadSettingsPart", "ApiKey", reader["ApiKey"].ToString());
|
||||||
site.As<InfosetPart>().Set("ReCaptchaSettingsPart", "TrustAuthenticatedUsers", reader["TrustAuthenticatedUsers"].ToString());
|
site.As<InfosetPart>().Store("ReCaptchaSettingsPart", "TrustAuthenticatedUsers", (bool)reader["TrustAuthenticatedUsers"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_TypePadSettingsPartRecord"), null);
|
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_AntiSpam_TypePadSettingsPartRecord"), null);
|
||||||
@@ -134,30 +134,48 @@ namespace Upgrade.Controllers {
|
|||||||
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner))
|
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner))
|
||||||
throw new AuthenticationException("");
|
throw new AuthenticationException("");
|
||||||
|
|
||||||
var lastContentItemId = 0;
|
var lastContentItemId = id;
|
||||||
// TypePadSettingsPartRecord
|
// TypePadSettingsPartRecord
|
||||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_ContentPermissions_ContentPermissionsPartRecord" + " WHERE Id > " + id),
|
_upgradeService.ExecuteReader("SELECT TOP " + BATCH + " * FROM " + _upgradeService.GetPrefixedTableName("Orchard_ContentPermissions_ContentPermissionsPartRecord" + " WHERE Id > " + id),
|
||||||
(reader, connection) => {
|
(reader, connection) => {
|
||||||
lastContentItemId = (int) reader["Id"];
|
lastContentItemId = (int) reader["Id"];
|
||||||
var contentPermissionPart = _orchardServices.ContentManager.Get(lastContentItemId);
|
var contentPermissionPart = _orchardServices.ContentManager.Get(lastContentItemId);
|
||||||
|
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "Enabled", reader["Enabled"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "Enabled", reader["Enabled"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "ViewContent", reader["ViewContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "ViewContent", reader["ViewContent"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "ViewOwnContent", reader["ViewOwnContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "ViewOwnContent", reader["ViewOwnContent"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "PublishContent", reader["PublishContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "PublishContent", reader["PublishContent"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "PublishOwnContent", reader["PublishOwnContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "PublishOwnContent", reader["PublishOwnContent"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "EditContent", reader["EditContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "EditContent", reader["EditContent"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "EditOwnContent", reader["EditOwnContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "EditOwnContent", reader["EditOwnContent"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "DeleteContent", reader["DeleteContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "DeleteContent", reader["DeleteContent"].ToString());
|
||||||
contentPermissionPart.As<InfosetPart>().Set("ContentPermissionsPart", "DeleteOwnContent", reader["DeleteOwnContent"].ToString());
|
contentPermissionPart.As<InfosetPart>().Store("ContentPermissionsPart", "DeleteOwnContent", reader["DeleteOwnContent"].ToString());
|
||||||
});
|
});
|
||||||
|
|
||||||
if (lastContentItemId == 0) {
|
if (lastContentItemId == id) {
|
||||||
// delete the table only when there is no more content to process
|
// delete the table only when there is no more content to process
|
||||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_ContentPermissions_ContentPermissionsPartRecord"), null);
|
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_ContentPermissions_ContentPermissionsPartRecord"), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonResult { Data = lastContentItemId };
|
return new JsonResult { Data = lastContentItemId };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public JsonResult MigrateContentMenuItemPart(int id) {
|
||||||
|
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner))
|
||||||
|
throw new AuthenticationException("");
|
||||||
|
|
||||||
|
var lastContentItemId = id;
|
||||||
|
// TypePadSettingsPartRecord
|
||||||
|
_upgradeService.ExecuteReader("SELECT TOP " + BATCH + " * FROM " + _upgradeService.GetPrefixedTableName("Orchard_ContentPicker_ContentMenuItemPartRecord" + " WHERE Id > " + id),
|
||||||
|
(reader, connection) => {
|
||||||
|
lastContentItemId = (int)reader["Id"];
|
||||||
|
var contentPermissionPart = _orchardServices.ContentManager.Get(lastContentItemId);
|
||||||
|
|
||||||
|
contentPermissionPart.As<InfosetPart>().Store("ContentMenuItemPart", "ContentItemId", (int)reader["ContentMenuItemRecord_id"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return new JsonResult { Data = lastContentItemId };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
Layout.Title = T("Migrate Infosets").ToString();
|
Layout.Title = T("Migrate Infosets").ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<div class="message message-Warning" id="message-progress" style="display: none"></div>
|
||||||
|
|
||||||
@using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "Infoset"))) {
|
@using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "Infoset"))) {
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>@T("Migrating Site Settings:")</legend>
|
<legend>@T("Migrating Site Settings:")</legend>
|
||||||
@@ -16,22 +18,31 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>@T("Migrating Body Parts:")</legend>
|
<legend>@T("Migrating Body Parts:")</legend>
|
||||||
<span class="hint">@T("This migration step will copy all Body Parts to Infosets.")</span>
|
<span class="hint">@T("This migration step will copy all Body Parts to Infosets.")</span>
|
||||||
|
<button type="button" class="button button-migrate" data-url="@Url.Action("MigrateBody", "Infoset")">@T("Migrate")</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<button type="button" class="button" id="button-migrate" data-url="@Url.Action("MigrateBody", "Infoset")">@T("Migrate")</button>
|
<legend>@T("Migrating Content Item Menu Parts:")</legend>
|
||||||
<div class="message message-Warning" id="message-progress" style="display: none"></div>
|
<span class="hint">@T("This migration step will copy all Content Item Permissions parts to Infosets.")</span>
|
||||||
|
<button type="button" class="button button-migrate" data-url="@Url.Action("MigrateContentPermissionsPart", "Infoset")">@T("Migrate")</button>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend>@T("Migrating Content Item Menu Parts:")</legend>
|
||||||
|
<span class="hint">@T("This migration step will copy all Content Item Menu parts to Infosets.")</span>
|
||||||
|
<button type="button" class="button button-migrate" data-url="@Url.Action("MigrateContentMenuItemPart", "Infoset")">@T("Migrate")</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
@using (Script.Foot()) {
|
@using (Script.Foot()) {
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
$(function() {
|
||||||
var antiForgeryToken = '@HttpUtility.JavaScriptStringEncode(Html.AntiForgeryTokenValueOrchard().ToString())';
|
var antiForgeryToken = '@HttpUtility.JavaScriptStringEncode(Html.AntiForgeryTokenValueOrchard().ToString())';
|
||||||
var endMessage = '@HttpUtility.JavaScriptStringEncode(T("All content items have been processed").Text)';
|
var endMessage = '@HttpUtility.JavaScriptStringEncode(T("All items have been processed").Text)';
|
||||||
|
|
||||||
$('#button-migrate').click(function () {
|
$('.button-migrate').click(function () {
|
||||||
var importUrl = $(this).data('url');
|
var importUrl = $(this).data('url');
|
||||||
|
|
||||||
var processed = 0;
|
var startId = 0;
|
||||||
$('#message-progress').show();
|
$('#message-progress').show();
|
||||||
|
|
||||||
var iId = setInterval(function() {
|
var iId = setInterval(function() {
|
||||||
@@ -40,25 +51,24 @@
|
|||||||
url: importUrl,
|
url: importUrl,
|
||||||
async: false,
|
async: false,
|
||||||
data: {
|
data: {
|
||||||
__RequestVerificationToken: antiForgeryToken
|
__RequestVerificationToken: antiForgeryToken,
|
||||||
|
id: startId // start at index 0
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function (data) {
|
||||||
console.log('items remaining: ' + data);
|
if (Number(data) == startId) {
|
||||||
processed += Number(data);
|
|
||||||
|
|
||||||
if (Number(data) == 0) {
|
|
||||||
clearInterval(iId);
|
clearInterval(iId);
|
||||||
$('#message-progress').text(endMessage);
|
$('#message-progress').text(endMessage);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
startId = Number(data);
|
||||||
|
$('#message-progress').text('Processing content item ' + startId);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fail: function(result) {
|
fail: function(result) {
|
||||||
processed = 0;
|
|
||||||
console.log("An error occured: " + result);
|
console.log("An error occured: " + result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#message-progress').text(processed + ' documents processed ...');
|
|
||||||
|
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -37,27 +37,24 @@ namespace Orchard.ContentManagement {
|
|||||||
TProperty value, bool versioned = false) where TPart : ContentPart {
|
TProperty value, bool versioned = false) where TPart : ContentPart {
|
||||||
|
|
||||||
var partName = contentPart.GetType().Name;
|
var partName = contentPart.GetType().Name;
|
||||||
|
|
||||||
var infosetPart = contentPart.As<InfosetPart>();
|
var infosetPart = contentPart.As<InfosetPart>();
|
||||||
var infoset = (versioned ? infosetPart.VersionInfoset : infosetPart.Infoset);
|
|
||||||
var partElement = infoset.Element.Element(partName);
|
|
||||||
if (partElement == null) {
|
|
||||||
partElement = new XElement(partName);
|
|
||||||
infoset.Element.Add(partElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
var propertyInfo = ReflectionHelper<TPart>.GetPropertyInfo(targetExpression);
|
var propertyInfo = ReflectionHelper<TPart>.GetPropertyInfo(targetExpression);
|
||||||
var name = propertyInfo.Name;
|
var name = propertyInfo.Name;
|
||||||
|
|
||||||
partElement.Attr(name, value);
|
Store(infosetPart, partName, name, value, versioned);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Store<TProperty>(this ContentPart contentPart, string name,
|
public static void Store<TProperty>(this ContentPart contentPart, string name,
|
||||||
TProperty value, bool versioned = false) {
|
TProperty value, bool versioned = false) {
|
||||||
|
|
||||||
var partName = contentPart.GetType().Name;
|
var partName = contentPart.GetType().Name;
|
||||||
|
|
||||||
var infosetPart = contentPart.As<InfosetPart>();
|
var infosetPart = contentPart.As<InfosetPart>();
|
||||||
|
|
||||||
|
Store(infosetPart, partName, name, value, versioned);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Store<TProperty>(this InfosetPart infosetPart, string partName, string name, TProperty value, bool versioned = false) {
|
||||||
|
|
||||||
var infoset = (versioned ? infosetPart.VersionInfoset : infosetPart.Infoset);
|
var infoset = (versioned ? infosetPart.VersionInfoset : infosetPart.Infoset);
|
||||||
var partElement = infoset.Element.Element(partName);
|
var partElement = infoset.Element.Element(partName);
|
||||||
if (partElement == null) {
|
if (partElement == null) {
|
||||||
|
Reference in New Issue
Block a user