#17447 There is a part named <content type>-2 generated

AddPart was looking at content type names to generate unique id
Parts should not have unique id generated in case of conflict
Throws an exception instead
GenerateName method made longer to avoid confusion in the future

Work Items: 17447

--HG--
branch : 1.x
extra : transplant_source : %A1%D8%F1%29%C26o%1A%FF%97%14%B9%00%B8wV%88%8DGR
This commit is contained in:
Louis DeJardin
2011-04-03 16:14:06 -07:00
parent cf0450cae6
commit 0605f0db28
3 changed files with 11 additions and 11 deletions

View File

@@ -77,7 +77,7 @@ namespace Orchard.ContentTypes.Controllers {
}
public ActionResult ContentTypeName(string displayName) {
return Json(_contentDefinitionService.GenerateName(displayName));
return Json(_contentDefinitionService.GenerateContentTypeNameFromDisplayName(displayName));
}
public ActionResult Edit(string id) {

View File

@@ -69,7 +69,7 @@ namespace Orchard.ContentTypes.Services {
}
if(String.IsNullOrWhiteSpace(name)) {
name = GenerateName(displayName);
name = GenerateContentTypeNameFromDisplayName(displayName);
}
while ( _contentDefinitionManager.GetTypeDefinition(name) != null )
@@ -185,10 +185,10 @@ namespace Orchard.ContentTypes.Services {
}
public EditPartViewModel AddPart(CreatePartViewModel partViewModel) {
var name = GenerateName(partViewModel.Name);
var name = partViewModel.Name;
while (_contentDefinitionManager.GetPartDefinition(name) != null)
name = VersionName(name);
if (_contentDefinitionManager.GetPartDefinition(name) != null)
throw new OrchardException(T("Cannot add part named '{0}'. It already exists.", name));
if (!String.IsNullOrEmpty(name)) {
_contentDefinitionManager.AlterPartDefinition(name, builder => builder.Attachable());
@@ -241,13 +241,13 @@ namespace Orchard.ContentTypes.Services {
}
//gratuitously stolen from the RoutableService
public string GenerateName(string name) {
name = SafeName(name);
public string GenerateContentTypeNameFromDisplayName(string displayName) {
displayName = SafeName(displayName);
while ( _contentDefinitionManager.GetTypeDefinition(name) != null )
name = VersionName(name);
while ( _contentDefinitionManager.GetTypeDefinition(displayName) != null )
displayName = VersionName(displayName);
return name;
return displayName;
}
private static string VersionName(string name) {

View File

@@ -13,7 +13,7 @@ namespace Orchard.ContentTypes.Services {
void RemoveType(string name);
void AddPartToType(string partName, string typeName);
void RemovePartFromType(string partName, string typeName);
string GenerateName(string displayName);
string GenerateContentTypeNameFromDisplayName(string displayName);
IEnumerable<EditPartViewModel> GetParts(bool metadataPartsOnly);
EditPartViewModel GetPart(string name);