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

fix .NET upgrade issue related to database provider packages #3494

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _ReSharper.Caches
Oqtane.Server/appsettings.json
Oqtane.Server/Data

/Oqtane.Server/Properties/PublishProfiles/FolderProfile.pubxml
Oqtane.Server/Properties/PublishProfiles/FolderProfile.pubxml
Oqtane.Server/Content
Oqtane.Server/Packages
Oqtane.Server/wwwroot/Content
Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Database.MySQL/Oqtane.Database.MySQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
</ItemGroup>

<Target Name="CopyPackage" AfterTargets="Pack">
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg.bak" />
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
</ItemGroup>

<Target Name="CopyPackage" AfterTargets="Pack">
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg.bak" />
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion Oqtane.Database.SqlServer/Oqtane.Database.SqlServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</ItemGroup>

<Target Name="CopyPackage" AfterTargets="Pack">
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg.bak" />
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg" />
</Target>

</Project>
2 changes: 1 addition & 1 deletion Oqtane.Database.Sqlite/Oqtane.Database.Sqlite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</ItemGroup>

<Target Name="CopyPackage" AfterTargets="Pack">
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg.bak" />
<Copy SourceFiles="$(OutputPath)..\$(PackageName)" DestinationFiles="..\Oqtane.Server\wwwroot\Packages\$(MSBuildProjectName).nupkg" />
</Target>

</Project>
39 changes: 7 additions & 32 deletions Oqtane.Server/Infrastructure/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,39 +215,14 @@ private Installation InstallDatabase(InstallConfig install)

try
{
bool installPackages = false;

// iterate database packages in installation folder
var packagesFolder = new DirectoryInfo(Path.Combine(_environment.ContentRootPath, Constants.PackagesFolder));
foreach (var package in packagesFolder.GetFiles("*.nupkg.bak"))
{
// determine if package needs to be upgraded or installed
bool upgrade = System.IO.File.Exists(package.FullName.Replace(".nupkg.bak",".log"));
if (upgrade || package.Name.StartsWith(Utilities.GetAssemblyName(install.DatabaseType)))
{
var packageName = Path.Combine(package.DirectoryName, package.Name);
packageName = packageName.Substring(0, packageName.IndexOf(".bak"));
package.MoveTo(packageName, true);
installPackages = true;
}
}
if (installPackages)
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var installationManager = scope.ServiceProvider.GetRequiredService<IInstallationManager>();
installationManager.InstallPackages();
}
}

// load the installation database type (if necessary)
if (Type.GetType(install.DatabaseType) == null)
{
var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
var assembliesFolder = new DirectoryInfo(assemblyPath);
var assemblyFile = new FileInfo($"{assembliesFolder}/{Utilities.GetAssemblyName(install.DatabaseType)}.dll");
AssemblyLoadContext.Default.LoadOqtaneAssembly(assemblyFile);
}
//if (Type.GetType(install.DatabaseType) == null)
//{
// var assemblyPath = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
// var assembliesFolder = new DirectoryInfo(assemblyPath);
// var assemblyFile = new FileInfo($"{assembliesFolder}/{Utilities.GetAssemblyName(install.DatabaseType)}.dll");
// AssemblyLoadContext.Default.LoadOqtaneAssembly(assemblyFile);
//}

result.Success = true;
}
Expand Down
35 changes: 9 additions & 26 deletions Oqtane.Server/Infrastructure/InstallationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,22 @@ public static string InstallPackages(string webRootPath, string contentRootPath)
Directory.CreateDirectory(sourceFolder);
}

// move packages to secure /Packages folder
foreach (var folderName in "Modules,Themes,Packages".Split(","))
// move core framework distribution packages to secure /Packages folder
string folder = Path.Combine(webRootPath, "Packages");
if (Directory.Exists(folder))
{
string folder = Path.Combine(webRootPath, folderName);
if (Directory.Exists(folder))
foreach (var file in Directory.GetFiles(folder, "*.nupkg"))
{
foreach (var file in Directory.GetFiles(folder, "*.nupkg*"))
var destinationFile = Path.Combine(sourceFolder, Path.GetFileName(file));
if (File.Exists(destinationFile))
{
var destinationFile = Path.Combine(sourceFolder, Path.GetFileName(file));
if (File.Exists(destinationFile))
{
File.Delete(destinationFile);
}

if (destinationFile.ToLower().EndsWith(".nupkg.bak"))
{
// leave a copy in the current folder as it is distributed with the core framework
File.Copy(file, destinationFile);
}
else
{
// move to destination
File.Move(file, destinationFile);
}
File.Delete(destinationFile);
}
}
else
{
Directory.CreateDirectory(folder);
File.Move(file, destinationFile);
}
}

// iterate through Nuget packages in source folder
// install Nuget packages in secure Packages folder
foreach (string packagename in Directory.GetFiles(sourceFolder, "*.nupkg"))
{
try
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.