Skip to content

Commit d9d5dc5

Browse files
elit0451nielslyngsoebergmania
authored
Item tracking improvements (#11919)
* Adding TrackedReferencesController * Adding/changing views * Adding/Editing js files * RelationService changes * RelationRepository changes * Adding missing translations * Adding/Modifying tests * Beginning of #9125 migration * Introducing a new component + refactoring based on that * Abstracting + refactoring * Work on content unpublishing * Work on media.delete * Various small changes * Beginning of #9119 migration * Changes on content.delete * Various fixes * Adding new keys used in the listview bulk actions * Adding methods to get the items used in relations from array of ids * Adding the checkLinkedItems function to the trackedReferencesResource * Passing the selected items from a listview to unpublish and delete * Adding umb-tracked-references-listview * Adding umb-tracked-references-listview-table with language column * Fixes for tracked references * Changes in listview unpublish dialog * Changes in listview delete dialog * Removing Variants logic as it is not currently supported * Visual fixes * Closing dialogs on click * Fix wording * Fix breaking changes * Change to a single title "Items in use" instead of 2 different for Content and Media * No need for obsoleting because we can change new controllers * Return ActionResult from actions * V9: Prevent delete or unpublish of items that have references (#12047) * Introducing config settings that prevent delete or unpublish of items referenced by other items * Disable deletion of content items and show a new warning * Disable deletion of media items and show a new warning * Disable deletion of list view items * Disable unpublish and bulk unpublish * Add a new warning * V9: Displaying descendants in use as part of item tracking (#12039) * Replace HasReferencesInDescendants with GetPagedDescendantsInReferences * Display descendants in use on parent's info tab * Add getPagedDescendantsInReferences to trackedReferencesResource * Add lang keys for Descendants in use * Refactoring controller actions * Don't call check descendants usage when it is a new item * rename busfy to busy * always show references * rearrange for scrollbar to appear at the edge of the dialog * use the word referenced instead of used * change fallback texts * Added "IsDependency" to relation types * refactor of umb-tracked-references * rename checkLinkedItems to getPagedReferencedItems * rename check to load, to be consistent with the rest. * Refactored backend . Needs frontend fixes * Cleanup * Use filters * Front-end refactor to match refactored end-points * Fixed bug + warning * Fixed query (more then 2100 descensdants) and optimized it (using nested select instead of inner join). * remove comment * hideNoneDependencies including varying text for the configuration * Hack for SqlCE :( * some final adjustments for item tracking ui * Unbreak change Co-authored-by: Niels Lyngsø <[email protected]> Co-authored-by: Bjarke Berg <[email protected]>
1 parent 2ff2ae3 commit d9d5dc5

File tree

69 files changed

+1709
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1709
-303
lines changed

src/Umbraco.Core/Configuration/Models/ContentSettings.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ @keyframes umbraco-preview-badge--effect {{
157157
internal const string StaticLoginBackgroundImage = "assets/img/login.jpg";
158158
internal const string StaticLoginLogoImage = "assets/img/application/umbraco_logo_white.svg";
159159
internal const bool StaticHideBackOfficeLogo = false;
160+
internal const bool StaticDisableDeleteWhenReferenced = false;
161+
internal const bool StaticDisableUnpublishWhenReferenced = false;
160162

161163
/// <summary>
162164
/// Gets or sets a value for the content notification settings.
@@ -226,6 +228,18 @@ @keyframes umbraco-preview-badge--effect {{
226228
[DefaultValue(StaticHideBackOfficeLogo)]
227229
public bool HideBackOfficeLogo { get; set; } = StaticHideBackOfficeLogo;
228230

231+
/// <summary>
232+
/// Gets or sets a value indicating whether to disable the deletion of items referenced by other items.
233+
/// </summary>
234+
[DefaultValue(StaticDisableDeleteWhenReferenced)]
235+
public bool DisableDeleteWhenReferenced { get; set; } = StaticDisableDeleteWhenReferenced;
236+
237+
/// <summary>
238+
/// Gets or sets a value indicating whether to disable the unpublishing of items referenced by other items.
239+
/// </summary>
240+
[DefaultValue(StaticDisableUnpublishWhenReferenced)]
241+
public bool DisableUnpublishWhenReferenced { get; set; } = StaticDisableUnpublishWhenReferenced;
242+
229243
/// <summary>
230244
/// Get or sets the model representing the global content version cleanup policy
231245
/// </summary>

src/Umbraco.Core/Events/RelateOnCopyNotificationHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public void Handle(ContentCopiedNotification notification)
3333
Constants.Conventions.RelationTypes.RelateDocumentOnCopyName,
3434
true,
3535
Constants.ObjectTypes.Document,
36-
Constants.ObjectTypes.Document);
36+
Constants.ObjectTypes.Document,
37+
false);
3738

3839
_relationService.Save(relationType);
3940
}

src/Umbraco.Core/Models/ContentEditing/RelationTypeDisplay.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,11 @@ public RelationTypeDisplay()
5555
/// </summary>
5656
[DataMember(Name = "notifications")]
5757
public List<BackOfficeNotification> Notifications { get; private set; }
58+
59+
/// <summary>
60+
/// Gets or sets a boolean indicating whether the RelationType should be returned in "Used by"-queries.
61+
/// </summary>
62+
[DataMember(Name = "isDependency", IsRequired = true)]
63+
public bool IsDependency { get; set; }
5864
}
5965
}

src/Umbraco.Core/Models/ContentEditing/RelationTypeSave.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ public class RelationTypeSave : EntityBasic
2323
/// </summary>
2424
[DataMember(Name = "childObjectType", IsRequired = false)]
2525
public Guid? ChildObjectType { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets a boolean indicating whether the RelationType should be returned in "Used by"-queries.
29+
/// </summary>
30+
[DataMember(Name = "isDependency", IsRequired = true)]
31+
public bool IsDependency { get; set; }
2632
}
2733
}

src/Umbraco.Core/Models/IRelationType.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
namespace Umbraco.Cms.Core.Models
66
{
7+
public interface IRelationTypeWithIsDependency : IRelationType
8+
{
9+
/// <summary>
10+
/// Gets or sets a boolean indicating whether the RelationType should be returned in "Used by"-queries.
11+
/// </summary>
12+
[DataMember]
13+
bool IsDependency { get; set; }
14+
}
15+
716
public interface IRelationType : IEntity, IRememberBeingDirty
817
{
918
/// <summary>

src/Umbraco.Core/Models/Mapping/RelationMapDefinition.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ private void Map(IRelationType source, RelationTypeDisplay target, MapperContext
3030
target.ChildObjectType = source.ChildObjectType;
3131
target.Id = source.Id;
3232
target.IsBidirectional = source.IsBidirectional;
33+
34+
if (source is IRelationTypeWithIsDependency sourceWithIsDependency)
35+
{
36+
target.IsDependency = sourceWithIsDependency.IsDependency;
37+
}
3338
target.Key = source.Key;
3439
target.Name = source.Name;
3540
target.Alias = source.Alias;
@@ -74,6 +79,11 @@ private static void Map(RelationTypeSave source, IRelationType target, MapperCon
7479
target.ChildObjectType = source.ChildObjectType;
7580
target.Id = source.Id.TryConvertTo<int>().Result;
7681
target.IsBidirectional = source.IsBidirectional;
82+
if (target is IRelationTypeWithIsDependency targetWithIsDependency)
83+
{
84+
targetWithIsDependency.IsDependency = source.IsDependency;
85+
}
86+
7787
target.Key = source.Key;
7888
target.Name = source.Name;
7989
target.ParentObjectType = source.ParentObjectType;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using Umbraco.Cms.Core.Models.Entities;
4+
5+
namespace Umbraco.Cms.Core.Models
6+
{
7+
[DataContract(Name = "relationItem", Namespace = "")]
8+
public class RelationItem
9+
{
10+
[DataMember(Name = "id")]
11+
public int NodeId { get; set; }
12+
13+
[DataMember(Name = "key")]
14+
public Guid NodeKey { get; set; }
15+
16+
[DataMember(Name = "name")]
17+
public string NodeName { get; set; }
18+
19+
[DataMember(Name = "type")]
20+
public string NodeType { get; set; }
21+
22+
[DataMember(Name = "udi")]
23+
public Udi NodeUdi => Udi.Create(NodeType, NodeKey);
24+
25+
[DataMember(Name = "icon")]
26+
public string ContentTypeIcon { get; set; }
27+
28+
[DataMember(Name = "alias")]
29+
public string ContentTypeAlias { get; set; }
30+
31+
[DataMember(Name = "contentTypeName")]
32+
public string ContentTypeName { get; set; }
33+
34+
[DataMember(Name = "relationTypeName")]
35+
public string RelationTypeName { get; set; }
36+
37+
[DataMember(Name = "relationTypeIsBidirectional")]
38+
public bool RelationTypeIsBidirectional { get; set; }
39+
40+
[DataMember(Name = "relationTypeIsDependency")]
41+
public bool RelationTypeIsDependency { get; set; }
42+
43+
}
44+
}

src/Umbraco.Core/Models/RelationType.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,28 @@ namespace Umbraco.Cms.Core.Models
99
/// </summary>
1010
[Serializable]
1111
[DataContract(IsReference = true)]
12-
public class RelationType : EntityBase, IRelationType
12+
public class RelationType : EntityBase, IRelationType, IRelationTypeWithIsDependency
1313
{
1414
private string _name;
1515
private string _alias;
1616
private bool _isBidirectional;
17+
private bool _isDependency;
1718
private Guid? _parentObjectType;
1819
private Guid? _childObjectType;
1920

2021
public RelationType(string alias, string name)
21-
: this(name: name, alias: alias, false, null, null)
22+
: this(name: name, alias: alias, false, null, null, false)
2223
{
2324
}
2425

26+
[Obsolete("Use ctor with isDependency parameter")]
2527
public RelationType(string name, string alias, bool isBidrectional, Guid? parentObjectType, Guid? childObjectType)
28+
:this(name,alias,isBidrectional, parentObjectType, childObjectType, false)
29+
{
30+
31+
}
32+
33+
public RelationType(string name, string alias, bool isBidrectional, Guid? parentObjectType, Guid? childObjectType, bool isDependency)
2634
{
2735
if (name == null) throw new ArgumentNullException(nameof(name));
2836
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name));
@@ -32,6 +40,7 @@ public RelationType(string name, string alias, bool isBidrectional, Guid? parent
3240
_name = name;
3341
_alias = alias;
3442
_isBidirectional = isBidrectional;
43+
_isDependency = isDependency;
3544
_parentObjectType = parentObjectType;
3645
_childObjectType = childObjectType;
3746
}
@@ -88,5 +97,11 @@ public Guid? ChildObjectType
8897
set => SetPropertyValueAndDetectChanges(value, ref _childObjectType, nameof(ChildObjectType));
8998
}
9099

100+
101+
public bool IsDependency
102+
{
103+
get => _isDependency;
104+
set => SetPropertyValueAndDetectChanges(value, ref _isDependency, nameof(IsDependency));
105+
}
91106
}
92107
}

src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Umbraco.Cms.Core.Models;
44
using Umbraco.Cms.Core.Models.Entities;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Umbraco.Cms.Core.Models;
4+
using Umbraco.Cms.Core.Models.Entities;
5+
6+
namespace Umbraco.Cms.Core.Persistence.Repositories
7+
{
8+
public interface ITrackedReferencesRepository
9+
{
10+
IEnumerable<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
11+
IEnumerable<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
12+
IEnumerable<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
13+
}
14+
}

src/Umbraco.Core/Services/IRelationService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using Umbraco.Cms.Core.Models;
44
using Umbraco.Cms.Core.Models.Entities;
@@ -215,7 +215,7 @@ public interface IRelationService : IService
215215
/// <param name="pageIndex"></param>
216216
/// <param name="pageSize"></param>
217217
/// <param name="totalChildren"></param>
218-
/// <returns></returns>
218+
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/></returns>
219219
IEnumerable<IUmbracoEntity> GetPagedParentEntitiesByChildId(int id, long pageIndex, int pageSize, out long totalChildren, params UmbracoObjectTypes[] entityTypes);
220220

221221
/// <summary>
@@ -225,7 +225,7 @@ public interface IRelationService : IService
225225
/// <param name="pageIndex"></param>
226226
/// <param name="pageSize"></param>
227227
/// <param name="totalChildren"></param>
228-
/// <returns></returns>
228+
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/></returns>
229229
IEnumerable<IUmbracoEntity> GetPagedChildEntitiesByParentId(int id, long pageIndex, int pageSize, out long totalChildren, params UmbracoObjectTypes[] entityTypes);
230230

231231
/// <summary>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Umbraco.Cms.Core.Models;
2+
3+
namespace Umbraco.Cms.Core.Services
4+
{
5+
public interface ITrackedReferencesService
6+
{
7+
PagedResult<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency);
8+
9+
10+
PagedResult<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency);
11+
12+
13+
PagedResult<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency);
14+
}
15+
}

src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ internal static IUmbracoBuilder AddRepositories(this IUmbracoBuilder builder)
4747
builder.Services.AddUnique<IPublicAccessRepository, PublicAccessRepository>();
4848
builder.Services.AddUnique<IRedirectUrlRepository, RedirectUrlRepository>();
4949
builder.Services.AddUnique<IRelationRepository, RelationRepository>();
50+
builder.Services.AddUnique<ITrackedReferencesRepository, TrackedReferencesRepository>();
5051
builder.Services.AddUnique<IRelationTypeRepository, RelationTypeRepository>();
5152
builder.Services.AddUnique<IServerRegistrationRepository, ServerRegistrationRepository>();
5253
builder.Services.AddUnique<ITagRepository, TagRepository>();

src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ internal static IUmbracoBuilder AddServices(this IUmbracoBuilder builder)
6363
builder.Services.AddUnique<IServerRegistrationService, ServerRegistrationService>();
6464
builder.Services.AddUnique<IEntityService, EntityService>();
6565
builder.Services.AddUnique<IRelationService, RelationService>();
66+
builder.Services.AddUnique<ITrackedReferencesService, TrackedReferencesService>();
6667
builder.Services.AddUnique<IMacroService, MacroService>();
6768
builder.Services.AddUnique<IMemberTypeService, MemberTypeService>();
6869
builder.Services.AddUnique<IMemberGroupService, MemberGroupService>();

src/Umbraco.Infrastructure/Events/RelateOnTrashNotificationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void Handle(ContentMovedToRecycleBinNotification notification)
6565
var documentObjectType = Constants.ObjectTypes.Document;
6666
const string relationTypeName = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName;
6767

68-
relationType = new RelationType(relationTypeName, relationTypeAlias, false, documentObjectType, documentObjectType);
68+
relationType = new RelationType(relationTypeName, relationTypeAlias, false, documentObjectType, documentObjectType, false);
6969
_relationService.Save(relationType);
7070
}
7171

@@ -123,7 +123,7 @@ public void Handle(MediaMovedToRecycleBinNotification notification)
123123
{
124124
var documentObjectType = Constants.ObjectTypes.Document;
125125
const string relationTypeName = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteName;
126-
relationType = new RelationType(relationTypeName, relationTypeAlias, false, documentObjectType, documentObjectType);
126+
relationType = new RelationType(relationTypeName, relationTypeAlias, false, documentObjectType, documentObjectType, false);
127127
_relationService.Save(relationType);
128128
}
129129

src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,21 +421,21 @@ void InsertDataTypeDto(int id, string editorAlias, string dbType, string configu
421421

422422
private void CreateRelationTypeData()
423423
{
424-
var relationType = new RelationTypeDto { Id = 1, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias, ChildObjectType = Cms.Core.Constants.ObjectTypes.Document, ParentObjectType = Cms.Core.Constants.ObjectTypes.Document, Dual = true, Name = Cms.Core.Constants.Conventions.RelationTypes.RelateDocumentOnCopyName };
424+
var relationType = new RelationTypeDto { Id = 1, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias, ChildObjectType = Cms.Core.Constants.ObjectTypes.Document, ParentObjectType = Cms.Core.Constants.ObjectTypes.Document, Dual = true, Name = Cms.Core.Constants.Conventions.RelationTypes.RelateDocumentOnCopyName, IsDependency = false};
425425
relationType.UniqueId = CreateUniqueRelationTypeId(relationType.Alias, relationType.Name);
426426
_database.Insert(Cms.Core.Constants.DatabaseSchema.Tables.RelationType, "id", false, relationType);
427-
relationType = new RelationTypeDto { Id = 2, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias, ChildObjectType = Cms.Core.Constants.ObjectTypes.Document, ParentObjectType = Cms.Core.Constants.ObjectTypes.Document, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName };
427+
relationType = new RelationTypeDto { Id = 2, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias, ChildObjectType = Cms.Core.Constants.ObjectTypes.Document, ParentObjectType = Cms.Core.Constants.ObjectTypes.Document, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteName, IsDependency = false };
428428
relationType.UniqueId = CreateUniqueRelationTypeId(relationType.Alias, relationType.Name);
429429
_database.Insert(Cms.Core.Constants.DatabaseSchema.Tables.RelationType, "id", false, relationType);
430-
relationType = new RelationTypeDto { Id = 3, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias, ChildObjectType = Cms.Core.Constants.ObjectTypes.Media, ParentObjectType = Cms.Core.Constants.ObjectTypes.Media, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteName };
430+
relationType = new RelationTypeDto { Id = 3, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias, ChildObjectType = Cms.Core.Constants.ObjectTypes.Media, ParentObjectType = Cms.Core.Constants.ObjectTypes.Media, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteName, IsDependency = false };
431431
relationType.UniqueId = CreateUniqueRelationTypeId(relationType.Alias, relationType.Name);
432432
_database.Insert(Cms.Core.Constants.DatabaseSchema.Tables.RelationType, "id", false, relationType);
433433

434-
relationType = new RelationTypeDto { Id = 4, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelatedMediaAlias, ChildObjectType = null, ParentObjectType = null, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelatedMediaName };
434+
relationType = new RelationTypeDto { Id = 4, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelatedMediaAlias, ChildObjectType = null, ParentObjectType = null, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelatedMediaName, IsDependency = true };
435435
relationType.UniqueId = CreateUniqueRelationTypeId(relationType.Alias, relationType.Name);
436436
_database.Insert(Cms.Core.Constants.DatabaseSchema.Tables.RelationType, "id", false, relationType);
437437

438-
relationType = new RelationTypeDto { Id = 5, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelatedDocumentAlias, ChildObjectType = null, ParentObjectType = null, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelatedDocumentName };
438+
relationType = new RelationTypeDto { Id = 5, Alias = Cms.Core.Constants.Conventions.RelationTypes.RelatedDocumentAlias, ChildObjectType = null, ParentObjectType = null, Dual = false, Name = Cms.Core.Constants.Conventions.RelationTypes.RelatedDocumentName, IsDependency = true };
439439
relationType.UniqueId = CreateUniqueRelationTypeId(relationType.Alias, relationType.Name);
440440
_database.Insert(Cms.Core.Constants.DatabaseSchema.Tables.RelationType, "id", false, relationType);
441441
}

src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ protected void DefinePlan()
283283

284284
// TO 9.4.0
285285
To<AddScheduledPublishingLock>("{DBBA1EA0-25A1-4863-90FB-5D306FB6F1E1}");
286+
To<UpdateRelationTypesToHandleDependencies>("{DED98755-4059-41BB-ADBD-3FEAB12D1D7B}");
286287
}
287288
}
288289
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Linq;
2+
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
3+
using Umbraco.Extensions;
4+
5+
6+
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_4_0
7+
{
8+
internal class UpdateRelationTypesToHandleDependencies : MigrationBase
9+
{
10+
public UpdateRelationTypesToHandleDependencies(IMigrationContext context)
11+
: base(context)
12+
{
13+
}
14+
15+
protected override void Migrate()
16+
{
17+
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList();
18+
19+
AddColumnIfNotExists<RelationTypeDto>(columns, "isDependency");
20+
21+
var aliasesWithDependencies = new[]
22+
{
23+
Core.Constants.Conventions.RelationTypes.RelatedDocumentAlias,
24+
Core.Constants.Conventions.RelationTypes.RelatedMediaAlias
25+
};
26+
27+
Database.Execute(
28+
Sql()
29+
.Update<RelationTypeDto>(u => u.Set(x => x.IsDependency, true))
30+
.WhereIn<RelationTypeDto>(x => x.Alias, aliasesWithDependencies));
31+
32+
}
33+
}
34+
}

src/Umbraco.Infrastructure/Persistence/Dtos/RelationTypeDto.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ internal class RelationTypeDto
4040
[Length(100)]
4141
[Index(IndexTypes.UniqueNonClustered, Name = "IX_umbracoRelationType_alias")]
4242
public string Alias { get; set; }
43+
44+
[Constraint(Default = "0")]
45+
[Column("isDependency")]
46+
public bool IsDependency { get; set; }
4347
}
4448
}

0 commit comments

Comments
 (0)