<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Dtos;

namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
{
    public class ConvertRelatedLinksToMultiUrlPicker : MigrationBase
    {
        public ConvertRelatedLinksToMultiUrlPicker(IMigrationContext context) : base(context)
        { }

        public override void Migrate()
        {
            var sqlDataTypes = Sql()
                .Select<DataTypeDto>()
                .From<DataTypeDto>()
                .Where<DataTypeDto>(x => x.EditorAlias == "Umbraco.RelatedLinks"
                                         || x.EditorAlias == "Umbraco.RelatedLinks2");

            var dataTypes = Database.Fetch<DataTypeDto>(sqlDataTypes);
            var dataTypeIds = dataTypes.Select(x => x.NodeId).ToList();

            var sqlPropertyTpes = Sql()
                .Select<PropertyTypeDto>()
                .From<PropertyTypeDto>()
                .Where<PropertyTypeDto>(x => dataTypeIds.Contains(x.DataTypeId));

            var propertyTypeIds = Database.Fetch<PropertyTypeDto>(sqlPropertyTpes).Select(x => x.Id);

            var sqlPropertyData = Sql()
                .Select<PropertyDataDto>()
                .From<PropertyDataDto>()
                .Where<PropertyDataDto>(x => propertyTypeIds.Contains(x.PropertyTypeId));

            var properties = Database.Fetch<PropertyDataDto>(sqlPropertyData);

            // Create a Multi URL Picker datatype for the converted RelatedLinks data
            if (properties.Any() == false)
                return;

            foreach (var property in properties)<commit_msg>Fixes issue with ConvertRelatedLinksToMultiUrlPicker migration since it produces invalid SQL if there are no values in the .Contains calls<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Dtos;

namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
{
    public class ConvertRelatedLinksToMultiUrlPicker : MigrationBase
    {
        public ConvertRelatedLinksToMultiUrlPicker(IMigrationContext context) : base(context)
        { }

        public override void Migrate()
        {
            var sqlDataTypes = Sql()
                .Select<DataTypeDto>()
                .From<DataTypeDto>()
                .Where<DataTypeDto>(x => x.EditorAlias == "Umbraco.RelatedLinks"
                                         || x.EditorAlias == "Umbraco.RelatedLinks2");

            var dataTypes = Database.Fetch<DataTypeDto>(sqlDataTypes);
            var dataTypeIds = dataTypes.Select(x => x.NodeId).ToList();

            if (dataTypeIds.Count == 0) return;

            var sqlPropertyTpes = Sql()
                .Select<PropertyTypeDto>()
                .From<PropertyTypeDto>()
                .Where<PropertyTypeDto>(x => dataTypeIds.Contains(x.DataTypeId));

            var propertyTypeIds = Database.Fetch<PropertyTypeDto>(sqlPropertyTpes).Select(x => x.Id).ToList();

            if (propertyTypeIds.Count == 0) return;

            var sqlPropertyData = Sql()
                .Select<PropertyDataDto>()
                .From<PropertyDataDto>()
                .Where<PropertyDataDto>(x => propertyTypeIds.Contains(x.PropertyTypeId));

            var properties = Database.Fetch<PropertyDataDto>(sqlPropertyData);

            // Create a Multi URL Picker datatype for the converted RelatedLinks data
            if (!properties.Any())
                return;

            foreach (var property in properties)
{'fraction_non_alphanumeric': 0.09787123572170302, 'fraction_numerical': 0.002596053997923157, 'mean_word_length': 2.4432529043789097, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5047414', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1007, 'n_words': 204}