Skip to content

Commit

Permalink
Fix Sqlite database locking issue (#13246)
Browse files Browse the repository at this point in the history
* Add locking for creating scope

* Lock the repository instead

* Add scope in action instead of locking in service

* Fix up post-merge

Co-authored-by: Zeegaan <nge@umbraco.dk>
  • Loading branch information
Zeegaan and Zeegaan authored Oct 24, 2022
1 parent b6af5de commit 73bbff0
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class ContentTypeController : ContentTypeControllerBase<IContentType>
private readonly ILogger<ContentTypeController> _logger;
private readonly PackageDataInstallation _packageDataInstallation;
private readonly BlockGridSampleHelper _blockGridSampleHelper;
private readonly ICoreScopeProvider _coreScopeProvider;

private readonly PropertyEditorCollection _propertyEditors;
// TODO: Split this controller apart so that authz is consistent, currently we need to authz each action individually.
Expand Down Expand Up @@ -99,7 +101,7 @@ public ContentTypeController(
{
}

[ActivatorUtilitiesConstructor]
[Obsolete("Please use constructor that takes an ICoreScopeProvider")]
public ContentTypeController(
ICultureDictionary cultureDictionary,
IContentTypeService contentTypeService,
Expand All @@ -120,6 +122,52 @@ public ContentTypeController(
EditorValidatorCollection editorValidatorCollection,
PackageDataInstallation packageDataInstallation,
BlockGridSampleHelper blockGridSampleHelper)
: this(
cultureDictionary,
contentTypeService,
mediaTypeService,
memberTypeService,
umbracoMapper,
localizedTextService,
serializer,
propertyEditors,
backofficeSecurityAccessor,
dataTypeService,
shortStringHelper,
fileService,
logger,
contentService,
contentTypeBaseServiceProvider,
hostingEnvironment,
editorValidatorCollection,
packageDataInstallation,
blockGridSampleHelper,
StaticServiceProvider.Instance.GetRequiredService<ICoreScopeProvider>())
{
}

[ActivatorUtilitiesConstructor]
public ContentTypeController(
ICultureDictionary cultureDictionary,
IContentTypeService contentTypeService,
IMediaTypeService mediaTypeService,
IMemberTypeService memberTypeService,
IUmbracoMapper umbracoMapper,
ILocalizedTextService localizedTextService,
IEntityXmlSerializer serializer,
PropertyEditorCollection propertyEditors,
IBackOfficeSecurityAccessor backofficeSecurityAccessor,
IDataTypeService dataTypeService,
IShortStringHelper shortStringHelper,
IFileService fileService,
ILogger<ContentTypeController> logger,
IContentService contentService,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IHostingEnvironment hostingEnvironment,
EditorValidatorCollection editorValidatorCollection,
PackageDataInstallation packageDataInstallation,
BlockGridSampleHelper blockGridSampleHelper,
ICoreScopeProvider coreScopeProvider)
: base(
cultureDictionary,
editorValidatorCollection,
Expand All @@ -144,6 +192,7 @@ public ContentTypeController(
_hostingEnvironment = hostingEnvironment;
_packageDataInstallation = packageDataInstallation;
_blockGridSampleHelper = blockGridSampleHelper;
_coreScopeProvider = coreScopeProvider;
}

[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentTypes)]
Expand Down Expand Up @@ -444,6 +493,7 @@ public IActionResult PostRenameContainer(int id, string name)

private ITemplate? CreateTemplateForContentType(string contentTypeAlias, string? contentTypeName)
{
using ICoreScope scope = _coreScopeProvider.CreateCoreScope();
ITemplate? template = _fileService.GetTemplate(contentTypeAlias);
if (template == null)
{
Expand All @@ -460,6 +510,8 @@ public IActionResult PostRenameContainer(int id, string name)
template = tryCreateTemplate.Result?.Entity;
}

scope.Complete();

return template;
}

Expand Down

0 comments on commit 73bbff0

Please sign in to comment.