Removing of Culture Specific from DB and Code in bulk

Vote:
 

Hi,

Good Day!

I got a requirement to remove Culture Specific attribute from the code, but the site is already in use and many properties have data for multiple languages. Still, I have to remove Culture Specific and the site should work without any issues. Below are the two activities I'm planning to do,

  1. Remove Culture Specific from code
  2. Create SQL Update query and execute with help of Optimizely support.

With the above steps I hope both Code and DB will be in Sync, so we will not face any issues. Please correct me if anything else I have to consider/missed?

Challenge with Step 2 above :

I'm trying to find the right SQL script, in that I just came to know that tblPropertyDefinition is responsible for holding the Culture Specific value in the Database,

Sample query:

select *  from dbo.tblPropertyDefinition where pkID='4703'

--update dbo.tblPropertyDefinition set LanguageSpecific=2 where pkID='4703'

But after updating with the above query the properties are disabled in the child page language version (i.e it's not working correctly), can you please someone have some idea on this issue?

If any other better idea also helpful.

Thanks in Advance,

Hari

 

#279599
May 02, 2022 12:56
Vote:
 

Hi,

There should be no need to go into the database.

As you mentioned, step 1 is to update in code and remove CultureSpecificAttribute from the property.

Step 2 would be to go into the admin UI, select the "Content Type" tab, locate your content type and edit the property. You can then either click "Revert to default" (reverts to the default settings as per the code) or uncheck "Unique value per language", afterwards click Save.

Further information is in the documentation, see "Editing a Property" under Properties.

#279661
Edited, May 03, 2022 10:04
Vote:
 

Thank you Jake for the response and time spent.

I agree with the above answer, however, We have to make the above changes in more than 5 environments, and around 60+ content properties need to be updated, so it's very difficult and time taking process to update in all environments and all properties.

My bad, I missed mentioning this information in the initial post.

#279662
May 03, 2022 10:40
Vote:
 

Got you. Then I'd probably do it as an IMigrationStep, that way you could be sure it went out to every environment in a controlled way.

You'd want something like this:

[ServiceConfiguration(typeof(IMigrationStep))]
public class DelocalizePropertiesMigrationStep : IMigrationStep
{
	public int Order => 1;
	public string Name => "Delocalize CMS Properties.";
	public string Description => "This migration removes the option to localize numerous CMS properties.";

	private readonly IContentTypeRepository _contentTypeRepository;
	private readonly IPropertyDefinitionRepository _propertyDefinitionRepository;

	public DelocalizePropertiesMigrationStep(IContentTypeRepository contentTypeRepository, IPropertyDefinitionRepository propertyDefinitionRepository)
	{
		_contentTypeRepository = contentTypeRepository;
		_propertyDefinitionRepository = propertyDefinitionRepository;
	}

	public bool Execute(IProgressMessenger progressMessenger)
	{
		ICollection<(Type ModelType, string PropertyName)> properties = new List<(Type, string)>
		{
			(typeof(StartPageType), nameof(StartPageType.Example))
		};

		var pos = 0;

		foreach (var (modelType, propertyName) in properties)
		{
			var success = false;

			try
			{
				success = TryDelocalizeProperty(modelType, propertyName);
			}
			catch (Exception ex)
			{
				// Log
			}

			++pos;

			progressMessenger.AddProgressMessageText($"{(success ? "Success:" : "Fail:")} {propertyName} on {modelType.Name}.", !success, (int)((100.0 * pos) / properties.Count));
		}

		return true;
	}

	private bool TryDelocalizeProperty(Type modelType, string propertyName)
	{
		var contentType = _contentTypeRepository.Load(modelType);

		if (contentType == null)
		{
			return false;
		}

		var propertyDefinition = _propertyDefinitionRepository.List(contentType.ID).SingleOrDefault(x => x.Name == propertyName);

		if (propertyDefinition == null || !propertyDefinition.LanguageSpecific)
		{
			return false;
		}

		propertyDefinition = propertyDefinition.CreateWritableClone();

		propertyDefinition.LanguageSpecific = false;

		_propertyDefinitionRepository.Save(propertyDefinition);

		return true;
	}
}
#279682
Edited, May 03, 2022 11:34
Harinarayanan - May 03, 2022 11:41
Thank you Jake..This helps a lot...
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.