Skip to content

Commit

Permalink
reverted broken filepaths and reverting unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Medek authored and Martin Medek committed Dec 16, 2024
1 parent 4d615e7 commit 4d796ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
43 changes: 9 additions & 34 deletions examples/Kentico.Xperience.UMT.Example.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

using CMS.Core;
using CMS.DataEngine;
using CMS.IO;
using CMS.MediaLibrary;

using Kentico.Xperience.UMT;
using Kentico.Xperience.UMT.Examples;
Expand All @@ -25,15 +23,9 @@

Service.Use<IConfiguration>(root);
CMS.Base.SystemContext.WebApplicationPhysicalPath = root.GetValue<string>("WebApplicationPhysicalPath");
string workDir = System.IO.Directory.GetCurrentDirectory();
string assetSearchPath = workDir;
if (args.Length > 0)
{
assetSearchPath = args[0];
}

string workDir = Directory.GetCurrentDirectory();
// note - this is currently required for asset import when UMT is used in other place then Kentico Xperience itself
System.IO.Directory.SetCurrentDirectory(root.GetValue<string>("WebApplicationPhysicalPath") ?? throw new InvalidOperationException("WebApplicationPhysicalPath must be set to valid directory path"));
Directory.SetCurrentDirectory(root.GetValue<string>("WebApplicationPhysicalPath") ?? throw new InvalidOperationException("WebApplicationPhysicalPath must be set to valid directory path"));

CMSApplication.Init();

Expand All @@ -52,9 +44,9 @@
if (useSerializedSample)
#pragma warning restore S2583
{
string path = System.IO.Path.GetFullPath(System.IO.Path.Combine(workDir, "../../../../../docs/Samples/basic.json"));
string sampleText = (await System.IO.File.ReadAllTextAsync(path) ?? throw new InvalidOperationException("Failed to load sample"))
.Replace("##ASSETDIR##", assetSearchPath.Replace(@"\", @"\\"));
string path = Path.GetFullPath(Path.Combine(workDir, "../../../../../docs/Samples/basic.json"));
string sampleText = (await File.ReadAllTextAsync(path) ?? throw new InvalidOperationException("Failed to load sample"))
.Replace("##ASSETDIR##", workDir.Replace(@"\", @"\\"));

sourceData = importService.FromJsonString(sampleText)?.ToList() ?? new List<IUmtModel>();
}
Expand All @@ -67,7 +59,7 @@
// update path to media files
if (umtModel is MediaFileModel mediaFileModel)
{
mediaFileModel.DataSourcePath = mediaFileModel.DataSourcePath?.Replace("##ASSETDIR##", assetSearchPath);
mediaFileModel.DataSourcePath = mediaFileModel.DataSourcePath?.Replace("##ASSETDIR##", workDir);
}

foreach ((string? key, object? value) in umtModel.CustomProperties)
Expand All @@ -76,7 +68,7 @@
{
case AssetFileSource assetSource:
{
assetSource.FilePath = assetSource.FilePath?.Replace("##ASSETDIR##", assetSearchPath);
assetSource.FilePath = assetSource.FilePath?.Replace("##ASSETDIR##", workDir);
umtModel.CustomProperties[key] = assetSource;
break;
}
Expand All @@ -97,7 +89,7 @@
{
case AssetFileSource assetSource:
{
assetSource.FilePath = assetSource.FilePath?.Replace("##ASSETDIR##", assetSearchPath);
assetSource.FilePath = assetSource.FilePath?.Replace("##ASSETDIR##", workDir);
break;
}
}
Expand Down Expand Up @@ -177,23 +169,6 @@
}
}

foreach (var mediaLibraryInfo in MediaLibraryInfoProvider.ProviderObject.Get())
{
try
{
string libraryFolderPath = MediaLibraryInfoProvider.GetMediaLibraryFolderPath(mediaLibraryInfo.LibraryFolder);
Console.WriteLine($"{mediaLibraryInfo.LibraryName}: {libraryFolderPath}");
}
catch (Exception ex)
{
Console.WriteLine($"{mediaLibraryInfo.LibraryName}: {mediaLibraryInfo.LibraryFolder} Error: {ex}");
}
}

Console.WriteLine($"WorkDir-Current: {System.IO.Directory.GetCurrentDirectory()}");
Console.WriteLine($"WorkDir-Prev : {workDir}");
Console.WriteLine($"WebAppPath : {CMS.Base.SystemContext.WebApplicationPhysicalPath}");

Console.WriteLine("Finished!");

#pragma warning restore S1135
#pragma warning restore S1135
10 changes: 5 additions & 5 deletions examples/Kentico.Xperience.UMT.Examples/Samples/AssetSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Kentico.Xperience.UMT.Examples
public static class AssetSamples
{
public static readonly Guid MEDIA_LIBRARY_SAMPLE_GUID = new("E3A9C50C-2B76-4BA8-AC19-2F0AA64C47D5");

[Sample("mediafile.sample.fromdisk", "", "Sample of media file loaded from disk")]
public static MediaFileModel SampleMediaFile => new()
{
Expand All @@ -16,9 +16,9 @@ public static class AssetSamples
FileName = "NewTestFile",
FileExtension = ".png",
FileTitle = "Title",
FilePath = "NewTestFile.png"
FilePath = "customdir/NewTestFile.png"
};

[Sample("mediafile.sample.fromurl", "", "Sample of media file downloaded from url")]
public static MediaFileModel SampleMediaFileFromUri => new()
{
Expand All @@ -29,9 +29,9 @@ public static class AssetSamples
FileName = "NewTestFileFromUri",
FileExtension = ".jpg",
FileTitle = "Old devnet screen",
FilePath = "NewTestFileFromUri.jpg"
FilePath = "customdir/NewTestFileFromUri.jpg"
};

// https://res-5.cloudinary.com/xperience-io/image/upload/c_lfill,dpr_1,w_768/f_auto,q_auto/v1/homepage/k-02-your-real-needs-at-its-core-1600x1200px_ihqknl

[Sample("medialibrary.sample", "", "Sample of media library")]
Expand Down
4 changes: 1 addition & 3 deletions src/Kentico.Xperience.UMT/InfoAdapter/MediaFileAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ protected override MediaFileInfo ObjectFactory(UmtModelInfo umtModelInfo, IUmtMo

var mediaLibrary = MediaLibraryInfoProvider.ProviderObject.Get(model.FileLibraryGuid!.Value);
MediaLibraryInfoProvider.CreateMediaLibraryFolder(mediaLibrary.LibraryID, Path.GetDirectoryName(model.FilePath));
Console.WriteLine("Path.getdir : " + Path.GetDirectoryName(model.FilePath));
Console.WriteLine("model.filepath: " + model.FilePath);

mediaFileInfo = new MediaFileInfo(uploadedFile, 0);
mediaFileInfo.SaveFileToDisk(true);
Expand Down Expand Up @@ -97,4 +95,4 @@ protected override MediaFileInfo MapProperties(IUmtModel umtModel, MediaFileInfo

return current;
}
}
}

0 comments on commit 4d796ed

Please sign in to comment.