Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V14 bugfix. added missing package scope #14711

Merged
merged 1 commit into from Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,4 +1,4 @@
using System.ComponentModel.DataAnnotations;

Check notice on line 1 in src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CreatedPackageSchemaRepository.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v14/dev)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 5.04 to 5.11, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
using System.Data;
using System.Globalization;
using System.IO.Compression;
Expand Down Expand Up @@ -168,7 +168,12 @@
.From<CreatedPackageSchemaDto>()
.Where<CreatedPackageSchemaDto>(x => x.PackageId == key);

List<CreatedPackageSchemaDto> schemaDtos = Database.Fetch<CreatedPackageSchemaDto>(query);
if (_scopeAccessor.AmbientScope is null)
{
return null;
}

List<CreatedPackageSchemaDto> schemaDtos = _scopeAccessor.AmbientScope.Database.Fetch<CreatedPackageSchemaDto>(query);

if (schemaDtos.IsCollectionEmpty())
{
Expand Down Expand Up @@ -215,7 +220,13 @@
.SelectCount()
.From<CreatedPackageSchemaDto>()
.Where<CreatedPackageSchemaDto>(x => x.Name == definition.Name);
var exists = Database.ExecuteScalar<int>(query);

if (_scopeAccessor.AmbientScope is null)
{
return false;
}

var exists = _scopeAccessor.AmbientScope.Database.ExecuteScalar<int>(query);

if (exists > 0)
{
Expand Down
Expand Up @@ -161,7 +161,12 @@
}

/// <inheritdoc/>
public Task<PackageDefinition?> GetCreatedPackageByKeyAsync(Guid key) => Task.FromResult(_createdPackages.GetByKey(key));
public Task<PackageDefinition?> GetCreatedPackageByKeyAsync(Guid key)
{
using ICoreScope scope = _coreScopeProvider.CreateCoreScope(autoComplete: true);

return Task.FromResult(_createdPackages.GetByKey(key));
}

[Obsolete("Use CreateCreatedPackageAsync or UpdateCreatedPackageAsync instead. Scheduled for removal in Umbraco 15.")]
public bool SaveCreatedPackage(PackageDefinition definition)
Expand Down Expand Up @@ -197,13 +202,15 @@
/// <inheritdoc/>
public async Task<Attempt<PackageDefinition, PackageOperationStatus>> UpdateCreatedPackageAsync(PackageDefinition package, Guid userKey)
{
using ICoreScope scope = _coreScopeProvider.CreateCoreScope();
if (_createdPackages.SavePackage(package) == false)
{
return Attempt.FailWithStatus(PackageOperationStatus.NotFound, package);
}

int currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId;
_auditService.Add(AuditType.New, currentUserId, -1, "Package", $"Created package '{package.Name}' updated. Package key: {package.PackageId}");
scope.Complete();

Check warning on line 213 in src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v14/dev)

❌ New issue: Code Duplication

The module contains 2 functions with similar structure: CreateCreatedPackageAsync,UpdateCreatedPackageAsync. Avoid duplicated, aka copy-pasted, code inside the module. More duplication lowers the code health.
return await Task.FromResult(Attempt.SucceedWithStatus(PackageOperationStatus.Success, package));
}

Expand Down