Mike Chambers
05/30/2024, 11:12 AMjson
"Unattended": {
"PackageMigrationsUnattended": false
to set all packages to have to migrate via the backoffice.
Is there a settings on the migrationBase
perhaps that I can use to just set that my package has to via the backoffice, and not unattended?Sebastiaan
05/30/2024, 11:27 AMMike Chambers
05/30/2024, 11:32 AMMike Chambers
05/30/2024, 11:32 AMMike Chambers
05/30/2024, 11:33 AMcsharp
public class MyPackageMigration : PackageMigrationBase
{
private IHostingEnvironment _hostingEnvironment;
public IglooPackageMigration(IPackagingService packagingService,
IMediaService mediaService,
MediaFileManager mediaFileManager,
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context,
IOptions<PackageMigrationSettings> packageMigrationsSettings, IHostingEnvironment hostingEnvironment)
: base(
packagingService,
mediaService,
mediaFileManager,
mediaUrlGenerators,
shortStringHelper,
contentTypeBaseServiceProvider,
context,
packageMigrationsSettings)
{
_hostingEnvironment = hostingEnvironment;
}
protected override void Migrate()
{
// doctype updatesand new dataypes only
XDocument xml = XDocument.Load(_hostingEnvironment.MapPathContentRoot("~/igloo/package.xml"));
if(xml != null) {
var importPackageExpression = ImportPackage;
importPackageExpression.FromEmbeddedResource(GetType());
importPackageExpression.FromXmlDataManifest(xml).Do();
}
}
}
Mike Chambers
05/30/2024, 11:36 AMMike Chambers
05/30/2024, 11:38 AMcsharp
var myContentBlockList = _dataTypeService.GetDataType(new Guid("e52e988a-65e8-45b0-87d7-dfa013357177"));
var instagramFeedKey = new Guid("07eb60f2-2b59-4bbf-9625-a5f7cd415873");
var instagramFeedSettingsKey = new Guid("5a8a306a-7e32-458c-ae28-47ed276c5be1");
IContentType instagramFeedContentType = _contentTypeService.Get(instagramFeedKey);
IContentType instagramFeedSettingsContentType = _contentTypeService.Get(instagramFeedSettingsKey);
if (myContentBlockList is null || instagramFeedContentType is null || instagramFeedSettingsContentType is null)
{
_logger.LogError("DataType update: Required elements not found for Instagram feed widget");
throw new Exception("DataType update: Required elements not found for Instagram feed widget");
}
var blockConfiguration = myContentBlockList.Configuration as BlockListConfiguration;
var blocks = blockConfiguration.Blocks.ToList();
// check we don't already have the block in the config somehow
if (!blocks.Exists(x => x.ContentElementTypeKey == instagramFeedContentType.Key))
{
blocks.Add(new BlockListConfiguration.BlockConfiguration
{
ContentElementTypeKey = instagramFeedContentType.Key,
SettingsElementTypeKey = instagramFeedSettingsContentType.Key
});
blockConfiguration.Blocks = blocks.ToArray();
_dataTypeService.Save(igContentBlockList);
_logger.LogInformation("adding new widget into My-Content-Grid");
}
Mike Chambers
05/30/2024, 11:44 AMMike Chambers
05/30/2024, 11:49 AMSebastiaan
05/30/2024, 12:43 PMMike Chambers
05/30/2024, 12:43 PMsave with events
method??Sebastiaan
05/30/2024, 12:44 PMSebastiaan
05/30/2024, 12:44 PMMike Chambers
05/30/2024, 12:46 PMMike Chambers
05/30/2024, 12:47 PMSebastiaan
05/30/2024, 12:47 PMMike Chambers
05/30/2024, 12:48 PMMike Chambers
05/30/2024, 12:49 PMcsharp
public void Save(IDataType dataType, int userId = -1)
{
EventMessages messages = this.EventMessagesFactory.Get();
dataType.CreatorId = userId;
using (ICoreScope coreScope = this.ScopeProvider.CreateCoreScope())
{
SaveEventArgs<IDataType> saveEventArgs = new SaveEventArgs<IDataType>(dataType);
DataTypeSavingNotification savingNotification = new DataTypeSavingNotification(dataType, messages);
if (coreScope.Notifications.PublishCancelable((ICancelableNotification) savingNotification))
{
coreScope.Complete();
}
else
{
if (string.IsNullOrWhiteSpace(dataType.Name))
throw new ArgumentException("Cannot save datatype with empty name.");
if (dataType.Name != null && dataType.Name.Length > (int) byte.MaxValue)
throw new InvalidOperationException("Name cannot be more than 255 characters in length.");
this._dataTypeRepository.Save(dataType);
coreScope.Notifications.Publish((INotification) new DataTypeSavedNotification(dataType, messages).WithStateFrom<DataTypeSavedNotification, DataTypeSavingNotification>(savingNotification));
this.Audit(AuditType.Save, userId, dataType.Id);
coreScope.Complete();
}
}
}
though stepping through the code I can see these are hit.. just no registered notificationhandler gets them ๐ฆRonald Barendse
05/30/2024, 4:42 PMRonald Barendse
05/30/2024, 4:46 PMUnscopedMigrationBase
and create your own scope (without suppressing notifications), all notifications will get published: https://github.com/umbraco/Umbraco-CMS/blob/41dddee620bc7a7c5c26d15550ee5f11111bf45c/src/Umbraco.Infrastructure/Migrations/UnscopedMigrationBase.cs#L8Mike Chambers
05/31/2024, 9:16 AM// that packages notification handlers may explode because that package isn't fully installed yet.
๐งจ
I am correct that an unscopedMigrationBase
would have the same potential ๐ฅ
Is it safest to use the aggregated notification to then ImportPackage.FromEmbeddedResource<CustomPackageMigration>().Do();
or
csharp
var file = _hostEnvironment.MapPathContentRoot("~/package/package1.xml");
if (System.IO.File.Exists(file))
{
XDocument xml = XDocument.Load(file);
if (xml is not null)
{
var importPackageExpression = ImportPackage;
importPackageExpression.FromEmbeddedResource(GetType());
importPackageExpression.FromXmlDataManifest(xml).Do();
}
}
Or am I skating on thin ice here whatever approach I take?Ronald Barendse
05/31/2024, 10:24 AMRonald Barendse
05/31/2024, 10:32 AMRonald Barendse
05/31/2024, 10:41 AMRonald Barendse
05/31/2024, 10:50 AMMike Chambers
05/31/2024, 1:57 PMRonald Barendse
05/31/2024, 4:33 PMLuuk Peters (ProudNerds)
11/28/2024, 3:18 PM