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

2 bugs found, with one solved => Multilangual site, Trailing spaces in replacement term removed #8

Open
onlinegroeicoach opened this issue Feb 4, 2020 · 5 comments

Comments

@onlinegroeicoach
Copy link

I've added the 8.x package to my Umbracxo 8.5.3. site, I've updated the source solution to 8.5.3. as well and ran into two issues.

The first is that in the FindAndReplaceApiController->content.SetValue(command.PropertyAlias, command.Value); is called without providing the culture which causes issues on amultilingual site (not sure if this still works if you site has 1 language.

Solution is ease:

  • In UpdateCommand add -> public string Culture { get; set; }

  • In FindAndReplaceApiController use -> content.SetValue(command.PropertyAlias, command.Value, command.Culture);

  • In FindAndReplaceservice.js you need to fill this value (it's supplied on the querystring):
    FindAndReplaceService.$inject = ['$http', '$routeParams', 'umbRequestHelper'];
    function setValue(contentId, propertyAlias, valueField, value) {

          var config = {
              PropertyAlias: propertyAlias,
              VersionId: contentId,
              **_Culture: $routeParams.mculture,_**
              Value: value
          };
         .....................
      }
    

The issue I had which I couldn't solve is that if the replacement terms ends with spaces, they are stripped off. There no trim() in the code so I suspect that this is something that AngularJS does unwanted. Any solution to this is also much appreciated ...

@onlinegroeicoach
Copy link
Author

I also editted the Search query to limit searches to selecture culture/language variation only. Also found out that the where clause on path was wrong supose your contentid = 111 it would also hit on 9111 or 1119. Anyway this is what I ended up with:

` [HttpGet]
public async Task<IEnumerable> FindPhrase(string phrase, int contentId, string culture)
{
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
{
var sqlParams = new { phrase = $"%{phrase}%",
contentId1 = $"{contentId}",
contentId2 = $"{contentId},%",
contentId3 = $"%,{contentId},%",
contentId4 = $"%,{contentId}",
culture = $"{culture}"
};

            var sqlQuery = $@"
            SELECT
                    [upd].[varcharValue] AS [VarcharValue]
                , [upd].[textValue] AS [TextValue]
                , [cv].[id] AS [VersionId]
                , [cv].[text] AS [NodeName]
                , [upt].[Alias] AS [PropertyAlias]
                , [upt].[Name] AS [PropertyName]
            FROM [umbracoDocument]
                INNER JOIN [umbracoContent] ON ([umbracoContent].[nodeId] = [umbracoDocument].[nodeId])
                INNER JOIN [umbracoNode] ON ([umbracoNode].[id] = [umbracoContent].[nodeId])
                INNER JOIN [umbracoContentVersion] [cv] ON ([cv].[nodeId] = [umbracoDocument].[nodeId])
                INNER JOIN [umbracoDocumentVersion] [pdv] ON ([pdv].[id] = [cv].[id])
                INNER JOIN [umbracoLanguage] [lang] ON ([lang].[languageISOCode] = @culture)
                INNER JOIN [umbracoContentVersionCultureVariation] [ccv] ON [ccv].[versionId] = [cv].[id] AND ([lang].[id] = [ccv].[languageId])
                INNER JOIN [umbracoPropertyData] [upd] ON ([upd].[versionId] = [cv].[id]) AND ([upd].[languageId] = [ccv].[languageId])
                INNER JOIN [cmsPropertyType] [upt] ON ([upt].[id] = [upd].[propertyTypeId])
            WHERE ([cv].[current] = 1)
                AND ([umbracoDocument].[published] = 1)
                AND ([umbracoNode].[path] = @contentId1 OR [umbracoNode].[path] LIKE @contentId2 OR [umbracoNode].[path] LIKE @contentId3 OR [umbracoNode].[path] LIKE @contentId4)
                AND
                (
                    (
                        [upd].[textValue] is not null AND [upd].[textValue] LIKE @phrase
                    )
                    OR
                    (
                        [upd].[varcharValue] is not null AND [upd].[varcharValue] LIKE @phrase
                    )
                )
            ORDER BY ([umbracoDocument].[nodeId])";

            var sql = scope.SqlContext.Sql(sqlQuery, sqlParams);

            var results = await scope.Database
                .QueryAsync<ContentDataModel>(sql);

            return results.ToList();
        }
    }`

And on the client site:

` function searchForPhrase(phrase, contentId) {

        var config = {
            params: {
                phrase: phrase,
                contentId: contentId,
                culture: $routeParams.mculture
            },
            headers: { 'Accept': 'application/json' }
        };`

Hope this helps anybody, despite my points for improved I like the plugin and it was a huge timesaver for me to have this example available.

@aochmann
Copy link
Contributor

aochmann commented Feb 7, 2020

Hi @onlinegroeicoach,
thanks for reporting and suggested fix 💪 . We'll take care of it.
If you want you can contribute and create PR for it.

@Sven883
Copy link

Sven883 commented Oct 21, 2022

@onlinegroeicoach we're having issues with the multi culture setup with the code provided in this issue.
We have a multi culture setup with 4 languages.
We're currently testing on NL setup, but we've noticed that our content is getting mixed up.
NL has content from DE, FR after using find and replace plugin.

Any idea what could cause this?

@Sven883
Copy link

Sven883 commented Oct 21, 2022

@onlinegroeicoach
Some more information:
Executing the sql directly via sql server management studio I noticed that there is a big difference between uppercase and lowercase.

For some reason if I look for 'WORD' first time -> Query doesn't find any results
If I query for 'word' -> query finds results
if I query for 'WORD' again -> query finds results (why does it find results now?)

Also - We're using Umbraco Blocklists, we noticed that all our language variants are always saved in the database on each language.

Query:

SELECT
[upd].[varcharValue] AS [VarcharValue]
, [upd].[textValue] AS [TextValue]
, [cv].[id] AS [VersionId]
, [cv].[text] AS [NodeName]
, [cv].[nodeId] AS [NodeId]
, [upt].[Alias] AS [PropertyAlias]
, [upt].[Name] AS [PropertyName]
, [lang].[languageISOCode] AS [FilterLanguage]
, [cv].[current] as [current]
, [ccv].[languageId] as [languageid]
FROM [umbracoDocument]
	INNER JOIN [umbracoContent] ON ([umbracoContent].[nodeId] = [umbracoDocument].[nodeId])
	INNER JOIN [umbracoNode] ON ([umbracoNode].[id] = [umbracoContent].[nodeId])
	INNER JOIN [umbracoContentVersion] [cv] ON ([cv].[nodeId] = [umbracoDocument].[nodeId])
	INNER JOIN [umbracoLanguage] [lang] ON ([lang].[languageISOCode] = 'nl')
	INNER JOIN [umbracoContentVersionCultureVariation] [ccv] ON [ccv].[versionId] = [cv].[id]AND ([lang].[id] = [ccv].[languageId])
	INNER JOIN [umbracoPropertyData] [upd] ON ([upd].[versionId] = [cv].[id]) AND ([lang].[id] = [ccv].[languageId])
	INNER JOIN [cmsPropertyType] [upt] ON ([upt].[id] = [upd].[propertyTypeId])
                    WHERE ([cv].[current] = 1)
                        AND ([umbracoDocument].[published] = 1)
                        AND ([umbracoNode].[path] = '1473' OR [umbracoNode].[path] like '%1473%' OR [umbracoNode].[path] LIKE '%1473')
                        
						and [cv].[nodeId] = '1473'
						and [upt].[Alias] = 'contentBlocks'
                    ORDER BY ([umbracoDocument].[nodeId])

Result:
image
With top to bottom being: en, nl & fr (de language isn't filled in in this case)

After publishing DE and using the above query again, DE is also added to this list.

This results in issues using the find and replace script. Any idea how we could update the sql query so we only retrieve textValues from the correct language?
Thanks in advance!

@Sven883
Copy link

Sven883 commented Oct 24, 2022

Found the problem! Issue was in the sql query ...
Thanks anyways!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants