Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Extensions;

namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_16_3_0;

Expand Down Expand Up @@ -69,43 +71,43 @@

private void IfNotExistsCreateBytesLabel()
{
if (Database.Exists<NodeDto>(Constants.DataTypes.LabelBytes))
if (NodeExists(_labelBytesDataTypeKey))
{
return;
}

var nodeDto = new NodeDto
{
NodeId = Constants.DataTypes.LabelBytes,
Trashed = false,
ParentId = -1,
UserId = -1,
Level = 1,
Path = "-1," + Constants.DataTypes.LabelBytes,
SortOrder = 40,
UniqueId = _labelBytesDataTypeKey,
Text = "Label (bytes)",
NodeObjectType = Constants.ObjectTypes.DataType,
CreateDate = DateTime.Now,
};

_ = Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto);
Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto);

var dataTypeDto = new DataTypeDto
{
NodeId = Constants.DataTypes.LabelBytes,
EditorAlias = Constants.PropertyEditors.Aliases.Label,
EditorUiAlias = "Umb.PropertyEditorUi.Label",
DbType = nameof(ValueStorageType.Nvarchar),
Configuration = "{\"umbracoDataValueType\":\"BIGINT\", \"labelTemplate\":\"{=value | bytes}\"}",
};

_ = Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto);
Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto);

Check warning on line 105 in src/Umbraco.Infrastructure/Migrations/Upgrade/V_16_3_0/MigrateMediaTypeLabelProperties.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Code Duplication

The module contains 2 functions with similar structure: IfNotExistsCreateBytesLabel,IfNotExistsCreatePixelsLabel. Avoid duplicated, aka copy-pasted, code inside the module. More duplication lowers the code health.
}

private void IfNotExistsCreatePixelsLabel()
{
if (Database.Exists<NodeDto>(Constants.DataTypes.LabelPixels))
if (NodeExists(_labelPixelsDataTypeKey))
{
return;
}
Expand All @@ -125,7 +127,7 @@
CreateDate = DateTime.Now,
};

_ = Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto);
Database.Insert(Constants.DatabaseSchema.Tables.Node, "id", false, nodeDto);

var dataTypeDto = new DataTypeDto
{
Expand All @@ -136,7 +138,16 @@
Configuration = "{\"umbracoDataValueType\":\"INT\", \"labelTemplate\":\"{=value}px\"}",
};

_ = Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto);
Database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, dataTypeDto);
}

private bool NodeExists(Guid uniqueId)
{
Sql<ISqlContext> sql = Database.SqlContext.Sql()
.Select<NodeDto>(x => x.NodeId)
.From<NodeDto>()
.Where<NodeDto>(x => x.UniqueId == uniqueId);
return Database.FirstOrDefault<NodeDto>(sql) is not null;
}

private async Task MigrateMediaTypeLabels()
Expand Down