<commit_before>﻿using N2.Edit.Installation;
using N2.Persistence;
using N2.Web;

namespace N2.Management.Installation
{
	[N2.Engine.Service(typeof(AbstractMigration))]
	public class UpdateAppPathMigration : AbstractMigration
	{
		IRepository<int, ContentItem> repository;
		private readonly IWebContext webContext;

		public UpdateAppPathMigration(IRepository<int, ContentItem> repository, IWebContext webContext)
		{
			this.repository = repository;
			this.webContext = webContext;

			Title = "Store the application path in content";
			Description = "Allows the site to change application virtual directory in the future.";
		}

		public override bool IsApplicable(DatabaseStatus status)
		{
			return status.RootItem[InstallationManager.InstallationAppPath] == null;
		}

		public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
		{
			preSchemaUpdateStatus.RootItem[InstallationManager.InstallationAppPath] = webContext.ToAbsolute("~/");
			repository.Update(preSchemaUpdateStatus.RootItem);
			repository.Flush();

			return new MigrationResult(this) { UpdatedItems = 1 };
		}
	}
}<commit_msg>Fixed app path migration issue when null root (ThreadId=235458)<commit_after>﻿using N2.Edit.Installation;
using N2.Persistence;
using N2.Web;

namespace N2.Management.Installation
{
	[N2.Engine.Service(typeof(AbstractMigration))]
	public class UpdateAppPathMigration : AbstractMigration
	{
		IRepository<int, ContentItem> repository;
		private readonly IWebContext webContext;

		public UpdateAppPathMigration(IRepository<int, ContentItem> repository, IWebContext webContext)
		{
			this.repository = repository;
			this.webContext = webContext;

			Title = "Store the application path in content";
			Description = "Allows the site to change application virtual directory in the future.";
		}

		public override bool IsApplicable(DatabaseStatus status)
		{
			return status.RootItem != null && status.RootItem[InstallationManager.InstallationAppPath] == null;
		}

		public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
		{
			preSchemaUpdateStatus.RootItem[InstallationManager.InstallationAppPath] = webContext.ToAbsolute("~/");
			repository.Update(preSchemaUpdateStatus.RootItem);
			repository.Flush();

			return new MigrationResult(this) { UpdatedItems = 1 };
		}
	}
}
{'fraction_non_alphanumeric': 0.08695652173913043, 'fraction_numerical': 0.007748600947051227, 'mean_word_length': 5.6022727272727275, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6719372', 'n_tokens_mistral': 720, 'n_tokens_neox': 643, 'n_words': 152}