Fixing MasterContentType for DocumentTypes.

Adding ParentId "listener" to the repositories that uses ParentId, so we can ensure that the path is updated correctly.
Fixing how AllowedTemplates are saved upon creation of a new DocumentType.
Ensuring DocumentType.Save is called when creting a new DocumentType.
Fixing Publish/RePublish of Content with previously published children.
Removing UpdateDocumentCache in the save event of editContent.aspx.cs as its now handled in the new api.
Rewiring template methods on DocumentType class to use the new api.
This commit is contained in:
Morten Christensen
2012-12-20 14:29:08 -01:00
parent 6a05c4d968
commit 9f2d41286c
14 changed files with 109 additions and 66 deletions

View File

@@ -298,7 +298,7 @@ namespace Umbraco.Core.Persistence.Repositories
}
//If Published state has changed then previous versions should have their publish state reset
if (shouldCreateNewVersion && entity.Published)
if (((ICanBeDirty)entity).IsPropertyDirty("Published"))
{
var publishedDocs = Database.Fetch<DocumentDto>("WHERE nodeId = @Id AND published = @IsPublished", new { Id = entity.Id, IsPublished = true });
foreach (var doc in publishedDocs)

View File

@@ -144,6 +144,7 @@ namespace Umbraco.Core.Persistence.Repositories
string.Format("DELETE FROM umbracoUser2NodePermission WHERE nodeId = @Id"),
string.Format("DELETE FROM cmsTagRelationship WHERE nodeId = @Id"),
string.Format("DELETE FROM cmsContentTypeAllowedContentType WHERE Id = @Id"),
string.Format("DELETE FROM cmsContentTypeAllowedContentType WHERE AllowedId = @Id"),
string.Format("DELETE FROM cmsContentType2ContentType WHERE parentContentTypeId = @Id"),
string.Format("DELETE FROM cmsContentType2ContentType WHERE childContentTypeId = @Id"),
string.Format("DELETE FROM cmsPropertyType WHERE contentTypeId = @Id"),
@@ -191,6 +192,13 @@ namespace Umbraco.Core.Persistence.Repositories
//Updates Modified date
((ContentType)entity).UpdatingEntity();
//Look up parent to get and set the correct Path if ParentId has changed
if (((ICanBeDirty)entity).IsPropertyDirty("ParentId"))
{
var parent = Database.First<NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
entity.Path = string.Concat(parent.Path, ",", entity.Id);
}
var factory = new ContentTypeFactory(NodeObjectTypeId);
var dto = factory.BuildDto(entity);

View File

@@ -153,6 +153,13 @@ namespace Umbraco.Core.Persistence.Repositories
//Updates Modified date and Version Guid
((DataTypeDefinition)entity).UpdatingEntity();
//Look up parent to get and set the correct Path if ParentId has changed
if (((ICanBeDirty)entity).IsPropertyDirty("ParentId"))
{
var parent = Database.First<NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
entity.Path = string.Concat(parent.Path, ",", entity.Id);
}
var factory = new DataTypeDefinitionFactory(NodeObjectTypeId);
//Look up DataTypeDefinition entry to get Primary for updating the DTO
var dataTypeDto = Database.SingleOrDefault<DataTypeDto>("WHERE nodeId = @Id", new { Id = entity.Id });

View File

@@ -234,6 +234,13 @@ namespace Umbraco.Core.Persistence.Repositories
//Updates Modified date
((Models.Media)entity).UpdatingEntity();
//Look up parent to get and set the correct Path if ParentId has changed
if (((ICanBeDirty)entity).IsPropertyDirty("ParentId"))
{
var parent = Database.First<NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
entity.Path = string.Concat(parent.Path, ",", entity.Id);
}
var factory = new MediaFactory(NodeObjectTypeId, entity.Id);
//Look up Content entry to get Primary for updating the DTO
var contentDto = Database.SingleOrDefault<ContentDto>("WHERE nodeId = @Id", new { Id = entity.Id });

View File

@@ -160,6 +160,13 @@ namespace Umbraco.Core.Persistence.Repositories
//Updates Modified date
((MediaType)entity).UpdatingEntity();
//Look up parent to get and set the correct Path if ParentId has changed
if (((ICanBeDirty)entity).IsPropertyDirty("ParentId"))
{
var parent = Database.First<NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
entity.Path = string.Concat(parent.Path, ",", entity.Id);
}
var factory = new MediaTypeFactory(NodeObjectTypeId);
var dto = factory.BuildDto(entity);

View File

@@ -226,6 +226,13 @@ namespace Umbraco.Core.Persistence.Repositories
}
}
//Look up parent to get and set the correct Path if ParentId has changed
if (((ICanBeDirty)entity).IsPropertyDirty("ParentId"))
{
var parent = Database.First<NodeDto>("WHERE id = @ParentId", new { ParentId = ((Template)entity).ParentId });
entity.Path = string.Concat(parent.Path, ",", entity.Id);
}
//Get TemplateDto from db to get the Primary key of the entity
var templateDto = Database.SingleOrDefault<TemplateDto>("WHERE nodeId = @Id", new { Id = entity.Id });
//Save updated entity to db

View File

@@ -539,17 +539,7 @@ namespace Umbraco.Core.Services
{
//TODO Refactor this so omitCacheRefresh isn't exposed in the public method, but only in an internal one as its purely there for legacy reasons.
//Look for children and unpublish them if any exists, otherwise just unpublish the passed in Content.
var children = GetChildrenDeep(content.Id);
var hasChildren = children.Any();
if (hasChildren)
children.Add(content);
var unpublished = hasChildren
? _publishingStrategy.UnPublish(children, userId)
: _publishingStrategy.UnPublish(content, userId);
var unpublished = _publishingStrategy.UnPublish(content, userId);
if (unpublished)
{
var uow = _uowProvider.GetUnitOfWork();
@@ -557,24 +547,8 @@ namespace Umbraco.Core.Services
{
repository.AddOrUpdate(content);
if (hasChildren)
{
foreach (var child in children)
{
SetWriter(child, userId);
repository.AddOrUpdate(child);
}
}
//Remove 'published' xml from the cmsContentXml table for the unpublished content and its (possible) children
//Remove 'published' xml from the cmsContentXml table for the unpublished content
uow.Database.Delete<ContentXmlDto>("WHERE nodeId = @Id", new {Id = content.Id});
if (hasChildren)
{
foreach (var child in children)
{
uow.Database.Delete<ContentXmlDto>("WHERE nodeId = @Id", new {Id = child.Id});
}
}
uow.Commit();
}
@@ -653,6 +627,15 @@ namespace Umbraco.Core.Services
if (omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(content);
if (HasChildren(content.Id))
{
var children = GetChildrenDeep(content.Id);
var shouldBeRepublished = children.Where(child => HasPublishedVersion(child.Id));
if (omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(shouldBeRepublished, false);
}
if (Saved != null)
Saved(content, e);

View File

@@ -10,14 +10,14 @@ NOTES:
* Compression/Combination/Minification is not enabled unless debug="false" is specified on the 'compiliation' element in the web.config
* A new version will invalidate both client and server cache and create new persisted files
-->
<clientDependency version="40" fileDependencyExtensions=".js,.css">
<clientDependency version="41" fileDependencyExtensions=".js,.css">
<fileRegistration defaultProvider="LoaderControlProvider">
<providers>
<add name="PageHeaderProvider" type="ClientDependency.Core.FileRegistration.Providers.PageHeaderProvider, ClientDependency.Core"/>
<add name="LazyLoadProvider" type="ClientDependency.Core.FileRegistration.Providers.LazyLoadProvider, ClientDependency.Core"/>
<add name="LoaderControlProvider" type="ClientDependency.Core.FileRegistration.Providers.LoaderControlProvider, ClientDependency.Core"/>
<add name="PlaceHolderProvider" type="ClientDependency.Core.FileRegistration.Providers.PlaceHolderProvider, ClientDependency.Core" enableCompositeFiles="true" javascriptPlaceHolderId="JavaScriptPlaceHolder" cssPlaceHolderId="CssPlaceHolder"/>
<add name="PageHeaderProvider" type="ClientDependency.Core.FileRegistration.Providers.PageHeaderProvider, ClientDependency.Core" />
<add name="LazyLoadProvider" type="ClientDependency.Core.FileRegistration.Providers.LazyLoadProvider, ClientDependency.Core" />
<add name="LoaderControlProvider" type="ClientDependency.Core.FileRegistration.Providers.LoaderControlProvider, ClientDependency.Core" />
<add name="PlaceHolderProvider" type="ClientDependency.Core.FileRegistration.Providers.PlaceHolderProvider, ClientDependency.Core" enableCompositeFiles="true" javascriptPlaceHolderId="JavaScriptPlaceHolder" cssPlaceHolderId="CssPlaceHolder" />
<!-- Used for loading dependencies in Canvas mode -->
<add name="CanvasProvider" type="umbraco.presentation.LiveEditing.CanvasClientDependencyProvider, umbraco" />
</providers>
@@ -26,8 +26,8 @@ NOTES:
<!-- This section is used for MVC only -->
<mvc defaultRenderer="StandardRenderer">
<renderers>
<add name="StandardRenderer" type="ClientDependency.Core.FileRegistration.Providers.StandardRenderer, ClientDependency.Core"/>
<add name="LazyLoadRenderer" type="ClientDependency.Core.FileRegistration.Providers.LazyLoadRenderer, ClientDependency.Core"/>
<add name="StandardRenderer" type="ClientDependency.Core.FileRegistration.Providers.StandardRenderer, ClientDependency.Core" />
<add name="LazyLoadRenderer" type="ClientDependency.Core.FileRegistration.Providers.LazyLoadRenderer, ClientDependency.Core" />
</renderers>
</mvc>
@@ -41,20 +41,12 @@ NOTES:
-->
<compositeFiles defaultProvider="defaultFileProcessingProvider" compositeFileHandlerPath="~/DependencyHandler.axd">
<fileProcessingProviders>
<add name="CompositeFileProcessor"
type="ClientDependency.Core.CompositeFiles.Providers.CompositeFileProcessingProvider, ClientDependency.Core"
enableCssMinify="true"
enableJsMinify="true"
persistFiles="true"
compositeFilePath="~/App_Data/TEMP/ClientDependency"
urlType="Base64QueryStrings" />
<add name="CompositeFileProcessor" type="ClientDependency.Core.CompositeFiles.Providers.CompositeFileProcessingProvider, ClientDependency.Core" enableCssMinify="true" enableJsMinify="true" persistFiles="true" compositeFilePath="~/App_Data/TEMP/ClientDependency" urlType="Base64QueryStrings" />
</fileProcessingProviders>
<!-- A file map provider stores references to dependency files by an id to be used in the handler URL when using the MappedId Url type -->
<fileMapProviders>
<add name="XmlFileMap"
type="ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper, ClientDependency.Core"
mapPath="~/App_Data/TEMP/ClientDependency"/>
<add name="XmlFileMap" type="ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper, ClientDependency.Core" mapPath="~/App_Data/TEMP/ClientDependency" />
</fileMapProviders>
<!--

View File

@@ -59,6 +59,8 @@ namespace umbraco
dt.MasterContentType = TypeID;
}
dt.Save();
m_returnUrl = "settings/editNodeTypeNew.aspx?id=" + dt.Id.ToString();
return true;

View File

@@ -319,7 +319,6 @@ namespace umbraco.cms.presentation
{
ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editContentPublishedHeader", null), ui.Text("speechBubbles", "editContentPublishedText", null));
library.UpdateDocumentCache(_document);
littPublishStatus.Text = ui.Text("content", "lastPublished", base.getUser()) + ": " + _document.VersionDate.ToString() + "<br/>";

View File

@@ -636,6 +636,8 @@ namespace umbraco.cms.businesslogic
SqlHelper.CreateParameter("@parentContentTypeId", parentContentTypeId),
SqlHelper.CreateParameter("@childContentTypeId", Id));
MasterContentTypes.Add(parentContentTypeId);
}
}

View File

@@ -114,11 +114,11 @@ namespace umbraco.cms.businesslogic.media
if (!e.Cancel)
{
ApplicationContext.Current.Services.ContentTypeService.Save(_mediaType);
//Ensure that MediaTypes are reloaded from db by clearing cache
InMemoryCacheProvider.Current.Clear();
ApplicationContext.Current.Services.ContentTypeService.Save(_mediaType);
base.Save();
FireBeforeSave(e);

View File

@@ -781,7 +781,7 @@ namespace umbraco.cms.businesslogic.web
if (!e.Cancel)
{
var result = ApplicationContext.Current.Services.ContentService.Publish(Content, u.Id, true);
var result = ApplicationContext.Current.Services.ContentService.Publish(Content, u.Id);
_published = result;
FireAfterPublish(e);

View File

@@ -220,6 +220,7 @@ namespace umbraco.cms.businesslogic.web
}
}
[Obsolete("Deprecated, Use SetDefaultTemplate() on Umbraco.Core.Models.ContentType", false)]
public int DefaultTemplate
{
get { return _defaultTemplate; }
@@ -227,15 +228,20 @@ namespace umbraco.cms.businesslogic.web
{
RemoveDefaultTemplate();
_defaultTemplate = value;
if (_defaultTemplate != 0)
SqlHelper.ExecuteNonQuery("update cmsDocumentType set IsDefault = 1 where contentTypeNodeId = " +
Id.ToString() + " and TemplateNodeId = " + value.ToString());
{
//SqlHelper.ExecuteNonQuery("update cmsDocumentType set IsDefault = 1 where contentTypeNodeId = " + Id.ToString() + " and TemplateNodeId = " + value.ToString());
var template = ApplicationContext.Current.Services.FileService.GetTemplate(_defaultTemplate);
_contentType.SetDefaultTemplate(template);
}
}
}
/// <summary>
/// Gets/sets the allowed templates for this document type.
/// </summary>
[Obsolete("Deprecated, Use AllowedTemplates property on Umbraco.Core.Models.ContentType", false)]
public template.Template[] allowedTemplates
{
get
@@ -254,12 +260,16 @@ namespace umbraco.cms.businesslogic.web
set
{
clearTemplates();
var templates = new List<ITemplate>();
foreach (template.Template t in value)
{
SqlHelper.ExecuteNonQuery("Insert into cmsDocumentType (contentTypeNodeId, templateNodeId) values (" +
Id + "," + t.Id + ")");
//SqlHelper.ExecuteNonQuery("Insert into cmsDocumentType (contentTypeNodeId, templateNodeId) values (" + Id + "," + t.Id + ")");
var template = ApplicationContext.Current.Services.FileService.GetTemplate(t.Id);
templates.Add(template);
_templateIds.Add(t.Id);
}
_contentType.AllowedTemplates = templates;
}
}
@@ -302,6 +312,7 @@ namespace umbraco.cms.businesslogic.web
#region Public Methods
[Obsolete("Deprecated, Use RemoveTemplate() on Umbraco.Core.Models.ContentType", false)]
public void RemoveTemplate(int templateId)
{
// remove if default template
@@ -313,9 +324,12 @@ namespace umbraco.cms.businesslogic.web
// remove from list of document type templates
if (_templateIds.Contains(templateId))
{
SqlHelper.ExecuteNonQuery("delete from cmsDocumentType where contentTypeNodeId = @id and templateNodeId = @templateId",
SqlHelper.CreateParameter("@id", this.Id), SqlHelper.CreateParameter("@templateId", templateId)
);
/*SqlHelper.ExecuteNonQuery("delete from cmsDocumentType where contentTypeNodeId = @id and templateNodeId = @templateId",
SqlHelper.CreateParameter("@id", this.Id), SqlHelper.CreateParameter("@templateId", templateId));*/
var template = _contentType.AllowedTemplates.FirstOrDefault(x => x.Id == templateId);
if (template != null)
_contentType.RemoveTemplate(template);
_templateIds.Remove(templateId);
}
}
@@ -337,21 +351,21 @@ namespace umbraco.cms.businesslogic.web
throw new ArgumentException("Can't delete a Document Type used as a Master Content Type. Please remove all references first!");
}
// delete all documents of this type
Document.DeleteFromType(this);
// Remove from cache
FlushFromCache(Id);
ApplicationContext.Current.Services.ContentTypeService.Delete(_contentType);
clearTemplates();
// Delete contentType
base.delete();
FireAfterDelete(e);
}
}
public void clearTemplates()
{
SqlHelper.ExecuteNonQuery("Delete from cmsDocumentType where contentTypeNodeId =" + Id);
//SqlHelper.ExecuteNonQuery("Delete from cmsDocumentType where contentTypeNodeId =" + Id);
_contentType.AllowedTemplates = new List<ITemplate>();
_templateIds.Clear();
}
@@ -439,10 +453,16 @@ namespace umbraco.cms.businesslogic.web
return doc;
}
[Obsolete("Deprecated, Use RemoveTemplate() on Umbraco.Core.Models.ContentType", false)]
public void RemoveDefaultTemplate()
{
_defaultTemplate = 0;
SqlHelper.ExecuteNonQuery("update cmsDocumentType set IsDefault = 0 where contentTypeNodeId = " + Id.ToString());
var template = _contentType.DefaultTemplate;
if(template != null)
_contentType.RemoveTemplate(template);
//SqlHelper.ExecuteNonQuery("update cmsDocumentType set IsDefault = 0 where contentTypeNodeId = " + Id.ToString());
}
public bool HasTemplate()
@@ -460,11 +480,20 @@ namespace umbraco.cms.businesslogic.web
if (!e.Cancel)
{
//Ensure that MediaTypes are reloaded from db by clearing cache
InMemoryCacheProvider.Current.Clear();
if (MasterContentType != 0)
_contentType.ParentId = MasterContentType;
foreach (var masterContentType in MasterContentTypes)
{
var contentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(masterContentType);
_contentType.AddContentType(contentType);
}
ApplicationContext.Current.Services.ContentTypeService.Save(_contentType);
//Ensure that DocumentTypes are reloaded from db by clearing cache
InMemoryCacheProvider.Current.Clear();
base.Save();
FireAfterSave(e);
}